diff --git a/app/(dashboard)/release-notes/page.tsx b/app/(dashboard)/release-notes/page.tsx index afc1907..eac1128 100644 --- a/app/(dashboard)/release-notes/page.tsx +++ b/app/(dashboard)/release-notes/page.tsx @@ -21,9 +21,10 @@ const releaseNotes: ReleaseNote[] = [ type: "minor", changes: [ { category: "feature", description: "Added the ability to view and re-download leave application forms in the Employee History page (Leave, Permit, and Sick tabs)" }, - { category: "feature", description: "Added employee alpha stats and employee alpha detail in Employee Performance Page" }, - { category: "feature", description: "Added total WFO, WFH and WFS in Admin Summary Report" }, - { category: "feature", description: "Added batch import from Excel files in Admin Manual Attendance" }, + { category: "feature", description: "Added Alpha statistics and detailed Alpha records on the Employee Performance page" }, + { category: "feature", description: "Added the ability to create manual attendance records for Alpha status on the Employee Performance page" }, + { category: "feature", description: "Added total counts for WFO, WFH, and WFS in the Admin Summary Report" }, + { category: "feature", description: "Added batch import functionality from Excel files in Admin Manual Attendance" }, ] }, { diff --git a/app/admin/manual/manual-presence/component/ImportExcel.tsx b/app/admin/manual/manual-presence/component/ImportExcel.tsx index 1a35610..97a8167 100644 --- a/app/admin/manual/manual-presence/component/ImportExcel.tsx +++ b/app/admin/manual/manual-presence/component/ImportExcel.tsx @@ -37,6 +37,7 @@ export default function ImportExcel() { const onDrop = useCallback((acceptedFiles: any[]) => { acceptedFiles.forEach(async (file: any) => { + setFullLoading(true); const reader = new FileReader(); const workbook = new ExcelJS.Workbook(); @@ -93,18 +94,18 @@ export default function ImportExcel() { return ( <> - setShowModal(true)}>Import Excel + setShowModal(true)}>Import Excel {showModal ? - 0 ? 'min-w-[90vw]' : 'sm:min-w-[600px]'} overflow-y-auto`}> + 0 ? 'min-w-[90vw]' : 'sm:min-w-[600px]'}`}> {rowData && rowData.length > 0 ? "Review Your Data" : "Upload Excel File"} {rowData && rowData.length > 0 ? "Please review attendance data first before saving!" : "Please attach your excel file for batching import"} - + {/* Drop area */} = ({ data }) => { defaultPageSize: 15, showSizeChanger: true, showQuickJumper: true, - size: 'middle' + size: 'middle' as any }, scroll: { x: 'max-content' }, tableLayout: 'auto', diff --git a/app/performance/[id]/components/CreateAttendance.tsx b/app/performance/[id]/components/CreateAttendance.tsx new file mode 100644 index 0000000..c48947f --- /dev/null +++ b/app/performance/[id]/components/CreateAttendance.tsx @@ -0,0 +1,204 @@ +"use client" + +import { useState, type FC } from 'react'; +import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog'; +import { DatePicker, Form, Input, Radio } from 'antd'; +import { Button } from '@/components/ui/button'; +import { CirclePlus, Loader2 } from 'lucide-react'; +import dayjs from 'dayjs'; +import { Label } from '@/components/ui/label'; +import { getIconWorkingStatus } from '@/lib/helper'; +import { useRouter } from 'next/navigation'; +import useMobileView from '@/hooks/useMobileView'; +import { useFetchWithAxios } from '@/lib/axios/useFetch'; +import { serverApiCall } from '@/lib/server-api'; +import { toast } from 'sonner'; +import { useSession } from 'next-auth/react'; + +type Props = { + user: any + date: string +}; + +const CreateAttendance: FC = ({ user, date }) => { + const [isLoading, setIsLoading] = useState(false) + const [showDialog, setShowDialog] = useState(false) + const [showConfirm, setShowConfirm] = useState(false) + const [workingStatus, setWorkingStatus] = useState('') + const [isCreateCheckout, setIsCreateCheckout] = useState(undefined) + const [checkinTime, setCheckInTime] = useState('') + const [checkoutTime, setCheckoutTime] = useState('') + const { data: session } = useSession() + + const router = useRouter() + const [form] = Form.useForm(); + const { isMobile } = useMobileView() + + const { data: resWorkingStatusList } = useFetchWithAxios('/presence/list-status') + + const workingStatusList = resWorkingStatusList?.working_status || [] + + const handleSubmit = async () => { + setIsLoading(true) + const data = form.getFieldsValue() + + const payload = { + "nik": user.nik, + "working_status": workingStatus, + "area_code": workingStatus === 'WFO' ? "A01" : undefined, + "working_hours_start": `${dayjs(date).format('YYYY-MM-DD')} ${checkinTime}:00`, + "create_checkout": isCreateCheckout, + "working_hours_end": isCreateCheckout ? `${dayjs(date).format('YYYY-MM-DD')} ${checkoutTime}:00` : undefined, + "note": data['note'] + } + + const res = await serverApiCall('POST', '/presence/manual', payload) + + if (res.success) { + toast.success('Attendance created successfully', { + description: 'Create manual attendance successfully!', + action: router.push('/admin/report/history')}>See attendance, + }) + handleClose() + router.refresh() + } else { + toast.error(`Fail to create attendance`, { description: `(${res.code || '-'}) ${res.message}` }) + } + + setIsLoading(false) + } + + const handleClose = () => { + setShowDialog(false) + setShowConfirm(false) + setCheckInTime('') + setCheckoutTime('') + form.resetFields() + } + + return ( + <> + {session?.user.detail.role.allow_admin_panel ? + setShowDialog(true)}> + + + : null + } + + {showDialog && + + + + + Create Attendance + + Create manual attendance for {user?.fullname} on {dayjs(date).format('dddd, DD MMMM YYYY')}. + + + + + setShowConfirm(true)} scrollToFirstError layout="vertical" size='small' requiredMark={false}> + + + Working status + + + setWorkingStatus('WFO')}> + + + Work From Office + + {workingStatusList && workingStatusList.length > 0 ? + workingStatusList.map((item: any, key: number) => + + setWorkingStatus(item.code)}> + + + {item.name} + + ) : + + Working status not available, please contact administrator. + + } + + + + {isMobile ? + setCheckInTime(e.target.value)} /> + : + setCheckInTime(dayjs(val).format('HH:mm'))} + className='input w-full' format='HH:mm' + getPopupContainer={(triggerNode: any) => triggerNode.parentNode} + showNow={false} + /> + } + + + setIsCreateCheckout(e.target.value)}> + Yes + No + + + {isCreateCheckout && + + {isMobile ? + setCheckoutTime(e.target.value)} /> + : + setCheckoutTime(dayjs(val).format('HH:mm'))} + className='input w-full' format='HH:mm' + getPopupContainer={(triggerNode: any) => triggerNode.parentNode} + showNow={false} + /> + } + + } + + + + + + + + Cancel + + { setShowConfirm(true) }} type='submit'> + {isLoading && ( + + )} + Save Attendance + + + + + + } + + {showConfirm && + + + + Are you absolutely sure? + + This action will be create a manual attendance for {user?.fullname} on {dayjs(date).format('dddd, DD MMMM YYYY')}. This data will be stored on our server, you can't change it when you done. + + + + setShowConfirm(false)}>Cancel + + {isLoading && ( + + )} + Continue + + + + + } + > + ); +} + +export default CreateAttendance; \ No newline at end of file diff --git a/app/performance/[id]/components/EmployeeAlpha.tsx b/app/performance/[id]/components/EmployeeAlpha.tsx index 83c309f..470bd03 100644 --- a/app/performance/[id]/components/EmployeeAlpha.tsx +++ b/app/performance/[id]/components/EmployeeAlpha.tsx @@ -1,6 +1,6 @@ "use client" -import { useState, type FC } from 'react'; +import { lazy, Suspense, useState, type FC } from 'react'; import { Dialog, DialogContent, @@ -8,12 +8,16 @@ import { DialogTitle, DialogDescription, } from '@/components/ui/dialog'; -import { CalendarX2, AlertTriangle, Calendar, ChevronRight, X, UserX, Eye } from 'lucide-react'; +import { CalendarX2, Calendar, Eye } from 'lucide-react'; import { Badge } from '@/components/ui/badge'; import { format, getMonth, getYear, parseISO } from 'date-fns'; import { Button } from '@/components/ui/button'; +import LazyLoading from '@/components/loader/LazyLoading'; + +const CreateAttendance = lazy(() => import('./CreateAttendance')); type Props = { + user: any alphaData: any[] }; @@ -22,7 +26,7 @@ const monthColors: Record = ({ alphaData }) => { +const EmployeeAlpha: FC = ({ alphaData, user }) => { const [open, setOpen] = useState(false); // Group by month @@ -90,25 +94,18 @@ const EmployeeAlpha: FC = ({ alphaData }) => { {dates.map((item, idx) => { const d = parseISO(item.date); return ( - + - - {format(d, 'EEEE')} - - - {format(d, 'dd MMMM yyyy')} - + {format(d, 'EEEE')} + {format(d, 'dd MMMM yyyy')} - - Alpha - + Alpha + }> + + ); })} diff --git a/app/performance/[id]/components/index.tsx b/app/performance/[id]/components/index.tsx index 3a97790..597fcb3 100644 --- a/app/performance/[id]/components/index.tsx +++ b/app/performance/[id]/components/index.tsx @@ -40,8 +40,6 @@ const PerformanceComponent: FC = async ({ id, start_date, end_date }) => const [user, performance, alpha] = await Promise.all([fetchUser, fetchPerformace, fetchAlpha]) - console.log(alpha) - return ( <> @@ -121,7 +119,9 @@ const PerformanceComponent: FC = async ({ id, start_date, end_date }) => Total Alpha - + }> + + diff --git a/app/performance/[id]/page.tsx b/app/performance/[id]/page.tsx index 2565aaf..88a9614 100644 --- a/app/performance/[id]/page.tsx +++ b/app/performance/[id]/page.tsx @@ -48,7 +48,7 @@ const PerformancePage: FC = async ({ params, searchParams }) => { - }> + }> diff --git a/lib/axios/useFetch.tsx b/lib/axios/useFetch.tsx index ca39346..3f98ae1 100644 --- a/lib/axios/useFetch.tsx +++ b/lib/axios/useFetch.tsx @@ -1,4 +1,4 @@ -import useSWR from 'swr' +import useSWR, { type SWRConfiguration } from 'swr' import { useSession } from 'next-auth/react'; import { type ResponseData } from '@/types/types'; import useAxiosAuth from './useAxiosAuth'; @@ -25,14 +25,17 @@ export default function useFetch(endpoint: string) { } -export function useFetchWithAxios(url: string) { +export function useFetchWithAxios(url: string | null, options?: SWRConfiguration) { const axios = useAxiosAuth(); - const fetcher = () => axios.get(url).then(res => res.data) - const { data, error, isLoading, mutate } = useSWR>(url, fetcher) + // Only define fetcher if url is present + const fetcher = (url: string) => axios.get(url).then(res => res.data) + + // Pass url directly. If it is null, SWR will pause. + const { data, error, isLoading, mutate } = useSWR>(url, fetcher, options) return { - data, + data: data?.data, isLoading, error, mutate diff --git a/lib/server-api.ts b/lib/server-api.ts index cb9ce04..36b975c 100644 --- a/lib/server-api.ts +++ b/lib/server-api.ts @@ -1,3 +1,5 @@ +"use server" + import { getServerSession } from "next-auth"; import { authOptions } from "@/pages/api/auth/[...nextauth]"; // Adjust path as needed import axios from "@/lib/axios"; // Your axios instance
Work From Office
{item.name}
- {format(d, 'EEEE')} -
- {format(d, 'dd MMMM yyyy')} -
{format(d, 'EEEE')}
{format(d, 'dd MMMM yyyy')}