diff --git a/.env.development b/.env.development index f7c6be9..07be579 100644 --- a/.env.development +++ b/.env.development @@ -6,8 +6,8 @@ NEXT_PUBLIC_APP_URL="http://localhost:1209" # 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/ +BASE_URL_API = https://api-hats.hisnutech.my.id/api/v1 +BASE_URL_IMG = https://api-hats.hisnutech.my.id/ NEXTAUTH_URL = http://localhost:1209 # NEXTAUTH_URL = http://localhost:7090/super-apps/api/auth @@ -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.0" \ No newline at end of file +NEXT_PUBLIC_APP_VERSION = "v1.1.1" \ No newline at end of file diff --git a/app/(dashboard)/profile/components/ChangeAvatar.tsx b/app/(dashboard)/profile/components/ChangeAvatar.tsx index 5b3c88c..468fcbf 100644 --- a/app/(dashboard)/profile/components/ChangeAvatar.tsx +++ b/app/(dashboard)/profile/components/ChangeAvatar.tsx @@ -94,6 +94,11 @@ const ChangeAvatar: FC = ({ nik, existAvatar }) => { setIsFullLoading(false) }) } else { + if (file.size > 5000000) { + toast.error('Failed upload photo', { description: 'File size too large, maximum 5MB' }) + return + } + let imageDataUrl = await readFile(file) // apply rotation if needed diff --git a/app/(dashboard)/release-notes/page.tsx b/app/(dashboard)/release-notes/page.tsx index dcde018..74e91f2 100644 --- a/app/(dashboard)/release-notes/page.tsx +++ b/app/(dashboard)/release-notes/page.tsx @@ -15,6 +15,18 @@ interface ReleaseNote { } const releaseNotes: ReleaseNote[] = [ + { + version: "v1.1.1", + date: "09 February 2026", + type: "minor", + changes: [ + { category: "feature", description: "Added application logging for backend API requests" }, + { category: "feature", description: "Implemented server actions for backend API requests" }, + { category: "bugfix", description: "Fixed donut chart click behavior on the employee homepage in mobile view" }, + { category: "bugfix", description: "Fixed session persistence issues for HATS Team and Release Notes pages" }, + { category: "improvement", description: "Limit file upload size for avatar" }, + ] + }, { version: "v1.1.0", date: "28 January 2026", @@ -27,8 +39,8 @@ const releaseNotes: ReleaseNote[] = [ { category: "improvement", description: "Replaced native img tags with LazyLoad Image component and added lazy loading for avatars" }, { category: "bugfix", description: "Fixed spamming \"Failed to fetch geolocation\" alerts when presence using mobile devices" }, { category: "feature", description: "Added progress bar indicator when route change in employee routes" }, - { category: 'feature', description:
Added hats team page
}, - { category: 'feature', description:
Added release notes page
}, + { category: 'feature', description:
Added HATs Team page
}, + { category: 'feature', description:
Added Release Notes page
}, ] }, { diff --git a/app/actions/user.ts b/app/actions/user.ts index 94b0016..c9a6ad7 100644 --- a/app/actions/user.ts +++ b/app/actions/user.ts @@ -1,33 +1,32 @@ "use server" import axios from "@/lib/axios"; +import { serverApiCall } from "@/lib/server-api"; import { authOptions } from "@/pages/api/auth/[...nextauth]"; import { getServerSession } from "next-auth"; import { revalidatePath } from "next/cache"; -export const editProfileData = async (payload: any) => { - try { - const session = await getServerSession(authOptions); - axios.defaults.headers.common['Authorization'] = `Bearer ${session?.user?.access_token}`; +export async function updateProfileAction(payload: any) { + const result = await serverApiCall('PUT', '/user/profile/update', payload); - await axios.put('/user/profile/update', payload) - revalidatePath('profile-data') - } catch (error: any) { - console.log("ERROR EDIT PROFILE:", error.response?.data?.code, error.response?.data?.message) - throw new Error(error as any) + if (result.success) { + revalidatePath('/profile'); } + + return result; } -export const changeAvatar = async (payload: any) => { - try { - const session = await getServerSession(authOptions); - axios.defaults.headers.common['Authorization'] = `Bearer ${session?.user?.access_token}`; +export async function changeAvatarAction(nik: string, base64Image: string) { + const cleanBase64 = base64Image ? base64Image.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '') : ''; - await axios.post('/user/profile/change-avatar', payload) - revalidatePath('/profile') - } catch (error) { - throw new Error(error as any) + const payload = { nik, avatar: cleanBase64 }; + const result = await serverApiCall('POST', '/user/change-avatar', payload); + + if (result.success) { + revalidatePath('/profile'); // Refresh data } + + return result; } export const changePassword = async (payload: any) => { diff --git a/app/admin/administration/user/page.tsx b/app/admin/administration/user/page.tsx index ff4de15..3863226 100644 --- a/app/admin/administration/user/page.tsx +++ b/app/admin/administration/user/page.tsx @@ -44,7 +44,7 @@ async function getData() { export default async function UserPage() { const data = await getData() - // console.log("DATA USER LENGTH :", data?.user?.length) + console.log("DATA USER LENGTH :", data?.user) return ( <> diff --git a/app/layout.tsx b/app/layout.tsx index fcea708..ba3f21c 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -17,7 +17,7 @@ import ProgressBarProviders from '@/providers/ProgressBarProvider'; const jakarta = Plus_Jakarta_Sans({ subsets: ['latin'] }) export const metadata: Metadata = { - metadataBase: new URL(process.env.NEXT_PUBLIC_APP_URL || 'https://his.nutech-integrasi.com'), + metadataBase: new URL(process.env.NEXT_PUBLIC_APP_URL || 'https://hats.hisnutech.my.id'), title: 'HIS Attendance Task System (H.A.T.s)', description: 'H.A.T.s HIS Attendance Task System (smart absence, task management, work permit and leave mangement, etc).', applicationName: 'HIS Attendance Task System (H.A.T.s)', diff --git a/app/opengraph-image.png b/app/opengraph-image.png new file mode 100644 index 0000000..affa88a Binary files /dev/null and b/app/opengraph-image.png differ diff --git a/app/twitter-image.png b/app/twitter-image.png new file mode 100644 index 0000000..affa88a Binary files /dev/null and b/app/twitter-image.png differ diff --git a/lib/logger.ts b/lib/logger.ts new file mode 100644 index 0000000..b855564 --- /dev/null +++ b/lib/logger.ts @@ -0,0 +1,50 @@ +// lib/logger.ts +import fs from 'fs'; +import path from 'path'; + +export const writeLog = (type: 'REQUEST' | 'RESPONSE' | 'ERROR', title: 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 (async version is complex, sync check is tiny and runs once) + if (!fs.existsSync(logDir)) { + fs.mkdirSync(logDir); + } + + const timestamp = now.toISOString(); + // Safe stringify to prevent circular reference crashes + const dataString = JSON.stringify(data, getCircularReplacer(), 2); + + const logEntry = `[${timestamp}] [${type}] ${title}\n${dataString}\n${'-'.repeat(50)}\n`; + + // Async append - we don't wait for this result + fs.appendFile(path.join(logDir, fileName), logEntry, (err) => { + if (err) console.error('Writing log failed:', err); + }); + + } catch (error) { + console.error('Logger internal error:', error); + } + }; + + // Trigger execution immediately but don't return a promise to the caller + logProcess(); +}; + +// Helper to handle circular references in JSON (common in Axios error objects) +const getCircularReplacer = () => { + const seen = new WeakSet(); + return (key: any, value: any) => { + if (typeof value === "object" && value !== null) { + if (seen.has(value)) { + return "[Circular]"; + } + seen.add(value); + } + return value; + }; +}; \ No newline at end of file diff --git a/lib/server-api.ts b/lib/server-api.ts new file mode 100644 index 0000000..62622c9 --- /dev/null +++ b/lib/server-api.ts @@ -0,0 +1,65 @@ +import { getServerSession } from "next-auth"; +import { authOptions } from "@/pages/api/auth/[...nextauth]"; // Adjust path as needed +import axios from "@/lib/axios"; // Your axios instance +import { writeLog } from "./logger"; + +// 1. Define a standard response format for all your actions +export type ActionResponse = + | { success: true; data?: T } + | { success: false; code: string | number; message: string; }; + +// 2. The Reusable Function +export async function serverApiCall( + method: 'GET' | 'POST' | 'PUT' | 'DELETE', + url: string, + payload?: any +): Promise> { + try { + + writeLog('REQUEST', `${method} ${url}`, payload || 'No Payload'); + + const session = await getServerSession(authOptions); + + const config = { + headers: { + Authorization: `Bearer ${session?.user?.access_token}`, + }, + }; + + let response; + switch (method) { + case 'POST': + response = await axios.post(url, payload, config); + break; + case 'PUT': + response = await axios.put(url, payload, config); + break; + case 'DELETE': + response = await axios.delete(url, config); + break; + default: + response = await axios.get(url, config); + break; + } + + writeLog('RESPONSE', `${method} ${url} - SUCCESS`, response.data); + + return { success: true, data: response.data }; + } catch (error: any) { + // 3. Detailed Error Handling (The part you wanted!) + const errorDetails = { + code: error.response?.data?.code || error.response?.status || '-', + message: error.response?.data?.message || error.response?.statusText || error.message || "An unexpected error occurred", + backendData: error.response?.data + }; + + writeLog('ERROR', `${method} ${url}`, errorDetails); + console.error(`[Server Action Error] ${method} ${url}:`, error.response?.data || error.message); + + return { + success: false, + code: error.response?.data?.code || error.response?.status || '-', + message: error.response?.data?.message || error.response?.statusText || error.message || "An unexpected error occurred", + }; + } +} \ No newline at end of file