From 83330418bcf5ba49d90b9053db63737ce6db5ad4 Mon Sep 17 00:00:00 2001 From: Ichsan Kurniawan Date: Mon, 12 Oct 2026 18:41:10 +0700 Subject: [PATCH] Add 'Promote to Project' flow for assignments Introduce a promote-to-project workflow and related UI/logic changes. Key changes: - Add Promote button/link in AssignmentDetail, AssignmentGrid, and AssignmentList to open the ProjectAssignmentForm in promote mode. - Propagate isPromote flag through pages and ProjectAssignmentForm: lock type to Project, prevent selecting IM, adjust headings/labels, and show badges. - When promoting, set payload fields (project_id, im_id) accordingly and POST to create a Project from an existing IM. - Autofill project/work-order fields from existing project selection and fetch WO sequence when project selected. - Update validation messages, toasts, and minor UI/text sizing tweaks. - Update UpdateAdministrationStatus to read/write notes (project_assignment_status_notes) and use it as initial remark. - Extend IProjectAssignment type with im_id and project_assignment_status_notes. - Remove .env.production.local (deleted). Files changed: multiple components under app/(dashboard)/task and type.assignment.ts (see diff). --- .env.production.local | 21 -- .../AssignmentDetailComponent.tsx | 14 +- .../ProjectAssignmentForm.tsx | 220 ++++++++++++------ .../[client_id]/project-assignments/page.tsx | 16 +- .../component/UpdateAdministrationStatus.tsx | 7 +- .../project-assignment/AssignmentGrid.tsx | 24 +- .../project-assignment/AssignmentList.tsx | 19 +- .../task/project-assignment/page.tsx | 14 +- app/(dashboard)/task/type.assignment.ts | 2 + 9 files changed, 218 insertions(+), 119 deletions(-) delete mode 100644 .env.production.local diff --git a/.env.production.local b/.env.production.local deleted file mode 100644 index c1256b2..0000000 --- a/.env.production.local +++ /dev/null @@ -1,21 +0,0 @@ -BASE_PATH = "" -NEXT_PUBLIC_APP_URL="https://dev-hats.hisnutech.my.id" - -BASE_URL_API = https://api-hats-dev.hisnutech.my.id/api/v1 -BASE_URL_IMG = https://api-hats.hisnutech.my.id/ - -NEXTAUTH_URL = https://dev-hats.hisnutech.my.id -NEXTAUTH_URL_INTERNAL = http://36.66.3.44:7005 - -NEXTAUTH_SECRET = 4339d50684523526005c1fcb34be0bb1 - -FIREBASE_API_KEY = AIzaSyAEkZCHhnyatsNiZ2dpjeaz6JqXYknKKHk -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.2.0" -NEXT_PUBLIC_MANAGER_USER_ID = '2' - -NEXT_PUBLIC_S3_IMAGE_URL = https://cdn.hisnutech.my.id/public \ No newline at end of file diff --git a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx index 9d11605..622b66d 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx @@ -15,7 +15,7 @@ import Link from 'next/link'; import { useRouter } from 'next/navigation'; import dayjs from 'dayjs'; import { - ArrowLeft, Briefcase, Calendar, ChevronDown, ClipboardCheck, Clock, ExternalLink, FileText, + ArrowLeft, ArrowUpRight, Briefcase, Calendar, ChevronDown, ClipboardCheck, Clock, ExternalLink, FileText, FolderGit2, History, LayoutGrid, List, Mail, Phone, UserPlus, Users, } from 'lucide-react'; import { Button } from '@/components/ui/button'; @@ -146,6 +146,18 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
+ {!isWorkOrder && ( + + )}
-

{isEdit ? 'Update' : 'Create Project'} Assignment

-

{clientId ? `For ${client?.name}` : 'Manage the creation and modification of assignment information'}

+
+

{isPromote ? 'Promote to Project' : isEdit ? 'Update Assignment' : 'Create Project Assignment'}

+ {isPromote && ( + + Promote Action + + )} +
+

+ {isPromote + ? 'Convert this Internal Memo into a Project with Work Orders' + : clientId + ? `For ${client?.name}` + : 'Manage the creation and modification of assignment information'} +

@@ -355,8 +409,13 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
field.onChange('Project')} - className={cn("cursor-pointer transition-all hover:border-his dark:hover:border-his duration-400", field.value === 'Project' && "ring-2 ring-his/10 border-his dark:ring-his/10 dark:border-his")} + className={cn("cursor-pointer transition-all hover:border-his dark:hover:border-his duration-400 relative", field.value === 'Project' && "ring-2 ring-his/10 border-his dark:ring-his/10 dark:border-his")} > + {isPromote && ( + + Locked for Promotion + + )}
@@ -370,9 +429,24 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign - field.onChange('IM')} - className={cn("cursor-pointer transition-all hover:border-his dark:hover:border-his duration-400", field.value === 'IM' && "ring-2 ring-his/10 border-his dark:ring-his/10 dark:border-his")} + { + if (isPromote) { + toast.info('Cannot select Internal Memo while promoting to Project'); + return; + } + field.onChange('IM'); + }} + className={cn( + "cursor-pointer transition-all hover:border-his dark:hover:border-his duration-400 relative", + field.value === 'IM' && "ring-2 ring-his/10 border-his dark:ring-his/10 dark:border-his", + isPromote && "opacity-40 cursor-not-allowed hover:border-border" + )} > + {isPromote && ( + + Unavailable + + )}
@@ -511,12 +585,12 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
- Import Existing Project + Import Existing Project Optional
-

+

Select an existing project for {selectedClient?.name || 'this client'} to autofill information, or create a new one below.

@@ -553,7 +627,7 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign form.setValue('description', p.description || '', { shouldValidate: true }); setOpenProjectSearch(false); - setIsExistProject(true); + setIsExistProject(p); toast.info(`Autofilled details from ${p.name}`); }} className="cursor-pointer py-2.5 px-3" @@ -561,11 +635,11 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
- + {p.name} -
- +
+ # {p.code} • @@ -624,7 +698,7 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign form.setValue('description', p.description || '', { shouldValidate: true }); setOpenProjectSearch(false); - setIsExistProject(true); + setIsExistProject(p); toast.info(`Switched project to ${p.name}`); }} className="cursor-pointer py-2.5 px-3" @@ -632,12 +706,12 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
- + {p.name} -
- - {p.code} +
+ + # {p.code} • Year: {p.year} @@ -655,10 +729,10 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign type="button" variant="ghost" size="sm" - className="h-7 px-2 text-xs text-muted-foreground hover:text-destructive hover:bg-destructive/10" + className="h-7 px-2 text-xs text-destructive hover:bg-destructive" onClick={handleClearProject} > - Clear / Create New + Clear / Create New
@@ -683,7 +757,7 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
-

+

Fields below are locked and autofilled from this existing project. Click Clear / Create New to enter new project details manually.

@@ -878,7 +952,7 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign

Full work order code will be submitted as: - {projectCode}-{field.value?.trim() || '...'} + # {projectCode}-{field.value?.trim() || '...'}

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 278a946..1eecdb2 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 @@ -8,14 +8,22 @@ type Props = { export default async function CreateAssignmentPage({ params, searchParams }: Props) { const { client_id } = await params; - const isEdit = (await searchParams)!.is_edit - const assignmentId = (await searchParams)!.assignment_id + const resolvedSearchParams = await searchParams; + const isEdit = resolvedSearchParams?.is_edit; + const assignmentId = resolvedSearchParams?.assignment_id; + const isPromote = resolvedSearchParams?.promote === 'true' || resolvedSearchParams?.is_promote === 'true'; - const client = await fetchData(`/client/${client_id}`) + const client = await fetchData(`/client/${client_id}`); return (
- +
); } \ No newline at end of file diff --git a/app/(dashboard)/task/component/UpdateAdministrationStatus.tsx b/app/(dashboard)/task/component/UpdateAdministrationStatus.tsx index 00cdaa6..317f863 100644 --- a/app/(dashboard)/task/component/UpdateAdministrationStatus.tsx +++ b/app/(dashboard)/task/component/UpdateAdministrationStatus.tsx @@ -85,10 +85,11 @@ export default function UpdateAdministrationStatus({ }, [initialStatusId]); useEffect(() => { - const initialRemark = assignment?.project_assignment_status?.remark || assignment?.project_assignment_status?.description || assignment?.note || ''; + const initialRemark = assignment?.project_assignment_status_notes || assignment?.project_assignment_status?.remark || assignment?.project_assignment_status?.description || assignment?.note || ''; setDescription(initialRemark); }, [assignment]); + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!effectiveId) { @@ -105,9 +106,7 @@ export default function UpdateAdministrationStatus({ try { const payload = { project_assignment_status_id: Number(selectedStatusId), - remark: description.trim(), - description: description.trim(), - note: description.trim(), + notes: description.trim(), }; const res = await serverApiCall('PUT', `/project-assignment/status/${effectiveId}`, payload); diff --git a/app/(dashboard)/task/component/project-assignment/AssignmentGrid.tsx b/app/(dashboard)/task/component/project-assignment/AssignmentGrid.tsx index b7cda15..89b3d4f 100644 --- a/app/(dashboard)/task/component/project-assignment/AssignmentGrid.tsx +++ b/app/(dashboard)/task/component/project-assignment/AssignmentGrid.tsx @@ -13,7 +13,7 @@ import { Tooltip, TooltipContent, TooltipTrigger, } from '@/components/ui/tooltip'; import { LazyImage } from '@/components/ui/lazy-image'; -import { Briefcase, Calendar, ExternalLink, MoreVertical, FolderGit2, FileText } from 'lucide-react'; +import { Briefcase, Calendar, ExternalLink, MoreVertical, FolderGit2, FileText, ArrowUpRight } from 'lucide-react'; import Link from 'next/link'; import BadgeStatus from '@/components/ui/badge-status'; import { formatAssignmentDate } from './AssignmentList'; @@ -47,17 +47,18 @@ export default function AssignmentGrid({ const assignmentDesc = assignment.wo_description || assignment.im_description || assignment.project?.description; const assignmentStatus = assignment.project_assignment_status?.name || assignment.project?.status; - const illustrationSrc = isProject - ? '/assets/illustrations/work_order.jpg' - : '/assets/illustrations/internal_memo.jpg'; + const illustrationSrc = isProject ? '/assets/illustrations/work_order.jpg' : '/assets/illustrations/internal_memo.jpg'; const effectiveClientId = clientId || assignment.client?.id; const assignmentDetailUrl = effectiveClientId ? `/task/client-detail/${effectiveClientId}/${assignment.id}` : '#'; - const projectDetailUrl = effectiveClientId && assignment.project?.id - ? `/task/client-detail/${effectiveClientId}/project-detail/${assignment.project.id}` - : null; + const projectDetailUrl = effectiveClientId && assignment.project?.id ? `/task/client-detail/${effectiveClientId}/project-detail/${assignment.project.id}` : null; const editAssignmentUrl = effectiveClientId ? `/task/client-detail/${effectiveClientId}/project-assignments?is_edit=true&assignment_id=${assignment.id}` + : `/task/project-assignment?is_edit=true&assignment_id=${assignment.id}`; + const promoteAssignmentUrl = !isProject + ? (effectiveClientId + ? `/task/client-detail/${effectiveClientId}/project-assignments?is_edit=true&assignment_id=${assignment.id}&promote=true` + : `/task/project-assignment?is_edit=true&assignment_id=${assignment.id}&promote=true`) : null; return ( @@ -122,7 +123,14 @@ export default function AssignmentGrid({ - + {promoteAssignmentUrl && ( + + + + Promote to Project + + + )} View Assignment Details diff --git a/app/(dashboard)/task/component/project-assignment/AssignmentList.tsx b/app/(dashboard)/task/component/project-assignment/AssignmentList.tsx index 7c562a4..445557d 100644 --- a/app/(dashboard)/task/component/project-assignment/AssignmentList.tsx +++ b/app/(dashboard)/task/component/project-assignment/AssignmentList.tsx @@ -12,7 +12,7 @@ import { Tooltip, TooltipContent, TooltipTrigger, } from '@/components/ui/tooltip'; import { LazyImage } from '@/components/ui/lazy-image'; -import { Briefcase, Calendar, MoreVertical, FolderGit2, FileText, BuildingComplex } from 'lucide-react'; +import { Briefcase, Calendar, MoreVertical, FolderGit2, FileText, BuildingComplex, ArrowUpRight } from 'lucide-react'; import Link from 'next/link'; import BadgeStatus from '@/components/ui/badge-status'; @@ -59,11 +59,14 @@ export default function AssignmentList({ const effectiveClientId = clientId || assignment.client?.id; const assignmentDetailUrl = effectiveClientId ? `/task/client-detail/${effectiveClientId}/${assignment.id}` : '#'; - const projectDetailUrl = effectiveClientId && assignment.project?.id - ? `/task/client-detail/${effectiveClientId}/project-detail/${assignment.project.id}` - : null; + const projectDetailUrl = effectiveClientId && assignment.project?.id ? `/task/client-detail/${effectiveClientId}/project-detail/${assignment.project.id}` : null; const editAssignmentUrl = effectiveClientId ? `/task/client-detail/${effectiveClientId}/project-assignments?is_edit=true&assignment_id=${assignment.id}` + : `/task/project-assignment?is_edit=true&assignment_id=${assignment.id}`; + const promoteAssignmentUrl = !isProject + ? (effectiveClientId + ? `/task/client-detail/${effectiveClientId}/project-assignments?is_edit=true&assignment_id=${assignment.id}&promote=true` + : `/task/project-assignment?is_edit=true&assignment_id=${assignment.id}&promote=true`) : null; return ( @@ -234,6 +237,14 @@ export default function AssignmentList({ + {promoteAssignmentUrl && ( + + + + Promote to Project + + + )} View Assignment Details diff --git a/app/(dashboard)/task/project-assignment/page.tsx b/app/(dashboard)/task/project-assignment/page.tsx index 95872e3..1508bb8 100644 --- a/app/(dashboard)/task/project-assignment/page.tsx +++ b/app/(dashboard)/task/project-assignment/page.tsx @@ -1,16 +1,22 @@ import ProjectAssignmentForm from "../client-detail/[client_id]/project-assignments/ProjectAssignmentForm"; type Props = { - searchParams: Promise<{ is_edit?: string; assignment_id?: string }> + searchParams: Promise<{ is_edit?: string; assignment_id?: string; promote?: string; is_promote?: string }> }; export default async function CreateAssignmentPage({ searchParams }: Props) { - const isEdit = (await searchParams)!.is_edit - const assignmentId = (await searchParams)!.assignment_id + const resolvedSearchParams = await searchParams; + const isEdit = resolvedSearchParams?.is_edit; + const assignmentId = resolvedSearchParams?.assignment_id; + const isPromote = resolvedSearchParams?.promote === 'true' || resolvedSearchParams?.is_promote === 'true'; return (
- +
); } \ No newline at end of file diff --git a/app/(dashboard)/task/type.assignment.ts b/app/(dashboard)/task/type.assignment.ts index df55797..82e7160 100644 --- a/app/(dashboard)/task/type.assignment.ts +++ b/app/(dashboard)/task/type.assignment.ts @@ -2,6 +2,7 @@ import { IUser } from "@/app/admin/administration/user/component/type" export interface IProjectAssignment { id: number + im_id?: any im_code?: any im_description?: any im_end_date?: any @@ -13,6 +14,7 @@ export interface IProjectAssignment { end_user: EndUser project?: Project project_assignment_status: ProjectStatus + project_assignment_status_notes?: string wo_code: string wo_description: string wo_name: string