mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
178 lines
9.5 KiB
TypeScript
178 lines
9.5 KiB
TypeScript
import { Metadata } from "next"
|
|
import dynamic from "next/dynamic"
|
|
import Link from "next/link"
|
|
import dayjs from "dayjs"
|
|
import { getServerSession } from "next-auth"
|
|
// import { Download } from 'lucide-react'
|
|
|
|
import { CalendarDateRangePicker } from "../components/DaterangePicker"
|
|
// import { MainNav } from "./components/MainNav"
|
|
// import { RecentSales } from "./components/RecentSales"
|
|
// import { UserNav } from "./components/UserNav"
|
|
// import TeamSwitcher from "./components/TeamSwitcher"
|
|
// import { Search } from "./components/Search"
|
|
|
|
import { Button } from "@/components/ui/button"
|
|
// import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
|
import { authOptions } from "@/pages/api/auth/[...nextauth]"
|
|
import { titleCase } from "@/lib/helper"
|
|
import { fetchDataWithPost } from "@/lib/fetchData"
|
|
// import { ToggleTheme } from "../admin/components/ToggleTheme"
|
|
// import Notification from "../admin/components/Notification"
|
|
import duration from 'dayjs/plugin/duration'
|
|
dayjs.extend(duration)
|
|
|
|
|
|
const Overview = dynamic(() => import("../components/Overview"), {
|
|
loading: () => <p>loading...</p>,
|
|
ssr: false
|
|
})
|
|
|
|
export const metadata: Metadata = {
|
|
title: "Dashboard",
|
|
description: "Employee dashboard page.",
|
|
}
|
|
|
|
export default async function DashboardPage() {
|
|
const session = await getServerSession(authOptions)
|
|
|
|
const today = fetchDataWithPost('/presence/history/today', { nik: session?.user.detail.nik })
|
|
const all = fetchDataWithPost('/presence/history', { nik: session?.user.detail.nik, start_date: dayjs().subtract(1, 'week'), end_date: dayjs().format('YYYY-MM-DD') })
|
|
const dashboard = fetchDataWithPost('/dashboard', {})
|
|
|
|
// Wait for the promises to resolve
|
|
const [todayPresence, allPresence, dataDashboard] = await Promise.all([today, all, dashboard])
|
|
|
|
const alreadyCheckin = todayPresence.history.length > 0
|
|
const alreadyCheckout = (alreadyCheckin && todayPresence.history[0].presence_checkout) || todayPresence.history.length === 0
|
|
|
|
const getWorkingHours = () => {
|
|
if (alreadyCheckin) {
|
|
const checkinTime = todayPresence.history[0].working_hours_start
|
|
if (alreadyCheckout) {
|
|
const checkoutTime = dayjs(todayPresence.history[0].presence_checkout.working_hours_end)
|
|
const duration = alreadyCheckin ? dayjs.duration(checkoutTime.diff(checkinTime)) : null
|
|
return duration
|
|
}
|
|
const duration = alreadyCheckin ? dayjs.duration(dayjs().diff(checkinTime)) : null
|
|
return duration
|
|
}
|
|
return null
|
|
}
|
|
|
|
const getHoursMinutes = () => {
|
|
const duration = getWorkingHours()
|
|
if (duration) {
|
|
const hours = duration.hours() || 0;
|
|
const minutes = duration.minutes() || 0;
|
|
return `${hours} hours ${minutes} minutes`
|
|
}
|
|
else return '0 hour'
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div className="flex-1 space-y-8 p-6 sm:p-8 pt-6">
|
|
<div className="flex items-start justify-between space-y-2">
|
|
<div>
|
|
<h2 className="text-lg sm:text-3xl font-medium tracking-tight capitalize">Welcome Back, <span className="font-bold">{titleCase(session?.user.detail.nickname!)}</span></h2>
|
|
<p className="text-xs md:text-base text-muted-foreground mt-1 block md:hidden">Welcome back, we miss your presence!</p>
|
|
<p className="text-xs md:text-base text-muted-foreground w-1/2 mt-2 hidden md:block">Here is your store performance, we hope this helps you unlock insights and empower your decision for continues growth</p>
|
|
</div>
|
|
<div className="flex items-center space-x-2">
|
|
<CalendarDateRangePicker />
|
|
<Link href={alreadyCheckout ? '/presence-v2' : '/presence-v2?checkout=true'} className="hidden sm:block">
|
|
<Button>Presence</Button>
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="space-y-4">
|
|
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
|
<Card>
|
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
|
<CardTitle className="text-sm font-medium">
|
|
Attendance Hours
|
|
</CardTitle>
|
|
<i className="ti ti-alarm icon h-4 w-4 text-muted-foreground text-xl"></i>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<div className="text-2xl font-bold">{todayPresence.history[0]?.working_hours_start ? dayjs(todayPresence.history[0]?.working_hours_start).format('HH:mm A') : '--:-- --'}</div>
|
|
<p className="text-xs text-muted-foreground">
|
|
today check-in
|
|
</p>
|
|
</CardContent>
|
|
</Card>
|
|
<Card>
|
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
|
<CardTitle className="text-sm font-medium">
|
|
Working Hours
|
|
</CardTitle>
|
|
<i className="ti ti-clock-play icon h-4 w-4 text-muted-foreground text-xl"></i>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<div className="text-2xl font-bold">{getHoursMinutes()}</div>
|
|
<p className="text-xs text-muted-foreground">
|
|
number of hours you worked today
|
|
</p>
|
|
</CardContent>
|
|
</Card>
|
|
<Card>
|
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
|
<CardTitle className="text-sm font-medium">Total Employee</CardTitle>
|
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" className="h-4 w-4 text-muted-foreground" >
|
|
<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2" />
|
|
<circle cx="9" cy="7" r="4" />
|
|
<path d="M22 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75" />
|
|
</svg>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<div className="text-2xl font-bold">{dataDashboard?.presence?.total_employee}</div>
|
|
<p className="text-xs text-muted-foreground">
|
|
number of employee in your department
|
|
</p>
|
|
</CardContent>
|
|
</Card>
|
|
<Card>
|
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
|
<CardTitle className="text-sm font-medium">
|
|
Work Permit & Leave
|
|
</CardTitle>
|
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" className="h-4 w-4 text-muted-foreground">
|
|
<path d="M22 12h-4l-3 9L9 3l-3 9H2" />
|
|
</svg>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<div className="text-2xl font-bold">7</div>
|
|
<p className="text-xs text-muted-foreground">
|
|
permission, leave and sick in this year
|
|
</p>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
<div className="grid gap-4 grid-cols-1 md:grid-cols-2 lg:grid-cols-7">
|
|
<Card className="lg:col-span-4">
|
|
<CardHeader>
|
|
<CardTitle>Overview</CardTitle>
|
|
<CardDescription>Your average check-in out stats for the past 2 weeks.</CardDescription>
|
|
</CardHeader>
|
|
<CardContent className="pl-2">
|
|
<Overview />
|
|
</CardContent>
|
|
</Card>
|
|
<Card className="lg:col-span-3">
|
|
<CardHeader>
|
|
<CardTitle>Last Check-in out</CardTitle>
|
|
<CardDescription>You made {allPresence?.history?.length} presence last week.</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<>THIS SHOULD BE RECENT SALES</>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</>
|
|
)
|
|
} |