Add CreateAttendance and update UI/hooks

Add a new CreateAttendance component to allow admins to create manual attendance (Alpha) with confirmation dialog and server API call. Lazy-load the CreateAttendance component in EmployeeAlpha and wrap usages with Suspense plus a loading fallback to reduce initial bundle size. Update Performance page to use a centered Suspense fallback. Improve ImportExcel UX by showing a full-loading state, tweaking button/icon styles, and fixing modal sizing/scroll behavior. Enhance useFetchWithAxios to accept nullable URLs and SWR options, adjust the fetcher signature, and return the nested data payload. Add a "use server" directive and imports in lib/server-api, and apply small type/formatting tweaks (table size cast and minor UI/text refinements).
This commit is contained in:
Ichsan Kurniawan
2026-02-22 23:33:15 +07:00
parent 85d8db1e54
commit 7d18e9f38f
9 changed files with 241 additions and 33 deletions
+8 -5
View File
@@ -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<ResponseData<any>>(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<ResponseData<any>>(url, fetcher, options)
return {
data,
data: data?.data,
isLoading,
error,
mutate
+2
View File
@@ -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