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 1ab1946..ee161b3 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx @@ -93,7 +93,7 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro const assignmentStartDate = assignment.wo_start_date || assignment.im_start_date const assignmentEndDate = assignment.wo_end_date || assignment.im_end_date const assignmentDesc = assignment.wo_description || assignment.im_description - const assignmentStatus = assignment.project?.status || assignment.project_status?.name + const assignmentStatus = assignment.project?.status || assignment.project_assignment_status?.name return ( @@ -298,7 +298,7 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro - + 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 f053e9f..14c5421 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 @@ -26,7 +26,6 @@ interface Props { export default function AssignmentDetail({ client, initialAssignment: assignment }: Props) { const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | undefined>() - const [selectedData, setSelectedData] = useState() const router = useRouter(); @@ -39,17 +38,15 @@ export default function AssignmentDetail({ client, initialAssignment: assignment const assignmentStartDate = assignment.wo_start_date || assignment.im_start_date const assignmentEndDate = assignment.wo_end_date || assignment.im_end_date const assignmentDesc = assignment.wo_description || assignment.im_description - const assignmentStatus = assignment.project?.status || assignment.project_status?.name + const assignmentStatus = assignment.project?.status || assignment.project_assignment_status?.name + + const statuslist = assignment.project_assignment_status_detail?.filter(status => status.start_date) || [] const handleClose = () => { - setSelectedData(undefined) setAction(undefined) } - const handleSuccess = () => { - router.refresh() - handleClose() - } + console.log(assignment) return ( <> @@ -202,7 +199,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
- {assignment.project_assignment_status_detail?.map((history, idx) => ( + {statuslist?.map((history, idx) => (
- {history.status} + {history.project_assignment_status.name} - {new Date(history.date_status_changed).toLocaleDateString()} + {history.start_date ? new Date(history.start_date).toLocaleDateString() : 'N/A'} - {history.end_date ? new Date(history.end_date).toLocaleDateString() : 'Present'}
-

{history.status_remarks}

- Recorded: {new Date(history.created_at!).toLocaleString()} + Recorded: {new Date(history.end_date!).toLocaleString()}

))} - {(!assignment.project_assignment_status_detail || assignment.project_assignment_status_detail.length === 0) && ( + {(!statuslist || statuslist.length === 0) && (

No history recorded yet.

)}
@@ -235,12 +231,12 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
{action === 'UPDATE_STATUS' ? - + : null } {action === 'MANAGE_EMPLOYEE' ? - + : null } diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-assignments/ProjectAssignmentForm.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-assignments/ProjectAssignmentForm.tsx index 4413f82..2e08cc2 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-assignments/ProjectAssignmentForm.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-assignments/ProjectAssignmentForm.tsx @@ -35,14 +35,17 @@ import { ComboboxCustomUI } from '@/components/ui/combobox-custom-ui'; import { LazyImage } from '@/components/ui/lazy-image'; import FormEndUser from '../../../component/FormEndUser'; import { IProject } from '../../../type.project'; +import FormClient from '../../../component/FormClient'; -type IStep = 'type' | 'details' | 'work-orders' | 'review'; +type IStep = 'type' | 'clients' | 'details' | 'work-orders' | 'review'; export const assignmentSchema = yup.object({ type: yup.string().oneOf(['Project', 'IM']).required('Project type is required'), // Details Step + client_id: yup.number().required('Client is required'), end_user_id: yup.number().required('End user is required'), + name: yup.string().required('Assignment name is required'), code: yup.string().required('Project code is required'), year: yup.string().required('Year is required'), @@ -67,7 +70,7 @@ export const assignmentSchema = yup.object({ // Infer the TypeScript type from the Yup schema export type AssignmentFormValues = yup.InferType; -export default function CreateAssignmentForm({ client, clientId, projectList, isEdit, assignmentId }: { client: IClient, projectList: IProject[], clientId: string, isEdit?: boolean, assignmentId?: string }) { +export default function ProjectAssignmentForm({ client, clientId, isEdit, assignmentId }: { client?: IClient, clientId?: string, isEdit?: boolean, assignmentId?: string }) { const [existAssignment, setIsExistAssignment] = useState(null) const [step, setStep] = useState('type'); const [loading, setIsLoading] = useState(false); @@ -75,14 +78,16 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is const [isExistProject, setIsExistProject] = useState(false) const [openProjectSearch, setOpenProjectSearch] = useState(false); const [showEndUserForm, setShowEndUserForm] = useState(false) + const [showClientForm, setShowClientForm] = useState(false) + const [selectedClient, setSelectedClient] = useState(client || null) + const [selectedEndUser, setSelectedEndUser] = useState(null) const router = useRouter(); - const { data: endUserList, mutate } = useFetchWithAxios('/end-user') - const form = useForm({ resolver: yupResolver(assignmentSchema), defaultValues: { + client_id: clientId ? Number(clientId) : undefined, type: 'Project', name: '', code: '', @@ -100,9 +105,14 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is const assignmentType = form.watch('type'); const formValues = form.watch(); + const { data: clientList, mutate: mutateClientList } = useFetchWithAxios('/client') + const { data: endUserList, mutate: mutateEndUserList } = useFetchWithAxios('/end-user') + const { data: projectList, mutate: mutateProjectList } = useFetchWithAxios(`/client/project/${formValues.client_id}`) + // 3. Navigation & Validation Logic const steps: { id: IStep; label: string }[] = [ { id: 'type', label: 'Type' }, + { id: 'clients', label: 'Clients' }, { id: 'details', label: 'Details' }, ...(assignmentType === 'Project' ? [{ id: 'work-orders' as IStep, label: 'Work Orders' }] : []), { id: 'review', label: 'Review' }, @@ -120,8 +130,11 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is if (res.success) { const data: IProjectAssignment = res.data.data form.setValue('type', data.project?.code ? 'Project' : 'IM') - form.setValue('name', data.project?.name || data.im_name) + + form.setValue('client_id', data.client.id) form.setValue('end_user_id', data.end_user.id) + + form.setValue('name', data.project?.name || data.im_name) form.setValue('code', data.project?.code || data.im_code) form.setValue('year', data.project?.year || data.im_year) form.setValue('startDate', data.project?.start_date || data.im_start_date) @@ -134,7 +147,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is form.setValue('workOrder.endDate' as any, data.wo_end_date) form.setValue('workOrder.description' as any, data.wo_description) - setStep('details') + setStep('clients') setIsExistAssignment(res.data.data) } else { @@ -153,6 +166,10 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is if (step === 'type') { isStepValid = await form.trigger(['type']); + if (isStepValid) setStep('clients'); + } + else if (step === 'clients') { + isStepValid = await form.trigger(['client_id', 'end_user_id']); if (isStepValid) setStep('details'); } else if (step === 'details') { @@ -167,7 +184,8 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is }; const handleBack = () => { - if (step === 'details') setStep('type'); + if (step === 'clients') setStep('type'); + if (step === 'details') setStep('clients'); else if (step === 'work-orders') setStep('details'); else if (step === 'review') setStep(assignmentType === 'Project' ? 'work-orders' : 'details'); }; @@ -176,8 +194,9 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is setIsLoading(true); const newPayload = { - "client_id": Number(clientId), - "end_user_id": Number(payload.end_user_id), + "client_id": Number(payload.end_user_id), + "end_user_id": payload.end_user_id ? Number(payload.end_user_id) : null, + "im_code": assignmentType === 'IM' ? payload.code : isEdit ? existAssignment?.im_code : "", "im_name": assignmentType === 'IM' ? payload.name : isEdit ? existAssignment?.im_name : "", "im_year": assignmentType === 'IM' ? Number(payload.year) : isEdit ? existAssignment?.im_year : 2026, @@ -191,7 +210,6 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is "project_start_date": assignmentType === 'Project' ? dayjs(payload.startDate).format('YYYY-MM-DD') : '', "project_end_date": assignmentType === 'Project' ? payload.endDate ? dayjs(payload.endDate).format('YYYY-MM-DD') : '' : '', "project_description": assignmentType === 'Project' ? payload.description : '', - "project_status_id": isEdit ? existAssignment?.project_status.id : 1, "wo_code": (payload.workOrder as any).code, "wo_name": (payload.workOrder as any).name, @@ -200,6 +218,8 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is "wo_description": (payload.workOrder as any).description, "wo_warranty": isEdit ? existAssignment?.wo_warranty : '', + "project_assignment_status_id": isEdit ? existAssignment?.project_assignment_status?.id : 1, + "note": isEdit ? existAssignment?.note : "", } @@ -213,7 +233,11 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is setIsLoading(false) if (res.success) { toast.success(`${payload.type} saved successfully`); - router.replace(`/task/client-detail/${clientId}`); + if (clientId) { + router.replace(`/task/client-detail/${clientId}`); + } else { + router.replace(`/task?tab=assignments`); + } } else { toast.error(`Fail to save assignment`, { description: `(${res.code || '-'}) ${res.message}` }) } @@ -232,7 +256,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is

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

-

For {client.name}

+

{clientId ? `For ${client?.name}` : ''}

@@ -315,7 +339,98 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is /> )} - {/* STEP 2: DETAILS */} + {/* STEP 2: CLIENTS */} + {step === 'clients' && ( + + + Client Details + Select the client and end user information for this assignment. + + + ( + + Client + +
+ 0 ? clientList.map((item: IClient) => ({ label: item.name, value: item.id, originalData: item })) : []} + value={field.value} onChange={field.onChange} onSelect={(option) => setSelectedClient(option.originalData as any)} placeholder='Select client' className='shrink' disabled={clientId ? true : false} + + // --- CUSTOM DROPDOWN OPTIONS --- + renderOption={(option, isSelected) => { + const item = option.originalData as IClient; + return ( +
+
+ +
+ + {item.name} + + + {item.description} + +
+
+ {isSelected && } +
+ ); + }} + /> + +
+
+ +
+ )} + /> + ( + + End User + +
+ 0 ? endUserList.map((item: IEndUser) => ({ label: item.name, value: item.id, originalData: item })) : []} + value={field.value} onChange={field.onChange} onSelect={(option) => setSelectedEndUser(option.originalData as any)} placeholder='Select end user' className='shrink' + + // --- CUSTOM DROPDOWN OPTIONS --- + renderOption={(option, isSelected) => { + const user = option.originalData as IEndUser; + return ( +
+
+ +
+ + {user.name} + + + {user.description} + +
+
+ {isSelected && } +
+ ); + }} + /> + +
+
+ +
+ )} + /> + +
+
+ )} + + {/* STEP 3: DETAILS */} {step === 'details' && ( @@ -348,7 +463,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is No projects found. - {projectList.map(p => ( + {projectList.map((p: IProject) => ( { @@ -382,46 +497,6 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is )} /> - ( - - End User - -
- 0 ? endUserList.map((item: IEndUser) => ({ label: item.name, value: item.id, originalData: item })) : []} - value={field.value} onChange={field.onChange} placeholder='Select end user' className='shrink' - - // --- CUSTOM DROPDOWN OPTIONS --- - renderOption={(option, isSelected) => { - const user = option.originalData as IEndUser; - return ( -
-
- -
- - {user.name} - - - {user.description} - -
-
- {isSelected && } -
- ); - }} - /> - -
-
- -
- )} - /> -
( @@ -469,7 +544,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is )} - {/* STEP 3: WORK ORDERS */} + {/* STEP 4: WORK ORDERS */} {step === 'work-orders' && (
@@ -522,7 +597,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
)} - {/* STEP 4: REVIEW */} + {/* STEP 5: REVIEW */} {step === 'review' && (
@@ -631,7 +706,8 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is - {showEndUserForm ? setShowEndUserForm(false)} onSuccess={() => { mutate(); setShowEndUserForm(false) }} /> : null} + {showEndUserForm ? setShowEndUserForm(false)} onSuccess={() => { mutateEndUserList(); setShowEndUserForm(false) }} /> : null} + {showClientForm ? setShowClientForm(false)} onSuccess={() => { mutateClientList(); setShowClientForm(false) }} /> : null} {isFullLoading ? : null} ); 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 7fb355d..278a946 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 @@ -2,7 +2,7 @@ import fetchData from "@/lib/fetchData"; import ProjectAssignmentForm from "./ProjectAssignmentForm"; type Props = { - params: Promise<{ client_id: string }> + params: Promise<{ client_id?: string }> searchParams: Promise<{ [key: string]: string | string[] | undefined }> }; @@ -11,17 +11,11 @@ export default async function CreateAssignmentPage({ params, searchParams }: Pro const isEdit = (await searchParams)!.is_edit const assignmentId = (await searchParams)!.assignment_id - const getClient = fetchData(`/client/${client_id}`) - const getProjectByClient = fetchData(`/client/project/${client_id}`) - - const [clientRes, projectList] = await Promise.all([getClient, getProjectByClient]); - const client = clientRes && clientRes.length > 0 ? clientRes[0] : clientRes + const client = await fetchData(`/client/${client_id}`) return (
- 0 ? projectList : []} - isEdit={isEdit ? true : false} assignmentId={assignmentId as any} - /> +
); } \ No newline at end of file diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/AssignedPeople.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/AssignedPeople.tsx index 193bcb2..f590915 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/AssignedPeople.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/AssignedPeople.tsx @@ -67,7 +67,7 @@ const AssignedPeople = ({ people }: Props) => { - {user.assigned_date ? dayjs(user.assigned_date).format('MMMM DD, YYYY') : 'N/A'} + {user.start_date ? `${dayjs(user.start_date).format('MMMM DD, YYYY')} - ${user.end_date ? dayjs(user.end_date).format('MMMM DD, YYYY') : 'N/A'}` : 'N/A'}
diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/StatusTimeline.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/StatusTimeline.tsx index 2ee736d..46e13b0 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/StatusTimeline.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/StatusTimeline.tsx @@ -1,5 +1,6 @@ import { ProjectAssignmentStatusDetail } from '@/app/(dashboard)/task/type.assignment'; import BadgeStatus from '@/components/ui/badge-status'; +import dayjs from 'dayjs'; import { Clock } from 'lucide-react'; interface StatusTimelineProps { @@ -7,22 +8,14 @@ interface StatusTimelineProps { } const StatusTimeline = ({ history }: StatusTimelineProps) => { - const formatDate = (date: string) => { - const d = new Date(date); - return { - date: d.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }), - time: d.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' }), - }; - }; return (
{/* Vertical connector line */} -
+
{history.map((item, i) => { - const { date, time } = formatDate(item.date_status_changed); const isLatest = i === 0; return ( @@ -38,20 +31,20 @@ const StatusTimeline = ({ history }: StatusTimelineProps) => { {/* Content */}
- + {isLatest && Current}
- {date} + {item.start_date ? dayjs(item.start_date).format('MMM D, YYYY') : ''} ยท - {time} + {item.end_date ? dayjs(item.end_date).format('MMM D, YYYY') : ''}
- {item.status_remarks && + {/* {item.status_remarks &&

{item.status_remarks}

- } + } */}
); diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/WorkOrderCard.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/WorkOrderCard.tsx index 5209419..3eb790e 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/WorkOrderCard.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/WorkOrderCard.tsx @@ -8,10 +8,8 @@ import StatusTimeline from './StatusTimeline'; import AssignedPeople from './AssignedPeople'; import BadgeStatus from '@/components/ui/badge-status'; import { IProjectAssignment } from '@/app/(dashboard)/task/type.assignment'; -import { useRouter } from 'next/navigation'; -import FormUpdateStatus from '@/app/(dashboard)/task/component/UpdateTimelineStatus'; -import ManageEmployee from '@/app/(dashboard)/task/component/AddTeam'; import UpdateTimelineStatus from '@/app/(dashboard)/task/component/UpdateTimelineStatus'; +import { ManageTeam } from '@/app/(dashboard)/task/component/ManageTeam'; interface WorkOrderCardProps { workOrder: IProjectAssignment; @@ -24,8 +22,6 @@ const WorkOrderCard = ({ workOrder, index, defaultOpen = false }: WorkOrderCardP const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | undefined>() const [selectedData, setSelectedData] = useState() - const router = useRouter(); - const formatDate = (date: string) => new Date(date).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }); @@ -34,10 +30,8 @@ const WorkOrderCard = ({ workOrder, index, defaultOpen = false }: WorkOrderCardP setAction(undefined) } - const handleSuccess = () => { - router.refresh() - handleClose() - } + const statusList = workOrder.project_assignment_status_detail?.filter(status => status.start_date) || [] + return ( <> @@ -56,7 +50,7 @@ const WorkOrderCard = ({ workOrder, index, defaultOpen = false }: WorkOrderCardP

{workOrder.wo_name}

- +
@@ -115,14 +109,14 @@ const WorkOrderCard = ({ workOrder, index, defaultOpen = false }: WorkOrderCardP

Assignment Timeline

- {workOrder.project_assignment_status_detail.length} status changes + {statusList.length} status changes

- +
{/* Assigned people */} @@ -150,7 +144,7 @@ const WorkOrderCard = ({ workOrder, index, defaultOpen = false }: WorkOrderCardP } {action === 'MANAGE_EMPLOYEE' ? - + : null } diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx index 62e2d6e..1f1aa37 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx @@ -31,6 +31,7 @@ export default async function ProjectDetailPage({ params, searchParams }: Props) const [client, project] = await Promise.all([getClientById, getAssignmentByProjectId]); + console.log(project) // 3. Handle 404 Securely on the server if (!project) { return ( @@ -106,7 +107,7 @@ export default async function ProjectDetailPage({ params, searchParams }: Props) ); // --- Status Filter --- - const itemStatus = item.project_status?.name?.toLowerCase(); + const itemStatus = item.project_assignment_status?.name?.toLowerCase(); const matchesStatus = activeStatuses.length === 0 || (itemStatus && activeStatuses.includes(itemStatus)); return matchesSearch && matchesStatus; diff --git a/app/(dashboard)/task/component/ClientGrid.tsx b/app/(dashboard)/task/component/ClientGrid.tsx index 3aea52d..90bead3 100644 --- a/app/(dashboard)/task/component/ClientGrid.tsx +++ b/app/(dashboard)/task/component/ClientGrid.tsx @@ -60,112 +60,118 @@ export default function ClientGrid({ clients }: { clients: IClient[] }) { transition={{ delay: i * 0.05 }} className="h-full" > - - -
- -
-
-
-

{client.name}

-

{client.end_user_name}

+ + + +
+ +
+
+
+

{client.name}

+

{client.end_user_name}

+
+ + +
- - -
-
-
-
- {/*

+

+
+ {/*

Currently managing a portfolio of {projectCount} projects and {imCount} internal memos. A dedicated team of {assignedEmployeeIds.length} experts is handling {woCount} work orders to ensure successful delivery for {client.endUser}.

*/} -

- {projectCount === 0 && imCount === 0 && woCount === 0 ? - "No active projects, internal memos, or work orders recorded for this client yet." - : - <> - {(projectCount! > 0 || imCount > 0) && ( - <> - Currently managing a portfolio of{" "} - {projectCount! > 0 && - {projectCount} project{projectCount! > 1 ? 's' : ''} - } - {projectCount! > 0 && imCount > 0 && " and "} - {imCount > 0 && - {imCount} internal memo{imCount > 1 ? 's' : ''} - } - .{" "} - - )} - {woCount! > 0 && ( - <> - A dedicated team of{" "} - {userCount} experts is handling{" "} - {woCount} work order{woCount! > 1 ? 's' : ''}{" "}to ensure successful delivery for {client.end_user_name}. - - )} - - } -

-
+

+ {projectCount === 0 && imCount === 0 && woCount === 0 ? + "No active projects, internal memos, or work orders recorded for this client yet." + : + <> + {(projectCount! > 0 || imCount > 0) && ( + <> + Currently managing a portfolio of{" "} + {projectCount! > 0 && + {projectCount} project{projectCount! > 1 ? 's' : ''} + } + {projectCount! > 0 && imCount > 0 && " and "} + {imCount > 0 && + {imCount} internal memo{imCount > 1 ? 's' : ''} + } + .{" "} + + )} + {woCount! > 0 && ( + <> + A dedicated team of{" "} + {userCount} experts is handling{" "} + {woCount} work order{woCount! > 1 ? 's' : ''}{" "}to ensure successful delivery for {client.end_user_name}. + + )} + + } +

+
-
-
- Assigned Team -
- {client.users?.slice(0, 5).map((user, key) => { - return ( -
- - - - - -

{user?.name}

-

{user?.position?.name}

-
-
+
+
+ Assigned Team +
+ {client.users?.slice(0, 5).map((user, key) => { + return ( +
+ + + + + +

{user?.name}

+

{user?.position?.name}

+
+
+
+ ); + })} + {client.users?.length! > 5 && +
+ +{client.users?.length! - 5}
- ); - })} - {client.users?.length! > 5 && -
- +{client.users?.length! - 5} -
- } - {client.users?.length === 0 && - No team assigned - } + } + {client.users?.length === 0 && + No team assigned + } +
+
+
+ + + + + + e.stopPropagation()}> + View Client Detail + + { setShowSelectedData(client); setAction('EDIT') }} onClick={(e) => e.stopPropagation()}> + Edit Client + + { setShowSelectedData(client); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}> + Delete Client + + +
-
- - - - - - - View Client Detail - - { setShowSelectedData(client); setAction('EDIT') }}>Edit Client - { setShowSelectedData(client); setAction('DELETE') }} className="text-destructive">Delete Client - - -
-
- - + + + ); })} diff --git a/app/(dashboard)/task/component/FormClient.tsx b/app/(dashboard)/task/component/FormClient.tsx index 7c9255e..79e46f7 100644 --- a/app/(dashboard)/task/component/FormClient.tsx +++ b/app/(dashboard)/task/component/FormClient.tsx @@ -31,11 +31,12 @@ type FormDataType = Yup.InferType; type Props = { data?: IClient + isRedirectToDetail?: boolean onCancel?: VoidFunction onSuccess?: VoidFunction; }; -const FormClient: FC = ({ data, onSuccess, onCancel }) => { +const FormClient: FC = ({ data, onSuccess, onCancel, isRedirectToDetail }) => { const [showEnduserForm, setShowEndUserForm] = useState(false) const [isLoading, setIsLoading] = useState(false) const [currentFile, setCurrentFile] = useState(undefined); @@ -146,10 +147,10 @@ const FormClient: FC = ({ data, onSuccess, onCancel }) => { setIsLoading(false) if (res.success) { toast.success('Client saved successfully') - if (data) { - onSuccess!() - } else { + if (isRedirectToDetail) { router.push(`/task/client-detail/${res.data?.data?.id}`) + } else { + onSuccess!() } } else { toast.error(`Fail to save client`, { description: `(${res.code || '-'}) ${res.message}` }) diff --git a/app/(dashboard)/task/component/HomeTask.tsx b/app/(dashboard)/task/component/HomeTask.tsx index 6f12345..26a5b3b 100644 --- a/app/(dashboard)/task/component/HomeTask.tsx +++ b/app/(dashboard)/task/component/HomeTask.tsx @@ -10,9 +10,10 @@ import FilterComponent from './FilterComponent'; import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, } from '@/components/ui/select'; +import Link from 'next/link'; interface ShellProps { - currentView: 'grid' | 'table'; + currentView: 'clients' | 'assignments'; } export default function HomeTask({ currentView }: ShellProps) { @@ -53,20 +54,28 @@ export default function HomeTask({ currentView }: ShellProps) { Show by - Clients - Project Assignment + Clients + Project Assignment - + {currentView === 'clients' ? + + : + + + + }
- {showForm && setShowForm(false)} onSuccess={() => { setShowForm(false); router.refresh() }} />} + {showForm && setShowForm(false)} onSuccess={() => { setShowForm(false); router.refresh() }} />} ); } \ No newline at end of file diff --git a/app/(dashboard)/task/component/ManageTeam.tsx b/app/(dashboard)/task/component/ManageTeam.tsx index 4af733f..249f004 100644 --- a/app/(dashboard)/task/component/ManageTeam.tsx +++ b/app/(dashboard)/task/component/ManageTeam.tsx @@ -27,30 +27,40 @@ import { toast } from "sonner"; import { serverApiCall } from "@/lib/server-api"; -export interface ITableData { - id: string; - fullname: string; - email: string; - avatar: string; - position: any; - start_date: string; - end_date: string; +export interface IProjectAssignmentAssignUserDetail { + id: number + end_date: any + start_date: any status: string + user: User +} + +export interface User { + id: number + fullname: string + position: Position + email: string + avatar: string +} + +export interface Position { + name: string } + export function ManageTeam({ assignmentId, onClose }: { assignmentId: number, onClose: VoidFunction }) { - const [editingId, setEditingId] = useState(null); - const [draftData, setDraftData] = useState>({}); + const [editingId, setEditingId] = useState(null); + const [draftData, setDraftData] = useState>({}); const [isSaving, setIsSaving] = useState(false); const [showAddTeamDialog, setShowAddTeamDialog] = useState(false); - const [deletedId, setDeletedId] = useState(null); + const [deletedId, setDeletedId] = useState(null); const { data: existUserAssign, isLoading, mutate } = useFetchWithAxios(`/project-assignment/assign-user/${assignmentId}`) const router = useRouter() - const handleEdit = (row: ITableData) => { + const handleEdit = (row: IProjectAssignmentAssignUserDetail) => { setEditingId(row.id); setDraftData({ @@ -82,7 +92,7 @@ export function ManageTeam({ assignmentId, onClose }: { assignmentId: number, on } }; - const handleDraftChange = (field: keyof ITableData, value: string) => { + const handleDraftChange = (field: any, value: string) => { setDraftData((prev) => ({ ...prev, [field]: value })); }; @@ -103,7 +113,7 @@ export function ManageTeam({ assignmentId, onClose }: { assignmentId: number, on return ( <> - +
Manage Team @@ -113,7 +123,7 @@ export function ManageTeam({ assignmentId, onClose }: { assignmentId: number, on
-
+
@@ -144,7 +154,7 @@ export function ManageTeam({ assignmentId, onClose }: { assignmentId: number, on : - existUserAssign.map((row: ITableData) => { + existUserAssign.map((row: IProjectAssignmentAssignUserDetail) => { const isEditing = editingId === row.id; const isOtherRowEditing = editingId !== null && editingId !== row.id; @@ -153,15 +163,15 @@ export function ManageTeam({ assignmentId, onClose }: { assignmentId: number, on
- - {row.fullname?.charAt(0)} + + {row.user.fullname?.charAt(0)}
- {row.fullname} - {row.position?.name} + {row.user.fullname} + {row.user.position?.name}
- {row.email} + {row.user.email}
diff --git a/app/(dashboard)/task/component/UpdateTimelineStatus.tsx b/app/(dashboard)/task/component/UpdateTimelineStatus.tsx index b2f4895..5cd18d3 100644 --- a/app/(dashboard)/task/component/UpdateTimelineStatus.tsx +++ b/app/(dashboard)/task/component/UpdateTimelineStatus.tsx @@ -18,6 +18,20 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import BadgeStatus from '@/components/ui/badge-status'; +import dayjs from 'dayjs'; + +export interface IProjectAssignmentTimeline { + id: number + end_date: any + start_date: any + project_assignment_status: ProjectAssignmentStatus +} + +export interface ProjectAssignmentStatus { + id: number + name: string + remark: any +} type Props = { @@ -26,7 +40,7 @@ type Props = { }; const UpdateTimelineStatus: FC = ({ assignmentId, onClose }) => { - const [editingId, setEditingId] = useState(null); + const [editingId, setEditingId] = useState(null); const [draftData, setDraftData] = useState({}); const [isSaving, setIsSaving] = useState(false); @@ -34,14 +48,14 @@ const UpdateTimelineStatus: FC = ({ assignmentId, onClose }) => { const router = useRouter() - const handleEdit = (row: any) => { + const handleEdit = (row: IProjectAssignmentTimeline) => { setEditingId(row.id); setDraftData({ - start_date_assign: row.start_date_assign, - end_date_assign: row.end_date_assign, - "note": draftData.note, - "remarks": draftData.note + detailId: Number(row.id), + masterId: Number(row.project_assignment_status.id), + start_date_assign: row.start_date, + end_date_assign: row.end_date, }); }; @@ -49,7 +63,8 @@ const UpdateTimelineStatus: FC = ({ assignmentId, onClose }) => { setIsSaving(true); const submitPayload = { - "project_status_id": Number(draftData.id), + "project_assignment_status_detail_id": Number(draftData.detailId), + "project_assignment_status_id": Number(draftData.masterId), "start_date": draftData.start_date_assign ? new Date(draftData.start_date_assign).toISOString() : '', "end_date": draftData.end_date_assign ? new Date(draftData.end_date_assign).toISOString() : '', "note": draftData.note, @@ -57,7 +72,7 @@ const UpdateTimelineStatus: FC = ({ assignmentId, onClose }) => { } console.log(submitPayload) - const res = await serverApiCall('PUT', `/project-assignment/status/${draftData.id}`, submitPayload) + const res = await serverApiCall('PUT', `/project-assignment/status/${assignmentId}`, submitPayload) setIsSaving(false); if (res.success) { @@ -101,7 +116,6 @@ const UpdateTimelineStatus: FC = ({ assignmentId, onClose }) => { Status Start Date End Date - Note/Remarks Action
@@ -124,21 +138,21 @@ const UpdateTimelineStatus: FC = ({ assignmentId, onClose }) => { : - existTimeline.map((row: any) => { + existTimeline.map((row: IProjectAssignmentTimeline) => { const isEditing = editingId === row.id; const isOtherRowEditing = editingId !== null && editingId !== row.id; return ( - + {isEditing ? handleDraftChange("start_date_assign", date as any)} /> : - {row.start_date_assign} + {row.start_date ? dayjs(row.start_date).format('MMM DD, YYYY') : null} } @@ -146,15 +160,7 @@ const UpdateTimelineStatus: FC = ({ assignmentId, onClose }) => { {isEditing ? handleDraftChange("end_date_assign", date as any)} /> : - {row.end_date_assign} - } - - - - {isEditing ? -