mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
initial commit for new hats app
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
BASE_PATH = ""
|
||||||
|
NEXT_PUBLIC_APP_URL="http://localhost:1209"
|
||||||
|
|
||||||
|
# BASE_URL_API = https://hats-his.nutech-integrasi.com/presence-api/api/v1
|
||||||
|
# BASE_URL_IMG = https://hats-his.nutech-integrasi.com/presence-api/
|
||||||
|
|
||||||
|
# BASE_URL_API = https://his.nutech-integrasi.com/presence-api/api/v1
|
||||||
|
# BASE_URL_IMG = https://his.nutech-integrasi.com/presence-api/
|
||||||
|
BASE_URL_API = https://36.66.3.44/presence-api/api/v1
|
||||||
|
BASE_URL_IMG = https://36.66.3.44/presence-api/
|
||||||
|
|
||||||
|
NEXTAUTH_URL = http://localhost:1209
|
||||||
|
# NEXTAUTH_URL = http://localhost:7090/super-apps/api/auth
|
||||||
|
NEXTAUTH_SECRET = hissuperappssecretcode2025
|
||||||
|
|
||||||
|
FIREBASE_API_KEY = AIzaSyAEkZCHhnyatsNiZ2dpjeaz6JqXYknKKHk
|
||||||
|
FIREBASE_APP_ID = "1:422528660020:web:db16e1cba4d357e32f1061"
|
||||||
|
|
||||||
|
DEVICE_CODE = "40001"
|
||||||
|
NEXT_PUBLIC_HATS_SUPPORT_NAME = "Amalia"
|
||||||
|
NEXT_PUBLIC_HATS_SUPPORT_PHONE = "6285214074002"
|
||||||
|
NEXT_PUBLIC_APP_VERSION = "v1.1.0"
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
BASE_PATH = ""
|
||||||
|
NEXT_PUBLIC_APP_URL="https://his.nutech-integrasi.com"
|
||||||
|
|
||||||
|
# BASE_URL_API = https://hats-his.nutech-integrasi.com/presence-api/api/v1
|
||||||
|
# BASE_URL_IMG = https://hats-his.nutech-integrasi.com/presence-api/
|
||||||
|
# NEXTAUTH_URL = https://hats-his.nutech-integrasi.com
|
||||||
|
# NEXTAUTH_URL_INTERNAL = http://36.66.3.44:7006
|
||||||
|
|
||||||
|
# BASE_URL_API = https://36.66.3.44/presence-api/api/v1
|
||||||
|
# BASE_URL_IMG = https://36.66.3.44/presence-api/
|
||||||
|
# NEXTAUTH_URL = https://36.66.3.44
|
||||||
|
|
||||||
|
BASE_URL_API = https://his.nutech-integrasi.com/presence-api/api/v1
|
||||||
|
BASE_URL_IMG = https://his.nutech-integrasi.com/presence-api/
|
||||||
|
NEXTAUTH_URL = https://his.nutech-integrasi.com
|
||||||
|
NEXTAUTH_URL_INTERNAL = http://36.66.3.44:7002
|
||||||
|
# NEXTAUTH_URL = http://localhost:7002
|
||||||
|
# NEXTAUTH_URL_INTERNAL = http://localhost:7002
|
||||||
|
|
||||||
|
NEXTAUTH_SECRET = 4339d50684523526005c1fcb34be0bb1
|
||||||
|
|
||||||
|
FIREBASE_API_KEY = AIzaSyAEkZCHhnyatsNiZ2dpjeaz6JqXYknKKHk
|
||||||
|
FIREBASE_APP_ID = "1:422528660020:web:db16e1cba4d357e32f1061"
|
||||||
|
|
||||||
|
DEVICE_CODE = "40001"
|
||||||
|
NEXT_PUBLIC_HATS_SUPPORT_NAME = "Amalia"
|
||||||
|
NEXT_PUBLIC_HATS_SUPPORT_PHONE = "6285214074002"
|
||||||
|
NEXT_PUBLIC_APP_VERSION = "v1.1.0"
|
||||||
+2
-2
@@ -31,11 +31,11 @@ yarn-error.log*
|
|||||||
.pnpm-debug.log*
|
.pnpm-debug.log*
|
||||||
|
|
||||||
# env files (can opt-in for committing if needed)
|
# env files (can opt-in for committing if needed)
|
||||||
.env*
|
# .env*
|
||||||
|
|
||||||
# vercel
|
# vercel
|
||||||
.vercel
|
.vercel
|
||||||
|
|
||||||
# typescript
|
# typescript
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
next-env.d.ts
|
next-env.d.ts
|
||||||
@@ -0,0 +1,178 @@
|
|||||||
|
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>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,309 @@
|
|||||||
|
import { Suspense, lazy } from "react"
|
||||||
|
import Link from "next/link"
|
||||||
|
import { getServerSession } from "next-auth"
|
||||||
|
import dayjs from "dayjs"
|
||||||
|
|
||||||
|
import { authOptions } from "@/pages/api/auth/[...nextauth]"
|
||||||
|
import { generateHourMinutes, titleCase } from "@/lib/helper"
|
||||||
|
import { fetchDataWithPost } from "@/lib/fetchData"
|
||||||
|
|
||||||
|
// import { CalendarDateRangePicker } from "./components/DaterangePicker"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Card900, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||||
|
|
||||||
|
import LazyLoading from "@/components/loader/LazyLoading"
|
||||||
|
|
||||||
|
// const LastPresence = lazy(() => import("./components/LastPresence"))
|
||||||
|
const WorkingHours = lazy(() => import("../components/WorkingHours"))
|
||||||
|
const PresenceHistory = lazy(() => import("../components/PresenceHistory"))
|
||||||
|
const PieChart = lazy(() => import("../components/PieChart"))
|
||||||
|
const AreaChart = lazy(() => import("../components/AreaChart"))
|
||||||
|
const PresenceDetail = lazy(() => import("../components/PresenceDetail"))
|
||||||
|
const NeedApproval = lazy(() => import("../components/NeedApproval"))
|
||||||
|
const AdjustmentAutoCheckout = lazy(() => import("../components/AdjustmentAutoCheckout"))
|
||||||
|
const TableEmployee = lazy(() => import("../components/TableEmployee"))
|
||||||
|
const EmployeeBirthday = lazy(() => import("../components/EmployeeBirthday"))
|
||||||
|
const EmployeeContractExp = lazy(() => import("../components/EmployeeContractExp"))
|
||||||
|
const ApprovalLeaveSick = lazy(() => import("../components/ApprovalLeaveSick"))
|
||||||
|
|
||||||
|
export const dynamic = 'force-dynamic'
|
||||||
|
|
||||||
|
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', {})
|
||||||
|
const last = fetchDataWithPost('/presence/last-status/today', { nik: session?.user.detail.nik })
|
||||||
|
|
||||||
|
// Wait for the promises to resolve
|
||||||
|
const [todayPresence, allPresence, dataDashboard, lastPresence] = await Promise.all([today, all, dashboard, last])
|
||||||
|
|
||||||
|
const alreadyCheckin = todayPresence.history.length > 0
|
||||||
|
const alreadyCheckout = (alreadyCheckin && todayPresence.history[0].presence_checkout) || todayPresence.history.length === 0
|
||||||
|
|
||||||
|
console.log(session)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="flex-1 space-y-8 p-6 sm:p-8 pt-3 sm:pt-7 pb-40 md:pb-8">
|
||||||
|
<div className="flex items-start justify-between space-y-2">
|
||||||
|
<div className="hidden sm:block">
|
||||||
|
<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">This is your dashboard of attendance, working hours and task report</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex sm:hidden justify-between">
|
||||||
|
<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 xl:w-2/3 mt-2">This is your dashboard of attendance, working hours and task report</p>
|
||||||
|
</div>
|
||||||
|
{lastPresence.is_checkin && lastPresence.device_code !== '11001' &&
|
||||||
|
<Link href='/iam-here'>
|
||||||
|
<Button variant='ghost' title="I'am Here">
|
||||||
|
<span className='animatecss animatecss-tada animatecss-infinite text-2xl'>👋🏻</span>
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
{/* <CalendarDateRangePicker /> */}
|
||||||
|
{alreadyCheckout ?
|
||||||
|
<Link href='/presence-v2' className="hidden sm:block">
|
||||||
|
<Button className="min-w-[104px]" >Check-in <i className="ti ti-login text-lg"></i></Button>
|
||||||
|
</Link>
|
||||||
|
:
|
||||||
|
<Link href={lastPresence.is_checkin && lastPresence.device_code === '11001' ? '' : '/presence-v2?checkout=true'} className="hidden sm:block">
|
||||||
|
<Button className="min-w-[104px]" disabled={lastPresence.is_checkin && lastPresence.device_code === '11001'}>Check-out <i className="ti ti-logout text-lg"></i></Button>
|
||||||
|
</Link>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-5">
|
||||||
|
<div className="grid gap-5 sm:grid-cols-2 lg:grid-cols-4">
|
||||||
|
<Card900>
|
||||||
|
<CardHeader className="flex flex-row items-center justify-between space-y-0">
|
||||||
|
<CardTitle className="text-sm font-medium">
|
||||||
|
{todayPresence.history.length === 0 || lastPresence.is_checkin ? "Today's Check-in" : "Today's Check-out"}
|
||||||
|
</CardTitle>
|
||||||
|
<i className="ti ti-brand-days-counter icon h-4 w-4 text-his text-xl"></i>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
{todayPresence.history.length === 0 || lastPresence.is_checkin ?
|
||||||
|
<div className="text-2xl font-bold">{todayPresence.history[0]?.working_hours_start ? dayjs(dataDashboard.presence?.todays_attendance_hours.check_in).format('HH:mm A') : '--:-- --'}</div>
|
||||||
|
:
|
||||||
|
<div className="text-2xl font-bold">{dataDashboard.presence?.todays_attendance_hours.check_out ? dayjs(dataDashboard.presence?.todays_attendance_hours.check_out).format('HH:mm A') : '--:-- --'}</div>
|
||||||
|
}
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
{todayPresence.history.length === 0 || lastPresence.is_checkin ? "your today's check-in time" : "your today's check-out time"}
|
||||||
|
</p>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
<Card900>
|
||||||
|
<CardHeader className="flex flex-row items-center justify-between space-y-0">
|
||||||
|
<CardTitle className="text-sm font-medium">
|
||||||
|
Today's Working Hours
|
||||||
|
</CardTitle>
|
||||||
|
<i className="ti ti-clock-play icon h-4 w-4 text-his text-xl"></i>
|
||||||
|
</CardHeader>
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<WorkingHours
|
||||||
|
currentTotalTime={dataDashboard.presence?.todays_working_hours_in_second.in_second}
|
||||||
|
isRunning={dataDashboard.presence?.todays_working_hours_in_second.running_count}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
</Card900>
|
||||||
|
<Card900>
|
||||||
|
<CardHeader className="flex flex-row items-center justify-between space-y-0">
|
||||||
|
<CardTitle className="text-sm font-medium">
|
||||||
|
Last Presence
|
||||||
|
</CardTitle>
|
||||||
|
<i className="ti ti-history icon h-4 w-4 text-his text-xl"></i>
|
||||||
|
</CardHeader>
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
{/* <LastPresence history={allPresence.history} /> */}
|
||||||
|
<CardContent>
|
||||||
|
<div className="text-2xl font-bold">
|
||||||
|
{dataDashboard.presence.last_presence.check_in ?
|
||||||
|
dayjs(dataDashboard.presence.last_presence.check_in).format('HH:mm a') + ' - ' + (dataDashboard.presence.last_presence.check_out ?
|
||||||
|
dayjs(dataDashboard.presence.last_presence.check_out).format('HH:mm a')
|
||||||
|
:
|
||||||
|
'--:--'
|
||||||
|
)
|
||||||
|
:
|
||||||
|
'--:-- - --:--'
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
your last presence {dataDashboard.presence.last_presence.check_in ? 'at ' + dayjs(dataDashboard.presence.last_presence.check_in).format('MMM DD, YYYY') : ''}
|
||||||
|
</p>
|
||||||
|
</CardContent>
|
||||||
|
</Suspense>
|
||||||
|
</Card900>
|
||||||
|
<Card900>
|
||||||
|
<CardHeader className="flex flex-row items-center justify-between space-y-0">
|
||||||
|
<CardTitle className="text-sm font-medium">Working Hour in this Month</CardTitle>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="icon text-his h-5 w-5">
|
||||||
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
||||||
|
<path d="M11.795 21h-6.795a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v4" />
|
||||||
|
<path d="M18 18m-4 0a4 4 0 1 0 8 0a4 4 0 1 0 -8 0" />
|
||||||
|
<path d="M15 3v4" />
|
||||||
|
<path d="M7 3v4" />
|
||||||
|
<path d="M3 11h16" />
|
||||||
|
<path d="M18 16.496v1.504l1 1" />
|
||||||
|
</svg>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className="text-2xl font-bold truncate">{dataDashboard?.presence?.working_hours_in_this_month ? generateHourMinutes(dataDashboard?.presence?.working_hours_in_this_month) : '0 Hour'}</div>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
number of working hours in this month
|
||||||
|
</p>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
</div>
|
||||||
|
<div className="grid gap-5 grid-cols-1 md:grid-cols-2">
|
||||||
|
<Card900>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Overview</CardTitle>
|
||||||
|
<CardDescription>Statistics of today's attendance summary.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="sm:pl-0">
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<PieChart data={dataDashboard.presence} />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
<Card900>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Your Statistics</CardTitle>
|
||||||
|
<CardDescription>Statistics of your attendance in last 14 days.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="px-0">
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<AreaChart data={dataDashboard.presence.statistics} />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
</div>
|
||||||
|
<div className="grid gap-5 grid-cols-1 md:grid-cols-2">
|
||||||
|
<Card900>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Attendance's List</CardTitle>
|
||||||
|
<CardDescription>List of today's attendance in your department.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="px-0">
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<PresenceDetail data={dataDashboard.presence} />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
<Card900>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Your History</CardTitle>
|
||||||
|
<CardDescription>List of your last 4 attendance history in this week.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="px-0">
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<PresenceHistory data={allPresence.history} />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
{(session?.user.detail.role.code === 'MNG' || session?.user.detail.role.code === 'TL') &&
|
||||||
|
<Card900>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Need to be Approve</CardTitle>
|
||||||
|
<CardDescription>List of today's attendance that require approval.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="px-0">
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<NeedApproval data={dataDashboard.presence?.need_to_be_approved} />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
}
|
||||||
|
{(session?.user.detail.role.code === 'MNG' || session?.user.detail.role.code === 'TL') && dataDashboard.presence?.need_to_be_approved_auto_checkout?.total > 0 &&
|
||||||
|
<Card900>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Adjustment Autocheckout</CardTitle>
|
||||||
|
<CardDescription>List of attendance that is not checked out.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="px-0">
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<AdjustmentAutoCheckout data={dataDashboard.presence?.need_to_be_approved_auto_checkout} />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
}
|
||||||
|
{(session?.user.detail.role.code === 'MNG' || session?.user.detail.role.code === 'TL') && dataDashboard.presence?.need_to_be_approved_application_form?.total > 0 &&
|
||||||
|
<Card900>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Work Leave and Sick Approval</CardTitle>
|
||||||
|
<CardDescription>List of work leave and sick application form.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="px-0">
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<ApprovalLeaveSick data={dataDashboard.presence?.need_to_be_approved_application_form} />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
}
|
||||||
|
<Card900>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Employees</CardTitle>
|
||||||
|
<CardDescription>List of employees in your department.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="px-0">
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<TableEmployee data={dataDashboard.employee} />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
<Card900>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Employee Birthday</CardTitle>
|
||||||
|
<CardDescription>List of employees birthday.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="px-0">
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<EmployeeBirthday data={dataDashboard.employee_birthday} />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
{session?.user.detail.role.code === 'MNG' &&
|
||||||
|
<Card900>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Employee Contract Expiration</CardTitle>
|
||||||
|
<CardDescription>List of employee contract expiration.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="px-0">
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<EmployeeContractExp data={dataDashboard.employee_contract_expiration} />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
{/* <Card className="pb-5">
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Employees</CardTitle>
|
||||||
|
<CardDescription>List of employees in your department.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="max-h-[400px] overflow-auto scrollbar-thin dark:scrollbar-track-zinc-white dark:scrollbar-track-zinc-950 scrollbar-thumb-zinc-400 dark:scrollbar-thumb-zinc-500">
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<TableEmployee data={dataDashboard.employee} />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card> */}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{lastPresence.is_checkin && lastPresence.device_code !== '11001' &&
|
||||||
|
<Link href='/iam-here' className='hidden sm:block fixed bottom-8 right-10'>
|
||||||
|
<button className='bg-his rounded-full h-12 w-12 flex justify-center items-center text-2xl hover:bg-opacity-80 duration-300' title="I'am Here">
|
||||||
|
<span className='animatecss animatecss-tada animatecss-infinite'>👋🏻</span>
|
||||||
|
</button>
|
||||||
|
</Link>
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
import { FC, MouseEvent, useEffect, useState } from 'react';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
day: any
|
||||||
|
monthIndex: number
|
||||||
|
dayOffList: any[]
|
||||||
|
onClickDate?: () => any
|
||||||
|
onClickEvent?: (event: any) => any
|
||||||
|
};
|
||||||
|
|
||||||
|
const colorClasses = ['bg-amber-500', 'bg-emerald-500', 'bg-indigo-500', 'bg-fuchsia-500']
|
||||||
|
|
||||||
|
const DayInCalendar: FC<Props> = ({ day, monthIndex, dayOffList, onClickDate, onClickEvent }) => {
|
||||||
|
const [event, setEvent] = useState<any>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const result = dayOffList.find(item => dayjs(item.date).format('DDMMYY') === dayjs(day).format('DDMMYY'))
|
||||||
|
setEvent(result)
|
||||||
|
}, [day, dayOffList])
|
||||||
|
|
||||||
|
const handleClikEvent = (e: MouseEvent<HTMLElement>, selectedEvent: any) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
// alert(JSON.stringify(selectedEvent))
|
||||||
|
onClickEvent!(selectedEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleAddEvent = () => {
|
||||||
|
onClickDate!()
|
||||||
|
}
|
||||||
|
|
||||||
|
const getDayStyle = (day: any) => {
|
||||||
|
if (day.format('DD-MM-YY') === dayjs().format('DD-MM-YY')) { // TODAY
|
||||||
|
return 'text-white bg-blue-500 w-7 h-7 rounded-full flex justify-center items-center mt-2'
|
||||||
|
} else if (day.format('MM-YY') !== dayjs().month(monthIndex).format('MM-YY')) { // DAY IN NOT CURRENT MONTH
|
||||||
|
return 'text-gray-300 dark:text-zinc-600'
|
||||||
|
} else if (dayjs(day).format('dddd').toLowerCase() === 'sunday') { // SUNDAY
|
||||||
|
return 'text-rose-500 dark:text-rose-900'
|
||||||
|
} else {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className={`relative border border-border flex flex-col items-center ${day.format('DD-MM-YY') === dayjs().format('DD-MM-YY') ? '' : ''}`}>
|
||||||
|
{/* <div className='absolute h-full w-full z-0' onClick={() => alert('absolute')}></div> */}
|
||||||
|
<header className='flex flex-col items-center w-full z-10'>
|
||||||
|
<p className={`text-sm p-1 font-medium my-1 ${getDayStyle(day)}`}>{dayjs(day).format('DD')}</p>
|
||||||
|
</header>
|
||||||
|
<div className='flex flex-1 flex-col w-full cursor-pointer z-10' onClick={handleAddEvent}>
|
||||||
|
{event &&
|
||||||
|
<span className={`bg-rose-500 dark:bg-rose-900 p-[3px] px-1 2xl:p-1 ml-1 mr-2 mb-1 text-white font-medium rounded truncate hover:bg-opacity-70 text-[10px] 2xl:text-xs`}
|
||||||
|
onClick={(e) => handleClikEvent(e, event)}
|
||||||
|
>
|
||||||
|
{event.name}
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
{/* {activities!.slice(0, 1).map((task, key) =>
|
||||||
|
<span key={key} className={`${colorClasses[Math.floor(Math.random() * colorClasses.length)]} p-[3px] px-1 2xl:p-1 ml-1 mr-2 mb-1 text-white font-medium rounded truncate hover:bg-opacity-70 text-xsm 2xl:text-xs`}
|
||||||
|
onClick={() => alert('this gonna be activities')}
|
||||||
|
>
|
||||||
|
{task.activity_txt}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{activities!.length > 1 &&
|
||||||
|
<span className={`bg-gray-500 p-[3px] px-1 2xl:p-1 ml-1 mr-2 mb-1 text-white font-medium rounded truncate hover:bg-opacity-70 text-xsm 2xl:text-xs`}
|
||||||
|
onClick={() => alert('this gonna be activities')}
|
||||||
|
>
|
||||||
|
+{activities!.length - 1} Aktivitas Lainnya..
|
||||||
|
</span>} */}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DayInCalendar;
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { Dispatch, FC, SetStateAction } from 'react';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { Dialog, DialogContent } from '@/components/ui/dialog';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
open: boolean
|
||||||
|
onOpenChange: Dispatch<SetStateAction<boolean>>
|
||||||
|
data: any
|
||||||
|
};
|
||||||
|
|
||||||
|
const DetailEvent: FC<Props> = ({ open, data, onOpenChange }) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className='overflow-y-auto max-h-[95vh] p-0'>
|
||||||
|
<img alt='event-ilustration' src='/assets/illustrations/event.png' className='h-44 w-full object-cover object-top' />
|
||||||
|
<div className='pt-4 pb-7 px-8 text-sm'>
|
||||||
|
<div className='flex items-start space-x-5'>
|
||||||
|
<div className='w-4 h-4 mt-2 rounded-md bg-rose-500 dark:bg-rose-900'></div>
|
||||||
|
<div>
|
||||||
|
<h1 className='text-2xl'>{data.name}</h1>
|
||||||
|
<p className='text-muted-foreground'>{dayjs(data.date).format('dddd, MMMM DD')}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='flex space-x-5 justify-start mt-4'>
|
||||||
|
<i className="ti ti-text-caption text-xl text-muted-foreground"></i>
|
||||||
|
<p>{data.description || '-'}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DetailEvent;
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import { Dispatch, FC, MouseEvent, SetStateAction, useState } from 'react';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { DatePicker } from 'antd';
|
||||||
|
import { Icons } from '@/components/Icons';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
open: boolean
|
||||||
|
onOpenChange: Dispatch<SetStateAction<boolean>>
|
||||||
|
onClose?: (e: MouseEvent<HTMLButtonElement>) => any
|
||||||
|
date: any
|
||||||
|
};
|
||||||
|
|
||||||
|
const NewEvent: FC<Props> = ({ open, onOpenChange, onClose, date }) => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
const [isAddTime, setIsAddTime] = useState(false)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader className='sr-only'>
|
||||||
|
<DialogTitle>Title</DialogTitle>
|
||||||
|
<DialogDescription>Description</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className='grid grid-cols-8 gap-y-5 my-5 text-sm'>
|
||||||
|
<span></span>
|
||||||
|
<input className='col-span-7 outline-none bg-transparent border-b border-border focus:border-his focus-visible:ring-offset-2 focus-visible:ring-his ring-offset-his caret-his py-1 text-xl duration-300' placeholder='Add title and time' />
|
||||||
|
<i className="ti ti-clock text-xl text-muted-foreground"></i>
|
||||||
|
<div className='col-span-7 flex justify-between items-center'>
|
||||||
|
<DatePicker defaultValue={dayjs(date)} format='MMMM DD, YYYY'
|
||||||
|
size='small' className='input w-48 px-3! z-10' getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||||
|
/>
|
||||||
|
{isAddTime ?
|
||||||
|
<DatePicker.TimePicker showSecond={false} format='HH:mm'
|
||||||
|
size='small' className='input w-max px-3!' getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||||
|
/>
|
||||||
|
:
|
||||||
|
<Button variant='outline' onClick={() => setIsAddTime(true)}>Add time</Button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<i className="ti ti-text-caption text-xl text-muted-foreground"></i>
|
||||||
|
<textarea className='col-span-7 bg-zinc-100 dark:bg-zinc-900 outline-none p-2 rounded-md caret-his' placeholder='Add description' rows={4} />
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant='secondary' disabled={isLoading} onClick={onClose} >
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button disabled={isLoading} onClick={() => setIsLoading(true)}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default NewEvent;
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
'use client'
|
||||||
|
import React, { FC, useEffect, useState } from 'react';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { generateCalendar } from '@/lib/helper';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import DayInCalendar from './DayInCalendar';
|
||||||
|
import NewEvent from './NewEvent';
|
||||||
|
import DetailEvent from './DetailEvent';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
dayOff: any[]
|
||||||
|
};
|
||||||
|
|
||||||
|
const CalendarComponent: FC<Props> = ({ dayOff }) => {
|
||||||
|
const [monthIndex, setMonthIndex] = useState(dayjs().month())
|
||||||
|
const [calendar, setCalendar] = useState(generateCalendar(dayjs().month()))
|
||||||
|
const [selectedEvent, setSelectedEvent] = useState<any>(null)
|
||||||
|
const [selectedDate, setSelectedDate] = useState<any>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setCalendar(generateCalendar(monthIndex))
|
||||||
|
}, [monthIndex])
|
||||||
|
|
||||||
|
const handlePrevMonth = () => {
|
||||||
|
setMonthIndex(monthIndex - 1)
|
||||||
|
}
|
||||||
|
const handleNextMonth = () => {
|
||||||
|
setMonthIndex(monthIndex + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleToday = () => {
|
||||||
|
setMonthIndex(dayjs().month())
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCreateEvent = (date: any) => {
|
||||||
|
setSelectedDate(date)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleClikEvent = (event: any) => {
|
||||||
|
setSelectedEvent(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='w-full min-h-screen h-max flex flex-col pt-6'>
|
||||||
|
<div className='flex flex-col md:flex-row items-center justify-between pb-5 space-y-4 md:space-y-0'>
|
||||||
|
<Button onClick={handleToday} className='px-8 w-full sm:w-max'>Today</Button>
|
||||||
|
<div className='w-full md:w-max flex items-center justify-between md:justify-center space-x-4'>
|
||||||
|
<Button size='icon' variant='outline' onClick={handlePrevMonth}><i className="ti ti-chevron-left" /></Button>
|
||||||
|
<span className='text-primary text-2xl'>{dayjs(new Date(dayjs().year(), monthIndex)).format('MMMM YYYY')}</span>
|
||||||
|
<Button size='icon' variant='outline' onClick={handleNextMonth}><i className="ti ti-chevron-right" /></Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='grid grid-cols-7 grid-rows-1 uppercase font-medium text-center text-xs md:text-sm mt-5'>
|
||||||
|
<div className='border-t border-l border-r border-border rounded-tl-md py-2 text-rose-500 dark:text-rose-900'>Sun</div>
|
||||||
|
<div className='border-t border-l border-r border-border py-2'>Mon</div>
|
||||||
|
<div className='border-t border-l border-r border-border py-2'>Tue</div>
|
||||||
|
<div className='border-t border-l border-r border-border py-2'>Wed</div>
|
||||||
|
<div className='border-t border-l border-r border-border py-2'>Thu</div>
|
||||||
|
<div className='border-t border-l border-r border-border py-2'>Fri</div>
|
||||||
|
<div className='border-t border-l border-r border-border rounded-tr-md py-2'>Sat</div>
|
||||||
|
</div>
|
||||||
|
<div className='flex-1 grid grid-cols-7 grid-rows-5 z-0'>
|
||||||
|
{calendar.map((week: any[], key) =>
|
||||||
|
<React.Fragment key={key}>
|
||||||
|
{week.map((day, keyx) =>
|
||||||
|
<DayInCalendar key={keyx}
|
||||||
|
day={day}
|
||||||
|
monthIndex={monthIndex}
|
||||||
|
dayOffList={dayOff}
|
||||||
|
onClickDate={() => handleCreateEvent(day)}
|
||||||
|
onClickEvent={(event) => handleClikEvent(event)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</React.Fragment>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{selectedDate &&
|
||||||
|
<NewEvent open={selectedDate} onOpenChange={setSelectedDate} onClose={() => setSelectedDate(null)}
|
||||||
|
date={selectedDate}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
{selectedEvent &&
|
||||||
|
<DetailEvent
|
||||||
|
open={selectedEvent} onOpenChange={setSelectedEvent}
|
||||||
|
data={selectedEvent}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CalendarComponent;
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import LazyLoading from '@/components/loader/LazyLoading';
|
||||||
|
import { Card, CardContent } from '@/components/ui/card';
|
||||||
|
import { Metadata } from 'next';
|
||||||
|
import { FC, Suspense } from 'react';
|
||||||
|
import CalendarComponent from './components';
|
||||||
|
import fetchData from '@/lib/fetchData';
|
||||||
|
|
||||||
|
type Props = {};
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "H.A.T.s Calendar",
|
||||||
|
description: "H.A.T.s Working Calendar",
|
||||||
|
}
|
||||||
|
|
||||||
|
const CalendarPage: FC<Props> = async () => {
|
||||||
|
const data = await fetchData('/dayoff')
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="flex-1 space-y-8 p-6 sm:p-8 pt-6 pb-36 md:pb-8">
|
||||||
|
<div className="flex flex-col sm:flex-row items-start justify-between space-y-2 sm:space-y-0">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-lg sm:text-3xl font-medium tracking-tight">H.A.T.s Calendar</h2>
|
||||||
|
<p className="text-xs md:text-base text-muted-foreground sm:mt-1 xl:w-2/3">A working calendar is not just a schedule; it's a roadmap to productivity, a daily commitment to progress, and a visual representation of how we invest our most precious resource: time.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Card>
|
||||||
|
<CardContent>
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<CalendarComponent dayOff={data.day_off} />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CalendarPage;
|
||||||
@@ -0,0 +1,330 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { FC, lazy, Suspense, useEffect, useState } from 'react';
|
||||||
|
import dayjs, { Dayjs } from 'dayjs';
|
||||||
|
import { DatePicker } from 'antd';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog';
|
||||||
|
import { Icons } from '@/components/Icons';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||||
|
import { toastError } from '@/lib/helper';
|
||||||
|
import PageLoading from '@/components/loader/PageLoading';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import FilterDataDashboard from './FilterDataDashboard';
|
||||||
|
import useMobileView from '@/hooks/useMobileView';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import FallbackAvatar from '@/components/loader/FallbackAvatar';
|
||||||
|
|
||||||
|
const ViewAvatar = lazy(() => import('@/components/ViewAvatar'));
|
||||||
|
const Avatar = lazy(() => import('@/components/ViewAvatar').then(mod => ({ default: mod.Avatar })));
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: any
|
||||||
|
className?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
const sortBy = 'presence_date'
|
||||||
|
const filterBy = ['fullname', 'position_name', 'working_status']
|
||||||
|
|
||||||
|
const AdjusmentAutoCheckout: FC<Props> = ({ data, className }) => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
const [isFullLoading, setIsFullLoading] = useState(false)
|
||||||
|
const [showDialog, setShowDialog] = useState(false)
|
||||||
|
const [showConfirm, setShowConfirm] = useState(false)
|
||||||
|
|
||||||
|
const [dataPresence, setDataPresence] = useState<any>(null)
|
||||||
|
const [presenceId, setPresenceId] = useState(0)
|
||||||
|
const [checkoutTime, setCheckoutTime] = useState<any>('')
|
||||||
|
|
||||||
|
const [dataFilter, setDataFilter] = useState<any[]>([])
|
||||||
|
const [search, setSearch] = useState('')
|
||||||
|
const [sort, setSort] = useState('desc')
|
||||||
|
|
||||||
|
const axios = useAxiosAuth()
|
||||||
|
const router = useRouter()
|
||||||
|
const { isMobile } = useMobileView()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let newData = [...data.list]
|
||||||
|
if (!search) {
|
||||||
|
newData = [...data.list]
|
||||||
|
} else {
|
||||||
|
newData = [...data.list].filter(item => (
|
||||||
|
filterBy.some(key => {
|
||||||
|
const value = item[key]?.toLowerCase();
|
||||||
|
return value && value.includes(search.toLowerCase());
|
||||||
|
})
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sort === 'asc') {
|
||||||
|
newData.sort((a, b) => (dayjs(a[sortBy]).isAfter(dayjs(b[sortBy])) ? 1 : -1))
|
||||||
|
} else {
|
||||||
|
newData.sort((b, a) => (dayjs(a[sortBy]).isAfter(dayjs(b[sortBy])) ? 1 : -1))
|
||||||
|
}
|
||||||
|
setDataFilter(newData)
|
||||||
|
}, [data.list, search, sort])
|
||||||
|
|
||||||
|
const handleFetchPresenceByID = async (presenceId: number) => {
|
||||||
|
try {
|
||||||
|
setPresenceId(presenceId)
|
||||||
|
setIsFullLoading(true)
|
||||||
|
const { data: res } = await axios.get('/presence/approval/info/' + presenceId)
|
||||||
|
// console.log(res)
|
||||||
|
setDataPresence(res.data)
|
||||||
|
setShowDialog(true)
|
||||||
|
} catch (error: any) {
|
||||||
|
toast.error(`Fail to get detail attendance`, {
|
||||||
|
description: `(${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
setIsFullLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleApproval = async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true)
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
"working_hours_start": dayjs(dataPresence?.working_hours_start).format('YYYY-MM-DD HH:mm:ss'),
|
||||||
|
"working_hours_end": `${dayjs(dataPresence.working_hours_start).format('YYYY-MM-DD')} ${checkoutTime}:00`
|
||||||
|
}
|
||||||
|
console.log(payload)
|
||||||
|
const { data: res } = await axios.put('/presence/approval/autocheckout/' + presenceId, payload)
|
||||||
|
|
||||||
|
toast.success('Success Approval', {
|
||||||
|
description: res.message,
|
||||||
|
action: <Button variant='outline' onClick={() => router.push('/admin/manual/approval-autocheckout')}>See approval</Button>,
|
||||||
|
})
|
||||||
|
|
||||||
|
setShowDialog(false)
|
||||||
|
setShowConfirm(false)
|
||||||
|
router.refresh()
|
||||||
|
} catch (error: any) {
|
||||||
|
toastError(toast, `Failed approval, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const disabledTime = (current: Dayjs | null) => {
|
||||||
|
if (!current) return {};
|
||||||
|
|
||||||
|
const disableHour = dayjs(dataPresence.working_hours_start).hour();
|
||||||
|
const disableMinute = dayjs(dataPresence.working_hours_start).minute();
|
||||||
|
|
||||||
|
return {
|
||||||
|
disabledHours: () => Array.from({ length: disableHour }, (_, i) => i),
|
||||||
|
disabledMinutes: (selectedHour: number) =>
|
||||||
|
selectedHour === disableHour
|
||||||
|
? Array.from({ length: disableMinute }, (_, i) => i)
|
||||||
|
: [],
|
||||||
|
disabledSeconds: () => [] // Optional, if you want to disable specific seconds
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<FilterDataDashboard search={search} onSearch={e => setSearch(e.target.value)} sort={sort} onSortChange={val => setSort(val)} />
|
||||||
|
<ScrollArea className={cn("hidden sm:block px-6", className)} height='max-h-[325px]'>
|
||||||
|
<div className="space-y-8">
|
||||||
|
{data && data.list?.length > 0 ?
|
||||||
|
dataFilter.map((item: any, key: number) =>
|
||||||
|
<div className="grid grid-cols-8" key={key}>
|
||||||
|
<div className="flex items-center col-span-4">
|
||||||
|
<Suspense fallback={<FallbackAvatar />}>
|
||||||
|
<ViewAvatar avatar={item.avatar} />
|
||||||
|
</Suspense>
|
||||||
|
<div className="ml-4 space-y-0.5 max-w-[70%] 2xl:max-w-[80%]">
|
||||||
|
<p className="text-xs sm:text-sm font-medium leading-none">{item.fullname}</p>
|
||||||
|
<p className="text-xs md:text-sm text-muted-foreground">
|
||||||
|
{item.position_name || '--'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='col-span-2 flex items-center text-2xl'>
|
||||||
|
<i className="ti ti-window-maximize text-his cursor-pointer hover:opacity-70 duration-300" onClick={() => handleFetchPresenceByID(item.presence_id)} title='Approval Attendance'></i>
|
||||||
|
</div>
|
||||||
|
<div className="col-span-2 text-xs text-right space-y-1">
|
||||||
|
{item.working_status === 'WFH' ?
|
||||||
|
<Badge variant='secondary' className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
:
|
||||||
|
item.working_status === 'WFS' ?
|
||||||
|
<Badge className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
:
|
||||||
|
item.working_status === 'SKT' ?
|
||||||
|
<Badge variant='destructive' className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
:
|
||||||
|
<Badge variant='outline' className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
}
|
||||||
|
<p className="font-semibold">{dayjs(item.working_hours_start).format('YYYY-MM-DD HH:mm')}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
:
|
||||||
|
<div className="h-32 w-full flex justify-center items-center" >
|
||||||
|
No results.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</ScrollArea>
|
||||||
|
|
||||||
|
{/* MOBILE VIEW */}
|
||||||
|
<div className={cn("overflow-y-auto block sm:hidden max-h-[325px] px-6", className)}>
|
||||||
|
<div className="w-full -mt-2">
|
||||||
|
{data && data.list?.length > 0 ?
|
||||||
|
dataFilter.map((item: any, key: number) =>
|
||||||
|
<div className="flex justify-between border-b border-zinc-300 dark:border-zinc-800 pt-3 pb-3.5" key={key} onClick={() => handleFetchPresenceByID(item.presence_id)} >
|
||||||
|
<div className="flex">
|
||||||
|
<Suspense fallback={<FallbackAvatar />}>
|
||||||
|
<Avatar avatar={item.avatar} className='w-10 h-10' sizes='40px' />
|
||||||
|
</Suspense>
|
||||||
|
<div className="ml-4 space-y-0.5">
|
||||||
|
<p className="text-sm font-medium leading-none">{item.fullname}</p>
|
||||||
|
<p className="text-xs text-muted-foreground pb-2">
|
||||||
|
{item.position_name || '--'}
|
||||||
|
</p>
|
||||||
|
<p className="text-xs font-semibold text-muted-foreground border-t border-zinc-300 dark:border-zinc-800 pt-1 w-max">{dayjs(item.working_hours_start).format('MMM DD, YYYY')}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="text-xs space-y-1">
|
||||||
|
{item.working_status === 'WFH' ?
|
||||||
|
<Badge variant='secondary' className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
:
|
||||||
|
item.working_status === 'WFS' ?
|
||||||
|
<Badge className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
:
|
||||||
|
item.working_status === 'SKT' ?
|
||||||
|
<Badge variant='destructive' className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
:
|
||||||
|
<Badge variant='outline' className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
:
|
||||||
|
<div className="h-32 w-full flex justify-center items-center" >
|
||||||
|
No results.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{showDialog &&
|
||||||
|
<AlertDialog open={true}>
|
||||||
|
<AlertDialogContent className='max-w-full md:max-w-[760px] py-6 md:px-10 overflow-y-auto max-h-[95vh]'>
|
||||||
|
<AlertDialogHeader className='flex flex-row justify-between'>
|
||||||
|
<div>
|
||||||
|
<AlertDialogTitle>Detail Attendance</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
This action cannot be undone. This will permanently <span className='font-bold'>Clear AutoCheckout</span> this presence.
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</div>
|
||||||
|
<Button variant='outline' size='icon' disabled={isLoading} onClick={() => setShowDialog(false)}><i className="ti ti-x text-xl"></i ></Button>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<div className='grid grid-cols-1 md:grid-cols-5 text-center md:text-left text-sm md:text-base md:my-3'>
|
||||||
|
<div className='col-span-2 flex flex-col items-center md:items-start'>
|
||||||
|
<Suspense fallback={<FallbackAvatar className='w-52 h-52 rounded-xl' />}>
|
||||||
|
<ViewAvatar isPresence avatar={dataPresence.face_image} className='w-52 h-52 sm:w-52 sm:h-52 rounded-xl shadow' sizes='208px' />
|
||||||
|
</Suspense>
|
||||||
|
<span className='text-base font-semibold mt-2'>{dataPresence.user.fullname}</span>
|
||||||
|
<span className='text-muted-foreground'>{dataPresence?.user?.position?.name || dataPresence?.user.nickname}</span>
|
||||||
|
</div>
|
||||||
|
<div className='col-span-3 space-y-4 mt-5 md:mt-0'>
|
||||||
|
<div className='flex flex-col items-center md:items-start'>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Presence information :</p>
|
||||||
|
<div className='flex items-center space-x-2'>
|
||||||
|
<p><span className='font-semibold'>{dayjs(dataPresence.working_hours_start).format('dddd, DD MMMM YYYY')}</span></p>
|
||||||
|
<Badge>{dataPresence.working_status}</Badge>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Check-in time :</p>
|
||||||
|
<p>{dayjs(dataPresence.working_hours_start).format('HH:mm A')}</p>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Check-In location :</p>
|
||||||
|
<p className='font-medium text-xs'>{dataPresence.latitude}, {dataPresence.longitude}</p>
|
||||||
|
<div>
|
||||||
|
{dataPresence.location_name || '-'}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{dataPresence.working_status !== 'WFO' &&
|
||||||
|
<div>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Check-In device :</p>
|
||||||
|
<p className='wrap-break-word'>{dataPresence.device.name || '-'}</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
{dataPresence.working_status !== 'WFO' &&
|
||||||
|
<div>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Check-In note :</p>
|
||||||
|
<p className='wrap-break-word'>{dataPresence.note || '-'}</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
<div>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Check-out time :</p>
|
||||||
|
{isMobile ?
|
||||||
|
<input className='input w-full' type='time' value={checkoutTime} onChange={(e) => setCheckoutTime(e.target.value)} />
|
||||||
|
:
|
||||||
|
<DatePicker.TimePicker
|
||||||
|
onChange={val => setCheckoutTime(dayjs(val).format('HH:mm'))}
|
||||||
|
disabledTime={disabledTime}
|
||||||
|
className='input' size='small' format='HH:mm'
|
||||||
|
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||||
|
showNow={false}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel disabled={isLoading} onClick={() => { setShowDialog(false); setDataPresence(null) }} >
|
||||||
|
Cancel
|
||||||
|
</AlertDialogCancel>
|
||||||
|
<AlertDialogAction disabled={isLoading} onClick={() => { setShowConfirm(true) }}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
Approve AutoCheckout
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
}
|
||||||
|
|
||||||
|
{showConfirm &&
|
||||||
|
<AlertDialog open={true}>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>Approval AutoCheckout Confirmation</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
This action cannot be undone. This will permanently <span className='font-bold'>Clear AutoCheckout</span> this presence.
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel disabled={isLoading} onClick={() => setShowConfirm(false)} className='text-red-500 font-semibold'>
|
||||||
|
Cancel
|
||||||
|
</AlertDialogCancel>
|
||||||
|
<AlertDialogAction disabled={isLoading} onClick={handleApproval}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
Continue
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
}
|
||||||
|
|
||||||
|
{isFullLoading && <PageLoading className='bg-opacity-40 dark:bg-opacity-20 z-999' />}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AdjusmentAutoCheckout;
|
||||||
@@ -0,0 +1,269 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { FC, lazy, Suspense, useEffect, useState } from 'react';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import FilterDataDashboard from './FilterDataDashboard';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog';
|
||||||
|
import { Icons } from '@/components/Icons';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||||
|
import { getVariantWorkingStatus, toastError } from '@/lib/helper';
|
||||||
|
import PageLoading from '@/components/loader/PageLoading';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import FallbackAvatar from '@/components/loader/FallbackAvatar';
|
||||||
|
|
||||||
|
const ViewAvatar = lazy(() => import('@/components/ViewAvatar'));
|
||||||
|
const Avatar = lazy(() => import('@/components/ViewAvatar').then(mod => ({ default: mod.Avatar })));
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: any
|
||||||
|
className?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
const sortBy = 'start_date'
|
||||||
|
const filterBy = ['fullname', 'position_name', 'category']
|
||||||
|
|
||||||
|
const ApprovalLeaveSick: FC<Props> = ({ data, className }) => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
const [isFullLoading, setIsFullLoading] = useState(false)
|
||||||
|
const [showDialog, setShowDialog] = useState(false)
|
||||||
|
const [showConfirm, setShowConfirm] = useState(false)
|
||||||
|
const [isApproval, setIsApproval] = useState(false)
|
||||||
|
const [dataPresence, setDataPresence] = useState<any>(null)
|
||||||
|
const [presenceId, setPresenceId] = useState(0)
|
||||||
|
const [dataFilter, setDataFilter] = useState<any[]>([])
|
||||||
|
const [search, setSearch] = useState('')
|
||||||
|
const [sort, setSort] = useState('desc')
|
||||||
|
|
||||||
|
const axios = useAxiosAuth()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let newData = [...data.list]
|
||||||
|
if (!search) {
|
||||||
|
newData = [...data.list]
|
||||||
|
} else {
|
||||||
|
newData = [...data.list].filter(item => (
|
||||||
|
filterBy.some(key => {
|
||||||
|
const value = item[key]?.toLowerCase();
|
||||||
|
return value && value.includes(search.toLowerCase());
|
||||||
|
})
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sort === 'asc') {
|
||||||
|
newData.sort((a, b) => (dayjs(a[sortBy]).isAfter(dayjs(b[sortBy])) ? 1 : -1))
|
||||||
|
} else {
|
||||||
|
newData.sort((b, a) => (dayjs(a[sortBy]).isAfter(dayjs(b[sortBy])) ? 1 : -1))
|
||||||
|
}
|
||||||
|
setDataFilter(newData)
|
||||||
|
}, [data.list, search, sort])
|
||||||
|
|
||||||
|
|
||||||
|
const handleFetchPresenceByID = async (presenceId: number) => {
|
||||||
|
try {
|
||||||
|
setPresenceId(presenceId)
|
||||||
|
setIsFullLoading(true)
|
||||||
|
const { data: res } = await axios.get('/application-form/approval/info/' + presenceId)
|
||||||
|
// console.log(res.data)
|
||||||
|
setDataPresence(res.data)
|
||||||
|
setShowDialog(true)
|
||||||
|
} catch (error: any) {
|
||||||
|
toast.error(`Fail to fetch presence`, {
|
||||||
|
description: `(${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
setIsFullLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleApproval = async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true)
|
||||||
|
const { data: res } = await axios.put('/application-form/approval/' + presenceId, {
|
||||||
|
"approve_status": isApproval
|
||||||
|
})
|
||||||
|
|
||||||
|
toast.success(isApproval ? 'Success Approval' : 'Success Decline', {
|
||||||
|
description: res.message,
|
||||||
|
action: <Button variant='outline' onClick={() => router.push('/admin/report/leave-permit-sick')}>See approval</Button>,
|
||||||
|
})
|
||||||
|
setShowDialog(false)
|
||||||
|
setShowConfirm(false)
|
||||||
|
router.refresh()
|
||||||
|
} catch (error: any) {
|
||||||
|
toastError(toast, `Failed approval, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(dataPresence)
|
||||||
|
// console.log(dataFilter)
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<FilterDataDashboard search={search} onSearch={e => setSearch(e.target.value)} sort={sort} onSortChange={val => setSort(val)} />
|
||||||
|
<ScrollArea className={cn("hidden sm:block px-6", className)} height='max-h-[325px]'>
|
||||||
|
<div className="space-y-8">
|
||||||
|
{data && data.list?.length > 0 ?
|
||||||
|
dataFilter.map((item: any, key: number) =>
|
||||||
|
<div className="grid grid-cols-8" key={key}>
|
||||||
|
<div className="flex items-center col-span-4">
|
||||||
|
<Suspense fallback={<FallbackAvatar />}>
|
||||||
|
<ViewAvatar avatar={item.avatar} />
|
||||||
|
</Suspense>
|
||||||
|
<div className="ml-4 space-y-0.5 max-w-[70%] 2xl:max-w-[80%]">
|
||||||
|
<p className="text-xs sm:text-sm font-medium leading-none">{item.fullname}</p>
|
||||||
|
<p className="text-xs md:text-sm text-muted-foreground">
|
||||||
|
{item.position_name || '--'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='col-span-2 flex items-center text-2xl'>
|
||||||
|
<i className="ti ti-window-maximize text-his cursor-pointer hover:opacity-70 duration-300" onClick={() => handleFetchPresenceByID(item.application_form_id)} title='Approval Leave and Sick'></i>
|
||||||
|
</div>
|
||||||
|
<div className="col-span-2 text-xs text-right space-y-1">
|
||||||
|
<Badge variant={getVariantWorkingStatus(item.category?.toUpperCase())}>{item.category}</Badge>
|
||||||
|
<p className="font-semibold">{dayjs(item.start_date).format('MMM DD, YYYY')}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
:
|
||||||
|
<div className="h-32 w-full flex justify-center items-center" >
|
||||||
|
No results.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</ScrollArea>
|
||||||
|
{/* MOBILE VIEW */}
|
||||||
|
<div className={cn("overflow-y-auto block sm:hidden max-h-[325px] px-6", className)}>
|
||||||
|
<div className="w-full -mt-2">
|
||||||
|
{data && data.list?.length > 0 ?
|
||||||
|
dataFilter.map((item: any, key: number) =>
|
||||||
|
<div className="flex justify-between border-b border-zinc-300 dark:border-zinc-800 pt-3 pb-3.5" key={key} onClick={() => handleFetchPresenceByID(item.application_form_id)}>
|
||||||
|
<div className="flex">
|
||||||
|
<Suspense fallback={<FallbackAvatar />}>
|
||||||
|
<Avatar avatar={item.avatar} className='w-10 h-10' sizes='40px' />
|
||||||
|
</Suspense>
|
||||||
|
<div className="ml-3.5 space-y-0.5">
|
||||||
|
<p className="text-sm font-medium leading-none">{item.fullname}</p>
|
||||||
|
<p className="text-xs text-muted-foreground pb-2">
|
||||||
|
{item.position_name || '--'}
|
||||||
|
</p>
|
||||||
|
<p className="text-xs font-semibold text-muted-foreground border-t border-zinc-300 dark:border-zinc-800 pt-1 w-max">{dayjs(item.start_date).format('MMM DD, YYYY')}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="text-xs w-max">
|
||||||
|
<Badge variant={getVariantWorkingStatus(item.category?.toUpperCase())}>{item.category}</Badge>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
:
|
||||||
|
<div className="h-32 w-full flex justify-center items-center" >
|
||||||
|
No results.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{showDialog &&
|
||||||
|
<AlertDialog open={true}>
|
||||||
|
<AlertDialogContent className='max-w-full md:max-w-[760px] py-6 md:px-10 overflow-y-auto max-h-[95vh]'>
|
||||||
|
<AlertDialogHeader className='flex flex-row justify-between'>
|
||||||
|
<div>
|
||||||
|
<AlertDialogTitle>Detail Application</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
This action cannot be undone. This will permanently approve or decline this application form.
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</div>
|
||||||
|
<Button variant='outline' size='icon' disabled={isLoading} onClick={() => setShowDialog(false)}><i className="ti ti-x text-xl"></i ></Button>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<div className='grid grid-cols-1 md:grid-cols-5 text-center md:text-left text-sm md:text-base md:my-3'>
|
||||||
|
<div className='col-span-2 flex flex-col items-center md:items-start'>
|
||||||
|
<Suspense fallback={<FallbackAvatar className='w-52 h-52 shadow' />}>
|
||||||
|
<ViewAvatar avatar={dataPresence?.avatar} className='w-52 h-52 sm:w-52 sm:h-52 shadow' sizes='208px' />
|
||||||
|
</Suspense>
|
||||||
|
<span className='text-base font-semibold mt-2'>{dataPresence.user.fullname}</span>
|
||||||
|
<span className='text-muted-foreground'>{dataPresence?.position_name || dataPresence?.user.nickname}</span>
|
||||||
|
</div>
|
||||||
|
<div className='col-span-3 space-y-4 mt-5 md:mt-0'>
|
||||||
|
<div>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Category</p>
|
||||||
|
<Badge variant={getVariantWorkingStatus(dataPresence.category.name)}>{dataPresence.category.name}</Badge>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Address</p>
|
||||||
|
<p>{dataPresence.contact_street}, {dataPresence.contact_city}</p>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Period</p>
|
||||||
|
<p>{dayjs(dataPresence.start_date).format('dddd, DD MMM YYYY')} <span className='text-muted-foreground'>to</span> {dayjs(dataPresence.end_date).format('dddd, DD MMM YYYY')}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Return to work</p>
|
||||||
|
<p>{dayjs(dataPresence.return_to_work_date).format('dddd, DD MMMM YYYY')}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Notes</p>
|
||||||
|
<p className='wrap-break-word'>{dataPresence.note || '-'}</p>
|
||||||
|
{dataPresence.tag.length > 0 && dataPresence.tag.map((item: string) =>
|
||||||
|
<Badge variant='secondary' className='mr-1' key={item}>{item}</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Send to</p>
|
||||||
|
<p>{dataPresence.superior}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Mentions to</p>
|
||||||
|
<p>{dataPresence.cc.length > 0 ? dataPresence.cc.join(', ') : '-'}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel disabled={isLoading} onClick={() => { setIsApproval(false); setShowConfirm(true) }} className='text-red-500 font-semibold'>
|
||||||
|
Decline
|
||||||
|
</AlertDialogCancel>
|
||||||
|
<AlertDialogAction disabled={isLoading} onClick={() => { setIsApproval(true); setShowConfirm(true) }}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
Approve
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
}
|
||||||
|
{showConfirm &&
|
||||||
|
<AlertDialog open={true}>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>Approval Confirmation</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
This action cannot be undone. This will permanently <span className='font-bold'>{isApproval ? 'Approve' : 'Decline'}</span> this application form.
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel disabled={isLoading} onClick={() => setShowConfirm(false)} className='text-red-500 font-semibold'>
|
||||||
|
Cancel
|
||||||
|
</AlertDialogCancel>
|
||||||
|
<AlertDialogAction disabled={isLoading} onClick={handleApproval}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
Continue
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
}
|
||||||
|
{isFullLoading && <PageLoading className='bg-opacity-40 dark:bg-opacity-20 z-999' />}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ApprovalLeaveSick;
|
||||||
@@ -0,0 +1,169 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { FC } from 'react';
|
||||||
|
import { type ApexOptions } from 'apexcharts';
|
||||||
|
import { useTheme } from 'next-themes';
|
||||||
|
import useMobileView from '@/hooks/useMobileView';
|
||||||
|
import dynamic from 'next/dynamic';
|
||||||
|
import LazyLoading from '@/components/loader/LazyLoading';
|
||||||
|
|
||||||
|
const ReactApexChart = dynamic(() => import('react-apexcharts'), {
|
||||||
|
loading: () => <LazyLoading />,
|
||||||
|
ssr: false
|
||||||
|
});
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: any
|
||||||
|
};
|
||||||
|
|
||||||
|
const AreaChart: FC<Props> = ({ data }) => {
|
||||||
|
const { theme, systemTheme } = useTheme()
|
||||||
|
const { isMobile } = useMobileView()
|
||||||
|
|
||||||
|
// console.log(data)
|
||||||
|
|
||||||
|
const options: ApexOptions = {
|
||||||
|
chart: {
|
||||||
|
type: 'area',
|
||||||
|
fontFamily: 'Inter, Arial, sans-serif',
|
||||||
|
toolbar: {
|
||||||
|
show: false
|
||||||
|
},
|
||||||
|
},
|
||||||
|
colors: ['#f43f5e', '#22c55e', '#8b5cf6', '#eab308', '#06b6d4'],
|
||||||
|
legend: {
|
||||||
|
position: 'top',
|
||||||
|
show: true,
|
||||||
|
fontSize: '16px',
|
||||||
|
labels: {
|
||||||
|
colors: theme === 'dark' ? '#fff' : theme === 'system' && systemTheme === 'dark' ? '#fff' : '#000',
|
||||||
|
useSeriesColors: false
|
||||||
|
},
|
||||||
|
},
|
||||||
|
dataLabels: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
stroke: {
|
||||||
|
show: true,
|
||||||
|
curve: 'smooth',
|
||||||
|
width: 2,
|
||||||
|
},
|
||||||
|
xaxis: {
|
||||||
|
type: 'datetime',
|
||||||
|
categories: data.list_date.slice(-14),
|
||||||
|
labels: {
|
||||||
|
show: true,
|
||||||
|
rotateAlways: true,
|
||||||
|
minHeight: 40,
|
||||||
|
maxHeight: 40,
|
||||||
|
format: 'dd/MM',
|
||||||
|
style: {
|
||||||
|
colors: theme === 'dark' ? '#a1a1aa' : theme === 'system' && systemTheme === 'dark' ? '#a1a1aa' : '#71717a',
|
||||||
|
fontSize: '14px',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
yaxis: {
|
||||||
|
min: 0,
|
||||||
|
max: 24,
|
||||||
|
labels: {
|
||||||
|
formatter: (val) => val.toFixed(0),
|
||||||
|
style: {
|
||||||
|
colors: theme === 'dark' ? '#a1a1aa' : theme === 'system' && systemTheme === 'dark' ? '#a1a1aa' : '#71717a',
|
||||||
|
fontSize: '14px',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
yaxis: {
|
||||||
|
lines: { show: false }
|
||||||
|
},
|
||||||
|
padding: {
|
||||||
|
right: 30 // Also you may want to increase this (based on the length of your labels)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fill: {
|
||||||
|
type: 'gradient',
|
||||||
|
gradient: {
|
||||||
|
shadeIntensity: 1,
|
||||||
|
inverseColors: false,
|
||||||
|
opacityFrom: 0.5,
|
||||||
|
opacityTo: 0.1,
|
||||||
|
stops: [20, 100, 100, 100]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
theme: theme === 'dark' ? 'dark' : theme === 'system' && systemTheme === 'dark' ? 'dark' : 'light',
|
||||||
|
style: { fontSize: '14px' },
|
||||||
|
x: {
|
||||||
|
format: 'MMM dd, yyyy'
|
||||||
|
},
|
||||||
|
y: {
|
||||||
|
formatter: (val) => val.toFixed(2)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
responsive: [{
|
||||||
|
breakpoint: 800,
|
||||||
|
options: {
|
||||||
|
legend: { fontSize: '14px' },
|
||||||
|
yaxis: {
|
||||||
|
min: 0,
|
||||||
|
max: 24,
|
||||||
|
labels: {
|
||||||
|
formatter: (val: any) => val.toFixed(0),
|
||||||
|
style: {
|
||||||
|
colors: theme === 'dark' ? '#a1a1aa' : theme === 'system' && systemTheme === 'dark' ? '#a1a1aa' : '#71717a',
|
||||||
|
fontSize: '12px',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
xaxis: {
|
||||||
|
labels: {
|
||||||
|
rotateAlways: true,
|
||||||
|
minHeight: 35,
|
||||||
|
maxHeight: 35,
|
||||||
|
style: {
|
||||||
|
colors: theme === 'dark' ? '#a1a1aa' : theme === 'system' && systemTheme === 'dark' ? '#a1a1aa' : '#71717a',
|
||||||
|
fontSize: '12px',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
// const series = [
|
||||||
|
// {
|
||||||
|
// name: data.report[1].name,
|
||||||
|
// data: data.report[1].data.slice(-7)
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// name: data.report[0].name,
|
||||||
|
// data: data.report[0].data.slice(-7)
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
|
||||||
|
const series = () => {
|
||||||
|
return data.report.map((item: any) => {
|
||||||
|
return {
|
||||||
|
name: item.name,
|
||||||
|
data: item.data.slice(-14)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='h-[300px] sm:h-[400px] flex items-center justify-center w-full -mt-3'>
|
||||||
|
<ReactApexChart
|
||||||
|
type='area'
|
||||||
|
options={options}
|
||||||
|
series={series()}
|
||||||
|
width={isMobile ? 350 : '200%'}
|
||||||
|
height='100%'
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AreaChart;
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { FC, type ReactNode } from 'react';
|
||||||
|
import { Card900, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
title: string
|
||||||
|
description?: string
|
||||||
|
children: ReactNode
|
||||||
|
};
|
||||||
|
|
||||||
|
const DashboardCard: FC<Props> = ({ title, description, children }) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Card900>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>{title}</CardTitle>
|
||||||
|
<CardDescription>{description}</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="sm:pl-0">
|
||||||
|
<ScrollArea className="px-6" height='max-h-[325px]'>
|
||||||
|
<div className="space-y-8 overflow-x-auto">
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</ScrollArea>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DashboardCard;
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { HTMLAttributes, useState } from "react"
|
||||||
|
import { CalendarIcon } from "@radix-ui/react-icons"
|
||||||
|
import { addDays, format } from "date-fns"
|
||||||
|
import { DateRange } from "react-day-picker"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"
|
||||||
|
import { Calendar } from "@/components/ui/calendar"
|
||||||
|
|
||||||
|
export function CalendarDateRangePicker({ className }: HTMLAttributes<HTMLDivElement>) {
|
||||||
|
|
||||||
|
const [date, setDate] = useState<DateRange | undefined>({
|
||||||
|
from: new Date(2023, 0, 20),
|
||||||
|
to: addDays(new Date(2023, 0, 20), 20),
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={cn("grid gap-2", className)}>
|
||||||
|
<Popover>
|
||||||
|
<PopoverTrigger asChild>
|
||||||
|
<Button id="date" variant={"outline"}
|
||||||
|
className={cn(
|
||||||
|
"w-full sm:w-[260px] justify-start text-left font-normal",
|
||||||
|
!date && "text-muted-foreground"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<CalendarIcon className="sm:mr-2 h-4 w-4" />
|
||||||
|
<div className="hidden sm:block">
|
||||||
|
{date?.from ? (
|
||||||
|
date.to ? (
|
||||||
|
<>
|
||||||
|
{format(date.from, "LLL dd, y")} -{" "}
|
||||||
|
{format(date.to, "LLL dd, y")}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
format(date.from, "LLL dd, y")
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<span>Pick a date</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</Button>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent className="w-auto p-0" align="end">
|
||||||
|
<Calendar
|
||||||
|
initialFocus
|
||||||
|
mode="range"
|
||||||
|
defaultMonth={date?.from}
|
||||||
|
selected={date}
|
||||||
|
onSelect={setDate}
|
||||||
|
numberOfMonths={2}
|
||||||
|
/>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import { FC, lazy, Suspense } from 'react';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
import FallbackAvatar from '@/components/loader/FallbackAvatar';
|
||||||
|
|
||||||
|
const ViewAvatar = lazy(() => import('@/components/ViewAvatar'));
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: any
|
||||||
|
className?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
const EmployeeBirthday: FC<Props> = ({ data, className }) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ScrollArea className={cn("hidden sm:block px-6", className)} height='max-h-[325px]'>
|
||||||
|
<div className="space-y-8">
|
||||||
|
{data && data.list?.length > 0 ?
|
||||||
|
data.list.map((item: any, key: number) =>
|
||||||
|
<div className="grid grid-cols-5" key={key}>
|
||||||
|
<div className="flex items-center col-span-2">
|
||||||
|
<Suspense fallback={<FallbackAvatar />}>
|
||||||
|
<ViewAvatar avatar={item.avatar} />
|
||||||
|
</Suspense>
|
||||||
|
<div className="ml-4 space-y-0.5 max-w-[70%] 2xl:max-w-[80%]">
|
||||||
|
<p className="text-xs sm:text-sm font-medium leading-none">{item.fullname}</p>
|
||||||
|
<p className="text-xs md:text-sm text-muted-foreground">
|
||||||
|
{item.position_name || '--'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-center items-center"><Badge>{item.birthday_date as any}</Badge></div>
|
||||||
|
<div className="font-medium text-sm col-span-2 flex justify-center items-center text-right">{item.division_name}</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
:
|
||||||
|
<div className="h-32 w-full flex justify-center items-center" >
|
||||||
|
No results.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</ScrollArea>
|
||||||
|
<div className={cn("overflow-y-auto block sm:hidden max-h-[325px] px-6", className)}>
|
||||||
|
<div className="space-y-8 w-full">
|
||||||
|
{data && data.list?.length > 0 ?
|
||||||
|
data.list.map((item: any, key: number) =>
|
||||||
|
<div className="flex" key={key}>
|
||||||
|
<Suspense fallback={<FallbackAvatar />}>
|
||||||
|
<ViewAvatar avatar={item.avatar} className='w-10 h-10' sizes='40px' />
|
||||||
|
</Suspense>
|
||||||
|
<div className="ml-4 space-y-0.5 text-xs">
|
||||||
|
<p className="text-sm font-medium leading-none">{item.fullname}</p>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
{item.position_name || '--'}
|
||||||
|
</p>
|
||||||
|
<div className="font-medium text-muted-foreground pb-1">{item.division_name}</div>
|
||||||
|
<div className="font-semibold border-t border-zinc-300 dark:border-zinc-800 pt-1 w-max">{item.birthday_date as any}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
:
|
||||||
|
<div className="h-32 w-full flex justify-center items-center" >
|
||||||
|
No results.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EmployeeBirthday;
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import { FC, lazy, Suspense } from 'react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
|
import FallbackAvatar from '@/components/loader/FallbackAvatar';
|
||||||
|
|
||||||
|
const ViewAvatar = lazy(() => import('@/components/ViewAvatar'));
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: any
|
||||||
|
className?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
const EmployeeContractExp: FC<Props> = ({ data, className }) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ScrollArea className={cn("hidden sm:block px-6", className)} height='max-h-[325px]'>
|
||||||
|
<div className="space-y-8">
|
||||||
|
{data && data.list?.length > 0 ?
|
||||||
|
data.list.map((item: any, key: number) =>
|
||||||
|
<div className="grid grid-cols-8" key={key}>
|
||||||
|
<div className="flex items-center col-span-3">
|
||||||
|
<Suspense fallback={<FallbackAvatar />}>
|
||||||
|
<ViewAvatar avatar={item.avatar} />
|
||||||
|
</Suspense>
|
||||||
|
<div className="ml-4 space-y-0.5 max-w-[70%] 2xl:max-w-[80%]">
|
||||||
|
<p className="text-xs sm:text-sm font-medium leading-none">{item.fullname}</p>
|
||||||
|
<p className="text-xs md:text-sm text-muted-foreground">
|
||||||
|
{item.position_name || '--'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="col-span-2 flex justify-center items-center"><Badge variant='destructive'>{item.contract_expiration_date as any}</Badge></div>
|
||||||
|
<div className="font-medium text-sm col-span-3 text-right">{item.division_name}</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
:
|
||||||
|
<div className="h-32 w-full flex justify-center items-center" >
|
||||||
|
No results.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</ScrollArea>
|
||||||
|
<div className={cn("overflow-y-auto block sm:hidden max-h-[325px] px-6", className)}>
|
||||||
|
<div className="space-y-8 w-max">
|
||||||
|
{data && data.list?.length > 0 ?
|
||||||
|
data.list.map((item: any, key: number) =>
|
||||||
|
<div className="grid grid-cols-8 gap-x-2" key={key}>
|
||||||
|
<div className="flex items-center col-span-3">
|
||||||
|
<Suspense fallback={<FallbackAvatar />}>
|
||||||
|
<ViewAvatar avatar={item.avatar} />
|
||||||
|
</Suspense>
|
||||||
|
<div className="ml-4 space-y-0.5 max-w-[70%] 2xl:max-w-[80%]">
|
||||||
|
<p className="text-xs sm:text-sm font-medium leading-none">{item.fullname}</p>
|
||||||
|
<p className="text-xs md:text-sm text-muted-foreground">
|
||||||
|
{item.position_name || '--'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="col-span-2 flex justify-center items-center"><Badge variant='destructive'>{item.contract_expiration_date as any}</Badge></div>
|
||||||
|
<div className="font-medium text-xs col-span-3 flex justify-center items-center">{item.division_name}</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
:
|
||||||
|
<div className="h-32 w-full flex justify-center items-center" >
|
||||||
|
No results.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EmployeeContractExp;
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||||
|
import { ChangeEvent, FC } from 'react';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
search: string
|
||||||
|
onSearch: (e: ChangeEvent<HTMLInputElement>) => any
|
||||||
|
sort: string
|
||||||
|
onSortChange: (value: string) => any
|
||||||
|
placeholder?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
const FilterDataDashboard: FC<Props> = ({ search, onSearch, sort, onSortChange, placeholder }) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="flex items-center px-5 -mt-3 mb-5">
|
||||||
|
<Input placeholder={placeholder || "Search attendance..."} className="max-w-sm" value={search} onChange={onSearch} />
|
||||||
|
<Select value={sort} onValueChange={onSortChange}>
|
||||||
|
<SelectTrigger className="ml-auto w-max dark:bg-black">
|
||||||
|
<SelectValue placeholder="Sort" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="desc">Desc</SelectItem>
|
||||||
|
<SelectItem value="asc">Asc</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default FilterDataDashboard;
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import FOOTER_MENU from '@/lib/data-footer';
|
||||||
|
import Link from 'next/link';
|
||||||
|
import { usePathname, useRouter } from 'next/navigation';
|
||||||
|
import { FC } from 'react';
|
||||||
|
|
||||||
|
type Props = {};
|
||||||
|
|
||||||
|
const Footer: FC<Props> = () => {
|
||||||
|
const pathname = usePathname()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
const getMenuActiveStyle = (path: string) => {
|
||||||
|
if (pathname?.startsWith(path) && (pathname !== '' && pathname !== '/') && (path !== '' && path !== '/')) {
|
||||||
|
return 'text-zinc-950 dark:text-white font-semibold dark:font-medium'
|
||||||
|
} else {
|
||||||
|
if (path === pathname) {
|
||||||
|
return 'text-zinc-950 dark:text-white font-semibold dark:font-medium'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<footer className="flex sm:hidden flex-col sticky bottom-2.5 z-10 backdrop-blur-lg bg-white/50 dark:bg-zinc-950/50 rounded-2xl mx-6 shadow-sm">
|
||||||
|
<div className="grid grid-cols-5 p-3 text-[10px] font-medium text-muted-foreground">
|
||||||
|
{FOOTER_MENU.map((item, key) =>
|
||||||
|
<Link href={item.path} onClick={() => router.push(item.path)}
|
||||||
|
className={`flex flex-col items-center space-y-0.5 ${getMenuActiveStyle(item.path)}`} key={key}
|
||||||
|
>
|
||||||
|
<i className={`${item.icon} text-xl`}></i>
|
||||||
|
<p>{item.title}</p>
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Footer;
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { FC, useEffect, useState } from 'react';
|
||||||
|
import Link from 'next/link';
|
||||||
|
import { usePathname, useRouter } from 'next/navigation';
|
||||||
|
import { useSession } from 'next-auth/react';
|
||||||
|
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||||
|
|
||||||
|
type Props = {};
|
||||||
|
|
||||||
|
const FooterV2: FC<Props> = () => {
|
||||||
|
const [lastPresence, setLastPresence] = useState<any>(null)
|
||||||
|
|
||||||
|
const pathname = usePathname()
|
||||||
|
const router = useRouter()
|
||||||
|
const { data: session } = useSession()
|
||||||
|
|
||||||
|
const axios = useAxiosAuth()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function fetchLastPresence() {
|
||||||
|
axios.post('/presence/last-status/today', { nik: session?.user.detail.nik })
|
||||||
|
.then(res => {
|
||||||
|
setLastPresence(res.data.data)
|
||||||
|
}).catch((err) => console.log(err))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchLastPresence()
|
||||||
|
}, [pathname])
|
||||||
|
|
||||||
|
const getMenuActiveStyle = (path: string) => {
|
||||||
|
if (pathname?.startsWith(path) && (pathname !== '' && pathname !== '/') && (path !== '' && path !== '/')) {
|
||||||
|
return 'text-his font-semibold'
|
||||||
|
} else {
|
||||||
|
if (path === pathname) {
|
||||||
|
return 'text-his font-semibold'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<footer className="fixed sm:hidden flex-col bottom-5 z-10 backdrop-blur-lg px-6 shadow-sm w-full">
|
||||||
|
<div className="w-full dark:bg-zinc-50 bg-zinc-900 rounded-full grid grid-cols-5 px-2 py-4 text-xs font-medium text-muted-foreground relative">
|
||||||
|
<Link prefetch href={'/'} onClick={() => router.push('/')}
|
||||||
|
className={`flex flex-col items-center space-y-0.5 ${getMenuActiveStyle('/')}`}
|
||||||
|
>
|
||||||
|
<i className='ti ti-home-stats icon text-2xl'></i>
|
||||||
|
<p>Home</p>
|
||||||
|
</Link>
|
||||||
|
<Link prefetch href={'/history'} onClick={() => router.push('/')}
|
||||||
|
className={`flex flex-col items-center space-y-0.5 ${getMenuActiveStyle('/history')}`}
|
||||||
|
>
|
||||||
|
<i className='ti ti-history-toggle icon text-2xl'></i>
|
||||||
|
<p>History</p>
|
||||||
|
</Link>
|
||||||
|
<div className={`absolute top-[18px] left-1/2 flex flex-col items-center ${getMenuActiveStyle('/presence-v2')}`} style={{ transform: 'translate(-50%, -50%)' }}>
|
||||||
|
<Link prefetch href={!lastPresence?.is_checkin ? '/presence-v2' : lastPresence?.device_code === "11001" ? '' : '/presence-v2?checkout=true'} className='w-16 h-16 p-0.5 rounded-full bg-zinc-950 dark:bg-zinc-50 flex justify-center items-center' >
|
||||||
|
<div className='h-full w-full bg-his rounded-full flex justify-center items-center text-white'>
|
||||||
|
<i className='ti ti-face-id icon text-3xl'></i>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
<p className='mt-0.5'>Presence</p>
|
||||||
|
</div>
|
||||||
|
<div></div>
|
||||||
|
<Link prefetch href={'/task'} onClick={() => router.push('/')}
|
||||||
|
className={`flex flex-col items-center space-y-0.5 ${getMenuActiveStyle('/task')}`}
|
||||||
|
>
|
||||||
|
<i className='ti ti-checklist icon text-2xl'></i>
|
||||||
|
<p>Task</p>
|
||||||
|
</Link>
|
||||||
|
<Link prefetch href={'/profile'} onClick={() => router.push('/')}
|
||||||
|
className={`flex flex-col items-center space-y-0.5 ${getMenuActiveStyle('/profile')}`}
|
||||||
|
>
|
||||||
|
<i className='ti ti-user-circle icon icon text-2xl'></i>
|
||||||
|
<p>Profile</p>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default FooterV2;
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { FC } from 'react';
|
||||||
|
import Logo from './Logo';
|
||||||
|
import { MainNav } from './MainNav';
|
||||||
|
import { UserNav } from './UserNav';
|
||||||
|
import { ToggleTheme } from '@/components/ToggleTheme';
|
||||||
|
import Notification from './Notification';
|
||||||
|
|
||||||
|
type Props = {};
|
||||||
|
|
||||||
|
const Header: FC<Props> = ({ }) => {
|
||||||
|
return (
|
||||||
|
<header className="flex flex-col sticky top-0 z-10 backdrop-blur-xl bg-white/70 dark:bg-zinc-950/10">
|
||||||
|
<div className="border-b dark:border-zinc-800">
|
||||||
|
<div className="flex h-16 items-center px-4">
|
||||||
|
<Logo />
|
||||||
|
<MainNav className="ml-12" />
|
||||||
|
<div className="ml-auto sm:hidden">
|
||||||
|
<Notification />
|
||||||
|
</div>
|
||||||
|
<div className="ml-auto hidden sm:flex items-center space-x-4">
|
||||||
|
<div className="flex items-center space-x-3 sm:border-r sm:pr-4 dark:border-zinc-800">
|
||||||
|
<Notification />
|
||||||
|
<ToggleTheme />
|
||||||
|
</div>
|
||||||
|
<UserNav />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Header;
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { FC, useEffect, useState } from 'react';
|
||||||
|
import { IHistory } from '../history/components/type';
|
||||||
|
import { CardContent } from '@/components/ui/card';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
history: IHistory[]
|
||||||
|
};
|
||||||
|
|
||||||
|
const LastPresence: FC<Props> = ({ history }) => {
|
||||||
|
const [latestPresenceCheckout, setLatestPresenceCheckout] = useState<any>(null)
|
||||||
|
const [latestPresenceCheckIn, setLatestPresenceCheckIn] = useState<any>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (history && history.length > 0) {
|
||||||
|
for (let i = 0; i < history.length; i++) {
|
||||||
|
if (history[i].presence_checkout) {
|
||||||
|
setLatestPresenceCheckIn(history[i].presence_checkout?.working_hours_start || null)
|
||||||
|
setLatestPresenceCheckout(history[i].presence_checkout?.working_hours_end || null)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [history])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<CardContent>
|
||||||
|
<div className="text-2xl font-bold">{latestPresenceCheckout ? dayjs(latestPresenceCheckIn).format('HH:mm a') + ' - ' + dayjs(latestPresenceCheckout).format('HH:mm a') : '--:-- - --:--'} </div>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
your last presence at {latestPresenceCheckIn ? dayjs(latestPresenceCheckIn).format('MMM DD, YYYY') : ''}
|
||||||
|
</p>
|
||||||
|
</CardContent>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LastPresence;
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { FC } from 'react';
|
||||||
|
import Link from 'next/link';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
className?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
const Logo: FC<Props> = ({ className }) => {
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{/* <Link href='/' className={cn('inline-flex items-center space-x-3 hover:opacity-70 duration-300', className)} onClick={() => router.refresh()}>
|
||||||
|
<div className='flex justify-center items-center w-10 h-10 rounded cursor-pointer float-left duration-500 hover:rotate-[360deg]'>
|
||||||
|
<img alt='logo' loading='lazy' src='/assets/LOGO_HATs.png' className='h-full w-full' />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h1 className='origin-left font-extrabold duration-300 text-xl'>H.<span className='text-his'>A</span>.T.<span className='text-his'>s</span></h1>
|
||||||
|
<p className='text-[8px] -mt-1 font-medium text-muted-foreground'>HIS Attendance Task System</p>
|
||||||
|
</div>
|
||||||
|
</Link> */}
|
||||||
|
<Link href='/' className={cn('inline-flex items-center space-x-3 hover:opacity-70 duration-300', className)} onClick={() => router.refresh()}>
|
||||||
|
<div className='flex justify-center items-center h-12 max-w-[140px] rounded cursor-pointer float-left duration-500'>
|
||||||
|
<img alt='logo' loading='lazy' src='/assets/LOGO_HIS_HATs_NI.png' className='h-full w-full' />
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Logo;
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
'use client'
|
||||||
|
import { HTMLAttributes } from "react"
|
||||||
|
import Link from "next/link"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import { usePathname } from "next/navigation"
|
||||||
|
import { useSession } from "next-auth/react"
|
||||||
|
|
||||||
|
export function MainNav({ className, ...props }: HTMLAttributes<HTMLElement>) {
|
||||||
|
const pathname = usePathname()
|
||||||
|
const { data: session } = useSession()
|
||||||
|
|
||||||
|
const getMenuActiveStyle = (path: string) => {
|
||||||
|
if (pathname?.startsWith(path) && (pathname !== '' && pathname !== '/') && (path !== '' && path !== '/')) {
|
||||||
|
return 'font-semibold text-primary border-b-[3px] border-his'
|
||||||
|
} else {
|
||||||
|
if (path === pathname) {
|
||||||
|
return 'font-semibold text-primary border-b-[3px] border-his'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 'text-muted-foreground'
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<nav className={cn("hidden md:flex items-center space-x-4 lg:space-x-6 h-16", className)} {...props}>
|
||||||
|
<Link
|
||||||
|
href="/" prefetch
|
||||||
|
className={`text-sm font-medium transition-colors hover:text-his hover:border-b-[3px] border-his pt-6 pb-5 ${getMenuActiveStyle('/')}`}
|
||||||
|
>
|
||||||
|
<i className="ti ti-layers-linked text-base mr-0.5"></i>
|
||||||
|
Overview
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
href="/history" prefetch
|
||||||
|
className={`text-sm font-medium transition-colors hover:text-his hover:border-b-[3px] border-his pt-6 pb-5 ${getMenuActiveStyle('/history')}`}
|
||||||
|
>
|
||||||
|
<i className="ti ti-history-toggle text-base mr-0.5"></i>
|
||||||
|
History
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
href="/task" prefetch
|
||||||
|
className={`text-sm font-medium transition-colors hover:text-his hover:border-b-[3px] border-his pt-6 pb-5 ${getMenuActiveStyle('/task')}`}
|
||||||
|
>
|
||||||
|
<i className="ti ti-checklist text-base mr-0.5"></i>
|
||||||
|
My Task
|
||||||
|
</Link>
|
||||||
|
{session?.user.detail.role.allow_admin_panel &&
|
||||||
|
<Link
|
||||||
|
href="/admin" prefetch title="Go to Admin Panel"
|
||||||
|
className={`text-sm font-medium transition-colors hover:text-his hover:border-b-[3px] border-his pt-6 pb-5 ${getMenuActiveStyle('/admin')}`}
|
||||||
|
>
|
||||||
|
<i className="ti ti-spy text-base mr-0.5"></i>
|
||||||
|
Admin Panel
|
||||||
|
</Link>
|
||||||
|
}
|
||||||
|
</nav>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,287 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { FC, lazy, Suspense, useEffect, useState } from 'react';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import FilterDataDashboard from './FilterDataDashboard';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog';
|
||||||
|
import { Icons } from '@/components/Icons';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||||
|
import PageLoading from '@/components/loader/PageLoading';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import FallbackAvatar from '@/components/loader/FallbackAvatar';
|
||||||
|
|
||||||
|
const ViewAvatar = lazy(() => import('@/components/ViewAvatar'));
|
||||||
|
const Avatar = lazy(() => import('@/components/ViewAvatar').then(mod => ({ default: mod.Avatar })));
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: any
|
||||||
|
className?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
const sortBy = 'presence_date'
|
||||||
|
const filterBy = ['fullname', 'position_name', 'working_status']
|
||||||
|
|
||||||
|
const NeedApproval: FC<Props> = ({ data, className }) => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
const [isFullLoading, setIsFullLoading] = useState(false)
|
||||||
|
const [showDialog, setShowDialog] = useState(false)
|
||||||
|
const [showConfirm, setShowConfirm] = useState(false)
|
||||||
|
const [isApproval, setIsApproval] = useState(false)
|
||||||
|
const [dataPresence, setDataPresence] = useState<any>(null)
|
||||||
|
const [presenceId, setPresenceId] = useState(0)
|
||||||
|
const [dataFilter, setDataFilter] = useState<any[]>([])
|
||||||
|
const [search, setSearch] = useState('')
|
||||||
|
const [sort, setSort] = useState('desc')
|
||||||
|
|
||||||
|
const axios = useAxiosAuth()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let newData = [...data.list]
|
||||||
|
if (!search) {
|
||||||
|
newData = [...data.list]
|
||||||
|
} else {
|
||||||
|
newData = [...data.list].filter(item => (
|
||||||
|
filterBy.some(key => {
|
||||||
|
const value = item[key]?.toLowerCase();
|
||||||
|
return value && value.includes(search.toLowerCase());
|
||||||
|
})
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sort === 'asc') {
|
||||||
|
newData.sort((a, b) => (dayjs(a[sortBy]).isAfter(dayjs(b[sortBy])) ? 1 : -1))
|
||||||
|
} else {
|
||||||
|
newData.sort((b, a) => (dayjs(a[sortBy]).isAfter(dayjs(b[sortBy])) ? 1 : -1))
|
||||||
|
}
|
||||||
|
setDataFilter(newData)
|
||||||
|
}, [data.list, search, sort])
|
||||||
|
|
||||||
|
const handleFetchPresenceByID = async (presenceId: number) => {
|
||||||
|
try {
|
||||||
|
setPresenceId(presenceId)
|
||||||
|
setIsFullLoading(true)
|
||||||
|
const { data: res } = await axios.get('/presence/approval/info/' + presenceId)
|
||||||
|
// console.log(res)
|
||||||
|
setDataPresence(res.data)
|
||||||
|
setShowDialog(true)
|
||||||
|
} catch (error: any) {
|
||||||
|
toast.error(`Failed to get detail attendance`, {
|
||||||
|
description: `(${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
setIsFullLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleApproval = async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true)
|
||||||
|
const { data: res } = await axios.put('/presence/approval/' + presenceId, {
|
||||||
|
"approve_status": isApproval
|
||||||
|
})
|
||||||
|
|
||||||
|
toast.success(isApproval ? 'Success Approval' : 'Success Decline', {
|
||||||
|
description: res.message,
|
||||||
|
action: <Button variant='outline' onClick={() => router.push('/admin/manual/approval')}>See approval</Button>,
|
||||||
|
})
|
||||||
|
setShowDialog(false)
|
||||||
|
setShowConfirm(false)
|
||||||
|
router.refresh()
|
||||||
|
} catch (error: any) {
|
||||||
|
toast.error(`Failed approval`, {
|
||||||
|
description: `(${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<FilterDataDashboard search={search} onSearch={e => setSearch(e.target.value)} sort={sort} onSortChange={val => setSort(val)} />
|
||||||
|
<ScrollArea className={cn("hidden sm:block px-6", className)} height='max-h-[325px]'>
|
||||||
|
<div className="space-y-8">
|
||||||
|
{data && data.list?.length > 0 ?
|
||||||
|
dataFilter.map((item: any, key: number) =>
|
||||||
|
<div className="grid grid-cols-8" key={key}>
|
||||||
|
<div className="flex items-center col-span-4">
|
||||||
|
<Suspense fallback={<FallbackAvatar />}>
|
||||||
|
<ViewAvatar avatar={item.avatar} />
|
||||||
|
</Suspense>
|
||||||
|
<div className="ml-4 space-y-0.5 max-w-[70%] 2xl:max-w-[80%]">
|
||||||
|
<p className="text-xs sm:text-sm font-medium leading-none">{item.fullname}</p>
|
||||||
|
<p className="text-xs md:text-sm text-muted-foreground">
|
||||||
|
{item.position_name || '--'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='col-span-2 flex items-center text-2xl'>
|
||||||
|
<i className="ti ti-window-maximize text-his cursor-pointer hover:opacity-70 duration-300" onClick={() => handleFetchPresenceByID(item.presence_id)} title='Approval Attendance'></i>
|
||||||
|
</div>
|
||||||
|
<div className="col-span-2 text-xs text-right space-y-1">
|
||||||
|
{item.working_status === 'WFH' ?
|
||||||
|
<Badge variant='secondary' className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
:
|
||||||
|
item.working_status === 'WFS' ?
|
||||||
|
<Badge className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
:
|
||||||
|
item.working_status === 'SKT' ?
|
||||||
|
<Badge variant='destructive' className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
:
|
||||||
|
<Badge variant='outline' className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
}
|
||||||
|
<p className="font-semibold">{dayjs(item.working_hours_start).format('YYYY-MM-DD HH:mm')}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
:
|
||||||
|
<div className="h-32 w-full flex justify-center items-center" >
|
||||||
|
No results.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</ScrollArea>
|
||||||
|
|
||||||
|
{/* MOBILE VIEW */}
|
||||||
|
<div className={cn("overflow-y-auto block sm:hidden max-h-[325px] px-6", className)}>
|
||||||
|
<div className="w-full -mt-2">
|
||||||
|
{data && data.list?.length > 0 ?
|
||||||
|
dataFilter.map((item: any, key: number) =>
|
||||||
|
<div className="flex justify-between border-b border-zinc-300 dark:border-zinc-800 pt-3 pb-3.5" key={key} onClick={() => handleFetchPresenceByID(item.presence_id)}>
|
||||||
|
<div className='flex'>
|
||||||
|
<Suspense fallback={<FallbackAvatar />}>
|
||||||
|
<Avatar avatar={item.avatar} className='w-10 h-10' sizes='40px' />
|
||||||
|
</Suspense>
|
||||||
|
<div className="ml-4 space-y-0.5">
|
||||||
|
<p className="text-sm font-medium leading-none">{item.fullname}</p>
|
||||||
|
<p className="text-xs text-muted-foreground pb-2">
|
||||||
|
{item.position_name || '--'}
|
||||||
|
</p>
|
||||||
|
<p className="text-xs font-semibold text-muted-foreground border-t border-zinc-300 dark:border-zinc-800 pt-1 w-max">{dayjs(item.working_hours_start).format('ddd, DD MMM YYYY HH:mm')}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="text-xs space-y-1">
|
||||||
|
{item.working_status === 'WFH' ?
|
||||||
|
<Badge variant='secondary' className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
:
|
||||||
|
item.working_status === 'WFS' ?
|
||||||
|
<Badge className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
:
|
||||||
|
item.working_status === 'SKT' ?
|
||||||
|
<Badge variant='destructive' className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
:
|
||||||
|
<Badge variant='outline' className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
:
|
||||||
|
<div className="h-32 w-full flex justify-center items-center" >
|
||||||
|
No results.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{showDialog &&
|
||||||
|
<AlertDialog open={true}>
|
||||||
|
<AlertDialogContent className='max-w-full md:max-w-[760px] py-6 md:px-10 overflow-y-auto max-h-[95vh]'>
|
||||||
|
<AlertDialogHeader className='flex flex-row justify-between'>
|
||||||
|
<div>
|
||||||
|
<AlertDialogTitle>Detail Attendance</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
This action cannot be undone. This will permanently approve or decline this presence.
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</div>
|
||||||
|
<Button variant='outline' size='icon' disabled={isLoading} onClick={() => setShowDialog(false)}><i className="ti ti-x text-xl"></i ></Button>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<div className='grid grid-cols-1 md:grid-cols-5 text-center md:text-left text-sm md:text-base md:my-3'>
|
||||||
|
<div className='col-span-2 flex flex-col items-center md:items-start'>
|
||||||
|
<Suspense fallback={<FallbackAvatar className='w-52 h-52 rounded-xl' />}>
|
||||||
|
<ViewAvatar isPresence avatar={dataPresence.face_image} className='w-52 h-52 sm:w-52 sm:h-52 rounded-xl shadow' sizes='208px' />
|
||||||
|
</Suspense>
|
||||||
|
<span className='text-base font-semibold mt-2'>{dataPresence.user.fullname}</span>
|
||||||
|
<span className='text-muted-foreground'>{dataPresence?.user?.position?.name || dataPresence?.user.nickname}</span>
|
||||||
|
</div>
|
||||||
|
<div className='col-span-3 space-y-4 mt-5 md:mt-0'>
|
||||||
|
<div className='flex flex-col items-center md:items-start'>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Presence information :</p>
|
||||||
|
<div className='flex items-center space-x-2'>
|
||||||
|
<p><span className='font-semibold'>{dayjs(dataPresence.working_hours_start).format('dddd, DD MMMM YYYY')}</span></p>
|
||||||
|
<Badge>{dataPresence.working_status}</Badge>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Check-in time :</p>
|
||||||
|
<p>{dayjs(dataPresence.working_hours_start).format('HH:mm A')}</p>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Location :</p>
|
||||||
|
<p className='font-medium text-xs'>{dataPresence.latitude}, {dataPresence.longitude}</p>
|
||||||
|
<div>
|
||||||
|
{dataPresence.location_name || '-'}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Device :</p>
|
||||||
|
<p className='wrap-break-word'>{dataPresence.device.name || '-'}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Notes :</p>
|
||||||
|
<p className='wrap-break-word'>{dataPresence.note || '-'}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Check-out time :</p>
|
||||||
|
<p>{dataPresence?.presence_checkout?.working_hours_start ? dayjs(dataPresence?.presence_checkout?.working_hours_end).format('HH:mm A') : 'Not check-out yet'}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel disabled={isLoading} onClick={() => { setIsApproval(false); setShowConfirm(true) }} className='text-red-500 font-semibold'>
|
||||||
|
Decline
|
||||||
|
</AlertDialogCancel>
|
||||||
|
<AlertDialogAction disabled={isLoading} onClick={() => { setIsApproval(true); setShowConfirm(true) }}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
Approve
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
}
|
||||||
|
{showConfirm &&
|
||||||
|
<AlertDialog open={true}>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>Approval Confirmation</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
This action cannot be undone. This will permanently <span className='font-bold'>{isApproval ? 'Approve' : 'Decline'}</span> this presence.
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel disabled={isLoading} onClick={() => setShowConfirm(false)} className='text-red-500 font-semibold'>
|
||||||
|
Cancel
|
||||||
|
</AlertDialogCancel>
|
||||||
|
<AlertDialogAction disabled={isLoading} onClick={handleApproval}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
Continue
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
}
|
||||||
|
{isFullLoading && <PageLoading className='bg-opacity-40 dark:bg-opacity-20 z-999' />}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default NeedApproval;
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import {
|
||||||
|
Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle,
|
||||||
|
} from "@/components/ui/card"
|
||||||
|
import { Switch } from "@/components/ui/switch"
|
||||||
|
import {
|
||||||
|
Popover, PopoverContent, PopoverTrigger,
|
||||||
|
} from "@/components/ui/popover"
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import { getMessaging, onMessage } from 'firebase/messaging';
|
||||||
|
import firebaseApp from '@/lib/firebase';
|
||||||
|
import { Bell, BellRing } from 'lucide-react';
|
||||||
|
|
||||||
|
const notifications = [
|
||||||
|
{
|
||||||
|
title: "Your call has been confirmed.",
|
||||||
|
description: "1 hour ago",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "You have a new message!",
|
||||||
|
description: "1 hour ago",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Your subscription is expiring soon!",
|
||||||
|
description: "2 hours ago",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
type CardProps = React.ComponentProps<typeof Card>
|
||||||
|
|
||||||
|
function Notification({ className, ...props }: CardProps) {
|
||||||
|
// const { fcmToken, notificationPermissionStatus } = useFcmToken();
|
||||||
|
|
||||||
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof window !== 'undefined' && 'serviceWorker' in navigator) {
|
||||||
|
const messaging = getMessaging(firebaseApp);
|
||||||
|
const unsubscribe = onMessage(messaging, (payload) => {
|
||||||
|
console.log('Foreground push notification received:', payload);
|
||||||
|
// Handle the received push notification while the app is in the foreground
|
||||||
|
// You can display a notification or update the UI based on the payload
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
unsubscribe(); // Unsubscribe from the onMessage event
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Popover>
|
||||||
|
<PopoverTrigger asChild>
|
||||||
|
<Button variant="outline" size="icon">
|
||||||
|
<Bell />
|
||||||
|
</Button>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent align='end' forceMount className='w-[380px] px-0 py-6'>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Notifications</CardTitle>
|
||||||
|
<CardDescription>You have 3 unread messages.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="grid gap-4 mt-5">
|
||||||
|
<div className=" flex items-center space-x-4 rounded-xl border dark:border-zinc-800 p-4">
|
||||||
|
<BellRing size={32} />
|
||||||
|
<div className="flex-1 space-y-1">
|
||||||
|
<p className="text-sm font-medium leading-none">
|
||||||
|
Push Notifications
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Send notifications to device.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
{/* <Switch className='cursor-not-allowed' defaultChecked={fcmToken !== '' && notificationPermissionStatus !== ''} checked={fcmToken !== '' && notificationPermissionStatus !== ''} onCheckedChange={() => { }} /> */}
|
||||||
|
<Switch />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{notifications.map((notification, index) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className="mb-4 grid grid-cols-[25px_1fr] items-start pb-4 last:mb-0 last:pb-0"
|
||||||
|
>
|
||||||
|
<span className="flex h-2 w-2 translate-y-1 rounded-full bg-sky-500" />
|
||||||
|
<div className="space-y-1">
|
||||||
|
<p className="text-sm font-medium leading-none">
|
||||||
|
{notification.title}
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
{notification.description}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
<CardFooter className='mt-6'>
|
||||||
|
<Button className="w-full">
|
||||||
|
<i className="ti ti-check text-lg h-4 w-4 icon"></i> Mark all as read
|
||||||
|
</Button>
|
||||||
|
</CardFooter>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Notification;
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import Chart from 'react-apexcharts';
|
||||||
|
import { type ApexOptions } from 'apexcharts';
|
||||||
|
import { useTheme } from "next-themes";
|
||||||
|
|
||||||
|
export default function Overview() {
|
||||||
|
const { theme } = useTheme()
|
||||||
|
|
||||||
|
const barChartDataDailyTraffic = [
|
||||||
|
{
|
||||||
|
name: "Daily Traffic",
|
||||||
|
data: [
|
||||||
|
Math.floor(Math.random() * 5000) + 1000,
|
||||||
|
Math.floor(Math.random() * 5000) + 1000,
|
||||||
|
Math.floor(Math.random() * 5000) + 1000,
|
||||||
|
Math.floor(Math.random() * 5000) + 1000,
|
||||||
|
Math.floor(Math.random() * 5000) + 1000,
|
||||||
|
Math.floor(Math.random() * 5000) + 1000,
|
||||||
|
Math.floor(Math.random() * 5000) + 1000,
|
||||||
|
Math.floor(Math.random() * 5000) + 1000,
|
||||||
|
Math.floor(Math.random() * 5000) + 1000,
|
||||||
|
Math.floor(Math.random() * 5000) + 1000,
|
||||||
|
Math.floor(Math.random() * 5000) + 1000,
|
||||||
|
Math.floor(Math.random() * 5000) + 1000,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const barChartOptionsDailyTraffic: ApexOptions = {
|
||||||
|
chart: {
|
||||||
|
toolbar: {
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
theme: theme,
|
||||||
|
},
|
||||||
|
xaxis: {
|
||||||
|
categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
|
||||||
|
labels: {
|
||||||
|
show: true,
|
||||||
|
style: {
|
||||||
|
colors: theme === 'dark' ? '#fff' : "#707070",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
axisBorder: {
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
axisTicks: {
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
yaxis: {
|
||||||
|
show: false,
|
||||||
|
labels: {
|
||||||
|
show: true,
|
||||||
|
style: {
|
||||||
|
colors: "#CBD5E0",
|
||||||
|
fontSize: "14px",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
show: false,
|
||||||
|
strokeDashArray: 5,
|
||||||
|
yaxis: {
|
||||||
|
lines: {
|
||||||
|
show: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
xaxis: {
|
||||||
|
lines: {
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fill: {
|
||||||
|
type: "gradient",
|
||||||
|
gradient: {
|
||||||
|
type: "vertical",
|
||||||
|
shadeIntensity: 1,
|
||||||
|
opacityFrom: 0.7,
|
||||||
|
opacityTo: 0.9,
|
||||||
|
colorStops: [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
offset: 0,
|
||||||
|
color: "#adfa1d",
|
||||||
|
opacity: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
offset: 100,
|
||||||
|
color: "#00ff00",
|
||||||
|
opacity: 0.28,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
dataLabels: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
plotOptions: {
|
||||||
|
bar: {
|
||||||
|
borderRadius: 5,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-full h-[275px] sm:h-[420px] 2xl:h-[450px]">
|
||||||
|
<Chart
|
||||||
|
options={barChartOptionsDailyTraffic}
|
||||||
|
series={barChartDataDailyTraffic}
|
||||||
|
type="bar"
|
||||||
|
width="100%"
|
||||||
|
height="100%"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,178 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { FC, useState } from 'react';
|
||||||
|
import { type ApexOptions } from 'apexcharts';
|
||||||
|
import { useTheme } from 'next-themes';
|
||||||
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import ViewAvatar from '@/components/ViewAvatar';
|
||||||
|
import dynamic from 'next/dynamic';
|
||||||
|
import LazyLoading from '@/components/loader/LazyLoading';
|
||||||
|
|
||||||
|
const ReactApexChart = dynamic(() => import('react-apexcharts'), {
|
||||||
|
loading: () => <LazyLoading />,
|
||||||
|
ssr: false
|
||||||
|
});
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: any
|
||||||
|
};
|
||||||
|
|
||||||
|
const PieChart: FC<Props> = ({ data }) => {
|
||||||
|
const [selectedWorkingStatus, setSelectedWorkingStatus] = useState('')
|
||||||
|
|
||||||
|
// const { windowWidth } = useMobileView()
|
||||||
|
const { theme, systemTheme } = useTheme()
|
||||||
|
|
||||||
|
const options: ApexOptions = {
|
||||||
|
chart: {
|
||||||
|
width: 1000,
|
||||||
|
height: 1000,
|
||||||
|
// width: windowWidth > 800 ? 1000 : 400,
|
||||||
|
// height: windowWidth > 800 ? 1000 : 400,
|
||||||
|
events: {
|
||||||
|
click(e, chart, options) {
|
||||||
|
const { selectedDataPoints, labels } = options.globals
|
||||||
|
if (selectedDataPoints.length > 0) {
|
||||||
|
const workingStatus = labels[selectedDataPoints[0]]
|
||||||
|
setSelectedWorkingStatus(workingStatus?.toUpperCase())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted: (chart) => {
|
||||||
|
chart.windowResizeHandler();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plotOptions: {
|
||||||
|
pie: {
|
||||||
|
expandOnClick: true,
|
||||||
|
donut: {
|
||||||
|
size: '55%',
|
||||||
|
labels: {
|
||||||
|
show: true,
|
||||||
|
name: {
|
||||||
|
show: true,
|
||||||
|
color: theme === 'dark' ? '#fff' : theme === 'system' && systemTheme === 'dark' ? '#fff' : '#000',
|
||||||
|
fontSize: '20px',
|
||||||
|
fontWeight: 'bold'
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
show: true,
|
||||||
|
color: theme === 'dark' ? '#fff' : theme === 'system' && systemTheme === 'dark' ? '#fff' : '#000',
|
||||||
|
fontSize: '32px',
|
||||||
|
fontWeight: 'bold'
|
||||||
|
},
|
||||||
|
total: {
|
||||||
|
show: true,
|
||||||
|
showAlways: true,
|
||||||
|
color: theme === 'dark' ? '#fff' : theme === 'system' && systemTheme === 'dark' ? '#fff' : '#000',
|
||||||
|
label: 'Total',
|
||||||
|
formatter: function (w) {
|
||||||
|
return w.globals.seriesTotals.reduce((a: number, b: number) => {
|
||||||
|
return a + b
|
||||||
|
}, 0)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
legend: {
|
||||||
|
show: true,
|
||||||
|
position: 'right',
|
||||||
|
fontSize: '16px',
|
||||||
|
// position: windowWidth > 800 ? 'right' : 'bottom',
|
||||||
|
// fontSize: windowWidth > 800 ? '16px' : '12px',
|
||||||
|
labels: {
|
||||||
|
colors: theme === 'dark' ? '#fff' : theme === 'light' ? '#000' : '#a1a1aa',
|
||||||
|
// useSeriesColors: true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
stroke: {
|
||||||
|
width: 0
|
||||||
|
},
|
||||||
|
dataLabels: {
|
||||||
|
enabled: true,
|
||||||
|
formatter: function (val: any, opts) {
|
||||||
|
// console.log(opts)
|
||||||
|
return opts.w.globals.labels[opts.seriesIndex] + ': ' + opts.w.globals.series[opts.seriesIndex]
|
||||||
|
// return opts.w.globals.series[opts.seriesIndex]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fill: {
|
||||||
|
type: 'gradient',
|
||||||
|
},
|
||||||
|
labels: ['WFO', 'WFS', 'WFH', 'Cuti', 'Izin', 'Sakit', 'Belum Absen'],
|
||||||
|
colors: ['#3b82f6', '#10b981', '#db2777', '#8b5cf6', '#06b6d4', '#f59e0b', '#84cc16'],
|
||||||
|
responsive: [{
|
||||||
|
breakpoint: 800,
|
||||||
|
options: {
|
||||||
|
chart: {
|
||||||
|
width: 400
|
||||||
|
},
|
||||||
|
legend: {
|
||||||
|
fontSize: '12px',
|
||||||
|
position: 'bottom'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
const series = [data.total_wfo, data.total_wfs, data.total_wfh, data.total_ct01, data.total_iz01, data.total_skt, data.total_belum_absen]
|
||||||
|
|
||||||
|
const handleGetListEmployee = () => {
|
||||||
|
if (!selectedWorkingStatus) return []
|
||||||
|
|
||||||
|
if (selectedWorkingStatus === 'BELUM ABSEN') {
|
||||||
|
return data.list.filter((item: any) => item.status_presence?.includes('Belum'))
|
||||||
|
} else {
|
||||||
|
return data.list.filter((item: any) => item.working_status?.toUpperCase().includes(selectedWorkingStatus))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='h-[300px] sm:h-[350px] flex items-center justify-center'>
|
||||||
|
<ReactApexChart
|
||||||
|
type='donut'
|
||||||
|
options={options}
|
||||||
|
series={series}
|
||||||
|
// width={windowWidth > 800 ? 525 : 400}
|
||||||
|
width={525}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{selectedWorkingStatus &&
|
||||||
|
<Dialog open={selectedWorkingStatus !== ''} onOpenChange={() => setSelectedWorkingStatus('')}>
|
||||||
|
<DialogContent className='overflow-y-auto max-h-[90vh]'>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>List Employee</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
The following is a list of employees who are <span className='font-bold'>{selectedWorkingStatus}</span>.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className='space-y-5 mt-2'>
|
||||||
|
{handleGetListEmployee().length > 0 ? handleGetListEmployee().map((item: any, key: number) =>
|
||||||
|
<div className="flex items-center col-span-4" key={key}>
|
||||||
|
<ViewAvatar avatar={item.avatar} />
|
||||||
|
<div className="ml-4 space-y-0.5 max-w-[70%] 2xl:max-w-[80%]">
|
||||||
|
<p className="text-xs sm:text-sm font-medium leading-none">{item.fullname}</p>
|
||||||
|
<p className="text-xs md:text-sm text-muted-foreground">
|
||||||
|
{item.position_name || '--'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) :
|
||||||
|
<span>No result</span>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant='secondary' onClick={() => setSelectedWorkingStatus('')}>Close</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PieChart;
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { FC, lazy, Suspense, useState } from 'react';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
import FilterDataDashboard from './FilterDataDashboard';
|
||||||
|
import useFilterDataDashboard from '@/hooks/useFilterDataDashboard';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { getVariantWorkingStatus } from '@/lib/helper';
|
||||||
|
import FallbackAvatar from '@/components/loader/FallbackAvatar';
|
||||||
|
|
||||||
|
const ViewAvatar = lazy(() => import('@/components/ViewAvatar'));
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: any
|
||||||
|
className?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
const PresenceDetail: FC<Props> = ({ data, className }) => {
|
||||||
|
const [sort, setSort] = useState('desc')
|
||||||
|
const [search, setSearch] = useState('')
|
||||||
|
|
||||||
|
const dataFilter = useFilterDataDashboard(data.list || [], search, sort, 'status_presence', ['fullname', 'position_name', 'working_status', 'status_presence'])
|
||||||
|
|
||||||
|
// console.log(dataFilter)
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<FilterDataDashboard search={search} onSearch={e => setSearch(e.target.value)} sort={sort} onSortChange={val => setSort(val)} />
|
||||||
|
<ScrollArea className={cn("hidden sm:block px-6", className)} height='max-h-[325px]'>
|
||||||
|
<div className="space-y-8">
|
||||||
|
{data && data.list?.length > 0 ?
|
||||||
|
dataFilter.map((item: any, key: number) =>
|
||||||
|
<div className="grid grid-cols-8" key={key}>
|
||||||
|
<div className="flex items-center col-span-4">
|
||||||
|
<Suspense fallback={<FallbackAvatar />}>
|
||||||
|
<ViewAvatar avatar={item.avatar} />
|
||||||
|
</Suspense>
|
||||||
|
<div className="ml-4 space-y-0.5 max-w-[70%] 2xl:max-w-[80%]">
|
||||||
|
<p className="text-xs sm:text-sm font-medium leading-none">{item.fullname}</p>
|
||||||
|
<p className="text-xs md:text-sm text-muted-foreground">
|
||||||
|
{item.position_name || '--'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='col-span-2'>
|
||||||
|
{item.working_status ?
|
||||||
|
<Badge variant={getVariantWorkingStatus(item.working_status)}>{item.working_status}</Badge>
|
||||||
|
:
|
||||||
|
<Badge variant='outline'></Badge>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div className="font-medium text-sm col-span-2 text-right flex flex-col">
|
||||||
|
{item.working_status !== null ?
|
||||||
|
item.status_presence === 'Check Out' ?
|
||||||
|
<p className='text-rose-500 font-semibold'>{dayjs(item.working_hours_end).format("HH:mm A")}</p>
|
||||||
|
:
|
||||||
|
<p className='text-green-500 font-semibold'>{dayjs(item.working_hours_start).format("HH:mm A")}</p>
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
<p>{item.status_presence as any}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
:
|
||||||
|
<div className="h-32 w-full flex justify-center items-center" >
|
||||||
|
No results.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</ScrollArea>
|
||||||
|
|
||||||
|
{/* MOBILE VIEW */}
|
||||||
|
<div className={cn("overflow-y-auto block sm:hidden max-h-[325px] px-6", className)}>
|
||||||
|
<div className="space-y-8">
|
||||||
|
{data && data.list?.length > 0 ?
|
||||||
|
dataFilter.map((item: any, key: number) =>
|
||||||
|
<div className="flex justify-between" key={key}>
|
||||||
|
<div className="flex">
|
||||||
|
<Suspense fallback={<FallbackAvatar />}>
|
||||||
|
<ViewAvatar avatar={item.avatar} className='w-10 h-10' sizes='40px' />
|
||||||
|
</Suspense>
|
||||||
|
<div className="ml-4 space-y-0.5">
|
||||||
|
<p className="text-sm font-medium leading-none">{item.fullname}</p>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
{item.position_name || '--'}
|
||||||
|
</p>
|
||||||
|
<div className="font-medium text-xs flex item-center gap-2 pt-1">
|
||||||
|
<p>{item.status_presence as any}</p>
|
||||||
|
{(item.working_status === 'WFO' || item.working_status === 'WFH' || item.working_status === 'WFS') && item.working_status !== null ?
|
||||||
|
item.status_presence === 'Check Out' ?
|
||||||
|
<p className='text-rose-500 font-semibold'>{dayjs(item.working_hours_end).format("HH:mm A")}</p>
|
||||||
|
:
|
||||||
|
<p className='text-green-500 font-semibold'>{dayjs(item.working_hours_start).format("HH:mm A")}</p>
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
{item.status_presence === 'Belum Check In' && <p className='ml-1 text-muted-foreground font-normal'>--:--</p>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
{item.working_status ?
|
||||||
|
<Badge variant={getVariantWorkingStatus(item.working_status)}>{item.working_status}</Badge>
|
||||||
|
:
|
||||||
|
<Badge variant='outline'></Badge>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
:
|
||||||
|
<div className="h-32 w-full flex justify-center items-center" >
|
||||||
|
No results.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// const PresenceDetail: FC<Props> = ({ data }) => {
|
||||||
|
// return (
|
||||||
|
// <>
|
||||||
|
// <ScrollArea className="px-6" height='max-h-[325px]'>
|
||||||
|
// <div className="space-y-8">
|
||||||
|
// {data && data.list?.length > 0 ?
|
||||||
|
// data.list.map((item: any, key: number) =>
|
||||||
|
// <div className="flex items-center" key={key}>
|
||||||
|
// {item.avatar ?
|
||||||
|
// <img loading='lazy' alt="avatar" src={process.env.BASE_URL_IMG + item.avatar} className="h-9 w-9 shadow-sm rounded-full object-cover border border-border" />
|
||||||
|
// :
|
||||||
|
// <Image alt='avatar' height={0} width={0} quality={50} src='/assets/no-avatar.jpg' className='h-9 w-9 shadow-sm rounded-full object-cover' />
|
||||||
|
// }
|
||||||
|
// <div className="ml-4 space-y-0.5 max-w-[70%] 2xl:max-w-[80%]">
|
||||||
|
// <p className="text-xs sm:text-sm font-medium leading-none">{item.fullname}</p>
|
||||||
|
// <p className="text-xs md:text-sm text-muted-foreground">
|
||||||
|
// {item.position_name || '--'}
|
||||||
|
// </p>
|
||||||
|
// </div>
|
||||||
|
// <div className="ml-auto text-xs text-right space-y-1">
|
||||||
|
// {item.working_status === 'WFH' ?
|
||||||
|
// <Badge variant='secondary' className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
// :
|
||||||
|
// item.working_status === 'WFS' ?
|
||||||
|
// <Badge className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
// :
|
||||||
|
// item.working_status === 'SKT' ?
|
||||||
|
// <Badge variant='destructive' className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
// :
|
||||||
|
// <Badge variant='outline' className="text-[11px]">{item.working_status}</Badge>
|
||||||
|
// }
|
||||||
|
// <p className="ml-auto font-medium text-xs sm:text-sm">{item.status_presence as any}</p>
|
||||||
|
// </div>
|
||||||
|
// </div>
|
||||||
|
// )
|
||||||
|
// :
|
||||||
|
// <div className="h-32 w-full flex justify-center items-center" >
|
||||||
|
// No results.
|
||||||
|
// </div>
|
||||||
|
// }
|
||||||
|
// </div>
|
||||||
|
// </ScrollArea>
|
||||||
|
// </>
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
export default PresenceDetail;
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
import { FC, Fragment } from 'react';
|
||||||
|
import Link from 'next/link';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { getVariantApproved } from '@/lib/helper';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: any
|
||||||
|
};
|
||||||
|
|
||||||
|
const PresenceHistory: FC<Props> = ({ data }) => {
|
||||||
|
|
||||||
|
// console.log(data)
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ScrollArea className="px-6" height='max-h-[325px] sm:max-h-[370px]'>
|
||||||
|
<div className="space-y-6 overflow-x-auto">
|
||||||
|
{data && data.length > 0 ?
|
||||||
|
<>
|
||||||
|
{
|
||||||
|
data.slice(0, 4).map((item: any, key: number) =>
|
||||||
|
<Fragment key={key}>
|
||||||
|
{item.presence_checkout &&
|
||||||
|
<div className="flex sm:items-center" >
|
||||||
|
<div className="min-w-9 min-h-9 max-w-9 max-h-9 object-cover rounded-full flex grow-0 justify-center items-center bg-rose-100 text-rose-600 shadow-sm">
|
||||||
|
<i className="ti ti-logout icon text-xl"></i>
|
||||||
|
</div>
|
||||||
|
<div className='ml-4 space-y-1'>
|
||||||
|
<p className="text-xs sm:text-sm font-medium leading-none">{dayjs(item.presence_checkout?.working_hours_end).format('dddd, DD MMM YYYY')}</p>
|
||||||
|
{item.working_status === 'WFO' ?
|
||||||
|
item.presence_checkout.auto_checkout || item.presence_checkout.manual_presence ?
|
||||||
|
<div className='flex items-center'>
|
||||||
|
<p className='text-xs md:text-sm text-muted-foreground'>{item.working_status} - </p>
|
||||||
|
{item.presence_checkout.auto_checkout && <Badge className='ml-1' variant='his'>auto checkout</Badge>}
|
||||||
|
{item.presence_checkout.manual_presence && <Badge className='ml-1' variant='his'>manual presence</Badge>}
|
||||||
|
</div>
|
||||||
|
:
|
||||||
|
<p className='text-xs md:text-sm text-muted-foreground'>{item.presence_checkout?.device?.name} - {item.presence_checkout?.area ? item.presence_checkout?.area?.name : item.presence_checkout?.location_name}</p>
|
||||||
|
:
|
||||||
|
item.presence_checkout.auto_checkout || item.presence_checkout.manual_presence ?
|
||||||
|
<div className='flex items-center'>
|
||||||
|
<p className='text-xs md:text-sm text-muted-foreground'>{item.working_status} - </p>
|
||||||
|
{item.presence_checkout.auto_checkout && <Badge className='ml-1' variant='his'>auto checkout</Badge>}
|
||||||
|
{item.presence_checkout.manual_presence && <Badge className='ml-1' variant='his'>manual presence</Badge>}
|
||||||
|
</div>
|
||||||
|
:
|
||||||
|
<p className='text-xs md:text-sm text-muted-foreground'>
|
||||||
|
{
|
||||||
|
item.working_status + ' - ' + item.presence_checkout?.location_name
|
||||||
|
}
|
||||||
|
</p>
|
||||||
|
}
|
||||||
|
{item.is_clear_auto_checkout === false &&
|
||||||
|
<Badge>need to be approve</Badge>
|
||||||
|
}
|
||||||
|
{item.is_clear_auto_checkout === true &&
|
||||||
|
<Badge variant='secondary'>approved</Badge>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div className="ml-auto font-semibold text-xs sm:text-base min-w-[70px]! sm:min-w-[90px]! text-right text-rose-500">{dayjs(item.presence_checkout?.working_hours_end).format('HH:mm A')}</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
<div className="flex sm:items-center" >
|
||||||
|
<div className="min-w-9 min-h-9 max-w-9 max-h-9 object-cover rounded-full flex grow-0 justify-center items-center bg-green-100 text-green-600 shadow-sm">
|
||||||
|
<i className="ti ti-login icon text-xl"></i>
|
||||||
|
</div>
|
||||||
|
<div className={`ml-4 ${item.working_status === 'WFH' || item.working_status === 'WFS' ? 'space-y-0' : 'space-y-1'}`}>
|
||||||
|
<p className="text-xs sm:text-sm font-medium leading-none">{dayjs(item.working_hours_start).format('dddd, DD MMM YYYY')}</p>
|
||||||
|
<div className="text-xs md:text-sm text-muted-foreground">
|
||||||
|
{item.manual_presence ?
|
||||||
|
<div className='flex items-center'>
|
||||||
|
<p className='text-xs md:text-sm text-muted-foreground'>{item.working_status} - </p>
|
||||||
|
<Badge className='ml-1' variant='his'>manual presence</Badge>
|
||||||
|
</div>
|
||||||
|
:
|
||||||
|
item.working_status === 'WFO' ?
|
||||||
|
item.device.name + ' - ' + item.area.name
|
||||||
|
:
|
||||||
|
item.working_status + ' - ' + item.location_name
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
{!item.manual_presence && (item.working_status === 'WFH' || item.working_status === 'WFS') &&
|
||||||
|
<Badge variant={getVariantApproved(item.status.code)}>{item.status.name}</Badge>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div className="ml-auto font-semibold text-xs sm:text-base min-w-[70px]! sm:min-w-[90px]! text-right text-green-500">{dayjs(item.working_hours_start).format('HH:mm A')}</div>
|
||||||
|
</div>
|
||||||
|
</Fragment>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
<Link href='/history'>
|
||||||
|
<Button className="w-full mt-10">Show More</Button>
|
||||||
|
</Link>
|
||||||
|
</>
|
||||||
|
|
||||||
|
:
|
||||||
|
<div className="h-32 w-full flex justify-center items-center" >
|
||||||
|
No results.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</ScrollArea>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PresenceHistory;
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { FC, lazy, Suspense, useState } from 'react';
|
||||||
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import FilterDataDashboard from './FilterDataDashboard';
|
||||||
|
import useFilterDataDashboard from '@/hooks/useFilterDataDashboard';
|
||||||
|
import FallbackAvatar from '@/components/loader/FallbackAvatar';
|
||||||
|
|
||||||
|
const ViewAvatar = lazy(() => import('@/components/ViewAvatar'));
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: any
|
||||||
|
};
|
||||||
|
|
||||||
|
const TableEmployee: FC<Props> = ({ data }) => {
|
||||||
|
const [search, setSearch] = useState('')
|
||||||
|
const [sort, setSort] = useState('desc')
|
||||||
|
|
||||||
|
const dataFilter = useFilterDataDashboard(data.list || [], search, sort, 'fullname', ['fullname', 'position_name', 'email'])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<FilterDataDashboard placeholder='Search employee..' search={search} onSearch={e => setSearch(e.target.value)} sort={sort} onSortChange={val => setSort(val)} />
|
||||||
|
<ScrollArea className="px-6" height='max-h-[325px]'>
|
||||||
|
<div className="space-y-8">
|
||||||
|
{data && data.list?.length > 0 ?
|
||||||
|
dataFilter.map((item: any, key: number) =>
|
||||||
|
<div className="flex sm:items-center" key={key}>
|
||||||
|
<Suspense fallback={<FallbackAvatar />}>
|
||||||
|
<ViewAvatar avatar={item.avatar} />
|
||||||
|
</Suspense>
|
||||||
|
<div className="ml-4 space-y-0.5 max-w-[70%] 2xl:max-w-[80%]">
|
||||||
|
<p className="text-xs sm:text-sm font-medium leading-none">{item.fullname}</p>
|
||||||
|
<p className="text-xs md:text-sm text-muted-foreground">{item.position_name || '--'}</p>
|
||||||
|
<a href={`mailto:${item.email}`} referrerPolicy="no-referrer">
|
||||||
|
<Badge variant='outline' className='block sm:hidden'>{item.email}</Badge>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<a href={`mailto:${item.email}`} referrerPolicy="no-referrer" className="ml-auto text-xs text-right hidden sm:block">
|
||||||
|
<Badge variant='outline'>{item.email}</Badge>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
:
|
||||||
|
<div className="h-32 w-full flex justify-center items-center" >
|
||||||
|
No results.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</ScrollArea>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// const TableEmployee: FC<Props> = ({ data }) => {
|
||||||
|
// return (
|
||||||
|
// <>
|
||||||
|
// <Table>
|
||||||
|
// <TableHeader>
|
||||||
|
// <TableRow>
|
||||||
|
// <TableHead>Employee</TableHead>
|
||||||
|
// <TableHead>Email</TableHead>
|
||||||
|
// <TableHead>Phone</TableHead>
|
||||||
|
// <TableHead>Employee type</TableHead>
|
||||||
|
// </TableRow>
|
||||||
|
// </TableHeader>
|
||||||
|
// <TableBody>
|
||||||
|
// {data && data.list?.length > 0 ?
|
||||||
|
// data.list.map((item: any, key: number) =>
|
||||||
|
// <TableRow key={key} className="border-none">
|
||||||
|
// <TableCell className="flex items-center min-w-[15rem]">
|
||||||
|
// {item.avatar ?
|
||||||
|
// <img loading='lazy' alt="avatar" src={process.env.BASE_URL_IMG + item.avatar} className="h-9 w-9 sm:h-10 sm:w-10 shadow-sm rounded-full object-cover border border-border" />
|
||||||
|
// :
|
||||||
|
// <Image alt='avatar' height={0} width={0} quality={50} src='/assets/no-avatar.jpg' className='h-9 w-9 sm:h-10 sm:w-10 shadow-sm rounded-full object-cover' />
|
||||||
|
// }
|
||||||
|
// <div className="ml-4 space-y-0.5 2xl:max-w-[80%]">
|
||||||
|
// <p className="text-xs sm:text-sm font-medium leading-none">{item.fullname}</p>
|
||||||
|
// <p className="text-xs md:text-sm text-muted-foreground">
|
||||||
|
// {item.position_name || '--'}
|
||||||
|
// </p>
|
||||||
|
// </div>
|
||||||
|
// </TableCell>
|
||||||
|
// <TableCell>{item.email}</TableCell>
|
||||||
|
// <TableCell>{item.phone_number}</TableCell>
|
||||||
|
// <TableCell className="min-w-[24rem] text-xs sm:text-sm">{item.employee_type_name}</TableCell>
|
||||||
|
// </TableRow>
|
||||||
|
// )
|
||||||
|
// :
|
||||||
|
// <div className="h-32 w-full flex justify-center items-center" >
|
||||||
|
// No results.
|
||||||
|
// </div>
|
||||||
|
// }
|
||||||
|
// </TableBody>
|
||||||
|
// </Table>
|
||||||
|
// </>
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
export default TableEmployee;
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import Link from "next/link";
|
||||||
|
import { signOut, useSession } from "next-auth/react";
|
||||||
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||||
|
|
||||||
|
export function UserNav() {
|
||||||
|
const { data: session } = useSession()
|
||||||
|
// console.log("SESSION USER NAV :", session)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="ghost" className="relative h-10 w-10 rounded-full">
|
||||||
|
<Avatar className="h-10 w-10">
|
||||||
|
{session?.user.detail.avatar ?
|
||||||
|
<AvatarImage src={`${process.env.BASE_URL_IMG}/${session?.user.detail.avatar}`} alt={session?.user.detail.nickname} />
|
||||||
|
:
|
||||||
|
<AvatarImage src='/assets/no-avatar.jpg' alt={session?.user.detail.nickname} />
|
||||||
|
}
|
||||||
|
<AvatarFallback>HIS</AvatarFallback>
|
||||||
|
</Avatar>
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent className="min-w-56" align="end" forceMount>
|
||||||
|
<DropdownMenuLabel className="font-normal">
|
||||||
|
<div className="flex flex-col space-y-1">
|
||||||
|
<p className="text-sm font-medium leading-none capitalize">{session?.user.detail.fullname}</p>
|
||||||
|
<p className="text-xs leading-none text-muted-foreground lowercase">
|
||||||
|
{session?.user.detail.email}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</DropdownMenuLabel>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
<DropdownMenuGroup>
|
||||||
|
<Link href='/profile'>
|
||||||
|
<DropdownMenuItem>
|
||||||
|
Profile
|
||||||
|
<DropdownMenuShortcut>⇧⌘P</DropdownMenuShortcut>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</Link>
|
||||||
|
<Link href={`/performance/${session?.user.detail.id}`}>
|
||||||
|
<DropdownMenuItem>
|
||||||
|
My Performance
|
||||||
|
<DropdownMenuShortcut>⌘C</DropdownMenuShortcut>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</Link>
|
||||||
|
<Link href='/leave'>
|
||||||
|
<DropdownMenuItem>
|
||||||
|
Apply for Leave
|
||||||
|
<DropdownMenuShortcut>⌘L</DropdownMenuShortcut>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</Link>
|
||||||
|
<Link href='/work-permit'>
|
||||||
|
<DropdownMenuItem>
|
||||||
|
Permit & Sick
|
||||||
|
<DropdownMenuShortcut>⌘S</DropdownMenuShortcut>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</Link>
|
||||||
|
<Link href='/calendar'>
|
||||||
|
<DropdownMenuItem>
|
||||||
|
H.A.T.s Calendar
|
||||||
|
<DropdownMenuShortcut>⌘C</DropdownMenuShortcut>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</Link>
|
||||||
|
<Link href='/release-notes'>
|
||||||
|
<DropdownMenuItem>
|
||||||
|
Release Notes
|
||||||
|
<DropdownMenuShortcut>⌘R</DropdownMenuShortcut>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</Link>
|
||||||
|
</DropdownMenuGroup>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
<DropdownMenuItem onClick={() => { signOut(); }} className="text-red-500 font-medium">
|
||||||
|
Log out
|
||||||
|
<DropdownMenuShortcut>⇧⌘Q</DropdownMenuShortcut>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { FC, useEffect, useState } from 'react';
|
||||||
|
import { CardContent } from '@/components/ui/card';
|
||||||
|
import dayjs from "dayjs"
|
||||||
|
import duration from 'dayjs/plugin/duration'
|
||||||
|
import { generateHourMinutes } from '@/lib/helper';
|
||||||
|
|
||||||
|
dayjs.extend(duration)
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
alreadyCheckin?: boolean
|
||||||
|
alreadyCheckout?: boolean
|
||||||
|
checkinTime?: any
|
||||||
|
checkoutTime?: any
|
||||||
|
isRunning?: boolean
|
||||||
|
currentTotalTime?: number
|
||||||
|
};
|
||||||
|
|
||||||
|
const WorkingHours: FC<Props> = ({ alreadyCheckin, alreadyCheckout, checkinTime, checkoutTime, currentTotalTime, isRunning }) => {
|
||||||
|
const [totalTime, setTotalTime] = useState(currentTotalTime!)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const intervalId = setInterval(() => {
|
||||||
|
if (currentTotalTime && isRunning) {
|
||||||
|
setTotalTime(prev => prev + 1)
|
||||||
|
}
|
||||||
|
}, 1000)
|
||||||
|
|
||||||
|
return () => clearInterval(intervalId); //This is important
|
||||||
|
}, [isRunning, currentTotalTime])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<CardContent>
|
||||||
|
<div className="text-2xl font-bold">{generateHourMinutes(totalTime)}</div>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
number of hours you worked today
|
||||||
|
</p>
|
||||||
|
</CardContent>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// const WorkingHours: FC<Props> = ({ alreadyCheckin, alreadyCheckout, checkinTime, checkoutTime }) => {
|
||||||
|
// const [workingHours, setWorkingHours] = useState('0 hour')
|
||||||
|
|
||||||
|
// useEffect(() => {
|
||||||
|
// const intervalId = setInterval(() => {
|
||||||
|
// const checkInTimeInDayJS = dayjs(checkinTime)
|
||||||
|
// const checkoutTimeinDayJS = dayjs(checkoutTime)
|
||||||
|
|
||||||
|
// if (alreadyCheckin) {
|
||||||
|
// if (alreadyCheckout) {
|
||||||
|
// const duration = alreadyCheckin ? dayjs.duration(checkoutTimeinDayJS.diff(checkInTimeInDayJS)) : null
|
||||||
|
// if (duration) {
|
||||||
|
// const hours = duration.hours() || 0;
|
||||||
|
// const minutes = duration.minutes() || 0;
|
||||||
|
// setWorkingHours(`${hours} hours ${minutes} minutes`)
|
||||||
|
// }
|
||||||
|
// else setWorkingHours('0 hour')
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// const duration = alreadyCheckin ? dayjs.duration(dayjs().diff(checkInTimeInDayJS)) : null
|
||||||
|
// if (duration) {
|
||||||
|
// const hours = duration.hours() || 0;
|
||||||
|
// const minutes = duration.minutes() || 0;
|
||||||
|
// setWorkingHours(`${hours} hours ${minutes} minutes`)
|
||||||
|
// }
|
||||||
|
// else setWorkingHours('0 hour')
|
||||||
|
// }
|
||||||
|
// }, 1000)
|
||||||
|
|
||||||
|
// return () => clearInterval(intervalId); //This is important
|
||||||
|
// }, [alreadyCheckin, alreadyCheckout, checkinTime, checkoutTime])
|
||||||
|
|
||||||
|
// return (
|
||||||
|
// <>
|
||||||
|
// <CardContent>
|
||||||
|
// <div className="text-2xl font-bold">{workingHours}</div>
|
||||||
|
// <p className="text-xs text-muted-foreground">
|
||||||
|
// number of hours you worked today
|
||||||
|
// </p>
|
||||||
|
// </CardContent>
|
||||||
|
// </>
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
export default WorkingHours;
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useEffect } from "react"
|
||||||
|
import Image from "next/image"
|
||||||
|
import Link from "next/link"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
|
||||||
|
export default function Error({
|
||||||
|
error,
|
||||||
|
reset,
|
||||||
|
}: {
|
||||||
|
error: Error
|
||||||
|
reset: () => void
|
||||||
|
}) {
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log({ name: error.name, cause: error.cause, message: error.message, stack: error.stack })
|
||||||
|
}, [error])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="h-[90vh] flex flex-col justify-center items-center overflow-x-hidden overflow-y-auto py-5">
|
||||||
|
<Image alt='ilustrations' height={0} width={0} quality={70} src='/assets/illustrations/maintenance.svg' className='w-80 md:w-md 2xl:w-160 shadow-sm rounded-full object-cover' />
|
||||||
|
<h2 className="text-xl sm:text-2xl font-semibold tracking-tight text-center">Oopps.. something went wrong!</h2>
|
||||||
|
<span className="text-center mt-1 mb-6 text-zinc-600 dark:text-zinc-400 md:w-9/12 break-all px-2 sm:px-0">{error.message || 'Sorry, system error has occurred'}</span>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Button onClick={() => window.location.reload()} variant='secondary' className="w-28">Try Again</Button>
|
||||||
|
<Link href='/auth'>
|
||||||
|
<Button variant='outline' className="w-28">Login</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
|
import { Badge } from "@/components/ui/badge";
|
||||||
|
import { Users, UserMinus } from "lucide-react";
|
||||||
|
import { lazy, Suspense } from "react";
|
||||||
|
import FallbackAvatar from "@/components/loader/FallbackAvatar";
|
||||||
|
import { Metadata } from "next";
|
||||||
|
|
||||||
|
const ViewAvatar = lazy(() => import("@/components/ViewAvatar"))
|
||||||
|
|
||||||
|
interface TeamMember {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
role: string;
|
||||||
|
avatar?: string;
|
||||||
|
joinDate: string;
|
||||||
|
endDate?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const activeMembers: TeamMember[] = [
|
||||||
|
{
|
||||||
|
id: "9",
|
||||||
|
name: "Stevanus Akbar Alexander",
|
||||||
|
role: "Manager",
|
||||||
|
joinDate: "2013-01-02T00:00:00.000Z",
|
||||||
|
avatar: "images/avatar/12345667892-avatar.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "19",
|
||||||
|
name: "Luthfi Aditama",
|
||||||
|
role: "Team Leader",
|
||||||
|
joinDate: "2017-04-04T00:00:00.000Z",
|
||||||
|
avatar: "images/avatar/04021704068-avatar.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "20",
|
||||||
|
name: "Mohamad Saeful Ihsan",
|
||||||
|
role: "Team Leader",
|
||||||
|
joinDate: "2017-05-15T00:00:00.000Z",
|
||||||
|
avatar: "images/avatar/04021705070-avatar.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "3",
|
||||||
|
name: "Ichsan Kurniawan",
|
||||||
|
role: "Front End Programmer",
|
||||||
|
joinDate: "2019-10-23T00:00:00.000Z",
|
||||||
|
avatar: "images/avatar/04031910149-avatar.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "8",
|
||||||
|
name: "Amalia Mandawati",
|
||||||
|
role: "Technical Writer",
|
||||||
|
joinDate: "2024-10-07T00:00:00.000Z",
|
||||||
|
avatar: "images/avatar/29121997000-avatar.png"
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const pastMembers: TeamMember[] = [
|
||||||
|
{
|
||||||
|
id: "2",
|
||||||
|
name: "Evan Arifial Hidayat",
|
||||||
|
role: "Mobile Programmer",
|
||||||
|
joinDate: "2022-04-01T00:00:00.000Z",
|
||||||
|
endDate: "2024-07-04T00:00:00.000Z",
|
||||||
|
avatar: "images/avatar/04032204216-avatar.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "10",
|
||||||
|
name: "Nofita Mahfudiyah",
|
||||||
|
role: "Technical Writer",
|
||||||
|
joinDate: "2022-09-22T00:00:00.000Z",
|
||||||
|
endDate: "2024-09-19T00:00:00.000Z",
|
||||||
|
avatar: "images/avatar/04032209230-avatar.png",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
const TeamMemberCard = ({ member, isPast = false }: { member: TeamMember; isPast?: boolean }) => {
|
||||||
|
const getRoleColor = (role: string) => {
|
||||||
|
switch (role.toLowerCase()) {
|
||||||
|
case "manager":
|
||||||
|
return "bg-amber-500/20 text-amber-700 dark:text-amber-500 border-amber-300";
|
||||||
|
case "team leader":
|
||||||
|
return "bg-purple-500/20 text-purple-700 dark:text-purple-400 border-purple-300";
|
||||||
|
case "front end programmer":
|
||||||
|
return "bg-cyan-500/20 text-cyan-700 dark:text-cyan-400 border-cyan-300";
|
||||||
|
case "mobile programmer":
|
||||||
|
return "bg-green-500/20 text-green-700 dark:text-green-400 border-green-300";
|
||||||
|
case "back end programmer":
|
||||||
|
return "bg-blue-500/20 text-blue-700 dark:text-blue-400 border-blue-300";
|
||||||
|
default:
|
||||||
|
return "bg-muted text-muted-foreground";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className={`transition-all duration-300 hover:shadow-lg ${isPast ? "opacity-70" : "hover:-translate-y-1"}`}>
|
||||||
|
<CardContent className="p-6 text-center">
|
||||||
|
<Suspense fallback={<FallbackAvatar className="w-20 h-20" />}>
|
||||||
|
<ViewAvatar avatar={member.avatar!} className={`rounded-full min-w-20 min-h-20 mx-auto ring-4 ${isPast ? "ring-muted" : "ring-primary/20"}`} sizes="80px" quality={75} />
|
||||||
|
</Suspense>
|
||||||
|
|
||||||
|
<h3 className={`font-semibold text-lg mb-1 mt-4 ${isPast ? "text-muted-foreground" : "text-foreground"}`}>
|
||||||
|
{member.name}
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<Badge variant="outline" className={`mb-3 ${getRoleColor(member.role)}`}>
|
||||||
|
{member.role}
|
||||||
|
</Badge>
|
||||||
|
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
{isPast ? (
|
||||||
|
<>
|
||||||
|
Joined: {new Date(member.joinDate).toLocaleDateString("id-ID", { year: "numeric", month: "short" })}
|
||||||
|
<br />
|
||||||
|
Ended: {new Date(member.endDate!).toLocaleDateString("id-ID", { year: "numeric", month: "short" })}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>Joined since {new Date(member.joinDate).toLocaleDateString("id-ID", { year: "numeric", month: "long" })}</>
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "Team - HIS Attendance Task System (H.A.T.s)",
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function HATsTeamPage() {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="flex items-center gap-4 sm:p-8 pt-6 px-6">
|
||||||
|
<div>
|
||||||
|
<h1 className="text-lg sm:text-3xl font-medium tracking-tight capitalize">H.A.T.s Team</h1>
|
||||||
|
<p className="text-xs md:text-base text-muted-foreground sm:mt-1">Get to know the Team behind this application.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<main className="container mx-auto px-4 pt-2 pb-6 space-y-12 xl:space-y-14">
|
||||||
|
{/* Active Members Section */}
|
||||||
|
<section>
|
||||||
|
<div className="flex items-center gap-3 mb-6">
|
||||||
|
<div className="p-2 bg-teal-500/30 rounded-lg">
|
||||||
|
<Users className="h-6 w-6 text-primary" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h2 className="text-2xl font-bold text-foreground">Current Team</h2>
|
||||||
|
<p className="text-muted-foreground">{activeMembers.length} team members who continuously work on developing and improving this application</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
|
||||||
|
{activeMembers.map((member) => (
|
||||||
|
<TeamMemberCard key={member.id} member={member} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{/* Past Members Section */}
|
||||||
|
<section>
|
||||||
|
<div className="flex items-center gap-3 mb-6">
|
||||||
|
<div className="p-2 bg-his/30 rounded-lg">
|
||||||
|
<UserMinus className="h-6 w-6 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h2 className="text-2xl font-bold text-foreground">Past Members</h2>
|
||||||
|
<p className="text-muted-foreground">Thank you for your valuable contributions</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
|
||||||
|
{pastMembers.map((member) => (
|
||||||
|
<TeamMemberCard key={member.id} member={member} isPast />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { Fragment, useMemo } from "react"
|
||||||
|
import dayjs from "dayjs"
|
||||||
|
import { useSearchParams } from "next/navigation"
|
||||||
|
|
||||||
|
import {
|
||||||
|
Table, TableBody, TableCell, TableHead, TableHeader, TableRow,
|
||||||
|
} from "@/components/ui/table"
|
||||||
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
import Pagination from "@/components/pagination"
|
||||||
|
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog"
|
||||||
|
import { getVariantApproved } from "@/lib/helper"
|
||||||
|
import { IHistory } from "../components/type"
|
||||||
|
import SortFilter from "../components/SortFilter"
|
||||||
|
import { CircleCheck } from "lucide-react"
|
||||||
|
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: IHistory[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function DataTable({ data }: Props) {
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
const currentPage = Number(searchParams!.get('page') as string) || 1;
|
||||||
|
const pageSize = Number(searchParams!.get('limit') as string) || 10;
|
||||||
|
const savedSort = searchParams!.get('sort') as string || ''
|
||||||
|
|
||||||
|
const currentTableData = useMemo(() => {
|
||||||
|
const newData = [...data]
|
||||||
|
if (savedSort && savedSort === 'asc') {
|
||||||
|
newData.sort((a, b) => (dayjs(a.working_hours_start).isAfter(dayjs(b.working_hours_start)) ? 1 : -1))
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstPageIndex = (currentPage - 1) * pageSize;
|
||||||
|
const lastPageIndex = firstPageIndex + pageSize;
|
||||||
|
return newData.slice(firstPageIndex, lastPageIndex);
|
||||||
|
}, [currentPage, pageSize, savedSort, data]);
|
||||||
|
|
||||||
|
// console.log(currentTableData)
|
||||||
|
|
||||||
|
const getTotalRows = () => {
|
||||||
|
let rowCount = 0;
|
||||||
|
data.forEach(entry => {
|
||||||
|
if (entry.presence_checkout !== null) {
|
||||||
|
rowCount += 2;
|
||||||
|
} else {
|
||||||
|
rowCount += 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return rowCount
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log(data)
|
||||||
|
const handleOpenMaps = (lat: any, long: any) => {
|
||||||
|
const url = `http://maps.google.com/maps?q=${lat}+${long}`
|
||||||
|
window.open(url, '_blank');
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log(data)
|
||||||
|
return (
|
||||||
|
<div className="w-full pt-2">
|
||||||
|
<SortFilter data={data} />
|
||||||
|
<div className="rounded-md border border-border mb-5">
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow >
|
||||||
|
<TableHead>Type</TableHead>
|
||||||
|
<TableHead>Date</TableHead>
|
||||||
|
<TableHead>Time</TableHead>
|
||||||
|
<TableHead>Time Code</TableHead>
|
||||||
|
<TableHead>Location</TableHead>
|
||||||
|
<TableHead>Device</TableHead>
|
||||||
|
<TableHead>Area</TableHead>
|
||||||
|
<TableHead>Note</TableHead>
|
||||||
|
<TableHead>Manual Presence</TableHead>
|
||||||
|
<TableHead>Auto Checkout</TableHead>
|
||||||
|
<TableHead>Approval</TableHead>
|
||||||
|
<TableHead>Photo</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{currentTableData.length > 0 ? (
|
||||||
|
currentTableData.map((row, key) => (
|
||||||
|
<Fragment key={key}>
|
||||||
|
{row.presence_checkout &&
|
||||||
|
<TableRow>
|
||||||
|
<TableCell className="text-center"><Badge variant='secondary'>Checkout</Badge></TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<div className="flex space-x-2">
|
||||||
|
<Badge variant="outline">{row.working_status}</Badge>
|
||||||
|
<span className="max-w-[500px] truncate font-medium">
|
||||||
|
{dayjs(row.presence_checkout?.presence_date).format('dddd, DD MMM YYYY')}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="truncate">{dayjs(row.presence_checkout?.working_hours_end).format('HH:mm A')}</TableCell>
|
||||||
|
<TableCell className="truncate min-w-28">CO-{Number(dayjs(row.presence_checkout?.working_hours_end).format('HH'))}</TableCell>
|
||||||
|
<TableCell className="truncate max-w-120 cursor-pointer hover:text-his duration-200" title={row.presence_checkout?.location_name} onClick={() => handleOpenMaps(row.presence_checkout.latitude, row.presence_checkout.longitude)}>
|
||||||
|
{row.presence_checkout?.location_name}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="truncate">{row.presence_checkout?.device?.name}</TableCell>
|
||||||
|
<TableCell className="truncate">{row.presence_checkout?.area?.name}</TableCell>
|
||||||
|
<TableCell className="truncate max-w-[20rem]" title={row.presence_checkout.note}>{row.presence_checkout.note}</TableCell>
|
||||||
|
<TableCell className="min-w-[150px] text-center">{row.presence_checkout?.manual_presence && <CircleCheck className="text-green-500" />}</TableCell>
|
||||||
|
<TableCell className="min-w-[140px] text-center">{row.presence_checkout?.auto_checkout && <CircleCheck className="text-green-500" />}</TableCell>
|
||||||
|
<TableCell className="min-w-[170px]">{row.is_clear_auto_checkout === true ?
|
||||||
|
<Badge variant='secondary'>approved</Badge> : row.is_clear_auto_checkout === false ? <Badge>need to be approve</Badge> : null
|
||||||
|
}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="min-w-[120px]">
|
||||||
|
{row.presence_checkout.face_image ?
|
||||||
|
<Dialog>
|
||||||
|
<DialogTrigger asChild><span className="text-his cursor-pointer hover:opacity-70 duration-200">View Photo</span></DialogTrigger>
|
||||||
|
<DialogContent className="p-0 w-full sm:w-[450px] rounded-2xl">
|
||||||
|
<img loading='lazy' alt="avatar" src={process.env.BASE_URL_IMG + row.presence_checkout?.face_image} className="w-full h-full shadow-sm rounded-2xl border border-border" />
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
}
|
||||||
|
<TableRow>
|
||||||
|
<TableCell className="text-center"><Badge>Checkin</Badge></TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<div className="flex space-x-2">
|
||||||
|
<Badge variant="outline">{row.working_status}</Badge>
|
||||||
|
<span className="max-w-[500px] truncate font-medium">
|
||||||
|
{dayjs(row.presence_date).format('dddd, DD MMM YYYY')}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="truncate">{dayjs(row.working_hours_start).format('HH:mm A')}</TableCell>
|
||||||
|
<TableCell className="truncate min-w-28">CI-{Number(dayjs(row.working_hours_start).format('HH'))}</TableCell>
|
||||||
|
<TableCell className="truncate max-w-120 cursor-pointer hover:text-his duration-200" title={row.location_name} onClick={() => handleOpenMaps(row.latitude, row.longitude)}>{row.location_name}</TableCell>
|
||||||
|
<TableCell className="truncate">{row.device.name}</TableCell>
|
||||||
|
<TableCell className="truncate">{row.area?.name}</TableCell>
|
||||||
|
<TableCell className="truncate max-w-[20rem]" title={row.note}>{row.note}</TableCell>
|
||||||
|
<TableCell className="min-w-[150px] text-center">{row.manual_presence && <CircleCheck className="text-green-500" />}</TableCell>
|
||||||
|
<TableCell></TableCell>
|
||||||
|
<TableCell className="min-w-[170px]">{!row.manual_presence && (row.working_status === 'WFH' || row.working_status === 'WFS') ?
|
||||||
|
<Badge variant={getVariantApproved(row.status?.code as any)}>{row.status?.name}</Badge> : <></>
|
||||||
|
}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="min-w-[120px]">
|
||||||
|
{row.face_image ?
|
||||||
|
<Dialog>
|
||||||
|
<DialogTrigger asChild><span className="text-his cursor-pointer hover:opacity-70 duration-200">View Photo</span></DialogTrigger>
|
||||||
|
<DialogContent className="p-0 w-full sm:w-[450px] rounded-2xl">
|
||||||
|
<img loading='lazy' alt="avatar" src={process.env.BASE_URL_IMG + row.face_image} className="w-full h-full shadow-sm rounded-2xl border border-border" />
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
</Fragment>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={12} className="h-32 text-center" >
|
||||||
|
No results.
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div >
|
||||||
|
|
||||||
|
<Pagination totalRowinTable={getTotalRows()} totalRows={data.length} />
|
||||||
|
</div >
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { Suspense, lazy } from 'react';
|
||||||
|
import { getServerSession } from 'next-auth';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||||
|
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||||
|
import LazyLoading from '@/components/loader/LazyLoading';
|
||||||
|
import { type IHistory } from '../components/type';
|
||||||
|
|
||||||
|
const DataTable = lazy(() => import('./DataTable'));
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function AttendanceHistory({ searchParams }: Props) {
|
||||||
|
const start_date = (await searchParams)!.start_date
|
||||||
|
const end_date = (await searchParams)!.end_date
|
||||||
|
const search = (await searchParams)!.search
|
||||||
|
|
||||||
|
const session = await getServerSession(authOptions)
|
||||||
|
const data = await fetchDataWithPost('/presence/history', { nik: session?.user.detail.nik, start_date: start_date || dayjs().subtract(1, 'month'), end_date: end_date || dayjs().add(1, 'month').format('YYYY-MM-DD') })
|
||||||
|
|
||||||
|
const getFilterData = () => {
|
||||||
|
if (data.history && data.history.length > 0) {
|
||||||
|
if (search) {
|
||||||
|
const text = search.toString().toLowerCase()
|
||||||
|
return data.history.filter((item: IHistory) => (
|
||||||
|
item.working_status?.toLowerCase() === text ||
|
||||||
|
item.location_name?.toLowerCase().includes(text) ||
|
||||||
|
item.device?.name?.toLowerCase().includes(text) ||
|
||||||
|
item.area?.name?.toLowerCase().includes(text) ||
|
||||||
|
item.note?.toLowerCase().includes(text)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
return data.history
|
||||||
|
}
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<DataTable data={getFilterData()} />
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { FC } from 'react';
|
||||||
|
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { DatePicker } from 'antd';
|
||||||
|
|
||||||
|
type Props = {};
|
||||||
|
|
||||||
|
const DateRangePicker: FC<Props> = () => {
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
const router = useRouter()
|
||||||
|
const path = usePathname()
|
||||||
|
|
||||||
|
const savedTab = searchParams!.get('tab') as string || '';
|
||||||
|
const savedLimit = Number(searchParams!.get('limit') as string) || 10;
|
||||||
|
const savedSort = searchParams!.get('sort') as string || '';
|
||||||
|
const startDate = searchParams!.get('start_date') as string || dayjs().subtract(1, 'month')
|
||||||
|
const endDate = searchParams!.get('end_date') as string || dayjs().add(1, 'month')
|
||||||
|
|
||||||
|
const handleGetQuery = () => {
|
||||||
|
const query = new URLSearchParams();
|
||||||
|
if (savedTab) query.set('tab', savedTab.toString());
|
||||||
|
if (savedLimit) query.set('limit', savedLimit.toString());
|
||||||
|
if (savedSort) query.set('sort', savedSort.toString());
|
||||||
|
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleChange = (values: any) => {
|
||||||
|
const existQuery = handleGetQuery()
|
||||||
|
|
||||||
|
if (values) {
|
||||||
|
const url = `${path}?start_date=${dayjs(values[0]).format('YYYY-MM-DD')}&end_date=${dayjs(values[1]).format('YYYY-MM-DD')}&page=1&${existQuery}`
|
||||||
|
router.replace(url)
|
||||||
|
} else {
|
||||||
|
const url = `${path}?${existQuery}`
|
||||||
|
router.replace(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DatePicker.RangePicker size='large' className='p-2 rounded-lg'
|
||||||
|
onChange={handleChange} defaultValue={[dayjs(startDate), dayjs(endDate)]}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DateRangePicker;
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
'use client'
|
||||||
|
import { FC, useState } from 'react';
|
||||||
|
import { useSession } from 'next-auth/react';
|
||||||
|
import { useSearchParams } from 'next/navigation';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { Icons } from '@/components/Icons';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { exportEmployeeHistory, exportTable } from '@/lib/exportExcel';
|
||||||
|
import { type IUser } from '@/app/admin/administration/user/component/type';
|
||||||
|
import type { ILeaveSickPermit, IHistory } from './type';
|
||||||
|
import { type IExcelJSColumnType } from '@/types/types';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: ILeaveSickPermit[] | IHistory[]
|
||||||
|
};
|
||||||
|
|
||||||
|
const ExportComponent: FC<Props> = ({ data }) => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
|
||||||
|
const { data: session } = useSession()
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
const tab = searchParams!.get('tab');
|
||||||
|
|
||||||
|
const handleExport = async () => {
|
||||||
|
setIsLoading(true)
|
||||||
|
if (tab === 'leave-permit') {
|
||||||
|
const columns: IExcelJSColumnType[] = [
|
||||||
|
{ header: 'No', key: 'number', width: 5, style: { numFmt: '0;[Red]0' } },
|
||||||
|
{ header: 'Application Code', key: 'application_form_code' },
|
||||||
|
{ header: 'N I K', key: 'nik' },
|
||||||
|
{ header: 'Employee', key: 'fullname' },
|
||||||
|
{ header: 'Category', key: 'category_name' },
|
||||||
|
{ header: 'Address', key: 'contact_street' },
|
||||||
|
{ header: 'City', key: 'contact_city' },
|
||||||
|
{ header: 'Start Date', key: 'start_date', style: { numFmt: 'dd/mm/yyyy' } },
|
||||||
|
{ header: 'End Date', key: 'end_date', style: { numFmt: 'dd/mm/yyyy' } },
|
||||||
|
{ header: 'Return to Work', key: 'return_to_work_date', style: { numFmt: 'dd/mm/yyyy' } },
|
||||||
|
{ header: 'Note', key: 'note' },
|
||||||
|
{ header: 'Apply at', key: 'created_at', style: { numFmt: 'dd/mm/yyyy' } },
|
||||||
|
{ header: 'Approved by', key: 'approved_by' },
|
||||||
|
{ header: 'Approved at', key: 'approved_at', style: { numFmt: 'dd/mm/yyyy' } },
|
||||||
|
{ header: 'Rejected by', key: 'rejected_by' },
|
||||||
|
{ header: 'Rejected at', key: 'rejected_at', style: { numFmt: 'dd/mm/yyyy' } },
|
||||||
|
]
|
||||||
|
|
||||||
|
const resBlob: any = await exportTable(session?.user.detail as IUser, data, columns, 'Leave, Permit and Sick Report')
|
||||||
|
if (resBlob) {
|
||||||
|
const url = URL.createObjectURL(resBlob);
|
||||||
|
|
||||||
|
// Create a link and trigger a click event to start the download
|
||||||
|
const a = document.createElement("a");
|
||||||
|
a.style.display = "none";
|
||||||
|
a.href = url;
|
||||||
|
a.download = `Leave, Permit and Sick Report - ${dayjs().format('YYYYMMDD HH:mm:ssa')}`; // Set the downloaded filename
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
|
||||||
|
// Clean up by removing the temporary link and URL
|
||||||
|
document.body.removeChild(a);
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const resBlob: any = await exportEmployeeHistory(session?.user.detail as IUser, data as IHistory[])
|
||||||
|
if (resBlob) {
|
||||||
|
/* USE THIS IF RES IS Base64String */
|
||||||
|
// window.open(
|
||||||
|
// res as string,
|
||||||
|
// '_blank', // <- This is what makes it open in a new window.
|
||||||
|
// );
|
||||||
|
|
||||||
|
//// Convert the response to blob and create a temporary URL
|
||||||
|
// const blob = await res.blob();
|
||||||
|
const url = URL.createObjectURL(resBlob);
|
||||||
|
|
||||||
|
// Create a link and trigger a click event to start the download
|
||||||
|
const a = document.createElement("a");
|
||||||
|
a.style.display = "none";
|
||||||
|
a.href = url;
|
||||||
|
a.download = `Attendance History - ${session?.user.detail.nickname} - ${dayjs().format('YYYYMMDD HHmmssa')}`; // Set the downloaded filename
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
|
||||||
|
// Clean up by removing the temporary link and URL
|
||||||
|
document.body.removeChild(a);
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button className="flex" disabled={isLoading} onClick={handleExport}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
Export
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ExportComponent;
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import { FC, useEffect, useState } from 'react';
|
||||||
|
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||||
|
import useDebounce from '@/hooks/useDebounce';
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import ExportComponent from './Export';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data?: any[]
|
||||||
|
};
|
||||||
|
|
||||||
|
const SortFilter: FC<Props> = ({ data }) => {
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
const router = useRouter()
|
||||||
|
const path = usePathname()
|
||||||
|
|
||||||
|
const savedTab = searchParams!.get('tab') as string || ''
|
||||||
|
const startDate = searchParams!.get('start_date') as string || ''
|
||||||
|
const endDate = searchParams!.get('end_date') as string || ''
|
||||||
|
const savedSort = searchParams!.get('sort') as string || ''
|
||||||
|
const savedPage = Number(searchParams!.get('page') as string) || 1;
|
||||||
|
const savedLimit = Number(searchParams!.get('limit') as string) || 10;
|
||||||
|
const savedSearch = searchParams!.get('search') as string || ''
|
||||||
|
|
||||||
|
const [search, setSearch] = useState(savedSearch);
|
||||||
|
const debouncedSearch = useDebounce(search, 1000);
|
||||||
|
|
||||||
|
const handleGetQuery = () => {
|
||||||
|
const query = new URLSearchParams();
|
||||||
|
if (savedTab) query.set('tab', savedTab.toString());
|
||||||
|
if (savedLimit) query.set('limit', savedLimit.toString());
|
||||||
|
if (startDate) query.set('start_date', startDate.toString());
|
||||||
|
if (endDate) query.set('end_date', endDate.toString());
|
||||||
|
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSortChange = (val: string) => {
|
||||||
|
const existQuery = handleGetQuery()
|
||||||
|
|
||||||
|
const url = `${path}?search=${savedSearch}&sort=${val}&page=${savedPage}&${existQuery}`
|
||||||
|
router.replace(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const existQuery = handleGetQuery()
|
||||||
|
|
||||||
|
const url = `${path}?search=${debouncedSearch}&sort=${savedSort}&page=1&${existQuery}`
|
||||||
|
router.replace(url)
|
||||||
|
}, [debouncedSearch])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='flex flex-col sm:flex-row py-4 sm:space-x-2 space-y-2 sm:space-y-0'>
|
||||||
|
<div className="flex items-center justify-between w-full">
|
||||||
|
<Input placeholder="Filter data..." className="max-w-sm" value={search} onChange={(e) => setSearch(e.target.value)} />
|
||||||
|
<Select value={savedSort} onValueChange={handleSortChange}>
|
||||||
|
<SelectTrigger className="ml-auto w-[100px]">
|
||||||
|
<SelectValue placeholder="Sort" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="asc">Asc</SelectItem>
|
||||||
|
<SelectItem value="desc">Desc</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<ExportComponent data={data!} />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SortFilter;
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
'use client'
|
||||||
|
import { FC } from 'react';
|
||||||
|
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||||
|
|
||||||
|
type Props = {};
|
||||||
|
|
||||||
|
const TabsComponent: FC<Props> = () => {
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
const savedTab = searchParams!.get('tab') as string || ''
|
||||||
|
const startDate = searchParams!.get('start_date') as string || dayjs().subtract(1, 'month')
|
||||||
|
const endDate = searchParams!.get('end_date') as string || dayjs().add(1, 'month')
|
||||||
|
const router = useRouter()
|
||||||
|
const path = usePathname()
|
||||||
|
|
||||||
|
|
||||||
|
const handleGetQuery = () => {
|
||||||
|
const query = new URLSearchParams();
|
||||||
|
if (startDate) query.set('start_date', dayjs(startDate.toString()).format('YYYY-MM-DD'));
|
||||||
|
if (endDate) query.set('end_date', dayjs(endDate.toString()).format('YYYY-MM-DD'));
|
||||||
|
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleChange = (tab: string) => {
|
||||||
|
const existQuery = handleGetQuery()
|
||||||
|
const url = `${path}?tab=${tab}&${existQuery}`
|
||||||
|
router.replace(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tabs defaultValue={savedTab ? savedTab as string : 'attendance'} className='sm:w-[385px]'>
|
||||||
|
<TabsList className="grid w-full grid-cols-2 bg-white dark:bg-zinc-900 h-10">
|
||||||
|
<TabsTrigger className='focus-visible:ring-zinc-500 ring-offset-soft data-[state=active]:bg-soft data-[state=active]:text-zinc-950' value="attendance" onClick={() => handleChange('attendance')}>Attendance</TabsTrigger>
|
||||||
|
<TabsTrigger className='focus-visible:ring-zinc-500 ring-offset-soft data-[state=active]:bg-soft data-[state=active]:text-zinc-950' value="leave-permit" onClick={() => handleChange('leave-permit')}>Leave, Permit & Sick</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
</Tabs>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TabsComponent;
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
export type IHistory = {
|
||||||
|
presence_checkin_code: string
|
||||||
|
nik: string
|
||||||
|
user: {
|
||||||
|
fullname: string
|
||||||
|
nickname: string
|
||||||
|
}
|
||||||
|
presence_date: string
|
||||||
|
working_hours_start: string
|
||||||
|
working_status: string
|
||||||
|
area: {
|
||||||
|
"code": string,
|
||||||
|
"name": string
|
||||||
|
}
|
||||||
|
location_name: string
|
||||||
|
latitude: Number
|
||||||
|
longitude: Number
|
||||||
|
device: {
|
||||||
|
code: string
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
manual_presence: boolean
|
||||||
|
status: {
|
||||||
|
code: string
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
note: string
|
||||||
|
auto_checkout: boolean
|
||||||
|
is_clear_auto_checkout: boolean
|
||||||
|
face_image: string
|
||||||
|
presence_checkout: IResponseCheckout
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IResponseCheckout extends IHistory {
|
||||||
|
presence_checkout_code: string
|
||||||
|
working_hours_end: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ILeaveSickPermit = {
|
||||||
|
id: number,
|
||||||
|
application_form_code: string,
|
||||||
|
sent_to: string,
|
||||||
|
user_id: number,
|
||||||
|
nik: string,
|
||||||
|
niktg: string,
|
||||||
|
nickname: string,
|
||||||
|
fullname: string,
|
||||||
|
gender: string,
|
||||||
|
avatar: string,
|
||||||
|
division_id: number,
|
||||||
|
division_code: string,
|
||||||
|
division_name: string,
|
||||||
|
category_id: number,
|
||||||
|
category_code: string,
|
||||||
|
category_name: string,
|
||||||
|
tag: string[],
|
||||||
|
start_date: string,
|
||||||
|
end_date: string,
|
||||||
|
return_to_work_date: string,
|
||||||
|
contact_street: string,
|
||||||
|
contact_city: string,
|
||||||
|
contact_phone_number: string,
|
||||||
|
created_at: string,
|
||||||
|
created_by: string,
|
||||||
|
updated_at: string,
|
||||||
|
updated_by: string,
|
||||||
|
deleted_at: string,
|
||||||
|
deleted_by: string,
|
||||||
|
approved_at: string,
|
||||||
|
approved_by: string,
|
||||||
|
rejected_at: string,
|
||||||
|
rejected_by: string,
|
||||||
|
note: string,
|
||||||
|
hc_checked_at: string,
|
||||||
|
hc_checked_by: string,
|
||||||
|
hc_approved_at: string,
|
||||||
|
hc_approved_by: string,
|
||||||
|
position_name: string,
|
||||||
|
evidence_image: string,
|
||||||
|
status_id: number,
|
||||||
|
cc: any[]
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useMemo } from "react"
|
||||||
|
import dayjs from "dayjs"
|
||||||
|
import { useSearchParams } from "next/navigation"
|
||||||
|
|
||||||
|
import {
|
||||||
|
Table, TableBody, TableCell, TableHead, TableHeader, TableRow,
|
||||||
|
} from "@/components/ui/table"
|
||||||
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
import Pagination from "@/components/pagination"
|
||||||
|
import { getVariantWorkingStatus } from "@/lib/helper"
|
||||||
|
import SortFilter from "../components/SortFilter"
|
||||||
|
import { type ILeaveSickPermit } from "../components/type"
|
||||||
|
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: ILeaveSickPermit[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function DataTable({ data }: Props) {
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
const currentPage = Number(searchParams!.get('page') as string) || 1;
|
||||||
|
const pageSize = Number(searchParams!.get('limit') as string) || 10;
|
||||||
|
const savedSort = searchParams!.get('sort') as string || ''
|
||||||
|
|
||||||
|
const currentTableData = useMemo(() => {
|
||||||
|
const newData = [...data]
|
||||||
|
if (savedSort && savedSort === 'asc') {
|
||||||
|
newData.sort((a, b) => (dayjs(a.start_date).isAfter(dayjs(b.start_date)) ? 1 : -1))
|
||||||
|
} else if (savedSort && savedSort === 'desc') {
|
||||||
|
newData.sort((b, a) => (dayjs(a.start_date).isAfter(dayjs(b.start_date)) ? 1 : -1))
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstPageIndex = (currentPage - 1) * pageSize;
|
||||||
|
const lastPageIndex = firstPageIndex + pageSize;
|
||||||
|
return newData.slice(firstPageIndex, lastPageIndex);
|
||||||
|
}, [currentPage, pageSize, savedSort, data]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-full pt-2">
|
||||||
|
<SortFilter data={data} />
|
||||||
|
<div className="rounded-md border border-border mb-5">
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow >
|
||||||
|
<TableHead>Category</TableHead>
|
||||||
|
<TableHead>Start Date</TableHead>
|
||||||
|
<TableHead>End Date</TableHead>
|
||||||
|
<TableHead>Return to Work</TableHead>
|
||||||
|
<TableHead>Address</TableHead>
|
||||||
|
<TableHead>City</TableHead>
|
||||||
|
<TableHead>Note</TableHead>
|
||||||
|
<TableHead>Apply at</TableHead>
|
||||||
|
<TableHead>Approval Status</TableHead>
|
||||||
|
<TableHead>Approval by</TableHead>
|
||||||
|
<TableHead>Approval at</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{currentTableData.length > 0 ? (
|
||||||
|
currentTableData.map((row, key) => (
|
||||||
|
<TableRow key={key}>
|
||||||
|
<TableCell className="text-center min-w-[135px]"><Badge variant={getVariantWorkingStatus(row.category_name)}>{row.category_name}</Badge></TableCell>
|
||||||
|
<TableCell className="truncate">{dayjs(row.start_date).format('YYYY-MM-DD')}</TableCell>
|
||||||
|
<TableCell className="truncate">{dayjs(row.end_date).format('YYYY-MM-DD')}</TableCell>
|
||||||
|
<TableCell className="truncate min-w-[140px]">{dayjs(row.return_to_work_date).format('YYYY-MM-DD')}</TableCell>
|
||||||
|
<TableCell className="truncate max-w-120" title={row.contact_street}>{row.contact_street}</TableCell>
|
||||||
|
<TableCell className="truncate max-w-[20rem]">{row.contact_city}</TableCell>
|
||||||
|
<TableCell className="truncate max-w-[20rem]">{row.note}</TableCell>
|
||||||
|
<TableCell className="truncate">{dayjs(row.created_at).format('YYYY-MM-DD')}</TableCell>
|
||||||
|
<TableCell className='text-center min-w-[170px]'>
|
||||||
|
{row.approved_at ?
|
||||||
|
<Badge variant='secondary'>approved</Badge> : row.rejected_at ? <Badge variant='destructive'>rejected</Badge> : <Badge>need to be approve</Badge>
|
||||||
|
}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className='min-w-[210px]'>
|
||||||
|
{row.approved_by ?
|
||||||
|
row.approved_by : row.rejected_by ? row.rejected_by : null
|
||||||
|
}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className='min-w-[150px]'>
|
||||||
|
{row.approved_at ?
|
||||||
|
dayjs(row.approved_at).format('YYYY-MM-DD HH:mm') : row.rejected_at ? dayjs(row.rejected_at).format('YYYY-MM-DD HH:mm') : null
|
||||||
|
}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={11} className="h-32 text-center" >
|
||||||
|
No results.
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Pagination totalRows={data.length} />
|
||||||
|
</div >
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { Suspense, lazy } from 'react';
|
||||||
|
import { getServerSession } from 'next-auth';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||||
|
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||||
|
import LazyLoading from '@/components/loader/LazyLoading';
|
||||||
|
import { type ILeaveSickPermit } from '../components/type';
|
||||||
|
|
||||||
|
const DataTable = lazy(() => import('./DataTable'));
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function LeavePermitHistory({ searchParams }: Props) {
|
||||||
|
const start_date = (await searchParams)!.start_date
|
||||||
|
const end_date = (await searchParams)!.end_date
|
||||||
|
const search = (await searchParams)!.search
|
||||||
|
|
||||||
|
const session = await getServerSession(authOptions)
|
||||||
|
const data = await fetchDataWithPost('/application-form/history', { nik: session?.user.detail.nik, start_date: start_date || dayjs().subtract(1, 'month'), end_date: end_date || dayjs().add(1, 'month').format('YYYY-MM-DD') })
|
||||||
|
|
||||||
|
const getFilterData = () => {
|
||||||
|
if (data.history && data.history.length > 0) {
|
||||||
|
if (search) {
|
||||||
|
const text = search.toString().toLowerCase()
|
||||||
|
return data.history.filter((item: ILeaveSickPermit) => (
|
||||||
|
item.category_name?.toLowerCase() === text ||
|
||||||
|
item.contact_street?.toLowerCase() === text ||
|
||||||
|
item.contact_city?.toLowerCase() === text ||
|
||||||
|
item.note?.toLowerCase() === text ||
|
||||||
|
item.approved_by?.toLowerCase().includes(text) ||
|
||||||
|
item.rejected_by?.toLowerCase().includes(text)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
return data.history
|
||||||
|
}
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<DataTable data={getFilterData()} />
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import SkeletonTable from "@/components/skeleton/SkeletonTable"
|
||||||
|
import { Skeleton } from "@/components/ui/skeleton"
|
||||||
|
|
||||||
|
export default function Loading() {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col w-full p-6">
|
||||||
|
<div className="flex justify-between items-center w-full">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="h-8 w-40" />
|
||||||
|
<Skeleton className="h-6 w-96" />
|
||||||
|
</div>
|
||||||
|
<Skeleton className="h-10 w-36 rounded-2xl" />
|
||||||
|
</div>
|
||||||
|
<SkeletonTable />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import { type Metadata } from "next";
|
||||||
|
|
||||||
|
import DateRangePicker from "./components/DateRangePicker";
|
||||||
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
|
import { Suspense, lazy } from "react";
|
||||||
|
import SkeletonTable from "@/components/skeleton/SkeletonTable";
|
||||||
|
import TabsComponent from "./components/Tabs";
|
||||||
|
import { getServerSession } from "next-auth";
|
||||||
|
import { authOptions } from "@/pages/api/auth/[...nextauth]";
|
||||||
|
|
||||||
|
const AttendanceHistory = lazy(() => import("./attendance"));
|
||||||
|
const LeavePermitHistory = lazy(() => import("./leave-permit"));
|
||||||
|
|
||||||
|
|
||||||
|
export async function generateMetadata(): Promise<Metadata> {
|
||||||
|
const session = await getServerSession(authOptions)
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: `History - ${session?.user?.detail.fullname || 'User'}`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function HistoryPage({ searchParams }: Props) {
|
||||||
|
const tab = (await searchParams)!.tab
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="flex-1 space-y-8 p-6 sm:p-8 pt-6 pb-36 md:pb-8">
|
||||||
|
<div className="flex flex-col sm:flex-row items-start justify-between space-y-2 sm:space-y-0">
|
||||||
|
<div>
|
||||||
|
<h1 className="text-lg sm:text-3xl font-medium tracking-tight capitalize">Attendance History</h1>
|
||||||
|
<p className="text-xs md:text-base text-muted-foreground sm:mt-1">Here is list of your attendance history</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<DateRangePicker />
|
||||||
|
{/* <ExportComponent data={all.history} /> */}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<TabsComponent />
|
||||||
|
<Card>
|
||||||
|
<CardContent>
|
||||||
|
<Suspense fallback={<SkeletonTable />} key={tab as string}>
|
||||||
|
{tab === 'leave-permit' ?
|
||||||
|
<LeavePermitHistory searchParams={searchParams} />
|
||||||
|
:
|
||||||
|
<AttendanceHistory searchParams={searchParams} />
|
||||||
|
}
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* <Card>
|
||||||
|
<CardContent>
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<DataTable data={getFilterData()} />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card> */}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,179 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { FC, useEffect, useState } from 'react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { useSession } from 'next-auth/react';
|
||||||
|
import { Camera as CameraIcon } from 'lucide-react';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { FormDescription, FormLabel } from '@/components/ui/form';
|
||||||
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
|
import { Separator } from '@/components/ui/separator';
|
||||||
|
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||||
|
import { Icons } from '@/components/Icons';
|
||||||
|
import CameraV2 from '../../presence-v2/components/CameraV2';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
|
type Props = {};
|
||||||
|
|
||||||
|
const FormComponent: FC<Props> = () => {
|
||||||
|
const OFFICE_PEJATEN_LATTITUDE = -6.27831622506824
|
||||||
|
const OFFICE_PEJATEN_LONGITUDE = 106.82955901443484
|
||||||
|
|
||||||
|
const [showCamera, setShowCamera] = useState(true)
|
||||||
|
const [photo, setPhoto] = useState('')
|
||||||
|
const [locationName, setLocationName] = useState('')
|
||||||
|
const [latitude, setLatitude] = useState(OFFICE_PEJATEN_LATTITUDE)
|
||||||
|
const [longitude, setLongitude] = useState(OFFICE_PEJATEN_LONGITUDE)
|
||||||
|
const [note, setNote] = useState('')
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
const [orientation, setOrientation] = useState<'portrait' | 'landscape' | 'square'>('portrait')
|
||||||
|
|
||||||
|
const { data: session } = useSession()
|
||||||
|
const router = useRouter()
|
||||||
|
const axios = useAxiosAuth()
|
||||||
|
|
||||||
|
const options: PositionOptions = {
|
||||||
|
enableHighAccuracy: false,
|
||||||
|
timeout: 10000,
|
||||||
|
maximumAge: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
const successCallback = (position: GeolocationPosition) => {
|
||||||
|
const x = position.coords.latitude;
|
||||||
|
const y = position.coords.longitude;
|
||||||
|
setLatitude(x); setLongitude(y)
|
||||||
|
displayLocation(x, y);
|
||||||
|
};
|
||||||
|
|
||||||
|
const errorCallback = (error: GeolocationPositionError) => {
|
||||||
|
let errorMessage = 'Unknown error';
|
||||||
|
switch (error.code) {
|
||||||
|
case 1:
|
||||||
|
errorMessage = 'Permission denied';
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
errorMessage = 'Position unavailable';
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
errorMessage = 'Timeout';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
toast.warning("Failed to fetch geolocation, reason: " + errorMessage)
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!navigator.geolocation) {
|
||||||
|
toast.warning('Geolocation not available in your apps')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
navigator.geolocation.getCurrentPosition(successCallback, errorCallback, options);
|
||||||
|
}, [successCallback])
|
||||||
|
|
||||||
|
|
||||||
|
const displayLocation = async (latitude: number, longitude: number) => {
|
||||||
|
const res = await fetch(`https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=jsonv2&zoom=13`)
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json()
|
||||||
|
console.log(data?.display_name)
|
||||||
|
setLocationName(data?.display_name)
|
||||||
|
} else {
|
||||||
|
alert(`${res.status} ${res.statusText}`)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleReceivePhoto = (photo: string, landscape?: boolean, w?: number, h?: number) => {
|
||||||
|
setOrientation(w! > h! ? 'landscape' : w === h ? 'square' : 'portrait')
|
||||||
|
setPhoto(photo)
|
||||||
|
setShowCamera(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit = () => {
|
||||||
|
|
||||||
|
if (!photo) {
|
||||||
|
toast.error('Photo is required!')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!note) {
|
||||||
|
toast.error('Please add a little notes!')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsLoading(true)
|
||||||
|
const payload = {
|
||||||
|
nik: session?.user.detail.nik,
|
||||||
|
location_name: locationName,
|
||||||
|
latitude,
|
||||||
|
longitude,
|
||||||
|
device_code: "40001",
|
||||||
|
note: note,
|
||||||
|
image: photo ? photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '') : '',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
console.log(payload)
|
||||||
|
axios.post('/presence/check-in/i-am-here', payload).then(res => {
|
||||||
|
toast.info(`Update Presence success`)
|
||||||
|
router.replace('/')
|
||||||
|
router.refresh()
|
||||||
|
}).catch(error => {
|
||||||
|
setIsLoading(false)
|
||||||
|
toast.error(`Update Presence failed`, { description: `(${error.response?.data?.code || error.response?.status || '-'}) ${error.response?.data?.message || error.response?.statusText || error.message}` })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='space-y-8'>
|
||||||
|
<div className='flex flex-col justify-center items-center space-y-5'>
|
||||||
|
{photo ?
|
||||||
|
<img alt='' src={photo} className={`btn-outline ${orientation === 'portrait' ? 'w-36 h-48' : orientation === 'landscape' ? 'w-48 h-36' : 'w-48 h-48'} rounded-xl object-cover shadow`} />
|
||||||
|
:
|
||||||
|
<div className='btn-outline w-36 h-48 rounded-xl flex items-center justify-center bg-zinc-200 dark:bg-zinc-800'></div>
|
||||||
|
}
|
||||||
|
<Button variant='outline' onClick={() => setShowCamera(true)}>
|
||||||
|
<CameraIcon className='mr-2 w-4 h-4' />Retake photo
|
||||||
|
</Button>
|
||||||
|
<div className='space-y-2 flex flex-col items-center'>
|
||||||
|
<div className='flex items-center space-x-2 text-xs sm:text-sm text-muted-foreground'>
|
||||||
|
<i className="ti ti-map-pin icon text-xl"></i>
|
||||||
|
<p>{OFFICE_PEJATEN_LATTITUDE}, {OFFICE_PEJATEN_LONGITUDE}</p>
|
||||||
|
</div>
|
||||||
|
<div className='flex items-center text-sm text-center w-full md:w-9/12'>
|
||||||
|
<p>{locationName}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Separator />
|
||||||
|
|
||||||
|
<div className='flex flex-col items-center space-y-3 w-full'>
|
||||||
|
<div className=' w-full space-y-2'>
|
||||||
|
<FormLabel>Note</FormLabel>
|
||||||
|
<Textarea
|
||||||
|
placeholder="Tell us a little bit about your presence"
|
||||||
|
className="resize-none" value={note} onChange={(e) => setNote(e.target.value)}
|
||||||
|
/>
|
||||||
|
<FormDescription>
|
||||||
|
Tambahkan catatan kehadiran jika diperlukan
|
||||||
|
</FormDescription>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex flex-col space-y-2'>
|
||||||
|
<Button type="submit" disabled={isLoading} onClick={handleSubmit}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
<Button variant='outline' onClick={() => router.back()} disabled={isLoading} >Cancel</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{showCamera && <CameraV2 onClose={() => setShowCamera(false)} onSubmit={handleReceivePhoto} />}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default FormComponent;
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import { FC, Suspense, lazy } from 'react';
|
||||||
|
import { type Metadata } from 'next';
|
||||||
|
import { redirect } from 'next/navigation';
|
||||||
|
import { Separator } from '@/components/ui/separator';
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import PageLoading from '@/components/loader/PageLoading';
|
||||||
|
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||||
|
import { getServerSession } from 'next-auth';
|
||||||
|
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||||
|
|
||||||
|
const FormComponent = lazy(() => import('./components/FormComponent'))
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "I'am Here",
|
||||||
|
description: "Employee update presence page.",
|
||||||
|
}
|
||||||
|
|
||||||
|
type Props = {};
|
||||||
|
|
||||||
|
const IamHerePage: FC<Props> = async () => {
|
||||||
|
const session = await getServerSession(authOptions)
|
||||||
|
const res = await fetchDataWithPost('/presence/last-status/today', { nik: session?.user.detail.nik })
|
||||||
|
|
||||||
|
if (res && res.is_checkin && res.device_code === '11001') {
|
||||||
|
redirect('/')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res && !res.is_checkin) {
|
||||||
|
redirect('/')
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='flex-1 w-full md:w-[800px] mx-auto px-5 py-10 md:p-10 pb-40 md:pb-10'>
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<div className='flex justify-center items-center flex-col'>
|
||||||
|
<CardTitle className="text-lg font-medium">I'am Here</CardTitle>
|
||||||
|
<p className="text-sm text-muted-foreground">Update your presence information with the latest data.</p>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<Separator className='w-10/12 xl:w-11/12 mx-auto' />
|
||||||
|
<CardContent className='mt-6'>
|
||||||
|
<Suspense fallback={<PageLoading />}>
|
||||||
|
<FormComponent />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default IamHerePage;
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { Suspense, lazy } from "react"
|
||||||
|
import LazyLoading from "@/components/loader/LazyLoading"
|
||||||
|
import Link from "next/link"
|
||||||
|
|
||||||
|
const Header = lazy(() => import("./components/Header"))
|
||||||
|
const FooterV2 = lazy(() => import("./components/FooterV2"))
|
||||||
|
// const Footer = lazy(() => import("./components/Footer"))
|
||||||
|
|
||||||
|
export default function HomeLayout({
|
||||||
|
children, // will be a page or nested layout
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<section className="flex flex-col h-screen overflow-y-hidden bg-soft dark:bg-zinc-950">
|
||||||
|
<div className="overflow-x-hidden overflow-y-auto min-h-screen flex flex-col">
|
||||||
|
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<Header />
|
||||||
|
</Suspense>
|
||||||
|
|
||||||
|
<div className="w-full 2xl:w-[1400px] mx-auto">
|
||||||
|
{/* <div> */}
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* <Footer /> */}
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<FooterV2 />
|
||||||
|
</Suspense>
|
||||||
|
|
||||||
|
<div className="mt-auto flex flex-col items-center justify-between pt-2 pb-6 px-3 sm:px-0 text-xs md:text-sm font-medium text-zinc-400 text-center gap-1">
|
||||||
|
<p className="mx-auto w-9/12 sm:w-full">© {new Date().getFullYear()} - H.A.T.s | Design & Develop by <Link href='/hats-team' className="hover:text-his hover:font-semibold hover:translate-y-2 duration-300">H.I.S Dev Super Team 😎</Link></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,381 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { ChangeEvent, FC, FormEvent, useRef, useState } from 'react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { DatePicker } from 'antd';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { PDFDocument } from 'pdf-lib';
|
||||||
|
import SignaturePad from "react-signature-canvas";
|
||||||
|
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||||
|
import { readFile } from '@/lib/helper';
|
||||||
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
|
import { Separator } from '@/components/ui/separator';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { Select as MultiSelect } from 'antd'
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Icons } from '@/components/Icons';
|
||||||
|
import { Switch } from '@/components/ui/switch';
|
||||||
|
import { type IProfile } from '../../profile/components/type';
|
||||||
|
import { type ResponseData } from '@/types/types';
|
||||||
|
import { type RangePickerProps } from 'antd/es/date-picker';
|
||||||
|
import relativeTime from "dayjs/plugin/relativeTime";
|
||||||
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import "dayjs/locale/id";
|
||||||
|
import { Label } from '@/components/ui/label';
|
||||||
|
|
||||||
|
dayjs.extend(customParseFormat);
|
||||||
|
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
TL_LIST?: any[]
|
||||||
|
};
|
||||||
|
|
||||||
|
const Component: FC<Props> = ({ TL_LIST }) => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
const [leaveType, setLeaveType] = useState('')
|
||||||
|
const [otherLeave, setOtherLeave] = useState('')
|
||||||
|
const [leavePeriod, setLeavePeriod] = useState<any>([])
|
||||||
|
const [leaveIn, setLeaveIn] = useState<any>(null)
|
||||||
|
const [address, setAddress] = useState('')
|
||||||
|
const [city, setCity] = useState('')
|
||||||
|
const [includeSign, setIncludeSign] = useState(false)
|
||||||
|
const [imgSign, setImgSign] = useState('')
|
||||||
|
const [signLabelUploaded, setSignLabelUploaded] = useState('Or upload your sign')
|
||||||
|
const [mentionsTo, setMentionsTo] = useState([])
|
||||||
|
|
||||||
|
const axios = useAxiosAuth()
|
||||||
|
const router = useRouter()
|
||||||
|
const signCanvas = useRef<SignaturePad>(null);
|
||||||
|
|
||||||
|
|
||||||
|
dayjs.locale("id");
|
||||||
|
dayjs.extend(relativeTime);
|
||||||
|
|
||||||
|
const handleSubmit = async (e: FormEvent<HTMLFormElement>, preview?: boolean) => {
|
||||||
|
e && e?.preventDefault()
|
||||||
|
setIsLoading(true)
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!leaveType) return handleError('Leave type cannot be empty!')
|
||||||
|
if (!leavePeriod || leavePeriod.length !== 2) return handleError('Leave period is not valid!')
|
||||||
|
if (!leaveIn) return handleError('Please select leave in first!')
|
||||||
|
if (!address) return handleError('Your data is not complete yet!')
|
||||||
|
if (!city) return handleError('Your data is not complete yet!')
|
||||||
|
|
||||||
|
const { data } = await axios.post('/user/profile', {})
|
||||||
|
const { data: profile }: ResponseData<IProfile> = data
|
||||||
|
|
||||||
|
const url = '/files/form_cuti_empty.pdf'
|
||||||
|
const existingPdfBytes = await fetch(url).then(res => res.arrayBuffer())
|
||||||
|
|
||||||
|
const pdfDoc = await PDFDocument.load(existingPdfBytes)
|
||||||
|
// const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||||
|
|
||||||
|
const pages = pdfDoc.getPages()
|
||||||
|
const firstPage = pages[0]
|
||||||
|
|
||||||
|
firstPage.drawText(profile.division?.name || '', { x: 165, y: 672, size: 11 }) // DEPARTMENT
|
||||||
|
firstPage.drawText(new Date().getFullYear().toString(), { x: 500, y: 672, size: 11 }) // YEAR
|
||||||
|
firstPage.drawText('Stevanus Akbar Alexander', { x: 243, y: 646, size: 11 }) // MGR DEPARTMENT
|
||||||
|
firstPage.drawText(profile.fullname, { x: 243, y: 628, size: 11 }) // NAME
|
||||||
|
firstPage.drawText(profile.position?.name || '', { x: 243, y: 608, size: 11 }) // Positiion
|
||||||
|
/* CUTI TAHUNAN */
|
||||||
|
if (leaveType === 'CT') {
|
||||||
|
firstPage.drawText('x', { x: 244, y: 582, size: 16 })
|
||||||
|
}
|
||||||
|
/* CUTI BESAR */
|
||||||
|
if (leaveType === 'CB') {
|
||||||
|
firstPage.drawText('x', { x: 244, y: 555, size: 16 })
|
||||||
|
}
|
||||||
|
/* CUTI MELAHIRKAN */
|
||||||
|
if (leaveType === 'CM') {
|
||||||
|
firstPage.drawText('x', { x: 374, y: 582, size: 16 })
|
||||||
|
}
|
||||||
|
/* LAINNYA */
|
||||||
|
if (leaveType === 'CL') {
|
||||||
|
firstPage.drawText('x', { x: 374, y: 555, size: 16 })
|
||||||
|
firstPage.drawText(otherLeave, { x: 443, y: 558, size: 10 })
|
||||||
|
}
|
||||||
|
|
||||||
|
firstPage.drawText(dayjs(leavePeriod[0]).format('dddd'), { x: 340, y: 506, size: 11 })
|
||||||
|
firstPage.drawText(dayjs(leavePeriod[0]).format('DD').split('')[0] + ' ' + dayjs(leavePeriod[0]).format('DD').split('')[1], { x: 416, y: 505, size: 13 })
|
||||||
|
firstPage.drawText(dayjs(leavePeriod[0]).format('MM').split('')[0] + ' ' + dayjs(leavePeriod[0]).format('MM').split('')[1], { x: 471, y: 505, size: 13 })
|
||||||
|
firstPage.drawText(dayjs(leavePeriod[0]).format('YY').split('')[0] + ' ' + dayjs(leavePeriod[0]).format('YY').split('')[1], { x: 522, y: 505, size: 13 })
|
||||||
|
|
||||||
|
firstPage.drawText(dayjs(leavePeriod[1]).format('dddd'), { x: 340, y: 483, size: 11 })
|
||||||
|
firstPage.drawText(dayjs(leavePeriod[1]).format('DD').split('')[0] + ' ' + dayjs(leavePeriod[1]).format('DD').split('')[1], { x: 416, y: 482, size: 13 })
|
||||||
|
firstPage.drawText(dayjs(leavePeriod[1]).format('MM').split('')[0] + ' ' + dayjs(leavePeriod[1]).format('MM').split('')[1], { x: 471, y: 482, size: 13 })
|
||||||
|
firstPage.drawText(dayjs(leavePeriod[1]).format('YY').split('')[0] + ' ' + dayjs(leavePeriod[1]).format('YY').split('')[1], { x: 522, y: 482, size: 13 })
|
||||||
|
|
||||||
|
firstPage.drawText(dayjs(leaveIn).format('dddd'), { x: 340, y: 461, size: 11 })
|
||||||
|
firstPage.drawText(dayjs(leaveIn).format('DD').split('')[0] + ' ' + dayjs(leaveIn).format('DD').split('')[1], { x: 416, y: 460, size: 13 })
|
||||||
|
firstPage.drawText(dayjs(leaveIn).format('MM').split('')[0] + ' ' + dayjs(leaveIn).format('MM').split('')[1], { x: 471, y: 460, size: 13 })
|
||||||
|
firstPage.drawText(dayjs(leaveIn).format('YY').split('')[0] + ' ' + dayjs(leaveIn).format('YY').split('')[1], { x: 522, y: 460, size: 13 })
|
||||||
|
|
||||||
|
|
||||||
|
firstPage.drawText(address, { x: 285, y: 428, size: 10 })
|
||||||
|
firstPage.drawText(city, { x: 285, y: 406, size: 11 })
|
||||||
|
firstPage.drawText(profile.phone_number || '', { x: 285, y: 384, size: 11 })
|
||||||
|
|
||||||
|
|
||||||
|
// firstPage.drawText(session?.user.detail.fullname!, { x: 167, y: 350, size: 10 })
|
||||||
|
firstPage.drawText(dayjs().format('DD MMMM YYYY'), { x: 167, y: 323, size: 10 })
|
||||||
|
|
||||||
|
firstPage.drawText('(' + profile.fullname.substring(0, 21) + ')', { x: 54, y: 230, size: 9 })
|
||||||
|
firstPage.drawText('(' + 'Stevanus Akbar Alexander'.substring(0, 21) + ')', { x: 161, y: 230, size: 9 })
|
||||||
|
|
||||||
|
if (includeSign && !signCanvas.current?.isEmpty()) {
|
||||||
|
const sign = await pdfDoc.embedPng(signCanvas.current?.getTrimmedCanvas().toDataURL('image/png', 1)!)
|
||||||
|
firstPage.drawImage(sign, { x: 54, y: 240, width: 100, height: 55 })
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
await pdfDoc.setTitle(`Form Cuti ${profile.fullname} - ${dayjs().format('YYYYMMDD')}`)
|
||||||
|
await pdfDoc.setSubject('SURAT PERMOHONAN FORM CUTI KARYAWAN')
|
||||||
|
await pdfDoc.setKeywords(['form cuti', 'super apps', 'his', 'nutech'])
|
||||||
|
await pdfDoc.setCreator(profile.fullname)
|
||||||
|
await pdfDoc.setAuthor('H.I.S Dev Super Team 😎')
|
||||||
|
await pdfDoc.setProducer('Super Apps')
|
||||||
|
await pdfDoc.setCreationDate(new Date())
|
||||||
|
await pdfDoc.setModificationDate(new Date())
|
||||||
|
|
||||||
|
const pdfBase64 = await pdfDoc.saveAsBase64({ dataUri: true })
|
||||||
|
|
||||||
|
if (!preview) {
|
||||||
|
const payload = {
|
||||||
|
"nik": profile.nik,
|
||||||
|
"send_to": 9,
|
||||||
|
// "send_to": 1,
|
||||||
|
"cc": mentionsTo,
|
||||||
|
"category": leaveType,
|
||||||
|
"start_date": dayjs(leavePeriod[0]).format('YYYY-MM-DD'),
|
||||||
|
"end_date": dayjs(leavePeriod[1]).format('YYYY-MM-DD'),
|
||||||
|
"return_to_work_date": dayjs(leaveIn).format('YYYY-MM-DD'),
|
||||||
|
"contact_street": address,
|
||||||
|
"contact_city": city,
|
||||||
|
"contact_phone_number": profile.phone_number
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(payload)
|
||||||
|
await axios.post('/application-form', payload)
|
||||||
|
|
||||||
|
const downloadLink = window.document.createElement('a');
|
||||||
|
downloadLink.style.display = "none";
|
||||||
|
downloadLink.href = pdfBase64;
|
||||||
|
downloadLink.download = `Form Cuti ${profile.fullname} - ${dayjs().format('YYYYMMDD')}`;
|
||||||
|
window.document.body.appendChild(downloadLink);
|
||||||
|
downloadLink.click();
|
||||||
|
window.document.body.removeChild(downloadLink);
|
||||||
|
|
||||||
|
handleSuccess('Apply for leave successfully, we generate E-Form for you')
|
||||||
|
} else {
|
||||||
|
// Create a new window
|
||||||
|
const newWindow: any = window.open("", "_blank", "width=800,height=600");
|
||||||
|
|
||||||
|
// Create an HTML document with an embedded data URL
|
||||||
|
const htmlDocument = `
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>PDF Preview</title>
|
||||||
|
</head>
|
||||||
|
<body style="margin: 0; height: 100vh;">
|
||||||
|
<embed src="${pdfBase64}" type="application/pdf" width="100%" height="100%" style="display: block;">
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`;
|
||||||
|
|
||||||
|
// Write the HTML document to the new window
|
||||||
|
newWindow.document.open();
|
||||||
|
newWindow.document.write(htmlDocument);
|
||||||
|
newWindow.document.close();
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.log(error)
|
||||||
|
handleError(`Fail to apply for leave, (${error.response?.data?.code || error.response?.status || '-'}) ${error.response?.data?.message || error.response?.statusText || error.message}`)
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSuccess = (message: string) => {
|
||||||
|
toast.info(message)
|
||||||
|
router.replace('/')
|
||||||
|
router.refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleError = (message: string) => {
|
||||||
|
toast.error("Oops! Something went wrong.", {
|
||||||
|
description: message,
|
||||||
|
action: <Button variant='outline' onClick={() => handleSubmit('' as any)}>Try again</Button>,
|
||||||
|
})
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
const clearSignCanvas = () => {
|
||||||
|
signCanvas.current?.clear();
|
||||||
|
setSignLabelUploaded('Or upload your sign')
|
||||||
|
}
|
||||||
|
|
||||||
|
const saveSign = () => {
|
||||||
|
if (signCanvas.current?.isEmpty()) return
|
||||||
|
setImgSign(signCanvas.current?.getTrimmedCanvas().toDataURL('image/png', 1)!)
|
||||||
|
}
|
||||||
|
|
||||||
|
const importSign = async (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
signCanvas.current?.clear()
|
||||||
|
|
||||||
|
const file = e.target.files![0]
|
||||||
|
setSignLabelUploaded(file.name)
|
||||||
|
const base64 = await readFile(file)
|
||||||
|
signCanvas.current?.fromDataURL(base64 as string)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// eslint-disable-next-line arrow-body-style
|
||||||
|
// const disabledDate: RangePickerProps['disabledDate'] = (current) => {
|
||||||
|
// // Can not select days before today and today
|
||||||
|
// return current && current < dayjs().endOf('day');
|
||||||
|
// };
|
||||||
|
|
||||||
|
// DISABLE DATE BEFORE 18 SEP 2023
|
||||||
|
// eslint-disable-next-line arrow-body-style
|
||||||
|
const disabledDate: RangePickerProps['disabledDate'] = (current) => {
|
||||||
|
const disabledDate = new Date('2023-09-18');
|
||||||
|
disabledDate.setHours(0, 0, 0, 0);
|
||||||
|
const disabledTimestamp = disabledDate.getTime();
|
||||||
|
|
||||||
|
const selectedTimestamp = current ? current.valueOf() : 0;
|
||||||
|
|
||||||
|
return selectedTimestamp < disabledTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line arrow-body-style
|
||||||
|
const disabledDateKembaliKerja: RangePickerProps['disabledDate'] = (current) => {
|
||||||
|
if (leavePeriod && leavePeriod.length === 2 && leavePeriod[1]) {
|
||||||
|
return current && current < dayjs(leavePeriod[1]).endOf('day');
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<form onSubmit={handleSubmit} className='space-y-8'>
|
||||||
|
<div className='space-y-2'>
|
||||||
|
<Label>Leave Type</Label>
|
||||||
|
<Select value={leaveType} onValueChange={val => setLeaveType(val)}>
|
||||||
|
{/* <Select > */}
|
||||||
|
<SelectTrigger className='w-full'>
|
||||||
|
<SelectValue placeholder="Select the type of leave" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="CT">Cuti Tahunan</SelectItem>
|
||||||
|
<SelectItem value="CM">Cuti Melahirkan</SelectItem>
|
||||||
|
<SelectItem value="CB">Cuti Besar</SelectItem>
|
||||||
|
<SelectItem value="CL">Lainnya</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<p className='text-muted-foreground text-sm'>Jenis cuti yang diambil, jika lainnya tuliskan alasan cuti tersebut</p>
|
||||||
|
{leaveType === 'CL' &&
|
||||||
|
<Input placeholder='Jelaskan alasan cuti...' value={otherLeave} onChange={e => setOtherLeave(e.target.value)} />
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Separator />
|
||||||
|
<div className='space-y-4'>
|
||||||
|
<div className='flex flex-col space-y-2'>
|
||||||
|
<Label>Leave Period</Label>
|
||||||
|
<DatePicker.RangePicker disabledDate={disabledDate} onChange={val => setLeavePeriod(val)} format={'MMM DD, YYYY'} size='small' className='px-3 py-2' />
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col space-y-2'>
|
||||||
|
<Label>Return to Work</Label>
|
||||||
|
<DatePicker disabledDate={disabledDateKembaliKerja} onChange={val => setLeaveIn(val)} defaultValue={leavePeriod && leavePeriod.length === 2 && dayjs(leavePeriod[1]).endOf('day')} format={'MMMM DD, YYYY'} size='small' className='px-3 py-2' disabled={leavePeriod?.length !== 2} />
|
||||||
|
</div>
|
||||||
|
<p className='text-muted-foreground text-sm'>Periode masa cuti dari mulai cuti sampai dengan kembali bekerja</p>
|
||||||
|
</div>
|
||||||
|
<Separator />
|
||||||
|
|
||||||
|
<div className='space-y-4'>
|
||||||
|
<div className='space-y-2'>
|
||||||
|
<Label>Address</Label>
|
||||||
|
<Textarea value={address} onChange={e => setAddress(e.target.value)} maxLength={255} />
|
||||||
|
</div>
|
||||||
|
<div className='space-y-2'>
|
||||||
|
<Label>City</Label>
|
||||||
|
<Input value={city} onChange={e => setCity(e.target.value)} maxLength={50} />
|
||||||
|
</div>
|
||||||
|
<p className='text-muted-foreground text-sm'>Alamat yang Dapat Dihubungi Ketika Cuti</p>
|
||||||
|
</div>
|
||||||
|
<Separator />
|
||||||
|
|
||||||
|
<div className='space-y-4'>
|
||||||
|
<div className='space-y-2'>
|
||||||
|
<Label>Send to</Label>
|
||||||
|
<Input defaultValue='Stevanus Akbar Alexander' disabled readOnly />
|
||||||
|
</div>
|
||||||
|
<div className='space-y-2'>
|
||||||
|
<Label>Mentions to</Label>
|
||||||
|
<MultiSelect mode="multiple" allowClear placeholder="Add mentions to Team Leader" size='large' className='w-full'
|
||||||
|
options={TL_LIST?.length! > 0 ? TL_LIST?.map(item => { return { value: item.id, label: item.fullname } }) : []} value={mentionsTo} onChange={(val) => setMentionsTo(val)}
|
||||||
|
optionFilterProp="children"
|
||||||
|
filterOption={(input, option) => (option?.label ?? '').toLowerCase().includes(input.toLowerCase())}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div className='space-y-4'>
|
||||||
|
<div className='flex items-center space-x-3'>
|
||||||
|
<Switch checked={includeSign} onCheckedChange={setIncludeSign} />
|
||||||
|
<Label>Add Signature</Label>
|
||||||
|
</div>
|
||||||
|
{includeSign &&
|
||||||
|
<div className='space-y-3'>
|
||||||
|
<p className='text-muted-foreground text-sm'>Draw your signature on the canvas</p>
|
||||||
|
<div className='w-full h-64 sm:h-96 relative'>
|
||||||
|
<SignaturePad
|
||||||
|
ref={signCanvas} canvasProps={{
|
||||||
|
className: 'border border-gray-400 rounded-2xl shadow bg-white w-full h-full absolute'
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col sm:flex-row sm:items-center justify-between space-y-2 sm:space-y-0'>
|
||||||
|
{/* <input placeholder='or upload sign' type='file' className='input' accept='image/*' onChange={importSign} /> */}
|
||||||
|
<div className="flex flex-row items-center">
|
||||||
|
<input type="file" id="custom-input" onChange={importSign} hidden />
|
||||||
|
<label htmlFor="custom-input"
|
||||||
|
className="block text-sm bg-orange-200 dark:bg-orange-800 text-orange-900 dark:text-orange-50 mr-3 py-2 px-4 rounded-md border-0 font-semibold cursor-pointer"
|
||||||
|
>
|
||||||
|
Choose file
|
||||||
|
</label>
|
||||||
|
<label className="text-sm text-muted-foreground">{signLabelUploaded}</label>
|
||||||
|
</div>
|
||||||
|
{/* <Button type='button' onClick={() => console.log(signCanvas.current?.isEmpty())}>Save</Button> */}
|
||||||
|
<Button variant='destructive' type='button' onClick={clearSignCanvas}>Clear</Button>
|
||||||
|
</div>
|
||||||
|
{imgSign && <img alt='' src={imgSign} className='border-2 border-gray-300 shadow rounded-2xl' />}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<Separator />
|
||||||
|
|
||||||
|
<div className='flex flex-col space-y-2'>
|
||||||
|
<Button type='button' variant='secondary' disabled={isLoading} onClick={() => handleSubmit('' as any, true)}><i className="ti ti-eye icon pb-1 mr-2"></i>Preview</Button>
|
||||||
|
<Button type="submit" disabled={isLoading}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
<Button type='reset' variant='outline' onClick={() => router.back()} disabled={isLoading} >Cancel</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Component;
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { type Metadata } from 'next';
|
||||||
|
import { Suspense, lazy } from 'react';
|
||||||
|
import { Separator } from '@/components/ui/separator';
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import PageLoading from '@/components/loader/PageLoading';
|
||||||
|
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||||
|
|
||||||
|
const FormComponent = lazy(() => import('./components'))
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "Apply for Leave",
|
||||||
|
}
|
||||||
|
|
||||||
|
const WorkLeave = async () => {
|
||||||
|
const res = await fetchDataWithPost('/user/position', { position_code: 'P02' })
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='flex-1 w-full md:w-[800px] mx-auto px-5 py-10 md:p-10 pb-40 md:pb-10'>
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<div className='flex justify-center items-center flex-col'>
|
||||||
|
<div className='flex items-center space-x-2'>
|
||||||
|
<CardTitle className="text-lg font-medium">Apply for Leave</CardTitle>
|
||||||
|
<i className="ti ti-speedboat icon text-3xl"></i>
|
||||||
|
</div>
|
||||||
|
<p className="text-sm text-muted-foreground">Complete your information to apply for leave</p>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<Separator className='w-10/12 xl:w-11/12 mx-auto' />
|
||||||
|
<CardContent className='mt-6'>
|
||||||
|
<Suspense fallback={<PageLoading />}>
|
||||||
|
<FormComponent TL_LIST={res} />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default WorkLeave;
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { Skeleton } from "@/components/ui/skeleton"
|
||||||
|
|
||||||
|
export default function Loading() {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col w-full p-6">
|
||||||
|
<div className="flex justify-between items-center w-full">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="h-8 w-40" />
|
||||||
|
<Skeleton className="h-6 w-96" />
|
||||||
|
</div>
|
||||||
|
<Skeleton className="h-10 w-36 rounded-2xl" />
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:sm:grid-cols-4 gap-5 mt-8">
|
||||||
|
<Skeleton className="h-32 rounded-2xl" />
|
||||||
|
<Skeleton className="h-32 rounded-2xl" />
|
||||||
|
<Skeleton className="h-32 rounded-2xl" />
|
||||||
|
<Skeleton className="h-32 rounded-2xl" />
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-5 mt-5">
|
||||||
|
<Skeleton className="h-64 rounded-2xl" />
|
||||||
|
<Skeleton className="h-64 rounded-2xl" />
|
||||||
|
<Skeleton className="h-64 rounded-2xl" />
|
||||||
|
<Skeleton className="h-64 rounded-2xl" />
|
||||||
|
</div>
|
||||||
|
<Skeleton className="h-64 rounded-2xl w-full mt-5 mb-16" />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import Image from 'next/image'
|
||||||
|
import Link from 'next/link'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
|
||||||
|
export default function NotFound() {
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen flex flex-col justify-center items-center overflow-x-hidden overflow-y-auto py-5">
|
||||||
|
<Image alt='404' height={0} width={0} quality={70} src='/assets/illustrations/404.svg' className='w-80 md:w-md 2xl:w-160 shadow-sm rounded-full object-cover' />
|
||||||
|
<h2 className="text-xl sm:text-2xl font-semibold tracking-tight text-center">404 Page not Found</h2>
|
||||||
|
<span className="text-center mt-1 mb-5 text-zinc-600 dark:text-zinc-400 md:w-9/12 break-all px-10 sm:px-0">Looks like the page you were looking for does not exist</span>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Link href='/'>
|
||||||
|
<Button variant='outline'>Back to Home</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
import { MouseEvent, useEffect, useRef, useState } from "react";
|
||||||
|
import { RefreshCw } from 'lucide-react'
|
||||||
|
import useMobileView from "@/hooks/useMobileView";
|
||||||
|
import './index.css'
|
||||||
|
|
||||||
|
const hasGetUserMedia = () => !!navigator.mediaDevices?.getUserMedia;
|
||||||
|
|
||||||
|
const VIDEO_WIDTH = 480
|
||||||
|
const VIDEO_HEIGHT = 720
|
||||||
|
const MOBILE_VIDEO_WIDTH = 360
|
||||||
|
const MOBILE_VIDEO_HEIGHT = 540
|
||||||
|
let STREAM = null as any
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
onClose: (e: MouseEvent<HTMLElement>) => any
|
||||||
|
onSubmit: (photo: string, landscape?: boolean, w?: number, h?: number) => any
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Camera({ onClose, onSubmit }: Props) {
|
||||||
|
const [streamWidth, setStreamWidth] = useState(VIDEO_WIDTH)
|
||||||
|
const [streamHeight, setStreamHeight] = useState(VIDEO_HEIGHT)
|
||||||
|
const [isMounted, setIsMounted] = useState(false)
|
||||||
|
const [photo, setPhoto] = useState('')
|
||||||
|
const { windowWidth } = useMobileView()
|
||||||
|
|
||||||
|
const webcamRef = useRef<HTMLVideoElement>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setIsMounted(true)
|
||||||
|
|
||||||
|
return () => setIsMounted(false)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
handleShowingCamera()
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (STREAM) {
|
||||||
|
STREAM.getTracks().forEach((track: any) => track.stop());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
|
const handleShowingCamera = async () => {
|
||||||
|
if (!hasGetUserMedia()) {
|
||||||
|
console.log(navigator)
|
||||||
|
alert("Camera is not supported on your browser")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// getUsermedia parameters
|
||||||
|
// const videoWidth = windowWidth < 480 ? { exact: VIDEO_HEIGHT, min: VIDEO_HEIGHT, max: VIDEO_HEIGHT } : { exact: VIDEO_WIDTH, min: VIDEO_WIDTH, max: VIDEO_WIDTH }
|
||||||
|
// const videoHeight = windowWidth < 480 ? { exact: VIDEO_WIDTH, min: VIDEO_WIDTH, max: VIDEO_WIDTH } : { exact: VIDEO_HEIGHT, min: VIDEO_HEIGHT, max: VIDEO_HEIGHT }
|
||||||
|
const videoWidth = windowWidth < 480 ? { exact: VIDEO_HEIGHT, min: VIDEO_HEIGHT, max: VIDEO_HEIGHT } : VIDEO_WIDTH
|
||||||
|
const videoHeight = windowWidth < 480 ? { exact: VIDEO_WIDTH, min: VIDEO_WIDTH, max: VIDEO_WIDTH } : VIDEO_HEIGHT
|
||||||
|
|
||||||
|
// getUsermedia parameters
|
||||||
|
const constraints: MediaStreamConstraints = {
|
||||||
|
video: {
|
||||||
|
facingMode: { exact: 'user' },
|
||||||
|
// width: VIDEO_WIDTH,
|
||||||
|
// height: VIDEO_HEIGHT, // REQUIRED VALUE: 480 720 1080
|
||||||
|
width: videoWidth,
|
||||||
|
height: videoHeight, // REQUIRED VALUE: 480 720 1080
|
||||||
|
frameRate: {
|
||||||
|
min: 30,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Activate the webcam stream.
|
||||||
|
navigator.mediaDevices.getUserMedia(constraints)
|
||||||
|
.then(function (stream) {
|
||||||
|
let stream_settings = stream.getVideoTracks()[0].getSettings();
|
||||||
|
setStreamWidth(stream_settings.width!)
|
||||||
|
setStreamHeight(stream_settings.height!)
|
||||||
|
|
||||||
|
STREAM = stream
|
||||||
|
webcamRef.current!.srcObject = stream
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
alert(error)
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const capture = async () => {
|
||||||
|
const canvas = document.createElement("canvas");
|
||||||
|
canvas.width = streamWidth || VIDEO_WIDTH
|
||||||
|
canvas.height = streamHeight || VIDEO_HEIGHT
|
||||||
|
|
||||||
|
try {
|
||||||
|
// console.log(canvas.width, canvas.height, webcamRef.current?.videoWidth, webcamRef.current?.videoHeight)
|
||||||
|
canvas.getContext('2d')!.drawImage(webcamRef.current!, 0, 0, webcamRef.current!.videoWidth, webcamRef.current!.videoHeight);
|
||||||
|
let image_data_url = canvas.toDataURL('image/jpeg');
|
||||||
|
|
||||||
|
// console.log(image_data_url);
|
||||||
|
setPhoto(image_data_url)
|
||||||
|
if (STREAM) {
|
||||||
|
STREAM.getTracks().forEach((track: any) => track.stop());
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error: " + err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className={`${isMounted ? 'open' : 'close'} custom-modal-background`} onClick={onClose}>
|
||||||
|
<div className={`${isMounted ? 'open' : 'close'} custom-modal w-11/12 md:!w-max text-white`} style={{ translate: '-50% -50%' }}>
|
||||||
|
<div className="w-full overflow-y-auto" style={{ maxHeight: '95vh' }}>
|
||||||
|
<section className='flex flex-col items-center justify-center relative' onClick={(e) => e.stopPropagation()}>
|
||||||
|
<div className={`relative bg-zinc-800 shadow-lg rounded-2xl ${streamWidth >= streamHeight && 'flex justify-center items-center'}`} style={{ width: windowWidth < VIDEO_WIDTH ? MOBILE_VIDEO_WIDTH : VIDEO_WIDTH, height: windowWidth < VIDEO_WIDTH ? MOBILE_VIDEO_HEIGHT : VIDEO_HEIGHT }}>
|
||||||
|
{photo ?
|
||||||
|
<img alt="" src={photo} style={{ transform: 'scaleX(-1)' }} className={`${streamWidth < streamHeight ? 'h-full w-full object-cover' : 'w-full'} rounded-2xl`} />
|
||||||
|
:
|
||||||
|
<video ref={webcamRef} id="webcam" autoPlay playsInline className="h-full w-full rounded-2xl"></video>
|
||||||
|
}
|
||||||
|
<div className="absolute top-4 md:top-5 w-full flex justify-between items-center px-5">
|
||||||
|
<button className="bg-black bg-opacity-40 w-12 h-12 flex justify-center items-center rounded-full hover:text-zinc-400 duration-300 sm:ml-0" onClick={onClose as any}>
|
||||||
|
<i className="ti ti-chevron-left icon text-4xl"></i>
|
||||||
|
</button>
|
||||||
|
{photo &&
|
||||||
|
<button className="bg-his bg-opacity-90 text-white w-12 h-12 flex justify-center items-center rounded-full hover:bg-his/70 duration-300 sm:mr-0" onClick={() => onSubmit(photo, streamWidth > streamHeight, streamWidth, streamHeight)}>
|
||||||
|
<i className="ti ti-send icon text-2xl"></i>
|
||||||
|
</button>
|
||||||
|
// <Button size='icon' variant='secondary' className="mr-16 sm:mr-0" onClick={() => onSubmit(photo)}><Send /></Button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-center items-center absolute bottom-5 w-full">
|
||||||
|
{!photo ?
|
||||||
|
<div className="bg-white rounded-full w-[88px] h-[88px] flex items-center justify-center cursor-pointer" onClick={capture}>
|
||||||
|
<div className="bg-zinc-950 rounded-full w-20 h-20 flex items-center justify-center">
|
||||||
|
<div className="bg-white rounded-full w-[70px] h-[70px]"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
:
|
||||||
|
<div className="bg-black bg-opacity-40 w-16 h-16 flex justify-center items-center rounded-full hover:text-zinc-400 mb-3 cursor-pointer duration-300">
|
||||||
|
<RefreshCw size={40} onClick={() => { setPhoto(''); handleShowingCamera() }} />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
import { MouseEvent, useCallback, useEffect, useRef, useState } from "react";
|
||||||
|
import Webcam from "react-webcam";
|
||||||
|
import { RefreshCw, SwitchCamera } from 'lucide-react'
|
||||||
|
import useMobileView from "@/hooks/useMobileView";
|
||||||
|
|
||||||
|
|
||||||
|
const VIDEO_WIDTH = 480
|
||||||
|
const VIDEO_HEIGHT = 720
|
||||||
|
const MOBILE_VIDEO_WIDTH = 360
|
||||||
|
const MOBILE_VIDEO_HEIGHT = 540
|
||||||
|
const FACING_MODE_USER = "user";
|
||||||
|
const FACING_MODE_ENVIRONMENT = "environment";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
onClose: (e: MouseEvent<HTMLElement>) => any,
|
||||||
|
onSubmit: (photo: string, landscape?: boolean, w?: number, h?: number) => any
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function CameraV2({ onClose, onSubmit }: Props) {
|
||||||
|
const [streamWidth, setStreamWidth] = useState(VIDEO_WIDTH)
|
||||||
|
const [streamHeight, setStreamHeight] = useState(VIDEO_HEIGHT)
|
||||||
|
const [isMounted, setIsMounted] = useState(false)
|
||||||
|
const [photo, setPhoto] = useState('')
|
||||||
|
const [facingMode, setFacingMode] = useState(FACING_MODE_USER);
|
||||||
|
|
||||||
|
const { windowWidth, isMobile } = useMobileView()
|
||||||
|
const webcamRef = useRef<Webcam>(null)
|
||||||
|
|
||||||
|
const videoWidth = windowWidth < 480 ? { exact: VIDEO_HEIGHT, min: VIDEO_HEIGHT, max: VIDEO_HEIGHT } : VIDEO_WIDTH
|
||||||
|
const videoHeight = windowWidth < 480 ? { exact: VIDEO_WIDTH, min: VIDEO_WIDTH, max: VIDEO_WIDTH } : VIDEO_HEIGHT
|
||||||
|
const videoConstraint: MediaTrackConstraints = {
|
||||||
|
// facingMode: { exact: 'user' },
|
||||||
|
facingMode: facingMode,
|
||||||
|
width: videoWidth,
|
||||||
|
height: videoHeight, // REQUIRED VALUE: 480 720 1080
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSwitchCamera = useCallback(() => {
|
||||||
|
setFacingMode(prevState => prevState === FACING_MODE_USER ? FACING_MODE_ENVIRONMENT : FACING_MODE_USER);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setIsMounted(true)
|
||||||
|
|
||||||
|
return () => setIsMounted(false)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const capture = async () => {
|
||||||
|
const ss = webcamRef.current?.getScreenshot()!
|
||||||
|
|
||||||
|
const stream_settings = webcamRef.current?.stream?.getVideoTracks()[0].getSettings()
|
||||||
|
setStreamWidth(stream_settings?.width!)
|
||||||
|
setStreamHeight(stream_settings?.height!)
|
||||||
|
|
||||||
|
setPhoto(ss)
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className={`${isMounted ? 'open' : 'close'} custom-modal-background`} onClick={onClose}>
|
||||||
|
<div className={`${isMounted ? 'open' : 'close'} custom-modal w-11/12 md:w-max!`} style={{ translate: '-50% -50%' }}>
|
||||||
|
<div className="w-full overflow-y-auto" style={{ maxHeight: '95vh' }}>
|
||||||
|
<section className='flex flex-col items-center justify-center relative' onClick={(e) => e.stopPropagation()}>
|
||||||
|
<div className={`relative bg-zinc-800 shadow-lg rounded-2xl ${streamWidth >= streamHeight && 'flex justify-center items-center'}`} style={{ width: windowWidth < VIDEO_WIDTH ? MOBILE_VIDEO_WIDTH : VIDEO_WIDTH, height: windowWidth < VIDEO_WIDTH ? MOBILE_VIDEO_HEIGHT : VIDEO_HEIGHT }}>
|
||||||
|
{photo ?
|
||||||
|
<img alt="" src={photo} className={`${streamWidth < streamHeight ? 'h-full w-full object-cover' : 'w-full'} rounded-2xl`} />
|
||||||
|
:
|
||||||
|
<Webcam
|
||||||
|
ref={webcamRef}
|
||||||
|
className="h-full w-full rounded-2xl"
|
||||||
|
mirrored={facingMode === FACING_MODE_ENVIRONMENT ? false : true}
|
||||||
|
screenshotQuality={1}
|
||||||
|
screenshotFormat="image/jpeg"
|
||||||
|
forceScreenshotSourceSize
|
||||||
|
videoConstraints={videoConstraint}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
<div className="absolute top-4 md:top-5 w-full flex justify-between items-center px-5">
|
||||||
|
<button className="bg-black bg-opacity-40 w-12 h-12 flex justify-center items-center rounded-full hover:text-zinc-400 duration-300 sm:ml-0" onClick={onClose as any}>
|
||||||
|
<i className="ti ti-chevron-left icon text-4xl"></i>
|
||||||
|
</button>
|
||||||
|
{photo &&
|
||||||
|
<button className="bg-his bg-opacity-90 text-white w-12 h-12 flex justify-center items-center rounded-full hover:bg-his/70 duration-300 sm:mr-0" onClick={() => onSubmit(photo, streamWidth > streamHeight, streamWidth, streamHeight)}>
|
||||||
|
<i className="ti ti-send icon text-2xl"></i>
|
||||||
|
</button>
|
||||||
|
// <Button size='icon' variant='secondary' className="mr-16 sm:mr-0" onClick={() => onSubmit(photo)}><Send /></Button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-center items-center absolute bottom-5 w-full">
|
||||||
|
{!photo ?
|
||||||
|
<>
|
||||||
|
<div className="bg-white rounded-full w-[88px] h-[88px] flex items-center justify-center cursor-pointer" onClick={capture}>
|
||||||
|
<div className="bg-zinc-950 rounded-full w-20 h-20 flex items-center justify-center">
|
||||||
|
<div className="bg-white rounded-full w-[70px] h-[70px] flex justify-center items-center"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{isMobile &&
|
||||||
|
<button className="absolute right-[22px] bg-black bg-opacity-40 w-12 h-12 flex justify-center items-center rounded-full" onClick={handleSwitchCamera}>
|
||||||
|
<SwitchCamera />
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
:
|
||||||
|
<div className="bg-black bg-opacity-40 w-16 h-16 flex justify-center items-center rounded-full hover:text-zinc-400 mb-3 cursor-pointer duration-300">
|
||||||
|
<RefreshCw size={40} onClick={() => setPhoto('')} />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,237 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { FC, useEffect, useState } from 'react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { useSession } from 'next-auth/react';
|
||||||
|
import { Camera as CameraIcon } from 'lucide-react';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
|
import CameraV2 from './CameraV2';
|
||||||
|
import { Separator } from '@/components/ui/separator';
|
||||||
|
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||||
|
import { Icons } from '@/components/Icons';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { Label } from '@/components/ui/label';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
isCheckout?: boolean
|
||||||
|
workingStatusList: any[]
|
||||||
|
};
|
||||||
|
|
||||||
|
const FormComponent: FC<Props> = ({ isCheckout, workingStatusList }) => {
|
||||||
|
const OFFICE_PEJATEN_LATTITUDE = -6.27831622506824
|
||||||
|
const OFFICE_PEJATEN_LONGITUDE = 106.82955901443484
|
||||||
|
|
||||||
|
const [showCamera, setShowCamera] = useState(true)
|
||||||
|
const [photo, setPhoto] = useState('')
|
||||||
|
const [locationName, setLocationName] = useState('')
|
||||||
|
const [latitude, setLatitude] = useState(OFFICE_PEJATEN_LATTITUDE)
|
||||||
|
const [longitude, setLongitude] = useState(OFFICE_PEJATEN_LONGITUDE)
|
||||||
|
const [workingStatus, setWorkingStatus] = useState('')
|
||||||
|
const [note, setNote] = useState('')
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
const [orientation, setOrientation] = useState<'portrait' | 'landscape' | 'square'>('portrait')
|
||||||
|
|
||||||
|
const { data: session } = useSession()
|
||||||
|
const router = useRouter()
|
||||||
|
const axios = useAxiosAuth()
|
||||||
|
|
||||||
|
const options: PositionOptions = {
|
||||||
|
enableHighAccuracy: true,
|
||||||
|
timeout: 10000,
|
||||||
|
maximumAge: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
const successCallback = (position: GeolocationPosition) => {
|
||||||
|
const x = position.coords.latitude;
|
||||||
|
const y = position.coords.longitude;
|
||||||
|
setLatitude(x); setLongitude(y)
|
||||||
|
displayLocation(x, y);
|
||||||
|
};
|
||||||
|
|
||||||
|
const errorCallback = (error: GeolocationPositionError) => {
|
||||||
|
let errorMessage = 'Unknown error';
|
||||||
|
switch (error.code) {
|
||||||
|
case 1:
|
||||||
|
errorMessage = 'Permission denied';
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
errorMessage = 'Position unavailable';
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
errorMessage = 'Timeout';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
toast.warning("Failed to fetch geolocation, reason: " + errorMessage)
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!navigator.geolocation) {
|
||||||
|
toast.warning('Geolocation not available in your apps')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
navigator.geolocation.getCurrentPosition(successCallback, errorCallback, options);
|
||||||
|
}, [successCallback])
|
||||||
|
|
||||||
|
|
||||||
|
const displayLocation = async (latitude: number, longitude: number) => {
|
||||||
|
const res = await fetch(`https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=jsonv2&zoom=13`)
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json()
|
||||||
|
console.log(data?.display_name)
|
||||||
|
setLocationName(data?.display_name)
|
||||||
|
} else {
|
||||||
|
toast.warning(`${res.status} ${res.statusText}`)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleReceivePhoto = (photo: string, landscape?: boolean, w?: number, h?: number) => {
|
||||||
|
setOrientation(w! > h! ? 'landscape' : w === h ? 'square' : 'portrait')
|
||||||
|
setPhoto(photo)
|
||||||
|
setShowCamera(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit = () => {
|
||||||
|
if (!isCheckout) {
|
||||||
|
if (!workingStatus) {
|
||||||
|
toast.error('Please select your working status first!')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!photo) {
|
||||||
|
toast.error('Photo is required!')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!note) {
|
||||||
|
toast.error('Please add a little notes!')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = isCheckout ? 'Check-Out' : 'Check-In'
|
||||||
|
const endpoint = isCheckout ? '/presence/check-out' : '/presence/check-in'
|
||||||
|
|
||||||
|
setIsLoading(true)
|
||||||
|
const payload = {
|
||||||
|
nik: session?.user.detail.nik,
|
||||||
|
datetime: null,
|
||||||
|
working_status: workingStatus,
|
||||||
|
image: photo ? photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '') : '',
|
||||||
|
location_name: locationName,
|
||||||
|
latitude,
|
||||||
|
longitude,
|
||||||
|
area_code: null,
|
||||||
|
device_code: process.env.DEVICE_CODE || "40001",
|
||||||
|
manual_presence: true,
|
||||||
|
note: note ? note : isCheckout ? '' : ''
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
console.log(payload)
|
||||||
|
axios.post(endpoint, payload).then(res => {
|
||||||
|
toast.info(`${title} success`)
|
||||||
|
router.replace('/')
|
||||||
|
router.refresh()
|
||||||
|
}).catch(error => {
|
||||||
|
setIsLoading(false)
|
||||||
|
toast.error(`${title} failed`, { description: `(${error.response?.data?.code || error.response?.status || '-'}) ${error.response?.data?.message || error.response?.statusText || error.message}}` })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const getIcon = (code: string) => {
|
||||||
|
switch (code) {
|
||||||
|
case 'WFH':
|
||||||
|
return 'ti ti-home'
|
||||||
|
case 'WFS':
|
||||||
|
return 'ti ti-building-community'
|
||||||
|
case 'SKT':
|
||||||
|
return 'ti ti-stethoscope'
|
||||||
|
case 'CT01':
|
||||||
|
return 'ti ti-speedboat'
|
||||||
|
default:
|
||||||
|
return 'ti ti-speedboat'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='space-y-8'>
|
||||||
|
<div className='flex flex-col justify-center items-center space-y-5'>
|
||||||
|
{photo ?
|
||||||
|
<img alt='' src={photo} className={`btn-outline ${orientation === 'portrait' ? 'w-36 h-48' : orientation === 'landscape' ? 'w-48 h-36' : 'w-48 h-48'} rounded-xl object-cover shadow`} />
|
||||||
|
:
|
||||||
|
<div className='btn-outline w-36 h-48 rounded-xl flex items-center justify-center bg-zinc-200 dark:bg-zinc-800'></div>
|
||||||
|
}
|
||||||
|
<Button variant='outline' onClick={() => setShowCamera(true)}>
|
||||||
|
<CameraIcon className='mr-1 w-4 h-4' />Retake photo
|
||||||
|
</Button>
|
||||||
|
<div className='space-y-2 flex flex-col items-center'>
|
||||||
|
<div className='flex items-center space-x-2 text-xs sm:text-sm text-muted-foreground'>
|
||||||
|
<i className="ti ti-map-pin icon text-xl"></i>
|
||||||
|
<p>{OFFICE_PEJATEN_LATTITUDE}, {OFFICE_PEJATEN_LONGITUDE}</p>
|
||||||
|
</div>
|
||||||
|
<div className='flex items-center text-sm text-center w-full md:w-9/12'>
|
||||||
|
<p>{locationName}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='flex items-center text-sm space-x-2'>
|
||||||
|
<p className='text-muted-foreground'>{isCheckout ? 'Check-out' : 'Check-in'} time: </p>
|
||||||
|
<p>{dayjs().format('HH:mm')}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Separator />
|
||||||
|
|
||||||
|
<div className='flex flex-col items-center space-y-3 w-full'>
|
||||||
|
{!isCheckout &&
|
||||||
|
<div className='space-y-2 flex flex-col items-center'>
|
||||||
|
<Label>Working status</Label>
|
||||||
|
<p className='text-xs sm:text-sm text-muted-foreground'>Status kerja pada saat absensi</p>
|
||||||
|
<div className='flex items-center flex-wrap space-x-5 text-sm'>
|
||||||
|
{workingStatusList && workingStatusList.length > 0 ?
|
||||||
|
workingStatusList.map((item, key) =>
|
||||||
|
<div className='flex flex-col items-center space-y-1' key={key}>
|
||||||
|
<button className={`rounded-xl w-20 h-20 ${workingStatus === item.code ? 'bg-zinc-200 dark:bg-zinc-700 ' : 'btn-outline'}`} onClick={() => setWorkingStatus(item.code)}>
|
||||||
|
<i className={`${getIcon(item.code)} icon text-2xl`}></i>
|
||||||
|
</button>
|
||||||
|
<p className='text-center'>{item.name}</p>
|
||||||
|
</div>
|
||||||
|
) :
|
||||||
|
<div>
|
||||||
|
Working status not available, please contact administrator.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
<div className=' w-full space-y-2'>
|
||||||
|
<Label>Note</Label>
|
||||||
|
<Textarea
|
||||||
|
placeholder="Tell us a little bit about your presence"
|
||||||
|
className="resize-none" value={note} onChange={(e) => setNote(e.target.value)}
|
||||||
|
/>
|
||||||
|
<p className='text-xs sm:text-sm text-muted-foreground'>
|
||||||
|
Tambahkan catatan kehadiran jika diperlukan
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex flex-col space-y-2'>
|
||||||
|
<Button type="submit" disabled={isLoading} onClick={handleSubmit}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
<Button variant='outline' onClick={() => router.back()} disabled={isLoading} >Cancel</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{showCamera && <CameraV2 onClose={() => setShowCamera(false)} onSubmit={handleReceivePhoto} />}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default FormComponent;
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#webcam {
|
||||||
|
clear: both;
|
||||||
|
display: block;
|
||||||
|
/* transform: rotateY(180deg); */
|
||||||
|
/* -webkit-transform: rotateY(180deg); */
|
||||||
|
/* -moz-transform: rotateY(180deg); */
|
||||||
|
transform: scaleX(-1);
|
||||||
|
-webkit-transform: scaleX(-1);
|
||||||
|
-moz-transform: scaleX(-1);
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { type Metadata } from 'next';
|
||||||
|
import { FC, Suspense, lazy } from 'react';
|
||||||
|
import { Separator } from '@/components/ui/separator';
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import PageLoading from '@/components/loader/PageLoading';
|
||||||
|
import fetchData from '@/lib/fetchData';
|
||||||
|
|
||||||
|
const FormComponent = lazy(() => import('./components/FormComponent'))
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "Presence",
|
||||||
|
description: "Employee presence page.",
|
||||||
|
}
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
searchParams?: Promise<{ [key: string]: string | string[] | undefined }>
|
||||||
|
};
|
||||||
|
|
||||||
|
const PresencePage: FC<Props> = async ({ searchParams }) => {
|
||||||
|
const checkout = (await searchParams)?.checkout
|
||||||
|
|
||||||
|
const res = await fetchData('/presence/list-status')
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='flex-1 w-full md:w-[800px] mx-auto px-5 py-10 md:p-10 pb-40 md:pb-10'>
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<div className='flex justify-center items-center flex-col'>
|
||||||
|
<CardTitle className="text-lg font-medium">{checkout === 'true' ? 'Check-out Presence' : 'Check-in Presence'}</CardTitle>
|
||||||
|
<p className="text-sm text-muted-foreground">This is how others will see you on the site.</p>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<Separator className='w-10/12 xl:w-11/12 mx-auto' />
|
||||||
|
<CardContent className='mt-6'>
|
||||||
|
<Suspense fallback={<PageLoading />}>
|
||||||
|
<FormComponent workingStatusList={res.working_status} isCheckout={checkout === 'true'} />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PresencePage;
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
import { MouseEvent, useEffect, useRef, useState } from "react";
|
||||||
|
import { X, Send, RefreshCw } from 'lucide-react'
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import './index.css'
|
||||||
|
|
||||||
|
const hasGetUserMedia = () => !!navigator.mediaDevices?.getUserMedia;
|
||||||
|
|
||||||
|
const VIDEO_WIDTH = 480
|
||||||
|
const VIDEO_HEIGHT = 720
|
||||||
|
let STREAM = null as any
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
onClose: (e: MouseEvent<HTMLElement>) => any,
|
||||||
|
onSubmit: (photo: string) => any
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Camera({ onClose, onSubmit }: Props) {
|
||||||
|
const [isMounted, setIsMounted] = useState(false)
|
||||||
|
const [photo, setPhoto] = useState('')
|
||||||
|
|
||||||
|
const webcamRef = useRef<HTMLVideoElement>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setIsMounted(true)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
setIsMounted(false)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
handleShowingCamera()
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (STREAM) {
|
||||||
|
STREAM.getTracks().forEach((track: any) => track.stop());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
|
const handleShowingCamera = async () => {
|
||||||
|
if (!hasGetUserMedia()) {
|
||||||
|
console.log(navigator)
|
||||||
|
alert("Camera is not supported by your browser")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// getUsermedia parameters
|
||||||
|
const constraints: MediaStreamConstraints = {
|
||||||
|
video: {
|
||||||
|
facingMode: { exact: 'user' },
|
||||||
|
width: VIDEO_WIDTH,
|
||||||
|
height: VIDEO_HEIGHT, // REQUIRED VALUE: 480 720 1080
|
||||||
|
frameRate: {
|
||||||
|
min: 30,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Activate the webcam stream.
|
||||||
|
navigator.mediaDevices.getUserMedia(constraints)
|
||||||
|
.then(function (stream) {
|
||||||
|
STREAM = stream
|
||||||
|
webcamRef.current!.srcObject = stream
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
alert(error)
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const capture = async () => {
|
||||||
|
const canvas = document.createElement("canvas");
|
||||||
|
canvas.width = VIDEO_WIDTH
|
||||||
|
canvas.height = VIDEO_HEIGHT
|
||||||
|
|
||||||
|
try {
|
||||||
|
// console.log(canvas.width, canvas.height, webcamRef.current?.videoWidth, webcamRef.current?.videoHeight)
|
||||||
|
canvas.getContext('2d')!.drawImage(webcamRef.current!, 0, 0, webcamRef.current!.videoWidth, webcamRef.current!.videoHeight);
|
||||||
|
let image_data_url = canvas.toDataURL('image/jpeg');
|
||||||
|
|
||||||
|
console.log(image_data_url);
|
||||||
|
setPhoto(image_data_url)
|
||||||
|
if (STREAM) {
|
||||||
|
STREAM.getTracks().forEach((track: any) => track.stop());
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error: " + err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className={`${isMounted ? 'open' : 'close'} custom-modal-background`} onClick={onClose}>
|
||||||
|
<div className={`${isMounted ? 'open' : 'close'} custom-modal w-11/12 md:!w-max`} style={{ translate: '-50% -50%' }}>
|
||||||
|
<div className="w-full overflow-y-auto" style={{ maxHeight: '95vh' }}>
|
||||||
|
<section className='flex flex-col items-center justify-center relative' onClick={(e) => e.stopPropagation()}>
|
||||||
|
<div className="relative bg-zinc-800 shadow-lg rounded-2xl" style={{ width: VIDEO_WIDTH, height: VIDEO_HEIGHT }}>
|
||||||
|
{photo ?
|
||||||
|
<img alt="" src={photo} style={{ transform: 'scaleX(-1)' }} className="object-cover h-full w-full rounded-2xl" />
|
||||||
|
:
|
||||||
|
<video ref={webcamRef} id="webcam" autoPlay playsInline className="h-full w-full rounded-2xl"></video>
|
||||||
|
}
|
||||||
|
<div className="absolute top-5 w-full flex justify-between items-center px-5">
|
||||||
|
<X className="cursor-pointer hover:text-zinc-400 duration-300 ml-16 sm:ml-0" size={28} onClick={onClose as any} />
|
||||||
|
{photo &&
|
||||||
|
<Button size='icon' variant='secondary' className="mr-16 sm:mr-0" onClick={() => onSubmit(photo)}><Send /></Button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-center items-center absolute bottom-20 sm:bottom-5 w-full">
|
||||||
|
{!photo ?
|
||||||
|
<div className="bg-white rounded-full w-[88px] h-[88px] flex items-center justify-center cursor-pointer" onClick={capture}>
|
||||||
|
<div className="bg-zinc-950 rounded-full w-20 h-20 flex items-center justify-center">
|
||||||
|
<div className="bg-white rounded-full w-[70px] h-[70px]"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
:
|
||||||
|
<div className="bg-black bg-opacity-40 w-16 h-16 flex justify-center items-center rounded-full hover:text-zinc-400 mb-3 cursor-pointer duration-300">
|
||||||
|
<RefreshCw size={46} onClick={() => { setPhoto(''); handleShowingCamera() }} />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,189 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { FC, useEffect, useState } from 'react';
|
||||||
|
import Link from 'next/link';
|
||||||
|
import { Camera as CameraIcon } from 'lucide-react';
|
||||||
|
import { DatePicker, Form, Input, Radio, Select } from 'antd';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { FormDescription, FormLabel } from '@/components/ui/form';
|
||||||
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
|
import Camera from './Camera';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
isCheckout?: boolean
|
||||||
|
};
|
||||||
|
|
||||||
|
const FormComponent: FC<Props> = ({ isCheckout }) => {
|
||||||
|
const OFFICE_PEJATEN_LATTITUDE = -6.27831622506824
|
||||||
|
const OFFICE_PEJATEN_LONGITUDE = 106.82955901443484
|
||||||
|
|
||||||
|
const [showCamera, setShowCamera] = useState(false)
|
||||||
|
const [photo, setPhoto] = useState('')
|
||||||
|
const [locationName, setLocationName] = useState('')
|
||||||
|
const [workingStatus, setWorkingStatus] = useState('WFO')
|
||||||
|
|
||||||
|
const options: PositionOptions = {
|
||||||
|
enableHighAccuracy: false,
|
||||||
|
timeout: 1000,
|
||||||
|
maximumAge: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!navigator.geolocation) {
|
||||||
|
return alert("Geolocation not available in your apps")
|
||||||
|
}
|
||||||
|
navigator.geolocation.getCurrentPosition(successCallback, errorCallback, options);
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const successCallback = (position: GeolocationPosition) => {
|
||||||
|
console.log(position)
|
||||||
|
const x = position.coords.latitude;
|
||||||
|
const y = position.coords.longitude;
|
||||||
|
displayLocation(x, y);
|
||||||
|
};
|
||||||
|
|
||||||
|
const errorCallback = (error: GeolocationPositionError) => {
|
||||||
|
let errorMessage = 'Unknown error';
|
||||||
|
switch (error.code) {
|
||||||
|
case 1:
|
||||||
|
errorMessage = 'Permission denied';
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
errorMessage = 'Position unavailable';
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
errorMessage = 'Timeout';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
alert(errorMessage)
|
||||||
|
};
|
||||||
|
|
||||||
|
const displayLocation = async (latitude: number, longitude: number) => {
|
||||||
|
// const res = await fetch('https://maps.googleapis.com/maps/api/geocode/json?latlng=' + latitude + ',' + longitude + '&sensor=true&key=' + '')
|
||||||
|
// const res = await fetch('https://maps.googleapis.com/maps/api/geocode/json?latlng=' + latitude + ',' + longitude + '&sensor=false&key=' + '')
|
||||||
|
const res = await fetch(`https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=jsonv2&zoom=13`)
|
||||||
|
// const res = await fetch(`https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=geojson&zoom=13`)
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json()
|
||||||
|
console.log(data?.display_name)
|
||||||
|
setLocationName(data?.display_name)
|
||||||
|
} else {
|
||||||
|
alert(`${res.status} ${res.statusText}`)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleReceivePhoto = (photo: string) => {
|
||||||
|
setPhoto(photo)
|
||||||
|
setShowCamera(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Form className='space-y-8'>
|
||||||
|
{/* <div className='mt-6'>
|
||||||
|
<FormLabel>N I K</FormLabel>
|
||||||
|
<Form.Item name='username' >
|
||||||
|
<Input placeholder="930915" className='input' />
|
||||||
|
</Form.Item>
|
||||||
|
<FormDescription>
|
||||||
|
Nomor induk karyawan yang sudah terdaftar di sistem. Silakan lihat pada <Link href="/niktg-list" className='text-blue-500 font-semibold'>link berikut</Link> untuk melihat daftar nik karyawan.
|
||||||
|
</FormDescription>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<FormLabel>Email</FormLabel>
|
||||||
|
<Form.Item>
|
||||||
|
<Select placeholder='Select a verified email to display'>
|
||||||
|
<Select.Option value="m@example.com">m@example.com</Select.Option>
|
||||||
|
<Select.Option value="m@google.com">m@google.com</Select.Option>
|
||||||
|
<Select.Option value="m@support.com">m@support.com</Select.Option>
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
|
<FormDescription>
|
||||||
|
You can manage verified email addresses in your{" "}
|
||||||
|
<Link href="/examples/forms">email settings</Link>.
|
||||||
|
</FormDescription>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<FormLabel>Datetime</FormLabel>
|
||||||
|
<Form.Item>
|
||||||
|
<DatePicker className='w-full h-10' showTime />
|
||||||
|
</Form.Item>
|
||||||
|
<FormDescription>
|
||||||
|
Tanggal dan waktu absensi
|
||||||
|
</FormDescription>
|
||||||
|
</div> */}
|
||||||
|
<div className='space-y-1'>
|
||||||
|
<FormLabel>Working status</FormLabel>
|
||||||
|
<FormDescription>Status kerja pada saat absensi</FormDescription>
|
||||||
|
<div className='flex items-center space-x-5'>
|
||||||
|
<div className='flex flex-col items-center space-y-1'>
|
||||||
|
<button className={`rounded-xl w-20 h-20 ${workingStatus === 'WFO' ? 'bg-zinc-200 dark:bg-zinc-700 ' : 'btn-outline'} `} onClick={() => setWorkingStatus('WFO')}>
|
||||||
|
<i className="ti ti-building-skyscraper icon text-2xl"></i>
|
||||||
|
</button>
|
||||||
|
<p>WFO</p>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col items-center space-y-1'>
|
||||||
|
<button className={`rounded-xl w-20 h-20 ${workingStatus === 'WFH' ? 'bg-zinc-200 dark:bg-zinc-700 ' : 'btn-outline'}`} onClick={() => setWorkingStatus('WFH')}>
|
||||||
|
<i className="ti ti-home icon text-2xl"></i>
|
||||||
|
</button>
|
||||||
|
<p>WFH</p>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col items-center space-y-1'>
|
||||||
|
<button className={`rounded-xl w-20 h-20 ${workingStatus === 'WFS' ? 'bg-zinc-200 dark:bg-zinc-700 ' : 'btn-outline'}`} onClick={() => setWorkingStatus('WFS')}>
|
||||||
|
<i className="ti ti-building-community icon text-2xl"></i>
|
||||||
|
</button>
|
||||||
|
<p>WFS</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/* <Form.Item>
|
||||||
|
<Radio.Group className='flex flex-col space-y-1'>
|
||||||
|
<Radio value={1}>
|
||||||
|
<FormLabel className='font-normal ml-2'>WFO</FormLabel>
|
||||||
|
</Radio>
|
||||||
|
<Radio value={2}>
|
||||||
|
<FormLabel className='font-normal ml-2'>WFH</FormLabel>
|
||||||
|
</Radio>
|
||||||
|
<Radio value={3}>
|
||||||
|
<FormLabel className='font-normal ml-2'>WFS</FormLabel>
|
||||||
|
</Radio>
|
||||||
|
</Radio.Group>
|
||||||
|
</Form.Item> */}
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col space-y-2'>
|
||||||
|
<FormLabel>Take photo</FormLabel>
|
||||||
|
{photo ?
|
||||||
|
<div className='flex flex-col space-y-2'>
|
||||||
|
<img src={photo} alt='' className='w-48 h-64 object-cover rounded-2xl shadow' style={{ transform: 'scaleX(-1)' }} />
|
||||||
|
<Button variant='outline' onClick={() => setShowCamera(true)}>
|
||||||
|
<CameraIcon className='mr-2 w-4 h-4' />Retake photo
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
:
|
||||||
|
<button className='btn-outline w-36 h-36 rounded-xl flex items-center justify-center'
|
||||||
|
onClick={() => setShowCamera(true)}
|
||||||
|
>
|
||||||
|
<CameraIcon size={64} />
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<FormLabel>Note</FormLabel>
|
||||||
|
<Form.Item>
|
||||||
|
<Textarea
|
||||||
|
placeholder="Tell us a little bit about yourself"
|
||||||
|
className="resize-none"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<FormDescription>
|
||||||
|
Tambahkan catatan kehadiran jika diperlukan
|
||||||
|
</FormDescription>
|
||||||
|
</div>
|
||||||
|
<Button type="submit">Submit</Button>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
{showCamera && <Camera onClose={() => setShowCamera(false)} onSubmit={handleReceivePhoto} />}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default FormComponent;
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#webcam {
|
||||||
|
clear: both;
|
||||||
|
display: block;
|
||||||
|
/* transform: rotateY(180deg); */
|
||||||
|
/* -webkit-transform: rotateY(180deg); */
|
||||||
|
/* -moz-transform: rotateY(180deg); */
|
||||||
|
transform: scaleX(-1);
|
||||||
|
-webkit-transform: scaleX(-1);
|
||||||
|
-moz-transform: scaleX(-1);
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { FC } from 'react';
|
||||||
|
import { Separator } from '@/components/ui/separator';
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import FormComponent from './components/FormComponent';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
searchParams: { [key: string]: string | string[] | undefined }
|
||||||
|
};
|
||||||
|
|
||||||
|
const PresencePage: FC<Props> = ({ searchParams: { checkout } }) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='flex-1 lg:w-1/2 mx-auto px-5 py-10 md:p-10 pb-16'>
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<div>
|
||||||
|
<CardTitle className="text-lg font-medium">{checkout === 'true' ? 'Check-out Presence' : 'Check-in Presence'}</CardTitle>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
This is how others will see you on the site.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<Separator className='w-10/12 xl:w-11/12 mx-auto' />
|
||||||
|
<CardContent className='mt-6'>
|
||||||
|
<FormComponent />
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PresencePage;
|
||||||
@@ -0,0 +1,249 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { ChangeEvent, FC, Fragment, lazy, Suspense, useCallback, useState } from 'react';
|
||||||
|
import Image from 'next/image';
|
||||||
|
import Cropper from 'react-easy-crop';
|
||||||
|
import { Range } from 'react-range';
|
||||||
|
import { getOrientation } from 'get-orientation/browser';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
|
||||||
|
import { Icons } from '@/components/Icons';
|
||||||
|
import { getCroppedImg, getRotatedImage } from '@/lib/canvasUtils';
|
||||||
|
import { blobToBase64, randomIntFromInterval, readFile } from '@/lib/helper';
|
||||||
|
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||||
|
import PageLoading from '@/components/loader/PageLoading';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import FallbackAvatar from '@/components/loader/FallbackAvatar';
|
||||||
|
|
||||||
|
const ViewAvatar = lazy(() => import('@/components/ViewAvatar'));
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
nik: string
|
||||||
|
existAvatar?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
const ORIENTATION_TO_ANGLE: any = {
|
||||||
|
'3': 180,
|
||||||
|
'6': 90,
|
||||||
|
'8': -90,
|
||||||
|
}
|
||||||
|
|
||||||
|
const ChangeAvatar: FC<Props> = ({ nik, existAvatar }) => {
|
||||||
|
const [isFullLoading, setIsFullLoading] = useState(false)
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
const [showFormDialog, setShowFormDialog] = useState(false)
|
||||||
|
const [imageSrc, setImageSrc] = useState<any>(null)
|
||||||
|
const [crop, setCrop] = useState({ x: 0, y: 0 })
|
||||||
|
const [rotation, setRotation] = useState(0)
|
||||||
|
const [zoom, setZoom] = useState(1)
|
||||||
|
const [croppedAreaPixels, setCroppedAreaPixels] = useState(null)
|
||||||
|
const [croppedImage, setCroppedImage] = useState<any>(null)
|
||||||
|
const [values, setValues] = useState([1])
|
||||||
|
const [values2, setValues2] = useState([0])
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
const axios = useAxiosAuth()
|
||||||
|
|
||||||
|
const onCropComplete = useCallback((croppedArea: any, croppedAreaPixels: any) => {
|
||||||
|
setCroppedAreaPixels(croppedAreaPixels)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const showCroppedImage = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const croppedImage = await getCroppedImg(
|
||||||
|
imageSrc,
|
||||||
|
croppedAreaPixels,
|
||||||
|
rotation
|
||||||
|
)
|
||||||
|
console.log('donee', croppedImage)
|
||||||
|
setCroppedImage(croppedImage)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
|
}, [imageSrc, croppedAreaPixels, rotation])
|
||||||
|
|
||||||
|
// eslint-disable-next-line
|
||||||
|
const onClose = useCallback(() => {
|
||||||
|
setCroppedImage(null)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const onFileChange = async (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
if (e.target.files && e.target.files.length > 0) {
|
||||||
|
const file = e.target.files[0]
|
||||||
|
if (file.name.includes('.HEIC') || file.name.includes('.heic')) {
|
||||||
|
setIsFullLoading(true)
|
||||||
|
const heic2any = (await import('heic2any')).default;
|
||||||
|
heic2any({
|
||||||
|
blob: file,
|
||||||
|
quality: file.size > 5000000 ? 0.05 : file.size > 4000000 ? 0.09 : file.size > 3000000 ? 0.1 : file.size > 2000000 ? 0.2 : 0.4,
|
||||||
|
toType: 'image/jpeg'
|
||||||
|
}).then(async (blob: any) => {
|
||||||
|
let imageDataUrl = await blobToBase64(blob)
|
||||||
|
|
||||||
|
const orientation = await getOrientation(file)
|
||||||
|
const rotation = ORIENTATION_TO_ANGLE[orientation]
|
||||||
|
if (rotation) {
|
||||||
|
imageDataUrl = await getRotatedImage(imageDataUrl, rotation)
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsFullLoading(false)
|
||||||
|
setImageSrc(imageDataUrl)
|
||||||
|
}).catch((err) => {
|
||||||
|
toast.error('Failed upload photo', { description: err.message })
|
||||||
|
setIsFullLoading(false)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
let imageDataUrl = await readFile(file)
|
||||||
|
|
||||||
|
// apply rotation if needed
|
||||||
|
const orientation = await getOrientation(file)
|
||||||
|
const rotation = ORIENTATION_TO_ANGLE[orientation]
|
||||||
|
if (rotation) {
|
||||||
|
imageDataUrl = await getRotatedImage(imageDataUrl, rotation)
|
||||||
|
}
|
||||||
|
|
||||||
|
setImageSrc(imageDataUrl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSavePhoto = async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true)
|
||||||
|
|
||||||
|
await axios.post('/user/change-avatar', { nik, avatar: croppedImage?.base64 ? croppedImage.base64?.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '') : '' })
|
||||||
|
|
||||||
|
toast.success('Avatar changed successfully.')
|
||||||
|
handleCloseDialog()
|
||||||
|
router.refresh()
|
||||||
|
} catch (error: any) {
|
||||||
|
toast.error(`Failed to change avatar`, {
|
||||||
|
description: `(${error?.response?.data?.code || error?.response?.status || '-'}) ${error?.response?.data?.message || error?.response?.statusText || error?.message}`
|
||||||
|
})
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCloseDialog = () => {
|
||||||
|
setIsLoading(false)
|
||||||
|
setShowFormDialog(false)
|
||||||
|
setImageSrc(null)
|
||||||
|
setCrop({ x: 0, y: 0 })
|
||||||
|
setRotation(0)
|
||||||
|
setZoom(1)
|
||||||
|
setCroppedAreaPixels(null)
|
||||||
|
setCroppedImage(null)
|
||||||
|
setValues([1])
|
||||||
|
setValues2([0])
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='flex flex-col sm:flex-row items-center sm:space-x-6 xl:space-x-8 space-y-5 sm:space-y-0 pt-6'>
|
||||||
|
<Suspense fallback={<FallbackAvatar className='w-[120px] h-[120px] md:w-40 md:h-40' />}>
|
||||||
|
<ViewAvatar avatar={existAvatar!} className='w-[120px] h-[120px] md:w-40 md:h-40 duration-300' sizes="(max-width: 768px) 100vw, 200px" quality={80} />
|
||||||
|
</Suspense>
|
||||||
|
<div className='flex flex-col items-center sm:items-start space-y-3'>
|
||||||
|
<p className='w-full xl:w-5/12 text-center sm:text-left text-sm'>Personalize your account with photos. Your profile photo will appear on apps and devices that use your Supper Apps account.</p>
|
||||||
|
<Dialog open={showFormDialog} onOpenChange={setShowFormDialog}>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<Button variant='outline' className='w-full sm:w-max'>Change Photo</Button>
|
||||||
|
</DialogTrigger>
|
||||||
|
<DialogContent className=" overflow-y-auto max-h-[95vh]">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle className="dark:text-white">Change profile photo</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Personalize your account with photos
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
{imageSrc ?
|
||||||
|
<Fragment>
|
||||||
|
<div className='w-full h-64 relative'>
|
||||||
|
<Cropper image={imageSrc} crop={crop} rotation={rotation} zoom={zoom} aspect={1 / 1}
|
||||||
|
onCropChange={setCrop}
|
||||||
|
onRotationChange={setRotation}
|
||||||
|
onCropComplete={onCropComplete}
|
||||||
|
onZoomChange={setZoom}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className=''>
|
||||||
|
<div className=''>
|
||||||
|
<label>Zoom {zoom?.toFixed(1)}x</label>
|
||||||
|
<Range step={0.1} min={1} max={3} values={values} onChange={(values) => { setValues(values); setZoom(values[0]) }}
|
||||||
|
renderTrack={({ props, children }) => (
|
||||||
|
<div {...props} key={randomIntFromInterval(0, 100)} className="w-full h-3 pr-2 my-4 bg-gray-200 rounded-md" >
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
renderThumb={({ props }) => (
|
||||||
|
<div {...props} key={randomIntFromInterval(100, 200)}
|
||||||
|
className="w-5 h-5 transform bg-his rounded-full focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-his"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label>Rotation {rotation}°</label>
|
||||||
|
<Range step={1} min={0} max={360} values={values2} onChange={(values) => { setValues2(values); setRotation(values[0]) }}
|
||||||
|
renderTrack={({ props, children }) => (
|
||||||
|
<div {...props} key={randomIntFromInterval(200, 300)} className="w-full h-3 pr-2 my-4 bg-gray-200 rounded-md" >
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
renderThumb={({ props }) => (
|
||||||
|
<div {...props} key={randomIntFromInterval(300, 400)}
|
||||||
|
className="w-5 h-5 transform bg-his rounded-full focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-his"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className='flex items-center justify-center mt-5'>
|
||||||
|
<Button onClick={showCroppedImage} variant='secondary' >
|
||||||
|
<i className="ti ti-eye text-lg mr-2"></i>
|
||||||
|
Preview
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{croppedImage &&
|
||||||
|
<div className='flex items-center justify-center flex-col mt-5'>
|
||||||
|
<Image alt='cropped-image' height={0} width={0} quality={100} src={croppedImage.base64} className='w-10/12 mx-auto rounded-xl border-2 border-slate-400 dark:border-slate-500' />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</Fragment>
|
||||||
|
:
|
||||||
|
<div className='flex flex-col justify-center items-center'>
|
||||||
|
{existAvatar ?
|
||||||
|
<Image src={`${process.env.BASE_URL_IMG}/${existAvatar}`} alt="avatar" width={120} height={120} className="rounded-full border dark:border-zinc-800 object-cover" />
|
||||||
|
:
|
||||||
|
<Image alt='avatar' height={0} width={0} sizes='50vw' quality={75} src='/assets/no-avatar.jpg' className='w-[120px] h-[120px] rounded-full border dark:border-zinc-800 object-cover' />
|
||||||
|
}
|
||||||
|
<label htmlFor='foto' className='text-his mt-4 font-medium cursor-pointer hover:underline hover:text-his/50 duration-300'>Change profile photo</label>
|
||||||
|
<input id='foto' type="file" onChange={onFileChange} accept="image/*,.heic" className='hidden' />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" type="button" onClick={handleCloseDialog} disabled={isLoading} >
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
{croppedImage &&
|
||||||
|
<Button type="submit" disabled={isLoading} onClick={handleSavePhoto}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{isFullLoading &&
|
||||||
|
<PageLoading className='bg-opacity-40 dark:bg-opacity-20 z-999' title='Uploading photo..' />
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ChangeAvatar;
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { FC, Suspense, lazy, useState } from 'react';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Dialog, DialogTrigger } from '@/components/ui/dialog';
|
||||||
|
import LazyLoading from '@/components/loader/LazyLoading';
|
||||||
|
import { type IUser } from '@/app/admin/administration/user/component/type';
|
||||||
|
|
||||||
|
const FormChangePassword = lazy(() => import('@/app/admin/administration/user/component/FormChangePassword'))
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data?: IUser
|
||||||
|
};
|
||||||
|
|
||||||
|
const ChangePassword: FC<Props> = ({ data }) => {
|
||||||
|
const [showFormChangePass, setShowFormChangePass] = useState(false)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Dialog open={showFormChangePass} onOpenChange={(state) => {
|
||||||
|
setShowFormChangePass(state)
|
||||||
|
}}>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<Button>Change password</Button>
|
||||||
|
</DialogTrigger>
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<FormChangePassword data={data} onCancel={() => setShowFormChangePass(false)} />
|
||||||
|
</Suspense>
|
||||||
|
</Dialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ChangePassword;
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
'use client'
|
||||||
|
import { useTheme } from 'next-themes';
|
||||||
|
import { FC } from 'react';
|
||||||
|
|
||||||
|
type Props = {};
|
||||||
|
|
||||||
|
const ChangeTheme: FC<Props> = ({ }) => {
|
||||||
|
const { theme, setTheme } = useTheme()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='hidden sm:flex flex-col sm:flex-row space-y-2 sm:space-y-0 sm sm:space-x-2 xl:space-x-4 font-medium'>
|
||||||
|
<div className='cursor-pointer' onClick={() => setTheme('light')}>
|
||||||
|
<div className={`items-center rounded-lg border-2 bg-popover p-1 hover:bg-accent hover:text-accent-foreground ${theme === 'light' ? 'border-his' : 'border-muted'}`}>
|
||||||
|
<div className="space-y-2 rounded-md bg-[#ecedef] p-2">
|
||||||
|
<div className="space-y-2 rounded-md bg-white p-2 shadow-sm">
|
||||||
|
<div className="h-2 w-20 rounded-lg bg-[#ecedef]" />
|
||||||
|
<div className="h-2 w-[100px] rounded-lg bg-[#ecedef]" />
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2 rounded-md bg-white p-2 shadow-sm">
|
||||||
|
<div className="h-4 w-4 rounded-full bg-[#ecedef]" />
|
||||||
|
<div className="h-2 w-[100px] rounded-lg bg-[#ecedef]" />
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2 rounded-md bg-white p-2 shadow-sm">
|
||||||
|
<div className="h-4 w-4 rounded-full bg-[#ecedef]" />
|
||||||
|
<div className="h-2 w-[100px] rounded-lg bg-[#ecedef]" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span className="block w-full p-2 text-center font-normal">
|
||||||
|
Light
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="[&:has([data-state=checked])>div]:border-primary cursor-pointer" onClick={() => setTheme('dark')}>
|
||||||
|
<div className={`items-center rounded-lg border-2 bg-popover p-1 hover:bg-accent hover:text-accent-foreground ${theme === 'dark' ? 'border-his' : 'border-muted'}`}>
|
||||||
|
<div className="space-y-2 rounded-md bg-slate-950 p-2">
|
||||||
|
<div className="space-y-2 rounded-md bg-slate-800 p-2 shadow-sm">
|
||||||
|
<div className="h-2 w-20 rounded-lg bg-slate-400" />
|
||||||
|
<div className="h-2 w-[100px] rounded-lg bg-slate-400" />
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2 rounded-md bg-slate-800 p-2 shadow-sm">
|
||||||
|
<div className="h-4 w-4 rounded-full bg-slate-400" />
|
||||||
|
<div className="h-2 w-[100px] rounded-lg bg-slate-400" />
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2 rounded-md bg-slate-800 p-2 shadow-sm">
|
||||||
|
<div className="h-4 w-4 rounded-full bg-slate-400" />
|
||||||
|
<div className="h-2 w-[100px] rounded-lg bg-slate-400" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span className="block w-full p-2 text-center font-normal">
|
||||||
|
Dark
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="[&:has([data-state=checked])>div]:border-primary cursor-pointer" onClick={() => setTheme('system')}>
|
||||||
|
<div className={`items-center rounded-lg border-2 bg-popover p-1 hover:bg-accent hover:text-accent-foreground ${theme === 'system' ? 'border-his' : 'border-muted'}`}>
|
||||||
|
<div className="space-y-2 rounded-md bg-zinc-950 p-2">
|
||||||
|
<div className="space-y-2 rounded-md bg-zinc-800 p-2 shadow-sm">
|
||||||
|
<div className="h-2 w-20 rounded-lg bg-zinc-400" />
|
||||||
|
<div className="h-2 w-[100px] rounded-lg bg-zinc-400" />
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2 rounded-md bg-zinc-800 p-2 shadow-sm">
|
||||||
|
<div className="h-4 w-4 rounded-full bg-zinc-400" />
|
||||||
|
<div className="h-2 w-[100px] rounded-lg bg-zinc-400" />
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2 rounded-md bg-zinc-800 p-2 shadow-sm">
|
||||||
|
<div className="h-4 w-4 rounded-full bg-zinc-400" />
|
||||||
|
<div className="h-2 w-[100px] rounded-lg bg-zinc-400" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span className="block w-full p-2 text-center font-normal">
|
||||||
|
System
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='sm:hidden flex flex-row space-x-2 font-medium'>
|
||||||
|
<div className='cursor-pointer' onClick={() => setTheme('light')}>
|
||||||
|
<div className={`items-center rounded-lg border-2 bg-popover p-1 hover:bg-accent hover:text-accent-foreground ${theme === 'light' ? 'border-his' : 'border-muted'}`}>
|
||||||
|
<div className="space-y-2 rounded-md bg-[#ecedef] p-2">
|
||||||
|
<div className="space-y-2 rounded-md bg-white p-2 shadow-sm">
|
||||||
|
<div className="h-2 w-5 rounded-lg bg-[#ecedef]" />
|
||||||
|
<div className="h-2 w-8 rounded-lg bg-[#ecedef]" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span className="block w-full p-2 text-center font-normal">
|
||||||
|
Light
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="[&:has([data-state=checked])>div]:border-primary cursor-pointer" onClick={() => setTheme('dark')}>
|
||||||
|
<div className={`items-center rounded-lg border-2 bg-popover p-1 hover:bg-accent hover:text-accent-foreground ${theme === 'dark' ? 'border-his' : 'border-muted'}`}>
|
||||||
|
<div className="space-y-2 rounded-md bg-slate-950 p-2">
|
||||||
|
<div className="space-y-2 rounded-md bg-slate-800 p-2 shadow-sm">
|
||||||
|
<div className="h-2 w-5 rounded-lg bg-slate-400" />
|
||||||
|
<div className="h-2 w-8 rounded-lg bg-slate-400" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span className="block w-full p-2 text-center font-normal">
|
||||||
|
Dark
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="[&:has([data-state=checked])>div]:border-primary cursor-pointer" onClick={() => setTheme('system')}>
|
||||||
|
<div className={`items-center rounded-lg border-2 bg-popover p-1 hover:bg-accent hover:text-accent-foreground ${theme === 'system' ? 'border-his' : 'border-muted'}`}>
|
||||||
|
<div className="space-y-2 rounded-md bg-zinc-950 p-2">
|
||||||
|
<div className="space-y-2 rounded-md bg-zinc-800 p-2 shadow-sm">
|
||||||
|
<div className="h-2 w-5 rounded-lg bg-zinc-400" />
|
||||||
|
<div className="h-2 w-8 rounded-lg bg-zinc-400" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span className="block w-full p-2 text-center font-normal">
|
||||||
|
System
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ChangeTheme;
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { FC, useEffect, useState } from 'react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { DatePicker, Form, Input, Select } from 'antd';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { Icons } from '@/components/Icons';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
|
||||||
|
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||||
|
import { type IProfile } from './type';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
|
const EDUCATION_LIST = [
|
||||||
|
{ value: 'D1', label: 'Diploma I' },
|
||||||
|
{ value: 'D2', label: 'Diploma 2' },
|
||||||
|
{ value: 'D3', label: 'Diploma 3' },
|
||||||
|
{ value: 'D4', label: 'Diploma 4' },
|
||||||
|
{ value: 'S1', label: 'Strata 1' },
|
||||||
|
{ value: 'S2', label: 'Strata 2' },
|
||||||
|
{ value: 'S3', label: 'Doktor' },
|
||||||
|
]
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data?: IProfile
|
||||||
|
};
|
||||||
|
|
||||||
|
const EditProfile: FC<Props> = ({ data }) => {
|
||||||
|
const [showDialog, setShowDialog] = useState(false)
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
const router = useRouter()
|
||||||
|
const axios = useAxiosAuth()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data) {
|
||||||
|
form.setFieldsValue(data)
|
||||||
|
if (data.birthday) form.setFieldValue('birthday', dayjs(data.birthday))
|
||||||
|
} else {
|
||||||
|
form.resetFields()
|
||||||
|
}
|
||||||
|
}, [data, form])
|
||||||
|
|
||||||
|
const handleSubmit = (value: any) => {
|
||||||
|
console.log(value)
|
||||||
|
|
||||||
|
handleUpdate(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleUpdate = async (payload: any) => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true)
|
||||||
|
|
||||||
|
await axios.put('/user/profile/update', payload)
|
||||||
|
|
||||||
|
toast.success('Profile changed successfully.')
|
||||||
|
form.resetFields()
|
||||||
|
setShowDialog(false)
|
||||||
|
router.refresh()
|
||||||
|
} catch (error: any) {
|
||||||
|
toast.error(`Fail to update profile`, { description: `(${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}` })
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCancel = () => {
|
||||||
|
form.resetFields()
|
||||||
|
setShowDialog(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Dialog open={showDialog} onOpenChange={(state) => {
|
||||||
|
setShowDialog(state)
|
||||||
|
}}>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<Button variant='secondary'>
|
||||||
|
Edit Profile <i className="ti ti-edit ml-2 text-lg"></i>
|
||||||
|
</Button>
|
||||||
|
</DialogTrigger>
|
||||||
|
{showDialog &&
|
||||||
|
<DialogContent className='max-h-[95vh] overflow-y-auto' forceMount>
|
||||||
|
<Form form={form} onFinish={handleSubmit} scrollToFirstError layout="vertical" size='small'>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle className="dark:text-white">Edit Profile</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Adjust your profile data with the latest data
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className='grid grid-cols-1 font-medium gap-y-0 mt-5'>
|
||||||
|
<Form.Item name='nickname' label='Nickname' >
|
||||||
|
<Input className="input" id="nickname" placeholder="John" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label='Phone Number' name='phone_number' rules={[
|
||||||
|
{ pattern: /^\d+$/, message: 'Invalid phone number' },
|
||||||
|
{ min: 10 }, { max: 13 }
|
||||||
|
]}>
|
||||||
|
<Input className="input" id="phone_number" placeholder="6281234567890" maxLength={13} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label='Office Email' name='email_office' rules={[
|
||||||
|
{ type: 'email', message: 'The input is not valid E-mail!' }]}
|
||||||
|
>
|
||||||
|
<Input className="input" id="email_office" placeholder="john@nutech-integrasi.com" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label='Personal Email' name='email_personal' rules={[
|
||||||
|
{ type: 'email', message: 'The input is not valid E-mail!' }]}
|
||||||
|
>
|
||||||
|
<Input className="input" id="email_personal" placeholder="john@gmail.com" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label='Birthdate' name='birthday'>
|
||||||
|
<DatePicker className='w-full' placeholder='Select date of birth' size='large'
|
||||||
|
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label='Last Education' name='last_education' >
|
||||||
|
<Select placeholder='Select last education' showSearch allowClear
|
||||||
|
optionFilterProp="children"
|
||||||
|
filterOption={(input, option) => (option?.label ?? '').toLowerCase().includes(input.toLowerCase())}
|
||||||
|
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||||
|
size='large'
|
||||||
|
options={EDUCATION_LIST} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label='Mayor' name='major' >
|
||||||
|
<Input className="input" id="major" placeholder="Informatics Engineering" />
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" type="button" onClick={handleCancel} disabled={isLoading} >
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" disabled={isLoading}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-2 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</Form>
|
||||||
|
</DialogContent>
|
||||||
|
}
|
||||||
|
</Dialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EditProfile;
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { FC, ReactNode, useState } from 'react';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
|
||||||
|
import useMobileView from '@/hooks/useMobileView';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
children?: ReactNode
|
||||||
|
};
|
||||||
|
|
||||||
|
const ForgotPassword: FC<Props> = ({ children }) => {
|
||||||
|
const { isMobile } = useMobileView()
|
||||||
|
const [showDialog, setShowDialog] = useState(false)
|
||||||
|
|
||||||
|
const handleForgotPassword = () => {
|
||||||
|
const name = process.env.NEXT_PUBLIC_HATS_SUPPORT_NAME
|
||||||
|
const phone = process.env.NEXT_PUBLIC_HATS_SUPPORT_PHONE
|
||||||
|
|
||||||
|
const text = `Hello ${name}, here I convey that I forgot my HIS Attendance Task System (H.A.T.s) account password, I ask for your help to reset my account password, thank you in advance :)`
|
||||||
|
|
||||||
|
let url = `https://wa.me/${phone}?text=${text}`
|
||||||
|
|
||||||
|
if (isMobile) {
|
||||||
|
url = `https://api.whatsapp.com/send?phone=${phone}&text=${text}`
|
||||||
|
} else {
|
||||||
|
url = `https://web.whatsapp.com/send?phone=${phone}&text=${text}`
|
||||||
|
}
|
||||||
|
|
||||||
|
window.open(url, '_blank')!.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Dialog open={showDialog} onOpenChange={setShowDialog}>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
{children ?
|
||||||
|
children
|
||||||
|
:
|
||||||
|
<Button variant='ghost'>I forgot my passsword</Button>
|
||||||
|
}
|
||||||
|
</DialogTrigger>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle className="dark:text-white">Confirm forgot password</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Are you sure to continue this process?
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<DialogFooter className='mt-5'>
|
||||||
|
<Button variant="outline" type="button" onClick={() => setShowDialog(false)} >
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" onClick={handleForgotPassword}>
|
||||||
|
Continue
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ForgotPassword;
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { FC, useState } from 'react';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { signOut } from 'next-auth/react';
|
||||||
|
import { LoaderCircle } from 'lucide-react';
|
||||||
|
|
||||||
|
type Props = {};
|
||||||
|
|
||||||
|
const Logout: FC<Props> = () => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
|
const handleLogout = async () => {
|
||||||
|
setIsLoading(true);
|
||||||
|
signOut();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='block sm:hidden'>
|
||||||
|
<Button variant='destructive' className='w-full' disabled={isLoading} onClick={handleLogout}>{isLoading ? <LoaderCircle className='animate-spin' /> : null} Logout</Button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Logout;
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { IArea } from "@/app/admin/administration/area/component/type"
|
||||||
|
import { ICompany } from "@/app/admin/administration/company/component/type"
|
||||||
|
import { IDivision } from "@/app/admin/administration/division/component/type"
|
||||||
|
import { IEmployeeType } from "@/app/admin/information/employee-type/component/type"
|
||||||
|
import { IMasterStatus } from "@/app/admin/information/master-status/component/type"
|
||||||
|
import { IPosition } from "@/app/admin/information/position/component/type"
|
||||||
|
import { IRole } from "@/app/admin/information/user-role/component/type"
|
||||||
|
|
||||||
|
export type IProfile = {
|
||||||
|
id: number
|
||||||
|
email: string
|
||||||
|
nik: number | string
|
||||||
|
niktg: number | string
|
||||||
|
fullname: string
|
||||||
|
nickname: string
|
||||||
|
gender: 'male' | 'female'
|
||||||
|
birthday: string
|
||||||
|
phone_number: string
|
||||||
|
avatar: string
|
||||||
|
email_office: string
|
||||||
|
email_personal: string
|
||||||
|
last_education: string
|
||||||
|
major: string
|
||||||
|
role: IRole
|
||||||
|
company: ICompany
|
||||||
|
division: IDivision
|
||||||
|
area: IArea
|
||||||
|
employee_type: IEmployeeType
|
||||||
|
position: IPosition
|
||||||
|
hire_date: string
|
||||||
|
contract_expiration_date: string
|
||||||
|
contract_count: number
|
||||||
|
activated_at: string
|
||||||
|
status: IMasterStatus
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { Skeleton } from "@/components/ui/skeleton"
|
||||||
|
|
||||||
|
export default function Loading() {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col w-full p-6 space-y-8">
|
||||||
|
<Skeleton className="h-10 w-40" />
|
||||||
|
<div className="flex flex-col w-full p-6 space-y-8 border border-border rounded-2xl">
|
||||||
|
<div className="w-full flex flex-row justify-between">
|
||||||
|
<Skeleton className="h-8 w-32" />
|
||||||
|
<Skeleton className="h-8 w-24" />
|
||||||
|
</div>
|
||||||
|
<Skeleton className="h-40 w-full" />
|
||||||
|
<Skeleton className="h-80 w-full" />
|
||||||
|
<Skeleton className="h-80 w-full" />
|
||||||
|
<Skeleton className="h-80 w-full" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,280 @@
|
|||||||
|
import { Suspense, lazy } from 'react';
|
||||||
|
import { type Metadata } from 'next';
|
||||||
|
import Link from 'next/link';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||||
|
import { Card, Card900, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import Logout from './components/Logout';
|
||||||
|
import LazyLoading from '@/components/loader/LazyLoading';
|
||||||
|
|
||||||
|
import { type IProfile } from './components/type';
|
||||||
|
import { type IUser } from '@/app/admin/administration/user/component/type';
|
||||||
|
import { getServerSession } from 'next-auth';
|
||||||
|
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||||
|
|
||||||
|
const ForgotPassword = lazy(() => import('./components/ForgotPassword'));
|
||||||
|
const ChangeTheme = lazy(() => import("./components/ChangeTheme"))
|
||||||
|
const ChangePassword = lazy(() => import("./components/ChangePassword"))
|
||||||
|
const EditProfile = lazy(() => import("./components/EditProfile"))
|
||||||
|
const ChangeAvatar = lazy(() => import("./components/ChangeAvatar"))
|
||||||
|
|
||||||
|
export async function generateMetadata(): Promise<Metadata> {
|
||||||
|
const session = await getServerSession(authOptions)
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: `${session?.user?.detail.fullname || 'User'}'s Profile`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function ProfilePage() {
|
||||||
|
const session = await getServerSession(authOptions)
|
||||||
|
const data: IProfile = await fetchDataWithPost('/user/profile', {}, 'default', { tags: ['profile-data'] })
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="flex-1 space-y-8 p-6 sm:p-8 pt-6 pb-44 md:pb-8">
|
||||||
|
<h1 className="text-lg sm:text-3xl font-medium tracking-tight capitalize">Account Settings</h1>
|
||||||
|
<Card className=''>
|
||||||
|
<CardHeader className='flex flex-row items-center justify-between'>
|
||||||
|
<CardTitle>My Profile</CardTitle>
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<EditProfile data={data} />
|
||||||
|
</Suspense>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className='space-y-6 text-sm sm:text-base'>
|
||||||
|
<Card900 className='sm:px-3'>
|
||||||
|
<CardContent>
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<ChangeAvatar nik={data.nik as string} existAvatar={data.avatar} />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
<Card900 className='sm:px-5'>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className='text-base'>Personal Information</CardTitle>
|
||||||
|
<CardDescription>This is how others will see you on the site.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className='grid grid-cols-1 sm:grid-cols-2 font-medium gap-y-3'>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Fullname</span>
|
||||||
|
<span>{data.fullname}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Nickname</span>
|
||||||
|
<span>{data.nickname}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Email Address</span>
|
||||||
|
<span className='lowercase'>{data.email}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Phone</span>
|
||||||
|
<span>{data.phone_number || '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>NIK</span>
|
||||||
|
<span>{data.nik || '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>NIKTG</span>
|
||||||
|
<span>{data.niktg || '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Office Email</span>
|
||||||
|
<span className='lowercase'>{data.email_office || '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Personal Email</span>
|
||||||
|
<span className='lowercase'>{data.email_personal || '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Sex</span>
|
||||||
|
<span>{data.gender || 'Male'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Birthday</span>
|
||||||
|
<span>{data.birthday ? dayjs(data.birthday).format('MMM DD, YYYY') : '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Last Education</span>
|
||||||
|
<span>{data.last_education} {data.major}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
<Card900 className='sm:px-5'>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className='text-base'>Address Information</CardTitle>
|
||||||
|
<CardDescription>Your address information, this is how others will see you on the site.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className='grid grid-cols-1 sm:grid-cols-2 font-medium gap-y-3'>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Address</span>
|
||||||
|
<span>-</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Village</span>
|
||||||
|
<span>-</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>District</span>
|
||||||
|
<span>-</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>City</span>
|
||||||
|
<span>-</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Province</span>
|
||||||
|
<span>-</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Zip code</span>
|
||||||
|
<span>-</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
<Card900 className='sm:px-5'>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className='text-base'>Work Information</CardTitle>
|
||||||
|
<CardDescription>Your work information, this is how others will see you on the site.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className='grid grid-cols-1 sm:grid-cols-2 font-medium gap-y-3'>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Role</span>
|
||||||
|
<span>{data.role?.name}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Company</span>
|
||||||
|
<span>{data.company?.name}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Department</span>
|
||||||
|
<span>{data.division?.name} ({data.division?.code})</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Area</span>
|
||||||
|
<span>-</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Position</span>
|
||||||
|
<span>{data.position?.name || '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Employee Type</span>
|
||||||
|
<span>{data.employee_type?.name || '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Hire Date</span>
|
||||||
|
<span>{data.hire_date ? dayjs(data.hire_date).format('MMM DD, YYYY') : '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Contract Expiration Date</span>
|
||||||
|
<span>{data.contract_expiration_date ? dayjs(data.contract_expiration_date).format('MMM DD, YYYY') : '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Contract Count</span>
|
||||||
|
<span>{data.contract_count || '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Status</span>
|
||||||
|
{data.status.code === 'A' ?
|
||||||
|
<div className="px-2 py-1.5 rounded-full bg-green-500 w-24 text-center text-white shadow">{data.status.name}</div>
|
||||||
|
:
|
||||||
|
<div className="px-2 py-1.5 rounded-full bg-zinc-500 w-24 text-center text-white shadow">{data.status.name}</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
<Card900 className='sm:px-5'>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className='text-base'>Password and Authentication</CardTitle>
|
||||||
|
<CardDescription>Make sure your account is secure by update your password.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className='flex flex-col sm:flex-row space-y-2 sm:space-y-0 sm sm:space-x-2'>
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<ChangePassword data={{ nik: data.nik } as IUser} />
|
||||||
|
</Suspense>
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<ForgotPassword />
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
<Card900 className='sm:px-5'>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className='text-base'>Theme Preferences</CardTitle>
|
||||||
|
<CardDescription>Choose how Super Apps looks to you. Select a single theme, or sync with your system and automatically switch between day and night themes.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<ChangeTheme />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card900>
|
||||||
|
|
||||||
|
<div className='space-y-4 block sm:hidden pt-3'>
|
||||||
|
{session?.user.detail.role.allow_admin_panel &&
|
||||||
|
<Link href='/admin' className='sm:hidden flex'>
|
||||||
|
<i className="ti ti-spy text-lg mr-3"></i>
|
||||||
|
<div className='w-full pb-3 flex items-center justify-between border-b border-border'>
|
||||||
|
<p>Admin Panel</p>
|
||||||
|
<i className="ti ti-chevron-right text-muted-foreground"></i>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
}
|
||||||
|
<Link href='/leave' className='sm:hidden flex'>
|
||||||
|
<i className="ti ti-speedboat text-lg mr-3"></i>
|
||||||
|
<div className='w-full pb-3 flex items-center justify-between border-b border-border'>
|
||||||
|
<p>Apply for Leave</p>
|
||||||
|
<i className="ti ti-chevron-right text-muted-foreground"></i>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
<Link href='/work-permit' className='sm:hidden flex'>
|
||||||
|
<i className="ti ti-stethoscope text-lg mr-3"></i>
|
||||||
|
<div className='w-full pb-3 flex items-center justify-between border-b border-border'>
|
||||||
|
<p>Permit & Sick</p>
|
||||||
|
<i className="ti ti-chevron-right text-muted-foreground"></i>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
<Link href='/calendar' className='sm:hidden flex'>
|
||||||
|
<i className="ti ti-calendar text-lg mr-3"></i>
|
||||||
|
<div className='w-full pb-3 flex items-center justify-between border-b border-border'>
|
||||||
|
<p>H.A.T.s Calendar</p>
|
||||||
|
<i className="ti ti-chevron-right text-muted-foreground"></i>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
<Link href={`/performance/${session?.user.detail.id}`} className='sm:hidden flex'>
|
||||||
|
<i className="ti ti-chart-area-line text-lg mr-3"></i>
|
||||||
|
<div className='w-full pb-3 flex items-center justify-between border-b border-border'>
|
||||||
|
<p>My Performance</p>
|
||||||
|
<i className="ti ti-chevron-right text-muted-foreground"></i>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
<div className='text-center text-sm text-muted-foreground space-y-2'>
|
||||||
|
<div className="text-center pt-2 sm:pt-3">
|
||||||
|
<Link href="/terms" className="underline underline-offset-4 hover:text-primary">
|
||||||
|
{/* <Link href="/performance/1" className="underline underline-offset-4 hover:text-primary"> */}
|
||||||
|
Terms of Service
|
||||||
|
</Link>{" "}
|
||||||
|
and{" "}
|
||||||
|
<Link href="/privacy-policy" className="underline underline-offset-4 hover:text-primary">
|
||||||
|
Privacy Policy
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
<p>App Version <Link href={`/release-notes#${process.env.NEXT_PUBLIC_APP_VERSION}`} className="underline hover:text-blue-500 duration-200">{process.env.NEXT_PUBLIC_APP_VERSION}</Link> </p>
|
||||||
|
</div>
|
||||||
|
<Logout />
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,190 @@
|
|||||||
|
import { Badge } from "@/components/ui/badge";
|
||||||
|
import { Bug, Calendar, Sparkles, Wrench, Zap } from "lucide-react";
|
||||||
|
import { Metadata } from "next";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { ReactNode } from "react";
|
||||||
|
|
||||||
|
interface ReleaseNote {
|
||||||
|
version: string;
|
||||||
|
date: string;
|
||||||
|
type: 'major' | 'minor' | 'patch';
|
||||||
|
changes: {
|
||||||
|
category: 'feature' | 'improvement' | 'bugfix' | 'breaking';
|
||||||
|
description: string | ReactNode;
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const releaseNotes: ReleaseNote[] = [
|
||||||
|
{
|
||||||
|
version: "v1.1.0",
|
||||||
|
date: "25 December 2025",
|
||||||
|
type: "minor",
|
||||||
|
changes: [
|
||||||
|
{ category: 'breaking', description: <div>Fixing Critical Security Vulnerability (React2Shell Security <Link href='https://www.cve.org/CVERecord?id=CVE-2025-55182' className="underline text-blue-500">CVE-2025-55182</Link>) in React Server Components. Please see this <Link href='https://react.dev/blog/2025/12/03/critical-security-vulnerability-in-react-server-components' className="underline text-blue-500"> React blog</Link> and this <Link href='https://vercel.com/kb/bulletin/react2shell' className="underline text-blue-500">Next.js bulletin</Link> to learn more about these vulnerabilities (December 3, 2025).</div> },
|
||||||
|
{ category: 'breaking', description: <div>Fixing two additional vulnerabilities (Denial of Service <Link href='https://www.cve.org/CVERecord?id=CVE-2025-55184' className="underline text-blue-500">CVE-2025-55184</Link> and Source Code Exposure <Link href='https://www.cve.org/CVERecord?id=CVE-2025-55183' className="underline text-blue-500">CVE-2025-55183</Link>) in React Server Components. Please see this <Link href='https://react.dev/blog/2025/12/11/denial-of-service-and-source-code-exposure-in-react-server-components' className="underline text-blue-500"> React blog</Link> and this <Link href='https://vercel.com/kb/bulletin/security-bulletin-cve-2025-55184-and-cve-2025-55183?inf_ver=2&inf_ctx=g-3JhSYYZ0cx0G92duvbVawt9MIUiJBx04F4TGk46SdN0tsn1FNDXF_G5vKieBlBKax98GA9lOoIe74XNaed1S6Wa8A9XVCcQnf7JfzhcMcYf7mVYAioJHKT9Sz7nfnFFJxWbT5NcYyo9VREl4uBiO2Kg2t3KGzayTEuONY9ltlAMbGM5Z1mivcoj51nMOAu9c0OrD6gBntT6f4p1hnaFo6EC84B8QRJzR76vvHPz8vVnwiEEeHb-XcKtmFe2TOsyeNm5HO9vJAje1YNVus4Raff2EPwyfGci7qB61IJx0MXss_h7pK0-2jDL3mQiodUo-BTOiItMTByT3jaKzQ9fw%3D%3D' className="underline text-blue-500">Next.js bulletin</Link> to learn more about these vulnerabilities (December 11, 2025).</div> },
|
||||||
|
{ category: "improvement", description: "Upgraded Next.js from v13.5.6 to v16.0.10" },
|
||||||
|
{ category: "improvement", description: "Upgraded React and ReactDOM from v18.2.0 to v19.2.3" },
|
||||||
|
{ category: "improvement", description: "Replaced native img tags with Next.js Image component and added lazy loading for avatars" },
|
||||||
|
{ category: "bugfix", description: "Fixed spamming \"Failed to fetch geolocation\" alerts when presence using mobile devices" },
|
||||||
|
{ category: 'feature', description: <div>Added <Link href="/hats-team" className="underline text-blue-500">hats team</Link> page</div> },
|
||||||
|
{ category: 'feature', description: <div>Added <Link href="/release-notes" className="underline text-blue-500">release notes</Link> page</div> },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
version: "v1.0.2",
|
||||||
|
date: "13 May 2024",
|
||||||
|
type: "minor",
|
||||||
|
changes: [
|
||||||
|
{ category: "feature", description: "Disabled time selection before check-in time in auto checkout adjustment" },
|
||||||
|
{ category: "feature", description: "Added camera switch for mobile view" },
|
||||||
|
{ category: "improvement", description: "Updated homepage UI responsiveness for mobile view" },
|
||||||
|
{ category: "feature", description: "Open Google Maps to show presence location in attendance history" },
|
||||||
|
{ category: "bugfix", description: "Fixed issues in manual attendance" },
|
||||||
|
{ category: "improvement", description: "Improved donut chart responsiveness on the homepage for mobile view" },
|
||||||
|
{ category: "feature", description: "Added progress bar indicator when route change in admin pane" },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
version: "v1.0.1",
|
||||||
|
date: "19 November 2023",
|
||||||
|
type: "minor",
|
||||||
|
changes: [
|
||||||
|
{ category: "feature", description: "Added detailed employee attendance list when clicking an attendance status on the donut chart" },
|
||||||
|
{ category: "feature", description: "Added \"I'm Here\" feature when users are present as WFS or WFO" },
|
||||||
|
{ category: "feature", description: "Employee performance detail page" },
|
||||||
|
{ category: "feature", description: "Calendar page" },
|
||||||
|
{ category: "feature", description: "Employee attendance distribution menu in the admin panel" },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
version: "v1.0.0",
|
||||||
|
date: "15 September 2023",
|
||||||
|
type: "major",
|
||||||
|
changes: [
|
||||||
|
{ category: "feature", description: "First release of the HIS Attendance Task System (H.A.T.s)" },
|
||||||
|
{ category: "feature", description: "Employee landing page with working hours, tasks, and attendance information" },
|
||||||
|
{ category: "feature", description: "Employee attendance history page" },
|
||||||
|
{ category: "feature", description: "Employee task management page" },
|
||||||
|
{ category: "feature", description: "Employee profile page" },
|
||||||
|
{ category: "feature", description: "Leave request feature" },
|
||||||
|
{ category: "feature", description: "Permission and sick leave request feature" },
|
||||||
|
{ category: "feature", description: "Admin panel menu" },
|
||||||
|
{ category: "feature", description: "Admin panel dashboard page" },
|
||||||
|
{ category: "feature", description: "Company, area, department, and employee management" },
|
||||||
|
{ category: "feature", description: "Attendance device and device type management" },
|
||||||
|
{ category: "feature", description: "Workday off management, global parameters, and audit trail" },
|
||||||
|
{ category: "feature", description: "Employee attendance reports, leave reports, sick leave reports, and attendance summary reports" },
|
||||||
|
{ category: "feature", description: "Manual attendance, attendance reports and approvals for non-WFO employees, and reports and approvals for employees who did not check out" },
|
||||||
|
{ category: "feature", description: "Information management for master status, working status, user roles, employee positions, and employee types" },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "Release Notes - HIS Attendance Task System (H.A.T.s)",
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function ReleaseNotesPage() {
|
||||||
|
const getCategoryIcon = (category: string) => {
|
||||||
|
switch (category) {
|
||||||
|
case 'feature':
|
||||||
|
return <Sparkles className="h-4 w-4 text-green-500" />;
|
||||||
|
case 'improvement':
|
||||||
|
return <Zap className="h-4 w-4 text-blue-500" />;
|
||||||
|
case 'bugfix':
|
||||||
|
return <Bug className="h-4 w-4 text-orange-500" />;
|
||||||
|
case 'breaking':
|
||||||
|
return <Wrench className="h-4 w-4 text-red-500" />;
|
||||||
|
default:
|
||||||
|
return <Sparkles className="h-4 w-4" />;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getCategoryLabel = (category: string) => {
|
||||||
|
switch (category) {
|
||||||
|
case 'feature':
|
||||||
|
return 'New Feature';
|
||||||
|
case 'improvement':
|
||||||
|
return 'Enhancement';
|
||||||
|
case 'bugfix':
|
||||||
|
return 'Bug Fix';
|
||||||
|
case 'breaking':
|
||||||
|
return 'Breaking Change';
|
||||||
|
default:
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getVersionBadge = (type: string) => {
|
||||||
|
switch (type) {
|
||||||
|
case 'major':
|
||||||
|
return <Badge className="bg-primary text-primary-foreground">Major</Badge>;
|
||||||
|
case 'minor':
|
||||||
|
return <Badge variant="secondary">Minor</Badge>;
|
||||||
|
case 'patch':
|
||||||
|
return <Badge variant="outline">Patch</Badge>;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="min-h-screen">
|
||||||
|
<div className="flex items-center gap-4 sm:p-8 pt-6 px-6">
|
||||||
|
<div>
|
||||||
|
<h1 className="text-lg sm:text-3xl font-medium tracking-tight capitalize">Release Notes</h1>
|
||||||
|
<p className="text-xs md:text-base text-muted-foreground sm:mt-1">Release Notes / Application Update History for HIS Attendance Task System (H.A.T.s)</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Content */}
|
||||||
|
<main className="container mx-auto px-4 py-8 max-w-3xl">
|
||||||
|
<div className="space-y-8">
|
||||||
|
{releaseNotes.map((release, index) => (
|
||||||
|
<div key={index} className="relative pl-8 pb-8 border-l-2 border-border last:border-l-0" id={release.version}>
|
||||||
|
{/* Timeline dot */}
|
||||||
|
<div className="absolute left-0 top-0 -translate-x-1/2 w-4 h-4 rounded-full bg-primary border-4 border-background" />
|
||||||
|
|
||||||
|
{/* Version header */}
|
||||||
|
<div className="mb-4">
|
||||||
|
<div className="flex items-center gap-3 flex-wrap">
|
||||||
|
<h2 className="text-2xl font-bold text-foreground">{release.version}</h2>
|
||||||
|
{getVersionBadge(release.type)}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2 mt-1 text-muted-foreground">
|
||||||
|
<Calendar className="h-4 w-4" />
|
||||||
|
<span className="text-sm">{release.date}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Changes */}
|
||||||
|
<div className="bg-card rounded-lg border p-4 py-6 sm:p-6 space-y-4">
|
||||||
|
{release.changes.map((change, changeIndex) => (
|
||||||
|
<div key={changeIndex} className="flex items-start gap-3">
|
||||||
|
{getCategoryIcon(change.category)}
|
||||||
|
<div className="flex-1">
|
||||||
|
<span className="text-xs font-medium text-muted-foreground uppercase tracking-wider">
|
||||||
|
{getCategoryLabel(change.category)}
|
||||||
|
</span>
|
||||||
|
<div className="text-foreground text-xs sm:text-sm">{change.description}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Footer */}
|
||||||
|
<div className="mt-8 text-center text-muted-foreground">
|
||||||
|
<p className="text-xs mt-2">
|
||||||
|
Have suggestions or found a bug? Please contact <Link href='/hats-team' className='underline text-his'>our support team</Link>.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
// import Image from 'next/image';
|
||||||
|
import { FC } from 'react';
|
||||||
|
// import { LazyLoadImage } from 'react-lazy-load-image-component';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
projectList: {
|
||||||
|
id: number
|
||||||
|
title: string
|
||||||
|
img: string
|
||||||
|
cover?: boolean
|
||||||
|
dark?: boolean
|
||||||
|
}[]
|
||||||
|
};
|
||||||
|
|
||||||
|
const TaskComponent: FC<Props> = ({ projectList }) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-5 sm:gap-6 mb-20'>
|
||||||
|
{projectList.map(item =>
|
||||||
|
<div key={item.id} className='border border-border rounded-2xl shadow overflow-hidden cursor-pointer hover:border-primary duration-500'>
|
||||||
|
{/* <Image alt={item.title} height={0} width={0} quality={100} src={item.img} className='h-48 w-full object-cover rounded-t-2xl' /> */}
|
||||||
|
<img alt={item.title} src={item.img} className='h-48 w-full rounded-t-2xl hover:scale-90 duration-500' />
|
||||||
|
<div className='flex flex-col p-6 overflow-hidden space-y-2 rounded-b-2xl bg-white dark:bg-zinc-900 z-10'>
|
||||||
|
<h3 className='text-lg font-semibold'>{item.title}</h3>
|
||||||
|
<p className='text-muted-foreground line-clamp-2 sm:line-clamp-3'>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TaskComponent;
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
import LazyLoading from "@/components/loader/LazyLoading"
|
||||||
|
import { Suspense } from "react"
|
||||||
|
import TaskComponent from "./component"
|
||||||
|
|
||||||
|
export default async function TaskPage() {
|
||||||
|
const LIST_PROJECT = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
title: 'Angksa Pura II',
|
||||||
|
img: '/assets/projects/ap2.jpg'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
title: 'ASDP',
|
||||||
|
img: '/assets/projects/asdp.png'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 4,
|
||||||
|
title: 'Imigrasi',
|
||||||
|
img: '/assets/projects/imigrasi.png'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
title: 'JakLingko',
|
||||||
|
img: '/assets/projects/jaklingko.png'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 5,
|
||||||
|
title: 'KAI Bandara',
|
||||||
|
img: '/assets/projects/kaibandara.png'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 6,
|
||||||
|
title: 'KAI Commuter',
|
||||||
|
img: '/assets/projects/kci.png'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 7,
|
||||||
|
title: 'LRT Jabodebek',
|
||||||
|
img: '/assets/projects/lrtjabo.png'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 8,
|
||||||
|
title: 'LRT Jakarta',
|
||||||
|
img: '/assets/projects/lrtjakarta.png'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 9,
|
||||||
|
title: 'LRT Sumsel',
|
||||||
|
img: '/assets/projects/lrtsumsel.png'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 10,
|
||||||
|
title: 'Telkomsel',
|
||||||
|
img: '/assets/projects/tsel.png'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 11,
|
||||||
|
title: 'Transjakarta',
|
||||||
|
img: '/assets/projects/transjakarta.jpg'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 12,
|
||||||
|
title: 'Nutech Integrasi',
|
||||||
|
img: '/assets/projects/nutech.png'
|
||||||
|
},
|
||||||
|
]
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="flex-1 space-y-8 p-6 sm:p-8 pt-6 pb-40 md:pb-8">
|
||||||
|
<div className="flex items-start justify-between space-y-2">
|
||||||
|
<div>
|
||||||
|
<h1 className="text-lg sm:text-3xl font-medium tracking-tight capitalize">My Task</h1>
|
||||||
|
<p className="text-xs md:text-base text-muted-foreground w-1/2 mt-2 hidden md:block">Something that can be done at any time is often done at no time. Do it now, or decide when you'll do it.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<TaskComponent projectList={LIST_PROJECT} />
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,214 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { FC, useState } from 'react';
|
||||||
|
import { useSession } from 'next-auth/react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { DatePicker, Form, Input, Select } from 'antd';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import type { RangePickerProps } from 'antd/es/date-picker';
|
||||||
|
import { Separator } from '@/components/ui/separator';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Icons } from '@/components/Icons';
|
||||||
|
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog';
|
||||||
|
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { Label } from '@/components/ui/label';
|
||||||
|
|
||||||
|
|
||||||
|
const OPTION_TAGS_PERMIT = [
|
||||||
|
{ label: 'Izin', value: 'permit' },
|
||||||
|
{ label: 'Bedrest', value: 'bedrest' },
|
||||||
|
{ label: 'Dirumah', value: 'dirumah' },
|
||||||
|
{ label: 'Haji / Umrah', value: 'haji/umrah' },
|
||||||
|
{ label: 'Travelling', value: 'travelling' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const OPTION_TAGS_SICK = [
|
||||||
|
{ label: 'Sakit', value: 'sick' },
|
||||||
|
{ label: 'Bedrest', value: 'bedrest' },
|
||||||
|
{ label: 'Dirumah', value: 'dirumah' },
|
||||||
|
{ label: 'Covid', value: 'covid' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const PERMIT_TYPE = [
|
||||||
|
{ lable: 'Permission', value: 'I', icon: 'ti ti-license' },
|
||||||
|
{ lable: 'Sick', value: 'S', icon: 'ti ti-stethoscope' },
|
||||||
|
]
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
TL_LIST?: any[]
|
||||||
|
};
|
||||||
|
|
||||||
|
const Component: FC<Props> = ({ TL_LIST }) => {
|
||||||
|
const [permitType, setPermitType] = useState<string>('')
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
const [leavePeriod, setLeavePeriod] = useState<any>([])
|
||||||
|
const [showConfirm, setShowConfirm] = useState(false)
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
const { data: session } = useSession()
|
||||||
|
const axios = useAxiosAuth()
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
setIsLoading(true)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const formData = form.getFieldsValue()
|
||||||
|
if (!permitType) return handleError('Leave type cannot be empty!')
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
"nik": session?.user.detail.nik,
|
||||||
|
"send_to": 9,
|
||||||
|
// "send_to": 1,
|
||||||
|
"cc": formData['cc'],
|
||||||
|
"category": permitType,
|
||||||
|
"start_date": dayjs(formData['start_date'][0]).format('YYYY-MM-DD'),
|
||||||
|
"end_date": dayjs(formData['start_date'][1]).format('YYYY-MM-DD'),
|
||||||
|
"return_to_work_date": dayjs(formData['return_to_work_date']).format('YYYY-MM-DD'),
|
||||||
|
"contact_street": formData['contact_street'],
|
||||||
|
"contact_city": formData['contact_city'],
|
||||||
|
"contact_phone_number": session?.user.detail.phone_number,
|
||||||
|
"note": formData['note'],
|
||||||
|
"tags": formData["tags"],
|
||||||
|
"image": ""
|
||||||
|
}
|
||||||
|
console.log(payload)
|
||||||
|
const { data } = await axios.post('/application-form', payload)
|
||||||
|
|
||||||
|
handleSuccess(data?.message)
|
||||||
|
} catch (error: any) {
|
||||||
|
console.log(error)
|
||||||
|
handleError(`Fail to apply for leave, (${error.response?.data?.code || error.response?.status || '-'}) ${error.response?.data?.message || error.response?.statusText || error.message}`, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSuccess = (message: string) => {
|
||||||
|
toast.success(message)
|
||||||
|
router.replace('/')
|
||||||
|
router.refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleError = (message: string, action?: boolean) => {
|
||||||
|
toast.error("Oops! Something went wrong.", {
|
||||||
|
description: message,
|
||||||
|
action: action ? <Button variant='outline' onClick={handleSubmit}>Try again</Button> : undefined,
|
||||||
|
})
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DISABLE DATE BEFORE 18 SEP 2023
|
||||||
|
// eslint-disable-next-line arrow-body-style
|
||||||
|
const disabledDate: RangePickerProps['disabledDate'] = (current) => {
|
||||||
|
const disabledDate = new Date('2023-09-18');
|
||||||
|
disabledDate.setHours(0, 0, 0, 0);
|
||||||
|
const disabledTimestamp = disabledDate.getTime();
|
||||||
|
|
||||||
|
const selectedTimestamp = current ? current.valueOf() : 0;
|
||||||
|
|
||||||
|
return selectedTimestamp < disabledTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line arrow-body-style
|
||||||
|
const disabledDateKembaliKerja: RangePickerProps['disabledDate'] = (current) => {
|
||||||
|
if (leavePeriod && leavePeriod.length === 2 && leavePeriod[1]) {
|
||||||
|
return current && current < dayjs(leavePeriod[1]).endOf('day');
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Form form={form} onFinish={() => setShowConfirm(true)} scrollToFirstError layout="vertical" size='small' requiredMark={false}>
|
||||||
|
<div className='space-y-3 flex flex-col items-center mb-5'>
|
||||||
|
<Label>Permit Type</Label>
|
||||||
|
<div className='flex items-center flex-wrap space-x-5 text-sm'>
|
||||||
|
{PERMIT_TYPE && PERMIT_TYPE.length > 0 ?
|
||||||
|
PERMIT_TYPE.map((item, key) =>
|
||||||
|
<div className='flex flex-col items-center space-y-1' key={key}>
|
||||||
|
<button type='button' className={`rounded-xl w-20 h-20 ${permitType === item.value ? 'bg-zinc-200 dark:bg-zinc-700 ' : 'btn-outline'}`} onClick={() => setPermitType(item.value)}>
|
||||||
|
<i className={`${item.icon} icon text-2xl`}></i>
|
||||||
|
</button>
|
||||||
|
<p className='text-center'>{item.lable}</p>
|
||||||
|
</div>
|
||||||
|
) :
|
||||||
|
<div>
|
||||||
|
Working status not available, please contact administrator.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='grid grid-cols-1 font-medium gap-y-0'>
|
||||||
|
<Form.Item label='Start-End Date' name='start_date' rules={[{ required: true }]} >
|
||||||
|
<DatePicker.RangePicker onChange={val => setLeavePeriod(val)} format={'MMM DD, YYYY'} size='small' className='input' disabledDate={disabledDate} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label='Return to Work Date' name='return_to_work_date' rules={[{ required: true }]} initialValue={leavePeriod && leavePeriod.length === 2 && dayjs(leavePeriod[1]).endOf('day')}>
|
||||||
|
<DatePicker disabledDate={disabledDateKembaliKerja} format={'MMMM DD, YYYY'} size='small' className='input' disabled={leavePeriod?.length !== 2} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label='Address' name='contact_street' rules={[{ required: true }]}>
|
||||||
|
<Input.TextArea className='input' placeholder='Please write address..' maxLength={255} rootClassName='px-3! py-2!' />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label='City' name='contact_city' rules={[{ required: true, max: 50 }]}>
|
||||||
|
<Input className='input' placeholder='Please write city' maxLength={50} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label='Note' name='note'>
|
||||||
|
<Input.TextArea className='input' placeholder='Reason note...' maxLength={255} rootClassName='px-3! py-2!' />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label='Tags' name='tags'>
|
||||||
|
<Select mode="multiple" allowClear placeholder="Select relate tags" options={permitType === 'S' ? OPTION_TAGS_SICK : OPTION_TAGS_PERMIT} size='large'
|
||||||
|
optionFilterProp="children"
|
||||||
|
filterOption={(input, option) => (option?.label ?? '').toLowerCase().includes(input.toLowerCase())}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label='Send to' name='send_to' initialValue='Stevanus Akbar Alexander'>
|
||||||
|
<Input className='input' disabled readOnly />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label='Mentions to' name='cc' >
|
||||||
|
<Select mode="multiple" allowClear placeholder="Add mentions to Team Leader" size='large'
|
||||||
|
options={TL_LIST?.length! > 0 ? TL_LIST?.map(item => { return { value: item.id, label: item.fullname } }) : []}
|
||||||
|
optionFilterProp="children"
|
||||||
|
filterOption={(input, option) => (option?.label ?? '').toLowerCase().includes(input.toLowerCase())}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Separator />
|
||||||
|
</div>
|
||||||
|
<Separator />
|
||||||
|
|
||||||
|
<div className='flex flex-col space-y-2'>
|
||||||
|
<Button type="submit" disabled={isLoading}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
<Button type='reset' variant='outline' onClick={() => router.back()} disabled={isLoading} >Cancel</Button>
|
||||||
|
</div>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
{showConfirm &&
|
||||||
|
<AlertDialog open={true}>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
This data will be stored on our server, you can change it whenever you want later.
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel disabled={isLoading} onClick={() => setShowConfirm(false)}>Cancel</AlertDialogCancel>
|
||||||
|
<AlertDialogAction disabled={isLoading} onClick={handleSubmit}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
Continue
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Component;
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { type Metadata } from 'next';
|
||||||
|
import { Suspense, lazy } from 'react';
|
||||||
|
import { Separator } from '@/components/ui/separator';
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import PageLoading from '@/components/loader/PageLoading';
|
||||||
|
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||||
|
|
||||||
|
const FormComponent = lazy(() => import('./components'))
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "Work Permit and Sick",
|
||||||
|
}
|
||||||
|
|
||||||
|
const WorkPermit = async () => {
|
||||||
|
const res = await fetchDataWithPost('/user/position', { position_code: 'P02' })
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='flex-1 w-full md:w-[800px] mx-auto px-5 py-10 md:p-10 pb-40 md:pb-10'>
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<div className='flex justify-center items-center flex-col'>
|
||||||
|
<div className='flex items-center space-x-2'>
|
||||||
|
<CardTitle className="text-lg font-medium">Permit and Sick</CardTitle>
|
||||||
|
<i className="ti ti-stethoscope icon text-2xl"></i>
|
||||||
|
</div>
|
||||||
|
<p className="text-sm text-muted-foreground text-center w-11/12 sm:w-full">Complete your information to apply for permit or sick</p>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<Separator className='w-10/12 xl:w-11/12 mx-auto' />
|
||||||
|
<CardContent className='mt-6'>
|
||||||
|
<Suspense fallback={<PageLoading />}>
|
||||||
|
<FormComponent TL_LIST={res} />
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default WorkPermit;
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { FC, Suspense, lazy } from 'react';
|
||||||
|
import InterceptModal from '@/components/modal/InterceptModal';
|
||||||
|
import LazyLoading from '@/components/loader/LazyLoading';
|
||||||
|
import DateRangePicker from '@/app/performance/[id]/components/DateRangePicker';
|
||||||
|
|
||||||
|
const PerformanceComponent = lazy(() => import('@/app/performance/[id]/components'));
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
params: Promise<{ id: string | undefined }>
|
||||||
|
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
|
||||||
|
};
|
||||||
|
|
||||||
|
const PerformanceModal: FC<Props> = async ({ params, searchParams }) => {
|
||||||
|
const id = (await params).id
|
||||||
|
const start_date = (await searchParams)!.start_date
|
||||||
|
const end_date = (await searchParams)!.end_date
|
||||||
|
|
||||||
|
return (
|
||||||
|
<InterceptModal>
|
||||||
|
<div className='space-y-5 mt-10 sm:mt-0'>
|
||||||
|
<DateRangePicker />
|
||||||
|
|
||||||
|
<Suspense key={`${start_date}${end_date}`} fallback={<LazyLoading />}>
|
||||||
|
<PerformanceComponent id={id} start_date={start_date as string} end_date={end_date as string} />
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
|
</InterceptModal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PerformanceModal;
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export default function Default() {
|
||||||
|
return null
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
"use server"
|
||||||
|
|
||||||
|
import { revalidatePath, revalidateTag } from "next/cache"
|
||||||
|
|
||||||
|
export async function revalidateTagFromClient(tagName: string) {
|
||||||
|
revalidateTag(tagName, 'default')
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function revalidatePathFromClient(originalPath: string, type?: "layout" | "page") {
|
||||||
|
revalidatePath(originalPath, type)
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
"use server"
|
||||||
|
|
||||||
|
import axios from "@/lib/axios";
|
||||||
|
import { authOptions } from "@/pages/api/auth/[...nextauth]";
|
||||||
|
import { getServerSession } from "next-auth";
|
||||||
|
import { revalidatePath } from "next/cache";
|
||||||
|
|
||||||
|
export const editProfileData = async (payload: any) => {
|
||||||
|
try {
|
||||||
|
const session = await getServerSession(authOptions);
|
||||||
|
axios.defaults.headers.common['Authorization'] = `Bearer ${session?.user?.access_token}`;
|
||||||
|
|
||||||
|
await axios.put('/user/profile/update', payload)
|
||||||
|
revalidatePath('profile-data')
|
||||||
|
} catch (error: any) {
|
||||||
|
console.log("ERROR EDIT PROFILE:", error.response?.data?.code, error.response?.data?.message)
|
||||||
|
throw new Error(error as any)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const changeAvatar = async (payload: any) => {
|
||||||
|
try {
|
||||||
|
const session = await getServerSession(authOptions);
|
||||||
|
axios.defaults.headers.common['Authorization'] = `Bearer ${session?.user?.access_token}`;
|
||||||
|
|
||||||
|
await axios.post('/user/profile/change-avatar', payload)
|
||||||
|
revalidatePath('/profile')
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(error as any)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const changePassword = async (payload: any) => {
|
||||||
|
try {
|
||||||
|
const session = await getServerSession(authOptions);
|
||||||
|
axios.defaults.headers.common['Authorization'] = `Bearer ${session?.user?.access_token}`;
|
||||||
|
|
||||||
|
await axios.post('/user/profile/change-password', payload)
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(error as any)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import { FC, ReactNode, useState } from 'react';
|
||||||
|
import { Icons } from '@/components/Icons';
|
||||||
|
import { AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog';
|
||||||
|
import { type ResponseData } from '@/types/types';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
title?: string
|
||||||
|
description?: string
|
||||||
|
onConfirm: () => Promise<any>
|
||||||
|
okText?: string
|
||||||
|
cancelText?: string
|
||||||
|
contentSuccess?: ReactNode | string
|
||||||
|
onOkSuccess?: () => any
|
||||||
|
};
|
||||||
|
|
||||||
|
const ConfirmAsync: FC<Props> = ({ title, description, onConfirm, okText, cancelText, contentSuccess, onOkSuccess }) => {
|
||||||
|
const [isLoading, setIsloading] = useState(false)
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
const confirm = async () => {
|
||||||
|
if (isLoading) return
|
||||||
|
try {
|
||||||
|
setIsloading(true)
|
||||||
|
const res: ResponseData = await onConfirm()
|
||||||
|
setIsloading(false)
|
||||||
|
|
||||||
|
console.log(res)
|
||||||
|
if (!res) return
|
||||||
|
|
||||||
|
if (res.code === '00') {
|
||||||
|
showSuccess()
|
||||||
|
} else {
|
||||||
|
showError(res.message)
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.log(error)
|
||||||
|
setIsloading(false)
|
||||||
|
showError(error?.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const showSuccess = () => {
|
||||||
|
router.refresh()
|
||||||
|
toast.info(contentSuccess || 'Data successfully removed.' as string)
|
||||||
|
onOkSuccess!()
|
||||||
|
};
|
||||||
|
|
||||||
|
const showError = (message?: string) => {
|
||||||
|
toast.error(message)
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>{title || 'Are you absolutely sure?'}</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
{description || 'This action cannot be undone. This will permanently delete this data and remove from our servers.'}
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel disabled={isLoading}>{cancelText || 'Cancel'}</AlertDialogCancel>
|
||||||
|
<AlertDialogAction disabled={isLoading} onClick={confirm}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
{okText || 'Continue'}
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ConfirmAsync;
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
import { useEffect, useState } from "react"
|
||||||
|
import { Form, Input, Select } from "antd"
|
||||||
|
import useAxiosAuth from "@/lib/axios/useAxiosAuth"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
import { Icons } from "@/components/Icons"
|
||||||
|
import useFetch from "@/hooks/useFetch"
|
||||||
|
import { type IArea } from "./type"
|
||||||
|
import { type ICompany } from "../../company/component/type"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
isUpdate?: boolean
|
||||||
|
data?: IArea
|
||||||
|
onCancel?: () => any
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function AreaForm({ data, isUpdate, onCancel }: Props) {
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
const router = useRouter()
|
||||||
|
const axios = useAxiosAuth()
|
||||||
|
|
||||||
|
const { data: companyList, isLoading: loadingCompany, error } = useFetch('/company')
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data) {
|
||||||
|
form.setFieldsValue(data)
|
||||||
|
if (data.company) form.setFieldValue('company_id', data.company.id)
|
||||||
|
} else {
|
||||||
|
form.resetFields()
|
||||||
|
}
|
||||||
|
}, [data, form])
|
||||||
|
|
||||||
|
const handleSubmit = (value: any) => {
|
||||||
|
console.log(value)
|
||||||
|
|
||||||
|
!isUpdate ? handleCreate(value) : handleUpdate(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCreate = async (payload: IArea) => {
|
||||||
|
try {
|
||||||
|
if (payload.latitude) payload['latitude'] = Number(payload.latitude)
|
||||||
|
if (payload.longitude) payload['longitude'] = Number(payload.longitude)
|
||||||
|
|
||||||
|
setIsLoading(true)
|
||||||
|
await axios.post('/area', payload)
|
||||||
|
|
||||||
|
handleSuccess('Data successfully created.')
|
||||||
|
} catch (error: any) {
|
||||||
|
handleError(`Data failed to create, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleUpdate = async (payload: IArea) => {
|
||||||
|
try {
|
||||||
|
if (payload.latitude) payload['latitude'] = Number(payload.latitude)
|
||||||
|
if (payload.longitude) payload['longitude'] = Number(payload.longitude)
|
||||||
|
|
||||||
|
setIsLoading(true)
|
||||||
|
await axios.put('/area/' + data?.id, payload)
|
||||||
|
|
||||||
|
handleSuccess('Data successfully updated.')
|
||||||
|
} catch (error: any) {
|
||||||
|
handleError(`Data failed to update, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSuccess = (message: string) => {
|
||||||
|
toast.info(message)
|
||||||
|
setIsLoading(false)
|
||||||
|
onCancel!()
|
||||||
|
router.refresh()
|
||||||
|
form.resetFields()
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleError = (message: string) => {
|
||||||
|
toast.error(message)
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DialogContent>
|
||||||
|
<Form form={form} onFinish={handleSubmit}>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle className="dark:text-white">{isUpdate ? 'Update area' : 'Create area'}</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Add a new team to manage products and customers
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="grid mt-8">
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="name">Area name</Label>
|
||||||
|
<Form.Item name='name' rules={[{ required: true, message: 'This field is required' }]} >
|
||||||
|
<Input className="input" id="name" placeholder="RESEARCH AND DEVELOPMENT" />
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="company_id">Company</Label>
|
||||||
|
<Form.Item name='company_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||||
|
<Select placeholder='Select company' showSearch allowClear loading={loadingCompany}
|
||||||
|
optionFilterProp="children"
|
||||||
|
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||||
|
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||||
|
>
|
||||||
|
{companyList?.company?.length > 0 && companyList.company.map((item: ICompany, key: number) =>
|
||||||
|
<Select.Option value={item.id} key={key}>{item.code} - {item.name}</Select.Option>
|
||||||
|
)}
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-2 gap-x-4">
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="latitude">latitude</Label>
|
||||||
|
<Form.Item name='latitude' >
|
||||||
|
<Input className="input" id="latitude" placeholder="-6.200000" />
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="longitude">longitude</Label>
|
||||||
|
<Form.Item name='longitude' >
|
||||||
|
<Input className="input" id="longitude" placeholder="106.816666" />
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="description">Description</Label>
|
||||||
|
<Form.Item name='description' >
|
||||||
|
<Input.TextArea className="input" id="description" placeholder="R&D Department PT Nutech Integrasi by Telkom Indonesia" />
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" type="button" onClick={onCancel} disabled={isLoading} >
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" disabled={isLoading}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</Form>
|
||||||
|
</DialogContent>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,191 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
||||||
|
import { MoreHorizontalIcon } from 'lucide-react';
|
||||||
|
import { Table } from 'antd';
|
||||||
|
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||||
|
import { MixerHorizontalIcon, PlusCircledIcon } from '@radix-ui/react-icons';
|
||||||
|
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||||
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { AlertDialog, AlertDialogTrigger } from '@/components/ui/alert-dialog';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { Dialog } from '@/components/ui/dialog';
|
||||||
|
import AreaForm from './Form';
|
||||||
|
import ConfirmAsync from './ConfirmAsync';
|
||||||
|
import { IArea } from './type';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: IArea[]
|
||||||
|
};
|
||||||
|
|
||||||
|
const ComponentAreaPage: FC<Props> = ({ data }) => {
|
||||||
|
const [filterData, setFilterData] = useState<IArea[]>([])
|
||||||
|
const [selectedData, setSelectedData] = useState<IArea | undefined>(undefined)
|
||||||
|
const [showFormDialog, setShowFormDialog] = useState(false)
|
||||||
|
|
||||||
|
const axios = useAxiosAuth()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data) {
|
||||||
|
setFilterData(data)
|
||||||
|
}
|
||||||
|
}, [data])
|
||||||
|
|
||||||
|
const handleDelete = (areaId: string | number) => {
|
||||||
|
return axios.delete(`/area/${areaId}`).then(res => res.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleResetForm = () => {
|
||||||
|
setSelectedData(undefined)
|
||||||
|
setShowFormDialog(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSearch = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const text = e.target.value
|
||||||
|
if (text) {
|
||||||
|
const newData = [...data!].filter(item => (
|
||||||
|
item.name?.toLowerCase().includes(text.toLowerCase()) ||
|
||||||
|
item.description?.toLowerCase().includes(text.toLowerCase())
|
||||||
|
))
|
||||||
|
setFilterData(newData)
|
||||||
|
} else {
|
||||||
|
setFilterData(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const Columns: ColumnsType<IArea> = [
|
||||||
|
{
|
||||||
|
title: 'Num',
|
||||||
|
dataIndex: 'key',
|
||||||
|
render: (text, record, index) => index + 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Code',
|
||||||
|
dataIndex: 'code',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Name',
|
||||||
|
dataIndex: 'name',
|
||||||
|
sorter: (a, b) => a.name.localeCompare(b.name)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Company',
|
||||||
|
dataIndex: 'company',
|
||||||
|
render: (text) => text?.name
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Coordinates',
|
||||||
|
dataIndex: 'latitude',
|
||||||
|
render: (text, record, index) => `${text},${record.longitude}`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Status',
|
||||||
|
dataIndex: 'status',
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
text: 'ACTIVE',
|
||||||
|
value: 'A',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'INACTIVE',
|
||||||
|
value: 'N',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'DELETED',
|
||||||
|
value: 'X',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
onFilter: (value, record) => record.status!.code.indexOf(value as string) === 0,
|
||||||
|
align: 'center',
|
||||||
|
render: (text, record) => (
|
||||||
|
<div className='flex justify-center text-white font-semibold text-xs'>
|
||||||
|
{record.status.code === 'A' ?
|
||||||
|
<div className="px-2 py-1.5 rounded-full bg-green-500 w-24">{record.status.name}</div>
|
||||||
|
:
|
||||||
|
<div className="px-2 py-1.5 rounded-full bg-rose-500 w-24">{record.status.name}</div>
|
||||||
|
}
|
||||||
|
</div>)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Description',
|
||||||
|
dataIndex: 'description',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Action',
|
||||||
|
key: 'action',
|
||||||
|
render: (_, record) => (
|
||||||
|
<AlertDialog>
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant='ghost' size="icon">
|
||||||
|
<MoreHorizontalIcon />
|
||||||
|
<span className="sr-only">Action Button</span>
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||||
|
<AlertDialogTrigger asChild>
|
||||||
|
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||||
|
</AlertDialogTrigger>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
<ConfirmAsync
|
||||||
|
onConfirm={() => handleDelete(record.id)}
|
||||||
|
onOkSuccess={() => { }}
|
||||||
|
/>
|
||||||
|
</AlertDialog>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const tableProps: TableProps<IArea> = {
|
||||||
|
bordered: false,
|
||||||
|
size: 'small',
|
||||||
|
showHeader: true,
|
||||||
|
pagination: {
|
||||||
|
pageSizeOptions: [5, 10, 20, 50],
|
||||||
|
defaultPageSize: 10,
|
||||||
|
showSizeChanger: true,
|
||||||
|
showQuickJumper: true,
|
||||||
|
size: 'default'
|
||||||
|
},
|
||||||
|
scroll: { x: 'max-content' },
|
||||||
|
tableLayout: 'auto',
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='flex flex-col space-y-4'>
|
||||||
|
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between space-y-2 sm:space-y-0">
|
||||||
|
<div className="flex flex-1 items-center space-x-2">
|
||||||
|
<Input placeholder="Search company..." className="h-8 w-full sm:w-[250px]" onChange={handleSearch} />
|
||||||
|
</div>
|
||||||
|
<Button variant='ghost' size="sm" className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||||
|
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||||
|
Create New Area
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<Table
|
||||||
|
{...tableProps}
|
||||||
|
rowKey='id'
|
||||||
|
columns={Columns}
|
||||||
|
dataSource={filterData || []}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Dialog open={showFormDialog} onOpenChange={(state) => {
|
||||||
|
if (state === false) setSelectedData(undefined)
|
||||||
|
setShowFormDialog(state)
|
||||||
|
}}>
|
||||||
|
<AreaForm
|
||||||
|
data={selectedData}
|
||||||
|
isUpdate={selectedData !== undefined}
|
||||||
|
onCancel={handleResetForm}
|
||||||
|
/>
|
||||||
|
</Dialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ComponentAreaPage;
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
export interface IArea {
|
||||||
|
id: number
|
||||||
|
code: string
|
||||||
|
name: string
|
||||||
|
company?: any
|
||||||
|
company_id: string
|
||||||
|
latitude?: number
|
||||||
|
longitude?: number
|
||||||
|
status: {
|
||||||
|
id: number
|
||||||
|
code: "A" | 'N' | 'X'
|
||||||
|
name: "ACTIVE" | 'INACTIVE' | 'DELETED'
|
||||||
|
}
|
||||||
|
description: string
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import { type Metadata } from 'next';
|
||||||
|
import { FC, Suspense, lazy } from 'react';
|
||||||
|
import { getServerSession } from 'next-auth';
|
||||||
|
import { Download } from 'lucide-react'
|
||||||
|
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { type ResponseData } from '@/types/types';
|
||||||
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import LazyLoading from '@/components/loader/LazyLoading';
|
||||||
|
|
||||||
|
const ComponentPage = lazy(() => import('./component'));
|
||||||
|
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "Admin | Area",
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getData() {
|
||||||
|
const { BASE_URL_API } = process.env
|
||||||
|
const session = await getServerSession(authOptions)
|
||||||
|
|
||||||
|
const res = await fetch(BASE_URL_API + '/area', {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${session?.user.access_token}`,
|
||||||
|
},
|
||||||
|
cache: 'no-cache',
|
||||||
|
next: {
|
||||||
|
tags: ['area']
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const data: ResponseData = await res.json()
|
||||||
|
|
||||||
|
// Recommendation: handle errors
|
||||||
|
if (!res.ok) {
|
||||||
|
// This will activate the closest `error.js` Error Boundary
|
||||||
|
throw new Error(`Failed to fetch data, ${data.code || res.status} ${data.message || res.statusText}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.data
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default async function AreaPage() {
|
||||||
|
const data = await getData()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<Card>
|
||||||
|
<CardHeader className='flex flex-row items-center justify-between space-y-2 sm:space-y-0'>
|
||||||
|
<div>
|
||||||
|
<CardTitle>Area</CardTitle>
|
||||||
|
<CardDescription>Here's a list of areas that have been registered!</CardDescription>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<ComponentPage
|
||||||
|
data={data.area}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { FC, ReactNode, useState } from 'react';
|
||||||
|
import { Icons } from '@/components/Icons';
|
||||||
|
import { AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog';
|
||||||
|
import { type ResponseData } from '@/types/types';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
title?: string
|
||||||
|
description?: string
|
||||||
|
onConfirm: () => Promise<any>
|
||||||
|
okText?: string
|
||||||
|
cancelText?: string
|
||||||
|
contentSuccess?: ReactNode | string
|
||||||
|
onOkSuccess?: () => any
|
||||||
|
};
|
||||||
|
|
||||||
|
const ConfirmAsync: FC<Props> = ({ title, description, onConfirm, okText, cancelText, contentSuccess, onOkSuccess }) => {
|
||||||
|
const [isLoading, setIsloading] = useState(false)
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
const confirm = async () => {
|
||||||
|
if (isLoading) return
|
||||||
|
try {
|
||||||
|
setIsloading(true)
|
||||||
|
const res: ResponseData = await onConfirm()
|
||||||
|
setIsloading(false)
|
||||||
|
|
||||||
|
console.log(res)
|
||||||
|
if (!res) return
|
||||||
|
|
||||||
|
if (res.code === '00') {
|
||||||
|
showSuccess()
|
||||||
|
} else {
|
||||||
|
showError(res.message)
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.log(error)
|
||||||
|
setIsloading(false)
|
||||||
|
showError(error?.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const showSuccess = () => {
|
||||||
|
router.refresh()
|
||||||
|
toast.success(contentSuccess || 'Data successfully removed.' as string)
|
||||||
|
onOkSuccess!()
|
||||||
|
};
|
||||||
|
|
||||||
|
const showError = (message?: string) => {
|
||||||
|
toast.error(message)
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>{title || 'Are you absolutely sure?'}</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
{description || 'This action cannot be undone. This will permanently delete this data and remove from our servers.'}
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel disabled={isLoading}>{cancelText || 'Cancel'}</AlertDialogCancel>
|
||||||
|
<AlertDialogAction disabled={isLoading} onClick={confirm}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
{okText || 'Continue'}
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ConfirmAsync;
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
import { useEffect, useState } from "react"
|
||||||
|
import { useSession } from "next-auth/react"
|
||||||
|
import { Form, Input } from "antd"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
import { Icons } from "@/components/Icons"
|
||||||
|
import { type ICompany } from "./type"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
isUpdate?: boolean
|
||||||
|
data?: ICompany
|
||||||
|
onCancel?: () => any
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function CompanyForm({ data, isUpdate, onCancel }: Props) {
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
|
||||||
|
const BASE_URL = process.env.BASE_URL_API
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
const { data: session } = useSession()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data) {
|
||||||
|
form.setFieldsValue(data)
|
||||||
|
} else {
|
||||||
|
form.resetFields()
|
||||||
|
}
|
||||||
|
}, [data, form])
|
||||||
|
|
||||||
|
const handleSubmit = (value: any) => {
|
||||||
|
console.log(value)
|
||||||
|
|
||||||
|
!isUpdate ? handleCreate(value) : handleUpdate(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCreate = async (payload: ICompany) => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true)
|
||||||
|
const res = await fetch(BASE_URL + '/company', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${session?.user.access_token}`,
|
||||||
|
},
|
||||||
|
body: JSON.stringify(payload)
|
||||||
|
})
|
||||||
|
|
||||||
|
const data = await res.json()
|
||||||
|
setIsLoading(false)
|
||||||
|
if (!res.ok) {
|
||||||
|
toast.error(`Data failed to create`, { description: `(${data.code || res.status}) ${data.message || res.statusText}` })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
toast.success('Data successfully created.')
|
||||||
|
router.refresh()
|
||||||
|
onCancel!()
|
||||||
|
} catch (error: any) {
|
||||||
|
toast.error(`Data failed to create, ${error.message}`)
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleUpdate = async (payload: ICompany) => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true)
|
||||||
|
const res = await fetch(BASE_URL + '/company/' + data?.id, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${session?.user.access_token}`,
|
||||||
|
},
|
||||||
|
body: JSON.stringify(payload)
|
||||||
|
})
|
||||||
|
|
||||||
|
const resData = await res.json()
|
||||||
|
setIsLoading(false)
|
||||||
|
if (!res.ok) {
|
||||||
|
toast.error(`Data failed to update`, { description: `(${resData.code || res.status}) ${resData.message || res.statusText}` })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
toast.success('Data successfully updated.')
|
||||||
|
router.refresh()
|
||||||
|
onCancel!()
|
||||||
|
} catch (error: any) {
|
||||||
|
toast.error(`Data failed to update`, { description: `${error.message}` })
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DialogContent>
|
||||||
|
<Form form={form} onFinish={handleSubmit}>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle className="dark:text-white">{isUpdate ? 'Update company' : 'Create company'}</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Add a new team to manage products and customers
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="grid mt-8">
|
||||||
|
{/* <div className="grid gap-2">
|
||||||
|
<Label htmlFor="code">Code</Label>
|
||||||
|
<Form.Item name='code' rules={[{ required: true, message: 'Please input company code!' }]} >
|
||||||
|
<Input className="input" id="code" />
|
||||||
|
</Form.Item>
|
||||||
|
</div> */}
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="name">Company name</Label>
|
||||||
|
<Form.Item name='name' rules={[{ required: true, message: 'Please input company name!' }]} >
|
||||||
|
<Input className="input" id="name" placeholder="PT KCI" />
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="description">Description</Label>
|
||||||
|
<Form.Item name='description' >
|
||||||
|
<Input.TextArea className="input" id="description" placeholder="PT Kereta Commuter Indonesia" />
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" type="button" onClick={onCancel} disabled={isLoading} >
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" disabled={isLoading}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</Form>
|
||||||
|
</DialogContent>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,215 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
||||||
|
import { useSession } from 'next-auth/react';
|
||||||
|
import { MoreHorizontalIcon } from 'lucide-react';
|
||||||
|
import { Table } from 'antd';
|
||||||
|
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||||
|
import { MixerHorizontalIcon, PlusCircledIcon } from '@radix-ui/react-icons';
|
||||||
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { AlertDialog, AlertDialogTrigger } from '@/components/ui/alert-dialog';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { Dialog } from '@/components/ui/dialog';
|
||||||
|
import CompanyForm from './Form';
|
||||||
|
import ConfirmAsync from './ConfirmAsync';
|
||||||
|
import { type ICompany } from './type';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: ICompany[]
|
||||||
|
};
|
||||||
|
|
||||||
|
const ComponentCompanyPage: FC<Props> = ({ data }) => {
|
||||||
|
const [filterData, setFilterData] = useState<ICompany[]>([])
|
||||||
|
const [selectedData, setSelectedData] = useState<ICompany | undefined>(undefined)
|
||||||
|
const [showFormDialog, setShowFormDialog] = useState(false)
|
||||||
|
|
||||||
|
const { data: session } = useSession()
|
||||||
|
const BASE_URL = process.env.BASE_URL_API
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data) {
|
||||||
|
setFilterData(data)
|
||||||
|
}
|
||||||
|
}, [data])
|
||||||
|
|
||||||
|
const handleDelete = (companyId: string | number) => {
|
||||||
|
// return new Promise((resolve, reject) => {
|
||||||
|
// if (Math.random() > 0.5) {
|
||||||
|
// setTimeout(() => {
|
||||||
|
// resolve("success")
|
||||||
|
// }, 2000);
|
||||||
|
// } else {
|
||||||
|
// setTimeout(reject, 2000);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
return fetch(`${BASE_URL}/company/${companyId}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${session?.user.access_token}`,
|
||||||
|
},
|
||||||
|
}).then(res => res.json())
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleResetForm = () => {
|
||||||
|
setSelectedData(undefined)
|
||||||
|
setShowFormDialog(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSearch = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const text = e.target.value
|
||||||
|
if (text) {
|
||||||
|
const newData = [...data!].filter(item => (
|
||||||
|
item.code?.toLowerCase().includes(text.toLowerCase()) ||
|
||||||
|
item.name?.toLowerCase().includes(text.toLowerCase()) ||
|
||||||
|
item.description?.toLowerCase().includes(text.toLowerCase())
|
||||||
|
))
|
||||||
|
setFilterData(newData)
|
||||||
|
} else {
|
||||||
|
setFilterData(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const Columns: ColumnsType<ICompany> = [
|
||||||
|
{
|
||||||
|
title: 'Num',
|
||||||
|
dataIndex: 'key',
|
||||||
|
render: (text, record, index) => index + 1
|
||||||
|
},
|
||||||
|
// {
|
||||||
|
// title: 'id',
|
||||||
|
// dataIndex: 'id',
|
||||||
|
// sorter: (a, b) => a.id! - b.id!,
|
||||||
|
// },
|
||||||
|
{
|
||||||
|
title: 'Code',
|
||||||
|
dataIndex: 'code',
|
||||||
|
sorter: (a, b) => a.code.localeCompare(b.code)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Name',
|
||||||
|
dataIndex: 'name',
|
||||||
|
sorter: (a, b) => a.name.localeCompare(b.name)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Status',
|
||||||
|
dataIndex: 'status',
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
text: 'ACTIVE',
|
||||||
|
value: 'A',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'INACTIVE',
|
||||||
|
value: 'N',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'DELETED',
|
||||||
|
value: 'X',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
onFilter: (value, record) => record.status!.code.indexOf(value as string) === 0,
|
||||||
|
align: 'center',
|
||||||
|
render: (text, record) => (
|
||||||
|
<div className='flex justify-center text-white font-semibold text-xs'>
|
||||||
|
{record.status.code === 'A' ?
|
||||||
|
<div className="px-2 py-1.5 rounded-full bg-green-500 w-24">{record.status.name}</div>
|
||||||
|
:
|
||||||
|
<div className="px-2 py-1.5 rounded-full bg-rose-500 w-24">{record.status.name}</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Description',
|
||||||
|
dataIndex: 'description',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Action',
|
||||||
|
key: 'action',
|
||||||
|
render: (_, record) => (
|
||||||
|
<AlertDialog>
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant='ghost' size="icon">
|
||||||
|
<MoreHorizontalIcon />
|
||||||
|
<span className="sr-only">Action Button</span>
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||||
|
<AlertDialogTrigger asChild>
|
||||||
|
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||||
|
</AlertDialogTrigger>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
<ConfirmAsync
|
||||||
|
onConfirm={() => handleDelete(record.id)}
|
||||||
|
onOkSuccess={() => { }}
|
||||||
|
/>
|
||||||
|
</AlertDialog>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const tableProps: TableProps<ICompany> = {
|
||||||
|
bordered: false,
|
||||||
|
size: 'small',
|
||||||
|
// expandable,
|
||||||
|
showHeader: true,
|
||||||
|
rowSelection: {
|
||||||
|
onChange: (selectedRowKeys: React.Key[], selectedRows: ICompany[]) => {
|
||||||
|
console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
|
||||||
|
},
|
||||||
|
getCheckboxProps: (record: ICompany) => ({
|
||||||
|
disabled: record.code === 'C01', // Column configuration not to be checked
|
||||||
|
name: record.id?.toString(),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
pagination: {
|
||||||
|
pageSizeOptions: [5, 10, 20, 50],
|
||||||
|
defaultPageSize: 10,
|
||||||
|
showSizeChanger: true,
|
||||||
|
showQuickJumper: true,
|
||||||
|
size: 'default',
|
||||||
|
},
|
||||||
|
scroll: { x: 'max-content' },
|
||||||
|
tableLayout: 'auto',
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='flex flex-col space-y-4'>
|
||||||
|
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between space-y-2 sm:space-y-0">
|
||||||
|
<div className="flex flex-1 items-center space-x-2">
|
||||||
|
<Input placeholder="Search company..." className="h-8 w-full sm:w-[250px]" onChange={handleSearch} />
|
||||||
|
</div>
|
||||||
|
<Button variant='ghost' size="sm" className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||||
|
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||||
|
Create New Compnay
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<Table
|
||||||
|
{...tableProps}
|
||||||
|
rowKey='id'
|
||||||
|
columns={Columns}
|
||||||
|
dataSource={filterData || []}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Dialog open={showFormDialog} onOpenChange={(state) => {
|
||||||
|
if (state === false) setSelectedData(undefined)
|
||||||
|
setShowFormDialog(state)
|
||||||
|
}}>
|
||||||
|
<CompanyForm
|
||||||
|
data={selectedData}
|
||||||
|
isUpdate={selectedData !== undefined}
|
||||||
|
onCancel={handleResetForm}
|
||||||
|
/>
|
||||||
|
</Dialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ComponentCompanyPage;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
export interface ICompany {
|
||||||
|
id: number
|
||||||
|
code: string
|
||||||
|
name: string
|
||||||
|
status: {
|
||||||
|
id: number
|
||||||
|
code: "A" | 'N' | 'X'
|
||||||
|
name: "ACTIVE" | 'INACTIVE' | 'DELETED'
|
||||||
|
}
|
||||||
|
description: string
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import { type Metadata } from 'next';
|
||||||
|
import { Suspense, lazy } from 'react';
|
||||||
|
import { getServerSession } from 'next-auth';
|
||||||
|
import { Download } from 'lucide-react'
|
||||||
|
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { type ResponseData } from '@/types/types';
|
||||||
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import LazyLoading from '@/components/loader/LazyLoading';
|
||||||
|
|
||||||
|
const ComponentPage = lazy(() => import('./component'));
|
||||||
|
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "Admin | Company",
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getData() {
|
||||||
|
const { BASE_URL_API } = process.env
|
||||||
|
const session = await getServerSession(authOptions)
|
||||||
|
|
||||||
|
const res = await fetch(BASE_URL_API + '/company', {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${session?.user.access_token}`,
|
||||||
|
},
|
||||||
|
cache: 'no-cache',
|
||||||
|
next: {
|
||||||
|
tags: ['company']
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const data: ResponseData = await res.json()
|
||||||
|
|
||||||
|
// Recommendation: handle errors
|
||||||
|
if (!res.ok) {
|
||||||
|
// This will activate the closest `error.js` Error Boundary
|
||||||
|
throw new Error(`Failed to fetch data, ${data.code || res.status} ${data.message || res.statusText}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.data
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default async function CompanyPage() {
|
||||||
|
const data = await getData()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<Card>
|
||||||
|
<CardHeader className='flex flex-row items-center justify-between space-y-2 sm:space-y-0'>
|
||||||
|
<div>
|
||||||
|
<CardTitle>Company</CardTitle>
|
||||||
|
<CardDescription>Here's a list of companies that have been registered!</CardDescription>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<ComponentPage
|
||||||
|
data={data.company}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import { FC, ReactNode, useState } from 'react';
|
||||||
|
import { Icons } from '@/components/Icons';
|
||||||
|
import { AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog';
|
||||||
|
import { type ResponseData } from '@/types/types';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
title?: string
|
||||||
|
description?: string
|
||||||
|
onConfirm: () => Promise<any>
|
||||||
|
okText?: string
|
||||||
|
cancelText?: string
|
||||||
|
contentSuccess?: ReactNode | string
|
||||||
|
onOkSuccess?: () => any
|
||||||
|
};
|
||||||
|
|
||||||
|
const ConfirmAsync: FC<Props> = ({ title, description, onConfirm, okText, cancelText, contentSuccess, onOkSuccess }) => {
|
||||||
|
const [isLoading, setIsloading] = useState(false)
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
const confirm = async () => {
|
||||||
|
if (isLoading) return
|
||||||
|
try {
|
||||||
|
setIsloading(true)
|
||||||
|
const res: ResponseData = await onConfirm()
|
||||||
|
setIsloading(false)
|
||||||
|
|
||||||
|
console.log(res)
|
||||||
|
if (!res) return
|
||||||
|
|
||||||
|
if (res.code === '00') {
|
||||||
|
showSuccess()
|
||||||
|
} else {
|
||||||
|
showError(res.message)
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.log(error)
|
||||||
|
setIsloading(false)
|
||||||
|
showError(error?.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const showSuccess = () => {
|
||||||
|
toast.success(contentSuccess || 'Data successfully removed.' as string)
|
||||||
|
router.refresh()
|
||||||
|
onOkSuccess!()
|
||||||
|
};
|
||||||
|
|
||||||
|
const showError = (message?: string) => {
|
||||||
|
toast.error(message)
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>{title || 'Are you absolutely sure?'}</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
{description || 'This action cannot be undone. This will permanently delete this data and remove from our servers.'}
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel disabled={isLoading}>{cancelText || 'Cancel'}</AlertDialogCancel>
|
||||||
|
<AlertDialogAction disabled={isLoading} onClick={confirm}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
{okText || 'Continue'}
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ConfirmAsync;
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
import { useEffect, useState } from "react"
|
||||||
|
import { Form, Input, Select } from "antd"
|
||||||
|
import useAxiosAuth from "@/lib/axios/useAxiosAuth"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
import { Icons } from "@/components/Icons"
|
||||||
|
import useFetch from "@/hooks/useFetch"
|
||||||
|
import { type ICompany } from "../../company/component/type"
|
||||||
|
import { type IDivision } from "./type"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
isUpdate?: boolean
|
||||||
|
data?: IDivision
|
||||||
|
onCancel?: () => any
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ComponentForm({ data, isUpdate, onCancel }: Props) {
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
const router = useRouter()
|
||||||
|
const axios = useAxiosAuth()
|
||||||
|
|
||||||
|
const { data: companyList, isLoading: loadingCompany, error } = useFetch('/company')
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data) {
|
||||||
|
form.setFieldsValue(data)
|
||||||
|
if (data.company) form.setFieldValue('company_id', data.company.id)
|
||||||
|
} else {
|
||||||
|
form.resetFields()
|
||||||
|
}
|
||||||
|
}, [data, form])
|
||||||
|
|
||||||
|
const handleSubmit = (value: any) => {
|
||||||
|
console.log(value)
|
||||||
|
|
||||||
|
!isUpdate ? handleCreate(value) : handleUpdate(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCreate = async (payload: IDivision) => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true)
|
||||||
|
await axios.post('/division', payload)
|
||||||
|
|
||||||
|
handleSuccess('Data successfully created.')
|
||||||
|
} catch (error: any) {
|
||||||
|
handleError(`Data failed to create, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleUpdate = async (payload: IDivision) => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true)
|
||||||
|
await axios.put('/division/' + data?.id, payload)
|
||||||
|
|
||||||
|
handleSuccess('Data successfully updated.')
|
||||||
|
} catch (error: any) {
|
||||||
|
handleError(`Data failed to update, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSuccess = (message: string) => {
|
||||||
|
toast.success(message)
|
||||||
|
setIsLoading(false)
|
||||||
|
onCancel!()
|
||||||
|
router.refresh()
|
||||||
|
form.resetFields()
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleError = (message: string) => {
|
||||||
|
toast.error(message)
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DialogContent>
|
||||||
|
<Form form={form} onFinish={handleSubmit}>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle className="dark:text-white">{isUpdate ? 'Update Division' : 'Create Division'}</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Add a new team to manage products and customers
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="grid mt-8">
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="code">Code</Label>
|
||||||
|
<Form.Item name='code' rules={[{ required: true, message: 'Please input company code!' }]} >
|
||||||
|
<Input className="input" id="code" placeholder="C01" />
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="name">Division name</Label>
|
||||||
|
<Form.Item name='name' rules={[{ required: true, message: 'This field is required' }]} >
|
||||||
|
<Input className="input" id="name" placeholder="RESEARCH AND DEVELOPMENT" />
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="company_id">Company</Label>
|
||||||
|
<Form.Item name='company_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||||
|
<Select placeholder='Select company' showSearch allowClear loading={loadingCompany}
|
||||||
|
optionFilterProp="children"
|
||||||
|
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||||
|
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||||
|
>
|
||||||
|
{companyList?.company?.length > 0 && companyList.company.map((item: ICompany, key: number) =>
|
||||||
|
<Select.Option value={item.id} key={key}>{item.code} - {item.name}</Select.Option>
|
||||||
|
)}
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="description">Description</Label>
|
||||||
|
<Form.Item name='description' >
|
||||||
|
<Input.TextArea className="input" id="description" placeholder="R&D Department PT Nutech Integrasi by Telkom Indonesia" />
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" type="button" onClick={onCancel} disabled={isLoading} >
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" disabled={isLoading}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</Form>
|
||||||
|
</DialogContent>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,188 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
||||||
|
import { MoreHorizontalIcon } from 'lucide-react';
|
||||||
|
import { Table } from 'antd';
|
||||||
|
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||||
|
import { MixerHorizontalIcon, PlusCircledIcon } from '@radix-ui/react-icons';
|
||||||
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { AlertDialog, AlertDialogTrigger } from '@/components/ui/alert-dialog';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { Dialog } from '@/components/ui/dialog';
|
||||||
|
import ComponentForm from './Form';
|
||||||
|
import ConfirmAsync from './ConfirmAsync';
|
||||||
|
import { IDivision } from './type';
|
||||||
|
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: IDivision[]
|
||||||
|
};
|
||||||
|
|
||||||
|
const ComponentPage: FC<Props> = ({ data }) => {
|
||||||
|
const [filterData, setFilterData] = useState<IDivision[]>([])
|
||||||
|
const [selectedData, setSelectedData] = useState<IDivision | undefined>(undefined)
|
||||||
|
const [showFormDialog, setShowFormDialog] = useState(false)
|
||||||
|
|
||||||
|
const axios = useAxiosAuth()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data) {
|
||||||
|
setFilterData(data)
|
||||||
|
}
|
||||||
|
}, [data])
|
||||||
|
|
||||||
|
const handleDelete = (divisionId: string | number) => {
|
||||||
|
return axios.delete(`/division/${divisionId}`).then(res => res.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleResetForm = () => {
|
||||||
|
setSelectedData(undefined)
|
||||||
|
setShowFormDialog(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSearch = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const text = e.target.value
|
||||||
|
if (text) {
|
||||||
|
const newData = [...data!].filter(item => (
|
||||||
|
item.name?.toLowerCase().includes(text.toLowerCase()) ||
|
||||||
|
item.description?.toLowerCase().includes(text.toLowerCase())
|
||||||
|
))
|
||||||
|
setFilterData(newData)
|
||||||
|
} else {
|
||||||
|
setFilterData(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const Columns: ColumnsType<IDivision> = [
|
||||||
|
{
|
||||||
|
title: 'Num',
|
||||||
|
dataIndex: 'key',
|
||||||
|
render: (text, record, index) => index + 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Code',
|
||||||
|
dataIndex: 'code',
|
||||||
|
sorter: (a, b) => a.code.localeCompare(b.code)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Division Name',
|
||||||
|
dataIndex: 'name',
|
||||||
|
sorter: (a, b) => a.name.localeCompare(b.name)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Company',
|
||||||
|
dataIndex: 'company',
|
||||||
|
render: (text) => text?.name
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Status',
|
||||||
|
dataIndex: 'status',
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
text: 'ACTIVE',
|
||||||
|
value: 'A',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'INACTIVE',
|
||||||
|
value: 'N',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'DELETED',
|
||||||
|
value: 'X',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
onFilter: (value, record) => record.status!.code.indexOf(value as string) === 0,
|
||||||
|
align: 'center',
|
||||||
|
render: (text, record) => (
|
||||||
|
<div className='flex justify-center text-white font-semibold text-xs'>
|
||||||
|
{record.status.code === 'A' ?
|
||||||
|
<div className="px-2 py-1.5 rounded-full bg-green-500 w-24">{record.status.name}</div>
|
||||||
|
:
|
||||||
|
<div className="px-2 py-1.5 rounded-full bg-rose-500 w-24">{record.status.name}</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Description',
|
||||||
|
dataIndex: 'description',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Action',
|
||||||
|
key: 'action',
|
||||||
|
render: (_, record) => (
|
||||||
|
<AlertDialog>
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant='ghost' size="icon">
|
||||||
|
<MoreHorizontalIcon />
|
||||||
|
<span className="sr-only">Action Button</span>
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||||
|
<AlertDialogTrigger asChild>
|
||||||
|
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||||
|
</AlertDialogTrigger>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
<ConfirmAsync
|
||||||
|
onConfirm={() => handleDelete(record.id)}
|
||||||
|
onOkSuccess={() => { }}
|
||||||
|
/>
|
||||||
|
</AlertDialog>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const tableProps: TableProps<IDivision> = {
|
||||||
|
bordered: false,
|
||||||
|
size: 'small',
|
||||||
|
showHeader: true,
|
||||||
|
pagination: {
|
||||||
|
pageSizeOptions: [5, 10, 20, 50],
|
||||||
|
defaultPageSize: 10,
|
||||||
|
showSizeChanger: true,
|
||||||
|
showQuickJumper: true,
|
||||||
|
size: 'default'
|
||||||
|
},
|
||||||
|
scroll: { x: 'max-content' },
|
||||||
|
tableLayout: 'auto',
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='flex flex-col space-y-4'>
|
||||||
|
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between space-y-2 sm:space-y-0">
|
||||||
|
<div className="flex flex-1 items-center space-x-2">
|
||||||
|
<Input placeholder="Search department..." className="h-8 w-full sm:w-[250px]" onChange={handleSearch} />
|
||||||
|
</div>
|
||||||
|
<Button variant='ghost' size="sm" className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||||
|
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||||
|
Create New Department
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<Table
|
||||||
|
{...tableProps}
|
||||||
|
rowKey='id'
|
||||||
|
columns={Columns}
|
||||||
|
dataSource={filterData || []}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Dialog open={showFormDialog} onOpenChange={(state) => {
|
||||||
|
if (state === false) setSelectedData(undefined)
|
||||||
|
setShowFormDialog(state)
|
||||||
|
}}>
|
||||||
|
<ComponentForm
|
||||||
|
data={selectedData}
|
||||||
|
isUpdate={selectedData !== undefined}
|
||||||
|
onCancel={handleResetForm}
|
||||||
|
/>
|
||||||
|
</Dialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ComponentPage;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
export interface IDivision {
|
||||||
|
id: number
|
||||||
|
code: string
|
||||||
|
name: string
|
||||||
|
company?: any
|
||||||
|
company_id: string
|
||||||
|
status: {
|
||||||
|
id: number
|
||||||
|
code: "A" | 'N' | 'X'
|
||||||
|
name: "ACTIVE" | 'INACTIVE' | 'DELETED'
|
||||||
|
}
|
||||||
|
description: string
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import { type Metadata } from 'next';
|
||||||
|
import { Suspense, lazy } from 'react';
|
||||||
|
import { getServerSession } from 'next-auth';
|
||||||
|
import { Download } from 'lucide-react'
|
||||||
|
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { type ResponseData } from '@/types/types';
|
||||||
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import LazyLoading from '@/components/loader/LazyLoading';
|
||||||
|
|
||||||
|
const ComponentPage = lazy(() => import('./component'));
|
||||||
|
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "Admin | Division",
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getData() {
|
||||||
|
const { BASE_URL_API } = process.env
|
||||||
|
const session = await getServerSession(authOptions)
|
||||||
|
|
||||||
|
const res = await fetch(BASE_URL_API + '/division', {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${session?.user.access_token}`,
|
||||||
|
},
|
||||||
|
cache: 'no-cache',
|
||||||
|
next: {
|
||||||
|
tags: ['division']
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const data: ResponseData = await res.json()
|
||||||
|
|
||||||
|
// Recommendation: handle errors
|
||||||
|
if (!res.ok) {
|
||||||
|
// This will activate the closest `error.js` Error Boundary
|
||||||
|
throw new Error(`Failed to fetch data, ${data.code || res.status} ${data.message || res.statusText}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.data
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default async function DivisionPage() {
|
||||||
|
const data = await getData()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<Card>
|
||||||
|
<CardHeader className='flex flex-row items-center justify-between space-y-2 sm:space-y-0'>
|
||||||
|
<div>
|
||||||
|
<CardTitle>Division</CardTitle>
|
||||||
|
<CardDescription>Here's a list of departments that have been registered!</CardDescription>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<Suspense fallback={<LazyLoading />}>
|
||||||
|
<ComponentPage
|
||||||
|
data={data.division}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
import { FC } from 'react';
|
||||||
|
import { type Metadata } from 'next';
|
||||||
|
import Link from 'next/link';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import fetchData from '@/lib/fetchData';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { type IUser } from '../component/type';
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "Admin | User Detail",
|
||||||
|
}
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
params: Promise<{ id: string | undefined }>
|
||||||
|
};
|
||||||
|
|
||||||
|
const UserDetailPage: FC<Props> = async ({ params }) => {
|
||||||
|
const id = (await params).id
|
||||||
|
|
||||||
|
const data: IUser = await fetchData(`/user/${id}`)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Card>
|
||||||
|
<CardHeader className='flex flex-col sm:flex-row items-center justify-between space-y-3 sm:space-y-0'>
|
||||||
|
<div className='flex items-center sm:space-x-5'>
|
||||||
|
<Link href='/admin/administration/user' className='hidden sm:block'>
|
||||||
|
<Button variant='outline' size='icon'>
|
||||||
|
<i className="ti ti-arrow-left text-xl"></i>
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
<div className='space-y-1'>
|
||||||
|
<CardTitle>User Detail</CardTitle>
|
||||||
|
<CardDescription>Detail of user id {id}</CardDescription>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{data.status.code === 'A' &&
|
||||||
|
<Link href={`create?is_update=true&id=${id}`} className='w-full sm:w-max'>
|
||||||
|
<Button variant='secondary' className='w-full'>
|
||||||
|
Edit <i className="ti ti-edit ml-2 text-lg"></i>
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
}
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className='grid grid-cols-1 sm:grid-cols-2 font-medium gap-y-5'>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Fullname</span>
|
||||||
|
<span>{data?.fullname}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Nickname</span>
|
||||||
|
<span>{data?.nickname}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Email address</span>
|
||||||
|
<span className='lowercase'>{data?.email}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Phone</span>
|
||||||
|
<span>{data.phone_number || '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>NIK</span>
|
||||||
|
<span>{data?.nik}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>NIKTG</span>
|
||||||
|
<span>{data?.niktg || '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Company</span>
|
||||||
|
<span>{data?.company?.name}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Area</span>
|
||||||
|
<span>{data?.area?.name}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Department</span>
|
||||||
|
<span>{data?.division?.name}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Role</span>
|
||||||
|
<span>{data?.role?.name}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Employee Type</span>
|
||||||
|
<span>{data?.employee_type?.name || '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Position</span>
|
||||||
|
<span>{data?.position?.name || '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Birthday</span>
|
||||||
|
<span>{data?.birthday ? dayjs(data?.birthday).format('MMM DD, YYYY') : '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Gender</span>
|
||||||
|
<span>{data?.gender || '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Hire Date</span>
|
||||||
|
<span>{data?.hire_date ? dayjs(data?.hire_date).format('MMM DD, YYYY') : '-'}</span>
|
||||||
|
</div><div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Contract Expiration Date</span>
|
||||||
|
<span>{data?.contract_expiration_date ? dayjs(data?.contract_expiration_date).format('MMM DD, YYYY') : '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Is Extend Contract</span>
|
||||||
|
<span>{data?.is_extend_contract || '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Office Email</span>
|
||||||
|
<span>{data?.email_office || '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Personal Email</span>
|
||||||
|
<span>{data?.email_personal || '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Last Education</span>
|
||||||
|
<span>{data?.last_education || '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Resign Date</span>
|
||||||
|
<span>{data?.resign_date ? dayjs(data?.resign_date).format('MMM DD, YYYY') : '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Resign Reason</span>
|
||||||
|
<span>{data?.resign_reason || '-'}</span>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<span className='text-muted-foreground'>Post Company</span>
|
||||||
|
<span>{data?.post_company || '-'}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default UserDetailPage;
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import { FC, ReactNode, useState } from 'react';
|
||||||
|
import { Icons } from '@/components/Icons';
|
||||||
|
import { AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog';
|
||||||
|
import { type ResponseData } from '@/types/types';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
title?: string
|
||||||
|
description?: string
|
||||||
|
onConfirm: () => Promise<any>
|
||||||
|
okText?: string
|
||||||
|
cancelText?: string
|
||||||
|
contentSuccess?: ReactNode | string
|
||||||
|
onOkSuccess?: () => any
|
||||||
|
};
|
||||||
|
|
||||||
|
const ConfirmAsync: FC<Props> = ({ title, description, onConfirm, okText, cancelText, contentSuccess, onOkSuccess }) => {
|
||||||
|
const [isLoading, setIsloading] = useState(false)
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
const confirm = async () => {
|
||||||
|
if (isLoading) return
|
||||||
|
try {
|
||||||
|
setIsloading(true)
|
||||||
|
const res: ResponseData = await onConfirm()
|
||||||
|
setIsloading(false)
|
||||||
|
|
||||||
|
console.log(res)
|
||||||
|
if (!res) return
|
||||||
|
|
||||||
|
if (res.code === '00') {
|
||||||
|
showSuccess()
|
||||||
|
} else {
|
||||||
|
showError(res.message)
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.log(error)
|
||||||
|
setIsloading(false)
|
||||||
|
showError(error?.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const showSuccess = () => {
|
||||||
|
toast.success(contentSuccess || 'Data successfully removed.' as string)
|
||||||
|
router.refresh()
|
||||||
|
onOkSuccess!()
|
||||||
|
};
|
||||||
|
|
||||||
|
const showError = (message?: string) => {
|
||||||
|
toast.error(message)
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AlertDialogContent onClick={e => e.stopPropagation()}>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>{title || 'Are you absolutely sure?'}</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
{description || 'This action cannot be undone. This will permanently delete this data and remove from our servers.'}
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel disabled={isLoading}>{cancelText || 'Cancel'}</AlertDialogCancel>
|
||||||
|
<AlertDialogAction disabled={isLoading} onClick={confirm}>
|
||||||
|
{isLoading && (
|
||||||
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
|
{okText || 'Continue'}
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ConfirmAsync;
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { FC } from 'react';
|
||||||
|
import Chart from 'react-apexcharts';
|
||||||
|
import { type ApexOptions } from 'apexcharts';
|
||||||
|
import { useTheme } from 'next-themes';
|
||||||
|
import useMobileView from '@/hooks/useMobileView';
|
||||||
|
import { getArrayRandomNumber, getLastNDays } from '@/lib/helper';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: any
|
||||||
|
};
|
||||||
|
|
||||||
|
const AreaChart: FC<Props> = ({ data }) => {
|
||||||
|
const { theme, systemTheme } = useTheme()
|
||||||
|
const { windowWidth } = useMobileView()
|
||||||
|
|
||||||
|
const options: ApexOptions = {
|
||||||
|
chart: {
|
||||||
|
type: 'area',
|
||||||
|
fontFamily: 'Inter, Arial, sans-serif',
|
||||||
|
toolbar: {
|
||||||
|
show: false
|
||||||
|
},
|
||||||
|
offsetX: windowWidth < 400 ? 430 : windowWidth < 600 ? 390 : 0
|
||||||
|
},
|
||||||
|
colors: ['#f43f5e', '#22c55e'],
|
||||||
|
legend: {
|
||||||
|
position: 'top',
|
||||||
|
show: true,
|
||||||
|
fontSize: '16px',
|
||||||
|
labels: {
|
||||||
|
colors: theme === 'dark' ? '#fff' : theme === 'system' && systemTheme === 'dark' ? '#fff' : '#000',
|
||||||
|
useSeriesColors: false
|
||||||
|
},
|
||||||
|
},
|
||||||
|
dataLabels: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
stroke: {
|
||||||
|
show: true,
|
||||||
|
curve: 'smooth',
|
||||||
|
width: 2,
|
||||||
|
},
|
||||||
|
xaxis: {
|
||||||
|
type: 'datetime',
|
||||||
|
categories: getLastNDays(30),
|
||||||
|
labels: {
|
||||||
|
show: true,
|
||||||
|
rotateAlways: true,
|
||||||
|
minHeight: 40,
|
||||||
|
maxHeight: 40,
|
||||||
|
format: 'dd/MM',
|
||||||
|
style: {
|
||||||
|
colors: theme === 'dark' ? '#a1a1aa' : theme === 'system' && systemTheme === 'dark' ? '#a1a1aa' : '#71717a',
|
||||||
|
fontSize: '14px',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
yaxis: {
|
||||||
|
// tickAmount: 24,
|
||||||
|
min: 0,
|
||||||
|
max: 24,
|
||||||
|
labels: {
|
||||||
|
formatter: (val) => val.toFixed(0),
|
||||||
|
style: {
|
||||||
|
colors: theme === 'dark' ? '#a1a1aa' : theme === 'system' && systemTheme === 'dark' ? '#a1a1aa' : '#71717a',
|
||||||
|
fontSize: '14px',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
yaxis: {
|
||||||
|
lines: { show: false }
|
||||||
|
},
|
||||||
|
padding: {
|
||||||
|
right: 25 // Also you may want to increase this (based on the length of your labels)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fill: {
|
||||||
|
type: 'gradient',
|
||||||
|
gradient: {
|
||||||
|
shadeIntensity: 1,
|
||||||
|
inverseColors: false,
|
||||||
|
opacityFrom: 0.5,
|
||||||
|
opacityTo: 0.1,
|
||||||
|
stops: [20, 100, 100, 100]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
theme: theme === 'dark' ? 'dark' : theme === 'system' && systemTheme === 'dark' ? 'dark' : 'light',
|
||||||
|
style: { fontSize: '14px' },
|
||||||
|
x: {
|
||||||
|
format: 'MMM dd, yyyy'
|
||||||
|
},
|
||||||
|
y: {
|
||||||
|
formatter: (val) => val.toFixed(2)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
responsive: [{
|
||||||
|
breakpoint: 800,
|
||||||
|
options: {
|
||||||
|
legend: { fontSize: '14px' },
|
||||||
|
yaxis: {
|
||||||
|
min: 0,
|
||||||
|
max: 24,
|
||||||
|
labels: {
|
||||||
|
formatter: (val: any) => val.toFixed(0),
|
||||||
|
style: {
|
||||||
|
colors: theme === 'dark' ? '#a1a1aa' : theme === 'system' && systemTheme === 'dark' ? '#a1a1aa' : '#71717a',
|
||||||
|
fontSize: '12px',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
xaxis: {
|
||||||
|
labels: {
|
||||||
|
rotateAlways: true,
|
||||||
|
minHeight: 35,
|
||||||
|
maxHeight: 35,
|
||||||
|
style: {
|
||||||
|
colors: theme === 'dark' ? '#a1a1aa' : theme === 'system' && systemTheme === 'dark' ? '#a1a1aa' : '#71717a',
|
||||||
|
fontSize: '12px',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
const series = [
|
||||||
|
{
|
||||||
|
name: 'Check-Out',
|
||||||
|
data: getArrayRandomNumber(30, 17, 24)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Check-In',
|
||||||
|
data: getArrayRandomNumber(30, 8, 11)
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{/* <div className='h-[400px] 2xl:h-[500px] flex items-center justify-center -mt-3 overflow-hidden overflow-x-auto max-w-[300px] sm:max-w-full'> */}
|
||||||
|
<div className='h-[400px] 2xl:h-[500px] flex items-center justify-center -mt-3 overflow-hidden overflow-x-auto' style={{ maxWidth: windowWidth > 760 ? '100%' : windowWidth > 400 ? 400 : 310 }}>
|
||||||
|
<Chart
|
||||||
|
type='area'
|
||||||
|
options={options}
|
||||||
|
series={series}
|
||||||
|
width={windowWidth > 1900 ? '450%' : windowWidth > 1500 ? '420%' : windowWidth > 1280 ? '405%' : windowWidth > 760 ? 640 : '390%'}
|
||||||
|
height='100%'
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AreaChart;
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { FC } from 'react';
|
||||||
|
import Chart from 'react-apexcharts';
|
||||||
|
import { type ApexOptions } from 'apexcharts';
|
||||||
|
import { useTheme } from 'next-themes';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: number[]
|
||||||
|
labels: string[]
|
||||||
|
colors: string[]
|
||||||
|
};
|
||||||
|
|
||||||
|
const DonutChart: FC<Props> = ({ data, labels, colors }) => {
|
||||||
|
const { theme, systemTheme } = useTheme()
|
||||||
|
|
||||||
|
const options: ApexOptions = {
|
||||||
|
chart: {
|
||||||
|
width: 200,
|
||||||
|
height: 200,
|
||||||
|
events: {
|
||||||
|
click(e, chart, options) {
|
||||||
|
// const { seriesIndex, dataPointIndex } = options
|
||||||
|
const { selectedDataPoints } = options.globals
|
||||||
|
// console.log(selectedDataPoints)
|
||||||
|
if (selectedDataPoints.length > 0) {
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plotOptions: {
|
||||||
|
pie: {
|
||||||
|
expandOnClick: true,
|
||||||
|
donut: {
|
||||||
|
size: '55%',
|
||||||
|
labels: {
|
||||||
|
show: true,
|
||||||
|
name: {
|
||||||
|
show: true,
|
||||||
|
color: theme === 'dark' ? '#fff' : theme === 'system' && systemTheme === 'dark' ? '#fff' : '#000',
|
||||||
|
fontSize: '20px',
|
||||||
|
fontWeight: 'bold'
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
show: true,
|
||||||
|
color: theme === 'dark' ? '#fff' : theme === 'system' && systemTheme === 'dark' ? '#fff' : '#000',
|
||||||
|
fontSize: '32px',
|
||||||
|
fontWeight: 'bold'
|
||||||
|
},
|
||||||
|
total: {
|
||||||
|
show: false
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
legend: {
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
stroke: {
|
||||||
|
width: 0
|
||||||
|
},
|
||||||
|
dataLabels: {
|
||||||
|
enabled: true,
|
||||||
|
formatter: function (val: any, opts) {
|
||||||
|
// console.log(opts)
|
||||||
|
return opts.w.globals.labels[opts.seriesIndex] + ': ' + opts.w.globals.series[opts.seriesIndex]
|
||||||
|
// return opts.w.globals.series[opts.seriesIndex]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fill: {
|
||||||
|
type: 'gradient',
|
||||||
|
},
|
||||||
|
labels: labels,
|
||||||
|
colors: colors,
|
||||||
|
responsive: [{
|
||||||
|
breakpoint: 800,
|
||||||
|
options: {
|
||||||
|
chart: {
|
||||||
|
width: 200
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
const series = data
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='flex items-center justify-center'>
|
||||||
|
<Chart
|
||||||
|
type='donut'
|
||||||
|
options={options}
|
||||||
|
series={series}
|
||||||
|
width={250}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DonutChart;
|
||||||
@@ -0,0 +1,293 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
||||||
|
import { Table } from 'antd';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { IHistory } from '@/app/(dashboard)/history/components/type';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { getVariantApproved, getVariantWorkingStatus } from '@/lib/helper';
|
||||||
|
import useMobileView from '@/hooks/useMobileView';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
data: IHistory[]
|
||||||
|
};
|
||||||
|
|
||||||
|
const TableAttendanceHistory: FC<Props> = ({ data }) => {
|
||||||
|
const [filterData, setFilterData] = useState<IHistory[]>([])
|
||||||
|
const { isMobile, windowWidth } = useMobileView()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data) {
|
||||||
|
setFilterData(data)
|
||||||
|
}
|
||||||
|
}, [data])
|
||||||
|
|
||||||
|
const handleSearch = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const text = e.target.value
|
||||||
|
if (text) {
|
||||||
|
const newData = [...data!].filter(item => (
|
||||||
|
item.user.fullname?.toLowerCase().includes(text.toLowerCase()) ||
|
||||||
|
item.working_status?.toLowerCase().includes(text.toLowerCase()) ||
|
||||||
|
item.device.name?.toLowerCase().includes(text.toLowerCase()) ||
|
||||||
|
item.location_name?.toLowerCase().includes(text.toLowerCase()) ||
|
||||||
|
item.note?.toLowerCase().includes(text.toLowerCase()) ||
|
||||||
|
item.presence_checkout?.location_name?.toLowerCase().includes(text.toLowerCase()) ||
|
||||||
|
item.presence_checkout?.note?.toLowerCase().includes(text.toLowerCase())
|
||||||
|
))
|
||||||
|
setFilterData(newData)
|
||||||
|
} else {
|
||||||
|
setFilterData(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const Columns: ColumnsType<IHistory> = [
|
||||||
|
{
|
||||||
|
title: 'Date',
|
||||||
|
dataIndex: 'presence_date',
|
||||||
|
sorter: ((a, b) => (dayjs(a.presence_date).isAfter(dayjs(b.presence_date)) ? 1 : -1)),
|
||||||
|
render: (val) => dayjs(val).format('MMM DD, YYYY')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Name',
|
||||||
|
dataIndex: 'fullname',
|
||||||
|
sorter: (a, b) => a.user.fullname.localeCompare(b.user.fullname),
|
||||||
|
render: (val, record) => record.user.fullname
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Working Status',
|
||||||
|
dataIndex: 'working_status',
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
text: 'WFO',
|
||||||
|
value: 'WFO',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'WFS',
|
||||||
|
value: 'WFS',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'WFH',
|
||||||
|
value: 'WFH',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Sakit',
|
||||||
|
value: 'SKT',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Izin',
|
||||||
|
value: 'IZ01',
|
||||||
|
}
|
||||||
|
],
|
||||||
|
onFilter: (value, record) => record.working_status!.indexOf(value as string) === 0,
|
||||||
|
sorter: (a, b) => a.working_status?.localeCompare(b.working_status),
|
||||||
|
render: (val, record) => <Badge variant={getVariantWorkingStatus(val)}>{val}</Badge>
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Approval',
|
||||||
|
dataIndex: 'status',
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
text: 'Approved',
|
||||||
|
value: 'AP',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Rejected',
|
||||||
|
value: 'R',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Need to be Appove',
|
||||||
|
value: 'NA',
|
||||||
|
}
|
||||||
|
],
|
||||||
|
onFilter: (value, record) => record.status.code!.indexOf(value as string) === 0,
|
||||||
|
render: (val, record) => record.working_status === 'WFH' || record.working_status === 'WFS' ? <Badge variant={getVariantApproved(record.status.code as any)}>{record.status.name}</Badge> : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Check-in',
|
||||||
|
dataIndex: 'working_hours_start',
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
text: 'Less than 10:00 AM',
|
||||||
|
value: 'lt_10', // You can use any value you prefer
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'More than or equal to 10:00 AM',
|
||||||
|
value: 'gte_10', // You can use any value you prefer
|
||||||
|
},
|
||||||
|
],
|
||||||
|
onFilter: (value, record) => {
|
||||||
|
const time = new Date(record.working_hours_start).getHours();
|
||||||
|
|
||||||
|
if (value === 'lt_10') {
|
||||||
|
return time < 10;
|
||||||
|
} else if (value === 'gte_10') {
|
||||||
|
return time >= 10;
|
||||||
|
}
|
||||||
|
return false; // If the value doesn't match any filter
|
||||||
|
},
|
||||||
|
render: (val) => <span className='text-green-500'>{dayjs(val).format('HH:mm A')}</span>
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Check-in Device',
|
||||||
|
dataIndex: 'device',
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
text: 'FR Device',
|
||||||
|
value: '11001',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Web App',
|
||||||
|
value: '40001',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Android App',
|
||||||
|
value: '20001',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'IOS App',
|
||||||
|
value: '30001',
|
||||||
|
}
|
||||||
|
],
|
||||||
|
onFilter: (value, record) => record.device.code!.indexOf(value as string) === 0,
|
||||||
|
render: (val, record) => record.device.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Check-in Location',
|
||||||
|
dataIndex: 'location_name',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Check-in Note',
|
||||||
|
dataIndex: 'note',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Check-in Photo',
|
||||||
|
dataIndex: 'face_image',
|
||||||
|
render: (val, record) => val ? <a onClick={(e) => e.stopPropagation()} className='text-his hover:opacity-70 duration-200' href={process.env.BASE_URL_IMG + val} target="_blank">View Photo</a> : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Check-out',
|
||||||
|
dataIndex: 'working_hours_end',
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
text: 'Less than 17:00 PM',
|
||||||
|
value: 'lt_17', // You can use any value you prefer
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'More than or equal to 17:00 PM',
|
||||||
|
value: 'gte_17', // You can use any value you prefer
|
||||||
|
},
|
||||||
|
],
|
||||||
|
onFilter: (value, record) => {
|
||||||
|
const time = new Date(record.presence_checkout?.working_hours_end).getHours();
|
||||||
|
|
||||||
|
if (value === 'lt_17') {
|
||||||
|
return time < 17;
|
||||||
|
} else if (value === 'gte_17') {
|
||||||
|
return time >= 17;
|
||||||
|
}
|
||||||
|
return false; // If the value doesn't match any filter
|
||||||
|
},
|
||||||
|
render: (val, record) => record.presence_checkout?.working_hours_end ? <span className='text-rose-500'>{dayjs(record.presence_checkout?.working_hours_end).format('HH:mm A')}</span> : undefined
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Check-out Device',
|
||||||
|
dataIndex: 'device',
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
text: 'FR Device',
|
||||||
|
value: '11001',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Web App',
|
||||||
|
value: '40001',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Android App',
|
||||||
|
value: '20001',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'IOS App',
|
||||||
|
value: '30001',
|
||||||
|
}
|
||||||
|
],
|
||||||
|
onFilter: (value, record) => record.presence_checkout?.device?.code!.indexOf(value as string) === 0,
|
||||||
|
render: (val, record) => record.presence_checkout?.device?.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Check-out Location',
|
||||||
|
dataIndex: 'location_name',
|
||||||
|
render: (val, record) => record.presence_checkout?.location_name
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Check-out Note',
|
||||||
|
dataIndex: 'note',
|
||||||
|
render: (val, record) => record.presence_checkout?.note
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Check-out Photo',
|
||||||
|
dataIndex: 'face_image',
|
||||||
|
render: (val, record) => record.presence_checkout?.face_image ? <a onClick={(e) => e.stopPropagation()} className='text-his hover:opacity-70 duration-200' href={process.env.BASE_URL_IMG + record.presence_checkout?.face_image} target="_blank">View Photo</a> : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Auto Checkout',
|
||||||
|
dataIndex: 'autocheckout',
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
text: 'Auto Checkout',
|
||||||
|
value: true,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
onFilter: (value, record) => record.presence_checkout?.auto_checkout?.valueOf() === true,
|
||||||
|
render: (val, record) => record.presence_checkout?.auto_checkout ? <i className="ti ti-check text-xl text-green-500"></i> : '-'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Clear AutoChekout',
|
||||||
|
dataIndex: 'status',
|
||||||
|
render: (val, record) => record?.is_clear_auto_checkout === false ? <Badge>need to be approve</Badge> : record.is_clear_auto_checkout === true ? <Badge variant='secondary'>approved</Badge> : undefined
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const tableProps: TableProps<IHistory> = {
|
||||||
|
size: 'small',
|
||||||
|
bordered: false,
|
||||||
|
showHeader: true,
|
||||||
|
pagination: {
|
||||||
|
pageSizeOptions: [5, 10, 20, 50],
|
||||||
|
defaultPageSize: 15,
|
||||||
|
showSizeChanger: true,
|
||||||
|
showQuickJumper: true,
|
||||||
|
size: 'default'
|
||||||
|
},
|
||||||
|
scroll: { x: 'max-content' },
|
||||||
|
tableLayout: 'auto',
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{/* <div className='flex flex-col space-y-4 max-w-[300px] sm:max-w-[500px] md:max-w-[600px] lg:max-w-[800px] xl:max-w-[1200px] 2xl:max-w-[1400px]'> */}
|
||||||
|
<div style={{ width: windowWidth > 1900 ? 1400 : windowWidth > 1280 ? 1200 : windowWidth > 1000 ? 800 : windowWidth > 760 ? 600 : windowWidth * 0.72 }} className='flex flex-col space-y-4'>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className="flex flex-1 items-center space-x-2">
|
||||||
|
<Input placeholder="Search attendance..." className="h-8 w-full sm:w-[250px]" onChange={handleSearch} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Table
|
||||||
|
{...tableProps}
|
||||||
|
onRow={(record, rowIndex) => {
|
||||||
|
return {
|
||||||
|
onClick: event => { console.log(record.face_image); }, // click row
|
||||||
|
};
|
||||||
|
}}
|
||||||
|
rowKey='presence_checkin_code'
|
||||||
|
columns={Columns}
|
||||||
|
dataSource={filterData || []}
|
||||||
|
style={{ cursor: "pointer" }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TableAttendanceHistory;
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user