mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 22:26:27 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user