diff --git a/app/(dashboard)/profile/components/type.ts b/app/(dashboard)/profile/components/type.ts index bdb4563..34f1bab 100644 --- a/app/(dashboard)/profile/components/type.ts +++ b/app/(dashboard)/profile/components/type.ts @@ -4,7 +4,7 @@ import { IDivision } from "@/app/admin/administration/division/component/type" import { IEmployeeType } from "@/app/admin/information/employee-type/component/type" import { IMasterStatus } from "@/app/admin/information/master-status/component/type" import { IPosition } from "@/app/admin/information/position/component/type" -import { IRole } from "@/app/admin/information/user-role/component/type" +import { IRole } from "@/types/rbac" export type IProfile = { id: number diff --git a/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx index 8a8e6ed..51530a2 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx @@ -133,13 +133,16 @@ export default function ClientDetailComponent({ clientId, assignmentLists, actio This client doesn't have any projects or internal memos yet. Try to change the filter or create one to get started.

- - - + {actions?.includes("CREATE_ASSIGNMENT") && + + + + } ) : activeLayout === 'grid' ? ( { @@ -161,6 +164,7 @@ export default function ClientDetailComponent({ clientId, assignmentLists, actio /> ) : ( { diff --git a/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientProfileCard.tsx b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientProfileCard.tsx index e8baf0f..f1fe131 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientProfileCard.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientProfileCard.tsx @@ -61,7 +61,7 @@ export default function ClientProfileCard({ client, clientId, actions }: Props) {/* Right: + New assignment Button */}
- {actions?.includes("CREATE") && + {actions?.includes("CREATE_ASSIGNMENT") &&
); diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-assignments/page.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-assignments/page.tsx index b8e4609..a5a0fab 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-assignments/page.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-assignments/page.tsx @@ -1,6 +1,7 @@ import type { Metadata } from 'next'; import ProjectAssignmentForm from "./ProjectAssignmentForm"; import { getClientById, getAssignmentById } from "../../../utils/queries"; +import { getNonAdminAccessPagePermission } from '@/lib/get-access-data'; type Props = { params: Promise<{ client_id?: string }> @@ -14,6 +15,8 @@ export async function generateMetadata({ params, searchParams }: Props): Promise const assignmentId = typeof resolvedSearchParams?.assignment_id === 'string' ? resolvedSearchParams.assignment_id : undefined; const isPromote = resolvedSearchParams?.promote === 'true' || resolvedSearchParams?.is_promote === 'true'; + await getNonAdminAccessPagePermission('/task', isPromote ? 'PROMOTE_ASSIGNMENT' : isEdit ? 'UPDATE_ASSIGNMENT' : 'CREATE_ASSIGNMENT'); + try { const clientPromise = client_id ? getClientById(client_id) : Promise.resolve(undefined); const assignmentPromise = assignmentId && (isEdit || isPromote) ? getAssignmentById(assignmentId) : Promise.resolve(undefined); diff --git a/app/(dashboard)/task/component/client/ClientMilestoneTimeline.tsx b/app/(dashboard)/task/component/client/ClientMilestoneTimeline.tsx index 563e0d0..1da06ce 100644 --- a/app/(dashboard)/task/component/client/ClientMilestoneTimeline.tsx +++ b/app/(dashboard)/task/component/client/ClientMilestoneTimeline.tsx @@ -3,6 +3,8 @@ import React from 'react'; import Link from 'next/link'; import dayjs from 'dayjs'; +import isSameOrAfter from 'dayjs/plugin/isSameOrAfter'; +import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'; import { Calendar, ChevronRight, Clock } from 'lucide-react'; import { HoverCard, HoverCardContent, HoverCardTrigger } from '@/components/ui/hover-card'; import BadgeStatus from '@/components/ui/badge-status'; @@ -10,6 +12,9 @@ import { cn } from '@/lib/utils'; import { IClient, IClientMilestone } from '../../types'; import { resolveTechnicalStatusMeta } from '../../utils/client-overview-helpers'; +dayjs.extend(isSameOrAfter); +dayjs.extend(isSameOrBefore); + interface ClientMilestoneTimelineProps { client: IClient; variant?: 'list' | 'grid'; @@ -20,6 +25,8 @@ interface GroupedMilestone { date: dayjs.Dayjs; percent: number; diffDays: number; + isOngoing: boolean; + hideDate: boolean; items: IClientMilestone[]; } @@ -38,37 +45,98 @@ export default function ClientMilestoneTimeline({ client, variant = 'list' }: Cl const maxDate = today.add(2, 'month').startOf('day'); const totalDays = maxDate.diff(today, 'day') || 60; - // Filter milestones whose start_date is within the 2-month range [today, today + 2 months] + // Helper to safely parse and normalize start and end dates (handling edge cases or inverted dates) + const getNormalizedDates = (m: IClientMilestone) => { + const d1 = m.start_date ? dayjs(m.start_date).startOf('day') : null; + const d2 = m.end_date ? dayjs(m.end_date).startOf('day') : null; + if (!d1 && !d2) return null; + if (d1 && !d2) return { startDate: d1, endDate: d1 }; + if (!d1 && d2) return { startDate: d2, endDate: d2 }; + const startDate = d1!.isBefore(d2!) ? d1! : d2!; + const endDate = d1!.isAfter(d2!) ? d1! : d2!; + return { startDate, endDate }; + }; + + // Filter milestones: + // 1. Ongoing agendas: started in the past (startDate < today), but endDate is still today or in the future (endDate >= today) + // 2. Upcoming agendas: startDate is between today and maxDate (within next 2 months) + const processedMilestones: { + item: IClientMilestone; + isOngoing: boolean; + targetDate: dayjs.Dayjs; + startDate: dayjs.Dayjs; + endDate: dayjs.Dayjs; + }[] = []; + const rawMilestones = client.milestone || []; - const validMilestones = rawMilestones.filter((m) => { - if (!m.start_date) return false; - const mDate = dayjs(m.start_date).startOf('day'); - const diff = mDate.diff(today, 'day'); - return diff >= 0 && diff <= totalDays; + rawMilestones.forEach((m) => { + const dates = getNormalizedDates(m); + if (!dates) return; + const { startDate, endDate } = dates; + + const isOngoing = startDate.isBefore(today) && (endDate.isAfter(today) || endDate.isSame(today, 'day')); + const isUpcoming = (startDate.isAfter(today) || startDate.isSame(today, 'day')) && (startDate.isBefore(maxDate) || startDate.isSame(maxDate, 'day')); + + if (isOngoing) { + processedMilestones.push({ + item: m, + isOngoing: true, + targetDate: today, // Position at the start of milestone + startDate, + endDate, + }); + } else if (isUpcoming) { + processedMilestones.push({ + item: m, + isOngoing: false, + targetDate: startDate, + startDate, + endDate, + }); + } }); - // Group milestones by start_date to handle multiple agendas on the exact same date + // Group milestones by target date / start milestone to handle multiple agendas on the same point const groupsMap: { [key: string]: GroupedMilestone } = {}; - validMilestones.forEach((item) => { - const mDate = dayjs(item.start_date).startOf('day'); - const dateKey = mDate.format('YYYY-MM-DD'); - const diffDays = mDate.diff(today, 'day'); - const rawPercent = (diffDays / totalDays) * 100; - const percent = Math.max(0, Math.min(100, rawPercent)); + processedMilestones.forEach(({ item, isOngoing, targetDate }) => { + let dateKey: string; + let percent: number; + let diffDays: number; + const isAtStart = isOngoing || targetDate.isSame(today, 'day'); + + if (isAtStart) { + // Group ongoing agendas at the beginning of milestone (0%) + dateKey = 'start-milestone'; + percent = 0; + diffDays = 0; + } else { + dateKey = targetDate.format('YYYY-MM-DD'); + diffDays = targetDate.diff(today, 'day'); + const rawPercent = (diffDays / totalDays) * 100; + percent = Math.max(0, Math.min(100, rawPercent)); + } if (!groupsMap[dateKey]) { groupsMap[dateKey] = { dateKey, - date: mDate, + date: targetDate, percent, diffDays, + isOngoing: false, + hideDate: false, items: [], }; } + groupsMap[dateKey].items.push(item); + if (isOngoing) { + groupsMap[dateKey].isOngoing = true; + // Hide date label underneath start dot because varying start dates in past would confuse users + groupsMap[dateKey].hideDate = true; + } }); - const groups = Object.values(groupsMap).sort((a, b) => a.diffDays - b.diffDays); + const groups = Object.values(groupsMap).sort((a, b) => a.percent - b.percent); // Compute sequential line gradient segments: // Starts at Hari Ini (0%, Merah Rose) -> Agenda 1 -> Agenda 2 -> ... -> Agenda N @@ -78,6 +146,13 @@ export default function ClientMilestoneTimeline({ client, variant = 'list' }: Cl let currentPercent = 0; let currentHex = START_LINE_HEX; + // If the first group is at 0%, its status color initiates the line gradient + if (groups[0]?.percent === 0) { + const firstGroup = groups[0]; + const firstMeta = resolveTechnicalStatusMeta(firstGroup.items[0]?.project_assignment_status?.name); + currentHex = firstMeta.hexColor; + } + for (let i = 0; i < groups.length; i++) { const group = groups[i]; const targetPercent = group.percent; @@ -91,10 +166,9 @@ export default function ClientMilestoneTimeline({ client, variant = 'list' }: Cl fromHex: currentHex, toHex: targetHex, }); + currentPercent = targetPercent; + currentHex = targetHex; } - - currentPercent = targetPercent; - currentHex = targetHex; } } @@ -138,7 +212,7 @@ export default function ClientMilestoneTimeline({ client, variant = 'list' }: Cl
{hasAgendas ? ( - {validMilestones.length} {validMilestones.length === 1 ? 'Agenda' : 'Agendas'} + {processedMilestones.length} {processedMilestones.length === 1 ? 'Agenda' : 'Agendas'} ) : ( @@ -150,7 +224,7 @@ export default function ClientMilestoneTimeline({ client, variant = 'list' }: Cl {/* Timeline Viewport Container with group/rail for sibling hover coordination */}
-
+
{/* Continuous 2-Month Horizontal Rail */}
{/* Gradient Segments connecting Hari Ini -> Agenda 1 -> Agenda 2 -> ... */} @@ -300,15 +374,17 @@ export default function ClientMilestoneTimeline({ client, variant = 'list' }: Cl {isMulti ? `${group.items.length} Agendas` : primaryMeta.shortName}
- {/* Date Label strictly underneath */} - - {group.date.format('DD MMM')} - + {/* Date Label strictly underneath (hidden for ongoing agendas with varying start dates) */} + {!group.hideDate ? ( + + {group.date.format('DD MMM')} + + ) : null} @@ -323,22 +399,28 @@ export default function ClientMilestoneTimeline({ client, variant = 'list' }: Cl
- {group.date.format('dddd, DD MMMM YYYY')} + + {group.isOngoing + ? 'Ongoing Milestones (Active Today)' + : group.date.format('dddd, DD MMMM YYYY')} +
- {group.diffDays === 0 - ? 'Today' - : group.diffDays === 1 - ? 'Tomorrow' - : `In ${group.diffDays} days`} + {group.isOngoing + ? 'Currently Active' + : group.diffDays === 0 + ? 'Today' + : group.diffDays === 1 + ? 'Tomorrow' + : `In ${group.diffDays} days`}
{/* Subtitle / Counter */}
{group.items.length === 1 - ? '1 milestone agenda on this date:' - : `${group.items.length} milestone agendas on this date:`} + ? (group.isOngoing ? '1 ongoing milestone agenda currently active:' : '1 milestone agenda on this date:') + : (group.isOngoing ? `${group.items.length} ongoing milestone agendas currently active:` : `${group.items.length} milestone agendas on this date:`)}
{/* List of Assignment Milestones */} diff --git a/app/admin/administration/user/create/UserCreateClient.tsx b/app/admin/administration/user/create/UserCreateClient.tsx index 0d88209..df2d406 100644 --- a/app/admin/administration/user/create/UserCreateClient.tsx +++ b/app/admin/administration/user/create/UserCreateClient.tsx @@ -15,13 +15,13 @@ import { titleCase } from '@/lib/helper'; import PageLoading from '@/components/loader/PageLoading'; import LazyLoading from '@/components/loader/LazyLoading'; import { type IUser } from '../component/type'; -import { type IRole } from '@/app/admin/information/user-role/component/type'; import { type ICompany } from '../../company/component/type'; import { type IArea } from '../../area/component/type'; import { type IDivision } from '../../division/component/type'; import { type IPosition } from '@/app/admin/information/position/component/type'; import { type IEmployeeType } from '@/app/admin/information/employee-type/component/type'; import { toast } from 'sonner'; +import { IRole } from '@/types/rbac'; type Props = {}; diff --git a/app/admin/components/SidebarItem.tsx b/app/admin/components/SidebarItem.tsx index 132f50e..44159ba 100644 --- a/app/admin/components/SidebarItem.tsx +++ b/app/admin/components/SidebarItem.tsx @@ -41,11 +41,7 @@ const SidebarItem: FC = ({ menu, expand, onChangeExpand }) => { } const getActiveBackgroundMenu = () => { - const currentPath = pathanme || ''; - const fullPath = '/admin' + (menu.path || ''); - const isActive = menu.path === '' ? currentPath === '/admin' || currentPath === '/admin/' : currentPath === fullPath || (menu.path && currentPath.startsWith(fullPath + '/')); - - if (isActive) { + if (pathanme === '/admin' + menu.path) { return { color: theme === 'dark' ? '#fff' : theme === 'system' && systemTheme === 'dark' ? '#fff' : '#fff', fontWeight: theme === 'light' ? 600 : theme === 'system' && systemTheme === 'light' ? 600 : undefined, diff --git a/app/forbidden/page.tsx b/app/forbidden/page.tsx index 6948a71..50b541e 100644 --- a/app/forbidden/page.tsx +++ b/app/forbidden/page.tsx @@ -1,14 +1,17 @@ import { Metadata } from 'next'; import Link from 'next/link'; import { Button } from '@/components/ui/button'; -import { Home, LayoutDashboard, ArrowLeft, ShieldX, Lock } from 'lucide-react'; +import { Home, LayoutDashboard, ArrowLeft, Lock } from 'lucide-react'; +import { getCacheServerSession } from '@/lib/get-access-data'; export const metadata: Metadata = { title: '403 Forbidden | H.A.T.s', description: 'You do not have permission to access this page.', }; -export default function ForbiddenPage() { +export default async function ForbiddenPage() { + const session = await getCacheServerSession() + return (
@@ -50,12 +53,14 @@ export default function ForbiddenPage() { - - - + {session?.user.detail.role.allow_admin_panel && + + + + }
{/* Switch Account Option */}