From 3c188e66d23dc1a1adf0d983e5586dc5408bc983 Mon Sep 17 00:00:00 2001 From: amaliadwiy Date: Thu, 28 May 2026 14:09:46 +0800 Subject: [PATCH] feat: tambah kolom Last Activity di tabel user management desa-plus --- .../routes/apps.$appId.users.index.tsx | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/frontend/routes/apps.$appId.users.index.tsx b/src/frontend/routes/apps.$appId.users.index.tsx index c37c43a..9ba0b80 100644 --- a/src/frontend/routes/apps.$appId.users.index.tsx +++ b/src/frontend/routes/apps.$appId.users.index.tsx @@ -34,6 +34,7 @@ import { TbBriefcase, TbCircleCheck, TbCircleX, + TbClock, TbHome2, TbId, TbMail, @@ -68,6 +69,7 @@ interface APIUser { idVillage: string idGroup: string idPosition: string + lastActivity: string | null } interface BaseUserForm { @@ -97,6 +99,15 @@ const REQUIRED_FIELDS = ['name', 'nik', 'phone', 'email', 'gender', 'idUserRole' const fetcher = (url: string) => fetch(url).then((res) => res.json()) +function getLastActivityInfo(lastActivity: string | null): { label: string; color: string } { + if (!lastActivity) return { label: 'Never', color: 'gray' } + const days = Math.floor((Date.now() - new Date(lastActivity).getTime()) / (1000 * 60 * 60 * 24)) + if (days < 1) return { label: 'Today', color: 'teal' } + if (days < 7) return { label: `${days}d ago`, color: 'teal' } + if (days <= 30) return { label: `${days}d ago`, color: 'yellow' } + return { label: `${days}d ago`, color: 'red' } +} + interface UserFormFieldsProps { values: BaseUserForm onChange: (updates: Partial) => void @@ -698,11 +709,12 @@ function UsersIndexPage() { {[ - { label: 'User & ID', col: 'name', width: '28%' }, - { label: 'Contact', col: null, width: '25%' }, - { label: 'Organization', col: null, width: '22%' }, - { label: 'Role', col: 'idUserRole', width: '15%' }, + { label: 'User & ID', col: 'name', width: '24%' }, + { label: 'Contact', col: null, width: '21%' }, + { label: 'Organization', col: null, width: '20%' }, + { label: 'Role', col: 'idUserRole', width: '13%' }, { label: 'Status', col: 'isActive', width: '10%' }, + { label: 'Last Activity', col: null, width: '12%' }, ].map(({ label, col, width }) => ( + + {(() => { + const { label, color } = getLastActivityInfo(user.lastActivity) + return ( + + + {label} + + ) + })()} + ))}