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
This commit is contained in:
Ichsan Kurniawan
2026-02-20 15:19:42 +07:00
parent d09799068d
commit 5a3629badf
54 changed files with 963 additions and 122 deletions
+5
View File
@@ -2,6 +2,7 @@ import { getServerSession } from "next-auth"
import { authOptions } from "@/pages/api/auth/[...nextauth]"
import { redirect } from "next/navigation"
import { ResponseData } from "@/types/types"
import { logger } from "./logger"
export default async function fetchData(url: string = '/', cache: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" = 'default', next?: NextFetchRequestConfig) {
const { BASE_URL_API } = process.env
@@ -20,6 +21,8 @@ export default async function fetchData(url: string = '/', cache: "default" | "f
// Recommendation: handle errors
if (!res.ok) {
logger.error(`ERROR FETCH DATA. http error: ${JSON.stringify(res)}. detail error: ${data}`);
console.log("FETCH ERROR DATA :", res.status, data)
if (res.status === 401 || res.status === 403) return redirect(`/auth?error=Session error or has expired !`)
// This will activate the closest `error.js` Error Boundary
@@ -56,6 +59,8 @@ export async function fetchDataWithPost(url: string = '/', payload: any = {}, ca
}
if (!res.ok) {
logger.error(`ERROR FETCH DATA. http error: ${JSON.stringify(res)}. detail error: ${data}`);
console.log("FETCH ERROR DATA :", res.status, data)
if (res.status === 401 || res.status === 403) redirect(`/auth?error=Session error or has expired !`);
+14
View File
@@ -0,0 +1,14 @@
// lib/client-logger.ts
import { sendLogToServer } from "@/app/actions/logger";
// We wrap the server action call so it behaves identically to the server logger.
// We DO NOT await these calls, so it acts as "fire and forget" and doesn't slow down the UI.
export const clientLogger = {
info: (message: string, data?: any) => { sendLogToServer('INFO', message, data); },
warn: (message: string, data?: any) => { sendLogToServer('WARN', message, data); },
error: (message: string, data?: any) => { sendLogToServer('ERROR', message, data); },
debug: (message: string, data?: any) => { sendLogToServer('DEBUG', message, data); },
apiReq: (message: string, data?: any) => { sendLogToServer('API_REQ', message, data); },
apiRes: (message: string, data?: any) => { sendLogToServer('API_RES', message, data); },
};
+56 -4
View File
@@ -35,16 +35,68 @@ export const writeLog = (type: 'REQUEST' | 'RESPONSE' | 'ERROR', title: string,
logProcess();
};
// Helper to handle circular references in JSON (common in Axios error objects)
// Added standard log levels alongside our custom API ones
type LogLevel = 'INFO' | 'WARN' | 'ERROR' | 'DEBUG' | 'API_REQ' | 'API_RES';
// Helper to handle circular references safely
const getCircularReplacer = () => {
const seen = new WeakSet();
return (key: any, value: any) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return "[Circular]";
}
if (seen.has(value)) return "[Circular]";
seen.add(value);
}
return value;
};
};
// Core write function (Runs in the background)
const writeToFile = (level: LogLevel, message: string, data?: any) => {
const logProcess = async () => {
try {
const now = new Date();
const dateStr = now.toISOString().split('T')[0];
const fileName = `${dateStr}.log`;
const logDir = path.join(process.cwd(), 'logs');
// Check folder exists
if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir);
}
const timestamp = now.toISOString();
// Only stringify data if it was actually provided
let dataString = '';
if (data !== undefined) {
dataString = typeof data === 'object'
? `\n${JSON.stringify(data, getCircularReplacer(), 2)}`
: `\n${data}`;
}
const logEntry = `[${timestamp}] [${level}] ${message}${dataString}\n${'-'.repeat(50)}\n`;
fs.appendFile(path.join(logDir, fileName), logEntry, (err) => {
if (err) console.error('Writing log failed:', err);
});
} catch (error) {
console.error('Logger internal error:', error);
}
};
logProcess(); // Fire and forget
};
// 🌟 Exported Logger Object for easy use anywhere!
export const logger = {
info: (message: string, data?: any) => writeToFile('INFO', message, data),
warn: (message: string, data?: any) => writeToFile('WARN', message, data),
error: (message: string, data?: any) => writeToFile('ERROR', message, data),
debug: (message: string, data?: any) => writeToFile('DEBUG', message, data),
// Specific methods for your API helper to keep things organized
apiReq: (message: string, data?: any) => writeToFile('API_REQ', message, data),
apiRes: (message: string, data?: any) => writeToFile('API_RES', message, data),
};
+1
View File
@@ -29,6 +29,7 @@ export async function serverApiCall<T>(
let response;
switch (method) {
case 'POST':
// response = await axios.post(`http://localhost:2709${url}`, payload, config);
response = await axios.post(url, payload, config);
break;
case 'PUT':