diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..f7c6be9 --- /dev/null +++ b/.env.development @@ -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" \ No newline at end of file diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..23c0a11 --- /dev/null +++ b/.env.production @@ -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" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5ef6a52..03efc75 100644 --- a/.gitignore +++ b/.gitignore @@ -31,11 +31,11 @@ yarn-error.log* .pnpm-debug.log* # env files (can opt-in for committing if needed) -.env* +# .env* # vercel .vercel # typescript *.tsbuildinfo -next-env.d.ts +next-env.d.ts \ No newline at end of file diff --git a/app/(dashboard)/(main)/page-backup.tsx b/app/(dashboard)/(main)/page-backup.tsx new file mode 100644 index 0000000..6c85d83 --- /dev/null +++ b/app/(dashboard)/(main)/page-backup.tsx @@ -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: () =>

loading...

, + 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 ( + <> +
+
+
+

Welcome Back, {titleCase(session?.user.detail.nickname!)}

+

Welcome back, we miss your presence!

+

Here is your store performance, we hope this helps you unlock insights and empower your decision for continues growth

+
+
+ + + + +
+
+ +
+
+ + + + Attendance Hours + + + + +
{todayPresence.history[0]?.working_hours_start ? dayjs(todayPresence.history[0]?.working_hours_start).format('HH:mm A') : '--:-- --'}
+

+ today check-in +

+
+
+ + + + Working Hours + + + + +
{getHoursMinutes()}
+

+ number of hours you worked today +

+
+
+ + + Total Employee + + + + + + + +
{dataDashboard?.presence?.total_employee}
+

+ number of employee in your department +

+
+
+ + + + Work Permit & Leave + + + + + + +
7
+

+ permission, leave and sick in this year +

+
+
+
+
+ + + Overview + Your average check-in out stats for the past 2 weeks. + + + + + + + + Last Check-in out + You made {allPresence?.history?.length} presence last week. + + + <>THIS SHOULD BE RECENT SALES + + +
+
+
+ + ) +} \ No newline at end of file diff --git a/app/(dashboard)/(main)/page.tsx b/app/(dashboard)/(main)/page.tsx new file mode 100644 index 0000000..bdfeeae --- /dev/null +++ b/app/(dashboard)/(main)/page.tsx @@ -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 ( + <> +
+
+
+

Welcome Back, {titleCase(session?.user.detail.nickname!)}

+

This is your dashboard of attendance, working hours and task report

+
+
+
+

Welcome Back, {titleCase(session?.user.detail.nickname!)}

+

This is your dashboard of attendance, working hours and task report

+
+ {lastPresence.is_checkin && lastPresence.device_code !== '11001' && + + + + } +
+
+ {/* */} + {alreadyCheckout ? + + + + : + + + + } +
+
+ +
+
+ + + + {todayPresence.history.length === 0 || lastPresence.is_checkin ? "Today's Check-in" : "Today's Check-out"} + + + + + {todayPresence.history.length === 0 || lastPresence.is_checkin ? +
{todayPresence.history[0]?.working_hours_start ? dayjs(dataDashboard.presence?.todays_attendance_hours.check_in).format('HH:mm A') : '--:-- --'}
+ : +
{dataDashboard.presence?.todays_attendance_hours.check_out ? dayjs(dataDashboard.presence?.todays_attendance_hours.check_out).format('HH:mm A') : '--:-- --'}
+ } +

+ {todayPresence.history.length === 0 || lastPresence.is_checkin ? "your today's check-in time" : "your today's check-out time"} +

+
+
+ + + + Today's Working Hours + + + + }> + + + + + + + Last Presence + + + + }> + {/* */} + +
+ {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') + : + '--:--' + ) + : + '--:-- - --:--' + } +
+

+ your last presence {dataDashboard.presence.last_presence.check_in ? 'at ' + dayjs(dataDashboard.presence.last_presence.check_in).format('MMM DD, YYYY') : ''} +

+
+
+
+ + + Working Hour in this Month + + + + + + + + + + + +
{dataDashboard?.presence?.working_hours_in_this_month ? generateHourMinutes(dataDashboard?.presence?.working_hours_in_this_month) : '0 Hour'}
+

+ number of working hours in this month +

+
+
+
+
+ + + Overview + Statistics of today's attendance summary. + + + }> + + + + + + + Your Statistics + Statistics of your attendance in last 14 days. + + + }> + + + + +
+
+ + + Attendance's List + List of today's attendance in your department. + + + }> + + + + + + + Your History + List of your last 4 attendance history in this week. + + + }> + + + + + {(session?.user.detail.role.code === 'MNG' || session?.user.detail.role.code === 'TL') && + + + Need to be Approve + List of today's attendance that require approval. + + + }> + + + + + } + {(session?.user.detail.role.code === 'MNG' || session?.user.detail.role.code === 'TL') && dataDashboard.presence?.need_to_be_approved_auto_checkout?.total > 0 && + + + Adjustment Autocheckout + List of attendance that is not checked out. + + + }> + + + + + } + {(session?.user.detail.role.code === 'MNG' || session?.user.detail.role.code === 'TL') && dataDashboard.presence?.need_to_be_approved_application_form?.total > 0 && + + + Work Leave and Sick Approval + List of work leave and sick application form. + + + }> + + + + + } + + + Employees + List of employees in your department. + + + }> + + + + + + + Employee Birthday + List of employees birthday. + + + }> + + + + + {session?.user.detail.role.code === 'MNG' && + + + Employee Contract Expiration + List of employee contract expiration. + + + }> + + + + + } +
+ {/* + + Employees + List of employees in your department. + + + }> + + + + */} +
+
+ + {lastPresence.is_checkin && lastPresence.device_code !== '11001' && + + + + } + + ) +} \ No newline at end of file diff --git a/app/(dashboard)/calendar/components/DayInCalendar.tsx b/app/(dashboard)/calendar/components/DayInCalendar.tsx new file mode 100644 index 0000000..68f27be --- /dev/null +++ b/app/(dashboard)/calendar/components/DayInCalendar.tsx @@ -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 = ({ day, monthIndex, dayOffList, onClickDate, onClickEvent }) => { + const [event, setEvent] = useState(null) + + useEffect(() => { + const result = dayOffList.find(item => dayjs(item.date).format('DDMMYY') === dayjs(day).format('DDMMYY')) + setEvent(result) + }, [day, dayOffList]) + + const handleClikEvent = (e: MouseEvent, 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 ( + <> +
+ {/*
alert('absolute')}>
*/} +
+

{dayjs(day).format('DD')}

+
+
+ {event && + handleClikEvent(e, event)} + > + {event.name} + + } + {/* {activities!.slice(0, 1).map((task, key) => + alert('this gonna be activities')} + > + {task.activity_txt} + + )} + {activities!.length > 1 && + alert('this gonna be activities')} + > + +{activities!.length - 1} Aktivitas Lainnya.. + } */} +
+
+ + ); +} + +export default DayInCalendar; \ No newline at end of file diff --git a/app/(dashboard)/calendar/components/DetailEvent.tsx b/app/(dashboard)/calendar/components/DetailEvent.tsx new file mode 100644 index 0000000..c977e30 --- /dev/null +++ b/app/(dashboard)/calendar/components/DetailEvent.tsx @@ -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> + data: any +}; + +const DetailEvent: FC = ({ open, data, onOpenChange }) => { + return ( + <> + + + event-ilustration +
+
+
+
+

{data.name}

+

{dayjs(data.date).format('dddd, MMMM DD')}

+
+
+
+ +

{data.description || '-'}

+
+
+
+
+ + ); +} + +export default DetailEvent; \ No newline at end of file diff --git a/app/(dashboard)/calendar/components/NewEvent.tsx b/app/(dashboard)/calendar/components/NewEvent.tsx new file mode 100644 index 0000000..1caefc2 --- /dev/null +++ b/app/(dashboard)/calendar/components/NewEvent.tsx @@ -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> + onClose?: (e: MouseEvent) => any + date: any +}; + +const NewEvent: FC = ({ open, onOpenChange, onClose, date }) => { + const [isLoading, setIsLoading] = useState(false) + const [isAddTime, setIsAddTime] = useState(false) + + return ( + <> + + + + Title + Description + +
+ + + +
+ triggerNode.parentNode} + /> + {isAddTime ? + triggerNode.parentNode} + /> + : + + } +
+ +