From 5a3629badf8c8b67a7997c0cb1b428bda4399f9e Mon Sep 17 00:00:00 2001 From: Ichsan Kurniawan Date: Fri, 20 Feb 2026 15:19:42 +0700 Subject: [PATCH] update performance, manual attendance, redownload leave form Added the ability to view and re-download leave application forms in the Employee History page (Leave, Permit, and Sick tabs) Added employee alpha stats and employee alpha detail in Employee Performance Page Added total WFO, WFH and WFS in Admin Summary Report Added batch import from Excel files in Admin Manual Attendance --- .env.development | 2 +- .gitignore | 4 +- app/(dashboard)/(main)/page.tsx | 2 +- app/(dashboard)/error.tsx | 2 + .../history/leave-permit/DataTable.tsx | 160 ++++++++++++++- .../iam-here/components/FormComponent.tsx | 67 +++--- app/(dashboard)/iam-here/page.tsx | 6 +- app/(dashboard)/leave/components/index.tsx | 10 +- app/(dashboard)/release-notes/page.tsx | 11 + app/actions/attendance.ts | 79 ++++++++ app/actions/logger.ts | 24 +++ .../administration/area/component/index.tsx | 2 +- .../company/component/index.tsx | 2 +- .../division/component/index.tsx | 2 +- .../administration/user/component/index.tsx | 2 +- app/admin/audit-trail/component/index.tsx | 2 +- app/admin/day-off/component/index.tsx | 1 + .../device/device-type/component/index.tsx | 2 +- app/admin/device/device/component/index.tsx | 2 +- app/admin/error.tsx | 4 +- .../global-parameter/component/index.tsx | 2 +- .../employee-type/component/index.tsx | 2 +- .../master-status/component/index.tsx | 2 +- .../information/position/component/index.tsx | 2 +- .../information/user-role/component/index.tsx | 2 +- .../working-status/component/index.tsx | 2 +- .../approval-autocheckout/component/index.tsx | 2 +- app/admin/manual/approval/component/index.tsx | 2 +- .../manual-presence/component/ImportExcel.tsx | 191 ++++++++++++++++++ app/admin/manual/manual-presence/page.tsx | 12 +- app/admin/menu/component/index.tsx | 2 +- .../report/distribution/component/index.tsx | 2 +- .../report/history/component/Columns.tsx | 5 + app/admin/report/history/component/index.tsx | 8 +- .../leave-permit-sick/component/index.tsx | 2 +- .../monthly-presence/component/Export.tsx | 3 + .../monthly-presence/component/index.tsx | 30 ++- .../monthly-presence/component/type.tsx | 3 + app/admin/report/monthly-presence/page.tsx | 4 +- app/error.tsx | 4 +- app/globals.css | 35 +++- .../[id]/components/EmployeeAlpha.tsx | 138 +++++++++++++ app/performance/[id]/components/Table.tsx | 8 +- app/performance/[id]/components/index.tsx | 58 +++--- app/performance/[id]/error.tsx | 37 ++++ app/performance/[id]/page.tsx | 12 +- components/ViewAvatar.tsx | 3 +- lib/fetchData.ts | 5 + lib/logger-client.ts | 14 ++ lib/logger.ts | 60 +++++- lib/server-api.ts | 1 + package-lock.json | 43 +++- package.json | 3 +- public/files/hats-batching-import.xlsx | Bin 0 -> 9128 bytes 54 files changed, 963 insertions(+), 122 deletions(-) create mode 100644 app/actions/attendance.ts create mode 100644 app/actions/logger.ts create mode 100644 app/admin/manual/manual-presence/component/ImportExcel.tsx create mode 100644 app/performance/[id]/components/EmployeeAlpha.tsx create mode 100644 app/performance/[id]/error.tsx create mode 100644 lib/logger-client.ts create mode 100644 public/files/hats-batching-import.xlsx diff --git a/.env.development b/.env.development index 07be579..b048205 100644 --- a/.env.development +++ b/.env.development @@ -19,4 +19,4 @@ 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.1" \ No newline at end of file +NEXT_PUBLIC_APP_VERSION = "v1.1.2" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 03efc75..a15f10f 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,6 @@ yarn-error.log* # typescript *.tsbuildinfo -next-env.d.ts \ No newline at end of file +next-env.d.ts + +*.log \ No newline at end of file diff --git a/app/(dashboard)/(main)/page.tsx b/app/(dashboard)/(main)/page.tsx index f650851..cdc017d 100644 --- a/app/(dashboard)/(main)/page.tsx +++ b/app/(dashboard)/(main)/page.tsx @@ -58,7 +58,7 @@ export default async function DashboardPage() { {lastPresence.is_checkin && lastPresence.device_code !== '11001' && } diff --git a/app/(dashboard)/error.tsx b/app/(dashboard)/error.tsx index 57b2344..00fd36c 100644 --- a/app/(dashboard)/error.tsx +++ b/app/(dashboard)/error.tsx @@ -4,6 +4,7 @@ import { useEffect } from "react" import Image from "next/image" import Link from "next/link" import { Button } from "@/components/ui/button" +import { clientLogger } from "@/lib/logger-client" export default function Error({ error, @@ -15,6 +16,7 @@ export default function Error({ useEffect(() => { console.log({ name: error.name, cause: error.cause, message: error.message, stack: error.stack }) + clientLogger.error(error.stack!) }, [error]) return ( diff --git a/app/(dashboard)/history/leave-permit/DataTable.tsx b/app/(dashboard)/history/leave-permit/DataTable.tsx index 1bfd56a..8051aa3 100644 --- a/app/(dashboard)/history/leave-permit/DataTable.tsx +++ b/app/(dashboard)/history/leave-permit/DataTable.tsx @@ -1,6 +1,6 @@ "use client" -import { useMemo } from "react" +import { useMemo, useState } from "react" import dayjs from "dayjs" import { useSearchParams } from "next/navigation" @@ -12,7 +12,19 @@ import Pagination from "@/components/pagination" import { getVariantWorkingStatus } from "@/lib/helper" import SortFilter from "../components/SortFilter" import { type ILeaveSickPermit } from "../components/type" +import { ResponseData } from "@/types/types" +import { IProfile } from "../../profile/components/type" +import { PDFDocument } from 'pdf-lib'; +import { toast } from "sonner" +import { Button } from "@/components/ui/button" +import { Download, Eye, Loader2 } from "lucide-react" +import useAxiosAuth from "@/lib/axios/useAxiosAuth" +import relativeTime from "dayjs/plugin/relativeTime"; +import customParseFormat from 'dayjs/plugin/customParseFormat'; + +import "dayjs/locale/id"; +dayjs.extend(customParseFormat); type Props = { data: ILeaveSickPermit[] @@ -20,10 +32,13 @@ type Props = { export default function DataTable({ data }: Props) { const searchParams = useSearchParams(); + const [isPreviewLoading, setIsPreviewLoading] = useState(false) + const [isDownLoading, setIsDownLoading] = useState(false) 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 axios = useAxiosAuth() const currentTableData = useMemo(() => { const newData = [...data] @@ -35,9 +50,137 @@ export default function DataTable({ data }: Props) { const firstPageIndex = (currentPage - 1) * pageSize; const lastPageIndex = firstPageIndex + pageSize; + return newData.slice(firstPageIndex, lastPageIndex); }, [currentPage, pageSize, savedSort, data]); + const handlePreviewOrSubmit = async (dataCuti: ILeaveSickPermit, preview?: boolean) => { + if (preview) setIsPreviewLoading(true) + else setIsDownLoading(true) + + dayjs.locale("id"); + dayjs.extend(relativeTime); + + try { + const { data } = await axios.post('/user/profile', {}) + const { data: profile }: ResponseData = 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 (dataCuti.category_code === 'CT') { + firstPage.drawText('x', { x: 244, y: 582, size: 16 }) + } + /* CUTI BESAR */ + if (dataCuti.category_code === 'CB') { + firstPage.drawText('x', { x: 244, y: 555, size: 16 }) + } + /* CUTI MELAHIRKAN */ + if (dataCuti.category_code === 'CM') { + firstPage.drawText('x', { x: 374, y: 582, size: 16 }) + } + /* LAINNYA */ + if (dataCuti.category_code === 'CL') { + firstPage.drawText('x', { x: 374, y: 555, size: 16 }) + // firstPage.drawText(otherLeave, { x: 443, y: 558, size: 10 }) + } + + firstPage.drawText(dayjs(dataCuti.start_date[0]).format('dddd'), { x: 340, y: 506, size: 11 }) + firstPage.drawText(dayjs(dataCuti.start_date[0]).format('DD').split('')[0] + ' ' + dayjs(dataCuti.start_date[0]).format('DD').split('')[1], { x: 416, y: 505, size: 13 }) + firstPage.drawText(dayjs(dataCuti.start_date[0]).format('MM').split('')[0] + ' ' + dayjs(dataCuti.start_date[0]).format('MM').split('')[1], { x: 471, y: 505, size: 13 }) + firstPage.drawText(dayjs(dataCuti.start_date[0]).format('YY').split('')[0] + ' ' + dayjs(dataCuti.start_date[0]).format('YY').split('')[1], { x: 522, y: 505, size: 13 }) + + firstPage.drawText(dayjs(dataCuti.end_date[1]).format('dddd'), { x: 340, y: 483, size: 11 }) + firstPage.drawText(dayjs(dataCuti.end_date[1]).format('DD').split('')[0] + ' ' + dayjs(dataCuti.end_date[1]).format('DD').split('')[1], { x: 416, y: 482, size: 13 }) + firstPage.drawText(dayjs(dataCuti.end_date[1]).format('MM').split('')[0] + ' ' + dayjs(dataCuti.end_date[1]).format('MM').split('')[1], { x: 471, y: 482, size: 13 }) + firstPage.drawText(dayjs(dataCuti.end_date[1]).format('YY').split('')[0] + ' ' + dayjs(dataCuti.end_date[1]).format('YY').split('')[1], { x: 522, y: 482, size: 13 }) + + firstPage.drawText(dayjs(dataCuti.return_to_work_date).format('dddd'), { x: 340, y: 461, size: 11 }) + firstPage.drawText(dayjs(dataCuti.return_to_work_date).format('DD').split('')[0] + ' ' + dayjs(dataCuti.return_to_work_date).format('DD').split('')[1], { x: 416, y: 460, size: 13 }) + firstPage.drawText(dayjs(dataCuti.return_to_work_date).format('MM').split('')[0] + ' ' + dayjs(dataCuti.return_to_work_date).format('MM').split('')[1], { x: 471, y: 460, size: 13 }) + firstPage.drawText(dayjs(dataCuti.return_to_work_date).format('YY').split('')[0] + ' ' + dayjs(dataCuti.return_to_work_date).format('YY').split('')[1], { x: 522, y: 460, size: 13 }) + + + firstPage.drawText(dataCuti.contact_street, { x: 285, y: 428, size: 10 }) + firstPage.drawText(dataCuti.contact_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(dataCuti.created_at).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 }) + + + const fileName = `Form Cuti ${profile.fullname} ${dayjs(dataCuti.start_date).format('YYYYMMDD')} - ${dayjs(dataCuti.end_date).format('YYYYMMDD')}` + + await pdfDoc.setTitle(fileName) + await pdfDoc.setSubject('SURAT PERMOHONAN FORM CUTI KARYAWAN') + await pdfDoc.setKeywords(['form cuti', 'hats', 'super apps', 'his', 'nutech']) + await pdfDoc.setCreator(profile.fullname) + await pdfDoc.setAuthor('H.I.S Dev Super Team 😎') + await pdfDoc.setProducer('H.A.T.s') + await pdfDoc.setCreationDate(new Date()) + await pdfDoc.setModificationDate(new Date()) + + const pdfBase64 = await pdfDoc.saveAsBase64({ dataUri: true }) + + if (!preview) { + const downloadLink = window.document.createElement('a'); + downloadLink.style.display = "none"; + downloadLink.href = pdfBase64; + downloadLink.download = fileName; + window.document.body.appendChild(downloadLink); + downloadLink.click(); + window.document.body.removeChild(downloadLink); + + toast.success('Download successfull', { description: `File "${fileName}.pdf" successfully downloaded` }) + } 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 = ` + + + + + PDF Preview + + + + + + `; + + // Write the HTML document to the new window + newWindow.document.open(); + newWindow.document.write(htmlDocument); + newWindow.document.close(); + } + } catch (error: any) { + console.log(error) + toast.error(`Fail to get the file`, { description: `(${error.response?.data?.code || error.response?.status || '-'}) ${error.response?.data?.message || error.response?.statusText || error.message}` }) + } finally { + setIsPreviewLoading(false) + setIsDownLoading(false) + } + + } + return (
@@ -56,6 +199,7 @@ export default function DataTable({ data }: Props) { Approval Status Approval by Approval at + Actions @@ -85,6 +229,20 @@ export default function DataTable({ data }: Props) { dayjs(row.approved_at).format('YYYY-MM-DD HH:mm') : row.rejected_at ? dayjs(row.rejected_at).format('YYYY-MM-DD HH:mm') : null } + + {row.category_code === 'I' || row.category_code === 'S' ? + null + : +
+ + +
+ } +
)) ) : ( diff --git a/app/(dashboard)/iam-here/components/FormComponent.tsx b/app/(dashboard)/iam-here/components/FormComponent.tsx index a24e273..cf6f8ab 100644 --- a/app/(dashboard)/iam-here/components/FormComponent.tsx +++ b/app/(dashboard)/iam-here/components/FormComponent.tsx @@ -1,20 +1,26 @@ "use client" -import { FC, useEffect, useState } from 'react'; +import { FC, useCallback, 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'; +import { Label } from '@/components/ui/label'; type Props = {}; +const GEOLOCATION_OPTIONS: PositionOptions = { + enableHighAccuracy: true, + timeout: 10000, + maximumAge: 0 +}; + const FormComponent: FC = () => { const OFFICE_PEJATEN_LATTITUDE = -6.27831622506824 const OFFICE_PEJATEN_LONGITUDE = 106.82955901443484 @@ -32,20 +38,34 @@ const FormComponent: FC = () => { const router = useRouter() const axios = useAxiosAuth() - const options: PositionOptions = { - enableHighAccuracy: false, - timeout: 10000, - maximumAge: 0 - }; + // 1. Wrap displayLocation in useCallback + const displayLocation = useCallback(async (latitude: number, longitude: number) => { + try { + 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 { + // Optional: Reduce noise by not toasting on minor network errors during typing + console.warn(`${res.status} ${res.statusText}`) + } + } catch (error) { + console.error("Error fetching location name", error) + } + }, []); - const successCallback = (position: GeolocationPosition) => { + // 2. Wrap successCallback in useCallback + const successCallback = useCallback((position: GeolocationPosition) => { const x = position.coords.latitude; const y = position.coords.longitude; - setLatitude(x); setLongitude(y) + setLatitude(x); + setLongitude(y); displayLocation(x, y); - }; + }, [displayLocation]); // Depends on displayLocation - const errorCallback = (error: GeolocationPositionError) => { + // 3. Wrap errorCallback in useCallback + const errorCallback = useCallback((error: GeolocationPositionError) => { let errorMessage = 'Unknown error'; switch (error.code) { case 1: @@ -58,28 +78,19 @@ const FormComponent: FC = () => { errorMessage = 'Timeout'; break; } + // Only toast if it's a serious permission issue, or throttle it toast.warning("Failed to fetch geolocation, reason: " + errorMessage) - }; + }, []); + // 4. Update useEffect dependencies 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}`) - } - }; + navigator.geolocation.getCurrentPosition(successCallback, errorCallback, GEOLOCATION_OPTIONS); + }, [successCallback, errorCallback]); // Now these dependencies are stable const handleReceivePhoto = (photo: string, landscape?: boolean, w?: number, h?: number) => { setOrientation(w! > h! ? 'landscape' : w === h ? 'square' : 'portrait') @@ -149,14 +160,14 @@ const FormComponent: FC = () => {
- Note +