mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 17:16:28 +00:00
Refactor assignment status & assignment form
Normalize project-assignment status handling and improve assignment creation flow. - Use project_assignment_status / project_assignment_status_detail fields throughout (ClientDetail, AssignmentDetail, WorkOrderCard, StatusTimeline, UpdateTimelineStatus, ProjectDetail filters) and prefer start_date/end_date for timeline ranges. - Filter timeline lists to only include entries with start_date and format dates using dayjs. - Update UpdateTimelineStatus to submit detail/master IDs and call PUT /project-assignment/status/:assignmentId; adjust table and editing state types. - Rework ManageTeam and related types to match API shape (user object nested) and update UI/behaviors. - Add a dedicated "Clients" step to ProjectAssignmentForm with client & end-user comboboxes, client creation modal, client/end-user fetching, validation, and navigation; fix payload mapping, default values, and post-submit routing. - Add new project-assignment page entry (app/(dashboard)/task/project-assignment/page.tsx). - Wrap ClientGrid cards in links and tidy card actions; adjust HomeTask view options and create-button behavior to route to project assignment flow. - Add optional redirect behavior to FormClient and small UI spacing/structure tweaks. These changes align front-end data structures with backend fields, improve timeline accuracy, and streamline the project assignment creation UX.
This commit is contained in:
@@ -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 (
|
||||
<motion.div key={assignment.id} initial={{ opacity: 0, y: 10 }} animate={{ opacity: 1, y: 0 }} className="h-full">
|
||||
@@ -298,7 +298,7 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<BadgeStatus status={assignment.project?.status || assignment.project_status?.name} />
|
||||
<BadgeStatus status={assignment.project?.status || assignment.project_assignment_status?.name} />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<DropdownMenu>
|
||||
|
||||
+11
-15
@@ -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<IProjectAssignment>()
|
||||
|
||||
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
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="relative space-y-8 before:absolute before:inset-0 before:ml-2.5 before:h-full before:w-0.5 before:-translate-x-px before:bg-accent">
|
||||
{assignment.project_assignment_status_detail?.map((history, idx) => (
|
||||
{statuslist?.map((history, idx) => (
|
||||
<div key={history.id} className="relative flex items-start gap-4 pl-8">
|
||||
<div className={cn(
|
||||
"absolute left-0 mt-1 w-5 h-5 rounded-full border-4 border-background z-10",
|
||||
@@ -211,20 +208,19 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
<div className="flex-1 space-y-1">
|
||||
<div className="flex items-center justify-between">
|
||||
<Badge variant={idx === 0 ? "default" : "outline"} className="text-[10px] h-5">
|
||||
{history.status}
|
||||
{history.project_assignment_status.name}
|
||||
</Badge>
|
||||
<span className="text-xs text-muted-foreground font-mono">
|
||||
{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'}
|
||||
</span>
|
||||
</div>
|
||||
<p className="text-sm font-medium">{history.status_remarks}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Recorded: {new Date(history.created_at!).toLocaleString()}
|
||||
Recorded: {new Date(history.end_date!).toLocaleString()}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{(!assignment.project_assignment_status_detail || assignment.project_assignment_status_detail.length === 0) && (
|
||||
{(!statuslist || statuslist.length === 0) && (
|
||||
<p className="text-sm text-muted-foreground italic pl-8">No history recorded yet.</p>
|
||||
)}
|
||||
</div>
|
||||
@@ -235,12 +231,12 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
</motion.div>
|
||||
|
||||
{action === 'UPDATE_STATUS' ?
|
||||
<UpdateTimelineStatus assignmentId={1} onClose={handleClose} />
|
||||
<UpdateTimelineStatus assignmentId={assignment.id} onClose={handleClose} />
|
||||
: null
|
||||
}
|
||||
|
||||
{action === 'MANAGE_EMPLOYEE' ?
|
||||
<ManageTeam assignmentId={1} onClose={handleClose} />
|
||||
<ManageTeam assignmentId={assignment.id} onClose={handleClose} />
|
||||
: null
|
||||
}
|
||||
</>
|
||||
|
||||
+133
-57
@@ -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<typeof assignmentSchema>;
|
||||
|
||||
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<IProjectAssignment | null>(null)
|
||||
const [step, setStep] = useState<IStep>('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<IClient | null>(client || null)
|
||||
const [selectedEndUser, setSelectedEndUser] = useState<IEndUser | null>(null)
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const { data: endUserList, mutate } = useFetchWithAxios('/end-user')
|
||||
|
||||
const form = useForm<AssignmentFormValues>({
|
||||
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
|
||||
</Button>
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold">{isEdit ? 'Update' : 'Create Project'} Assignment</h1>
|
||||
<p className="text-muted-foreground">For {client.name}</p>
|
||||
<p className="text-muted-foreground">{clientId ? `For ${client?.name}` : ''}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -315,7 +339,98 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* STEP 2: DETAILS */}
|
||||
{/* STEP 2: CLIENTS */}
|
||||
{step === 'clients' && (
|
||||
<Card900>
|
||||
<CardHeader>
|
||||
<CardTitle>Client Details</CardTitle>
|
||||
<CardDescription>Select the client and end user information for this assignment.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
<FormField control={form.control} name='client_id'
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Client</FormLabel>
|
||||
<FormControl>
|
||||
<div className="flex gap-4">
|
||||
<ComboboxCustomUI options={clientList && clientList.length > 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 (
|
||||
<div className={`flex items-center justify-between w-full py-1 rounded-sm ${isSelected ? 'bg-zinc-800' : ''}`}>
|
||||
<div className="flex items-center gap-3">
|
||||
<LazyImage className='w-10 h-10 rounded-md border border-border' alt={item.name} src={item.photo ? item.photo : '/assets/ilustration.png'} />
|
||||
<div className="flex flex-col">
|
||||
<span className={`text-sm ${isSelected ? 'font-bold text-primary' : ''}`}>
|
||||
{item.name}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground truncate">
|
||||
{item.description}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{isSelected && <CheckCircle className="h-5 w-5 -translate-x-2" />}
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<Button type="button" variant="outline" size="icon" onClick={() => setShowClientForm(true)}>
|
||||
<Plus className="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField control={form.control} name='end_user_id'
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>End User</FormLabel>
|
||||
<FormControl>
|
||||
<div className="flex gap-4">
|
||||
<ComboboxCustomUI options={endUserList && endUserList.length > 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 (
|
||||
<div className={`flex items-center justify-between w-full py-1 rounded-sm ${isSelected ? 'bg-zinc-800' : ''}`}>
|
||||
<div className="flex items-center gap-3">
|
||||
<LazyImage className='w-10 h-10 rounded-md border border-border' alt={user.name} src={user.photo ? user.photo : '/assets/ilustration.png'} />
|
||||
<div className="flex flex-col">
|
||||
<span className={`text-sm ${isSelected ? 'font-bold text-primary' : ''}`}>
|
||||
{user.name}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground truncate">
|
||||
{user.description}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{isSelected && <CheckCircle className="h-5 w-5 -translate-x-2" />}
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<Button type="button" variant="outline" size="icon" onClick={() => setShowEndUserForm(true)}>
|
||||
<Plus className="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
</CardContent>
|
||||
</Card900>
|
||||
)}
|
||||
|
||||
{/* STEP 3: DETAILS */}
|
||||
{step === 'details' && (
|
||||
<Card900>
|
||||
<CardHeader>
|
||||
@@ -348,7 +463,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
<CommandList>
|
||||
<CommandEmpty>No projects found.</CommandEmpty>
|
||||
<CommandGroup heading="Recent Projects">
|
||||
{projectList.map(p => (
|
||||
{projectList.map((p: IProject) => (
|
||||
<CommandItem
|
||||
key={p.id}
|
||||
onSelect={() => {
|
||||
@@ -382,46 +497,6 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField control={form.control} name='end_user_id'
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>End User</FormLabel>
|
||||
<FormControl>
|
||||
<div className="flex gap-4">
|
||||
<ComboboxCustomUI options={endUserList && endUserList.length > 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 (
|
||||
<div className={`flex items-center justify-between w-full py-1 rounded-sm ${isSelected ? 'bg-zinc-800' : ''}`}>
|
||||
<div className="flex items-center gap-3">
|
||||
<LazyImage className='w-10 h-10 rounded-md border border-border' alt={user.name} src={user.photo ? `${process.env.BASE_URL_IMG}/${user.photo}` : '/assets/ilustration.png'} />
|
||||
<div className="flex flex-col">
|
||||
<span className={`text-sm ${isSelected ? 'font-bold text-primary' : ''}`}>
|
||||
{user.name}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground truncate">
|
||||
{user.description}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{isSelected && <CheckCircle className="h-5 w-5 -translate-x-2" />}
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<Button type="button" variant="outline" size="icon" onClick={() => setShowEndUserForm(true)}>
|
||||
<Plus className="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<div className="grid md:grid-cols-2 gap-4">
|
||||
<FormField control={form.control} name="code" disabled={isExistProject} render={({ field }) => (
|
||||
<FormItem>
|
||||
@@ -469,7 +544,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
</Card900>
|
||||
)}
|
||||
|
||||
{/* STEP 3: WORK ORDERS */}
|
||||
{/* STEP 4: WORK ORDERS */}
|
||||
{step === 'work-orders' && (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
@@ -522,7 +597,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* STEP 4: REVIEW */}
|
||||
{/* STEP 5: REVIEW */}
|
||||
{step === 'review' && (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
@@ -631,7 +706,8 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
</form>
|
||||
</Form>
|
||||
|
||||
{showEndUserForm ? <FormEndUser onCancel={() => setShowEndUserForm(false)} onSuccess={() => { mutate(); setShowEndUserForm(false) }} /> : null}
|
||||
{showEndUserForm ? <FormEndUser onCancel={() => setShowEndUserForm(false)} onSuccess={() => { mutateEndUserList(); setShowEndUserForm(false) }} /> : null}
|
||||
{showClientForm ? <FormClient onCancel={() => setShowClientForm(false)} onSuccess={() => { mutateClientList(); setShowClientForm(false) }} /> : null}
|
||||
{isFullLoading ? <PageLoading /> : null}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -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 (
|
||||
<div className="max-w-4xl mx-auto p-6 sm:p-8 pt-6 pb-20">
|
||||
<ProjectAssignmentForm client={client} clientId={client_id} projectList={projectList && projectList.length > 0 ? projectList : []}
|
||||
isEdit={isEdit ? true : false} assignmentId={assignmentId as any}
|
||||
/>
|
||||
<ProjectAssignmentForm client={client} clientId={client_id} isEdit={isEdit ? true : false} assignmentId={assignmentId as any} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+1
-1
@@ -67,7 +67,7 @@ const AssignedPeople = ({ people }: Props) => {
|
||||
</span>
|
||||
<span className="text-xs font-medium text-foreground inline-flex items-center gap-1">
|
||||
<Calendar className="w-3 h-3" />
|
||||
{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'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+7
-14
@@ -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 (
|
||||
<div className="relative">
|
||||
{/* Vertical connector line */}
|
||||
<div className="absolute left-[15px] top-2 bottom-2 w-px bg-linear-to-b from-primary/40 via-border to-transparent" />
|
||||
<div className="absolute left-3.75 top-2 bottom-2 w-px bg-linear-to-b from-primary/40 via-border to-transparent" />
|
||||
|
||||
<div className="space-y-5">
|
||||
{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 */}
|
||||
<div className="flex-1 min-w-0 pb-1">
|
||||
<div className="flex flex-wrap items-center gap-2 mb-1">
|
||||
<BadgeStatus status={item.status} />
|
||||
<BadgeStatus status={item.project_assignment_status.name} />
|
||||
{isLatest && <span className="text-xs font-bold uppercase tracking-wider text-primary">Current</span>}
|
||||
</div>
|
||||
<div className="flex items-center gap-1.5 text-xs text-muted-foreground mb-1.5">
|
||||
<Clock className="w-3 h-3" />
|
||||
<span>{date}</span>
|
||||
<span>{item.start_date ? dayjs(item.start_date).format('MMM D, YYYY') : ''}</span>
|
||||
<span className="opacity-50">·</span>
|
||||
<span className="font-mono">{time}</span>
|
||||
<span className="font-mono">{item.end_date ? dayjs(item.end_date).format('MMM D, YYYY') : ''}</span>
|
||||
</div>
|
||||
{item.status_remarks &&
|
||||
{/* {item.status_remarks &&
|
||||
<p className="text-sm text-foreground/80 bg-muted/30 rounded-md px-3 py-2 border border-border/50">
|
||||
{item.status_remarks}
|
||||
</p>
|
||||
}
|
||||
} */}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
+7
-13
@@ -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<IProjectAssignment>()
|
||||
|
||||
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 (
|
||||
<>
|
||||
<Card900 className="overflow-hidden border-border/60 bg-card/80 backdrop-blur-sm hover:shadow-xl transition-all text-sm border-l-4 border-l-primary">
|
||||
@@ -56,7 +50,7 @@ const WorkOrderCard = ({ workOrder, index, defaultOpen = false }: WorkOrderCardP
|
||||
<h3 className="text-base sm:text-xl font-bold text-foreground wrap-break-word flex-1 min-w-0">
|
||||
{workOrder.wo_name}
|
||||
</h3>
|
||||
<BadgeStatus status={workOrder.project_status?.name} />
|
||||
<BadgeStatus status={workOrder.project_assignment_status?.name} />
|
||||
</div>
|
||||
<div className="flex flex-col sm:flex-row sm:items-center gap-1.5 sm:gap-3 text-muted-foreground sm:flex-wrap">
|
||||
<span className="inline-flex items-center gap-1.5 font-mono">
|
||||
@@ -115,14 +109,14 @@ const WorkOrderCard = ({ workOrder, index, defaultOpen = false }: WorkOrderCardP
|
||||
<div>
|
||||
<h4 className="text-base font-bold text-foreground">Assignment Timeline</h4>
|
||||
<p className="text-muted-foreground">
|
||||
{workOrder.project_assignment_status_detail.length} status changes
|
||||
{statusList.length} status changes
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<Button size='sm' onClick={() => { setAction('UPDATE_STATUS'); setSelectedData(workOrder) }}><IterationCcw /> Update Status</Button>
|
||||
</div>
|
||||
|
||||
<StatusTimeline history={workOrder.project_assignment_status_detail} />
|
||||
<StatusTimeline history={statusList} />
|
||||
</div>
|
||||
|
||||
{/* Assigned people */}
|
||||
@@ -150,7 +144,7 @@ const WorkOrderCard = ({ workOrder, index, defaultOpen = false }: WorkOrderCardP
|
||||
}
|
||||
|
||||
{action === 'MANAGE_EMPLOYEE' ?
|
||||
<ManageEmployee assignmentId={selectedData?.id!} onCancel={handleClose} onSuccess={handleSuccess} />
|
||||
<ManageTeam assignmentId={selectedData?.id!} onClose={handleClose} />
|
||||
: null
|
||||
}
|
||||
</>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -60,112 +60,118 @@ export default function ClientGrid({ clients }: { clients: IClient[] }) {
|
||||
transition={{ delay: i * 0.05 }}
|
||||
className="h-full"
|
||||
>
|
||||
<Card900 className="h-full group overflow-hidden hover:shadow-lg transition-all duration-300 border-primary/5 hover:border-primary/20 flex flex-col py-0">
|
||||
<CardContent className="p-0 flex flex-col h-full">
|
||||
<div className="relative h-32 bg-accent/50 overflow-hidden">
|
||||
<LazyImage
|
||||
src={client.photo!}
|
||||
alt={client.name}
|
||||
className="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500"
|
||||
/>
|
||||
<div className="absolute inset-0 bg-linear-to-t from-black/80 via-black/40 to-transparent" />
|
||||
<div className="absolute bottom-4 left-4 right-4 flex items-end justify-between">
|
||||
<div className="text-white">
|
||||
<h3 className="font-bold text-lg leading-tight">{client.name}</h3>
|
||||
<p className="text-xs opacity-80">{client.end_user_name}</p>
|
||||
<Link href={`/task/client-detail/${client.id}`} className="h-full">
|
||||
<Card900 className="h-full group overflow-hidden hover:shadow-lg transition-all duration-300 border-primary/5 hover:border-primary/20 flex flex-col py-0">
|
||||
<CardContent className="p-0 flex flex-col h-full">
|
||||
<div className="relative h-32 bg-accent/50 overflow-hidden">
|
||||
<LazyImage
|
||||
src={client.photo!}
|
||||
alt={client.name}
|
||||
className="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500"
|
||||
/>
|
||||
<div className="absolute inset-0 bg-linear-to-t from-black/80 via-black/40 to-transparent" />
|
||||
<div className="absolute bottom-4 left-4 right-4 flex items-end justify-between">
|
||||
<div className="text-white">
|
||||
<h3 className="font-bold text-lg leading-tight">{client.name}</h3>
|
||||
<p className="text-xs opacity-80">{client.end_user_name}</p>
|
||||
</div>
|
||||
<Link href={`/task/client-detail/${client.id}`}>
|
||||
<Button size="icon" variant="secondary" className="h-8 w-8 rounded-full opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<ExternalLink className="w-4 h-4" />
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
<Link href={`/task/client-detail/${client.id}`}>
|
||||
<Button size="icon" variant="secondary" className="h-8 w-8 rounded-full opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<ExternalLink className="w-4 h-4" />
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
<div className="p-5 flex flex-col flex-1 justify-between gap-4">
|
||||
<div className="space-y-2">
|
||||
{/* <p className="text-sm leading-relaxed text-muted-foreground line-clamp-3 h-16">
|
||||
<div className="p-5 flex flex-col flex-1 justify-between gap-4">
|
||||
<div className="space-y-2">
|
||||
{/* <p className="text-sm leading-relaxed text-muted-foreground line-clamp-3 h-16">
|
||||
Currently managing a portfolio of <span className="font-bold text-foreground">{projectCount} projects</span> and <span className="font-bold text-foreground">{imCount} internal memos</span>.
|
||||
A dedicated team of <span className="font-bold text-foreground">{assignedEmployeeIds.length} experts</span> is handling <span className="font-bold text-foreground">{woCount} work orders</span> to ensure successful delivery for <span className="italic">{client.endUser}</span>.
|
||||
</p> */}
|
||||
<p className="text-sm leading-relaxed text-muted-foreground line-clamp-3 h-16">
|
||||
{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 &&
|
||||
<span className="font-bold text-foreground">{projectCount} project{projectCount! > 1 ? 's' : ''}</span>
|
||||
}
|
||||
{projectCount! > 0 && imCount > 0 && " and "}
|
||||
{imCount > 0 &&
|
||||
<span className="font-bold text-foreground">{imCount} internal memo{imCount > 1 ? 's' : ''}</span>
|
||||
}
|
||||
.{" "}
|
||||
</>
|
||||
)}
|
||||
{woCount! > 0 && (
|
||||
<>
|
||||
A dedicated team of{" "}
|
||||
<span className="font-bold text-foreground">{userCount} experts</span> is handling{" "}
|
||||
<span className="font-bold text-foreground">{woCount} work order{woCount! > 1 ? 's' : ''}</span>{" "}to ensure successful delivery for <span className="italic">{client.end_user_name}</span>.
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
<p className="text-sm leading-relaxed text-muted-foreground line-clamp-3 h-16">
|
||||
{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 &&
|
||||
<span className="font-bold text-foreground">{projectCount} project{projectCount! > 1 ? 's' : ''}</span>
|
||||
}
|
||||
{projectCount! > 0 && imCount > 0 && " and "}
|
||||
{imCount > 0 &&
|
||||
<span className="font-bold text-foreground">{imCount} internal memo{imCount > 1 ? 's' : ''}</span>
|
||||
}
|
||||
.{" "}
|
||||
</>
|
||||
)}
|
||||
{woCount! > 0 && (
|
||||
<>
|
||||
A dedicated team of{" "}
|
||||
<span className="font-bold text-foreground">{userCount} experts</span> is handling{" "}
|
||||
<span className="font-bold text-foreground">{woCount} work order{woCount! > 1 ? 's' : ''}</span>{" "}to ensure successful delivery for <span className="italic">{client.end_user_name}</span>.
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between pt-4 pb-2 border-t border-border">
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-[10px] uppercase tracking-wider font-semibold text-muted-foreground">Assigned Team</span>
|
||||
<div className="flex -space-x-2 overflow-hidden">
|
||||
{client.users?.slice(0, 5).map((user, key) => {
|
||||
return (
|
||||
<div key={key}>
|
||||
<Tooltip>
|
||||
<TooltipTrigger>
|
||||
<LazyImage src={user?.avatar ? `${process.env.BASE_URL_IMG}/${user?.avatar}` : '/assets/no-avatar.jpg'} alt={user?.fullname!} className="inline-block h-8 w-8 rounded-full border-2 border-background cursor-help hover:scale-110 hover:z-10 transition-transform" />
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<p className="text-xs font-bold">{user?.name}</p>
|
||||
<p className="text-[10px] opacity-80">{user?.position?.name}</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<div className="flex items-center justify-between pt-4 pb-2 border-t border-border">
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-[10px] uppercase tracking-wider font-semibold text-muted-foreground">Assigned Team</span>
|
||||
<div className="flex -space-x-2 overflow-hidden">
|
||||
{client.users?.slice(0, 5).map((user, key) => {
|
||||
return (
|
||||
<div key={key}>
|
||||
<Tooltip>
|
||||
<TooltipTrigger>
|
||||
<LazyImage src={user?.avatar ? `${process.env.BASE_URL_IMG}/${user?.avatar}` : '/assets/no-avatar.jpg'} alt={user?.fullname!} className="inline-block h-8 w-8 rounded-full border-2 border-background cursor-help hover:scale-110 hover:z-10 transition-transform" />
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<p className="text-xs font-bold">{user?.name}</p>
|
||||
<p className="text-[10px] opacity-80">{user?.position?.name}</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{client.users?.length! > 5 &&
|
||||
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-accent ring-2 ring-background text-[10px] font-bold">
|
||||
+{client.users?.length! - 5}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{client.users?.length! > 5 &&
|
||||
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-accent ring-2 ring-background text-[10px] font-bold">
|
||||
+{client.users?.length! - 5}
|
||||
</div>
|
||||
}
|
||||
{client.users?.length === 0 &&
|
||||
<span className="text-[10px] text-muted-foreground italic">No team assigned</span>
|
||||
}
|
||||
}
|
||||
{client.users?.length === 0 &&
|
||||
<span className="text-[10px] text-muted-foreground italic">No team assigned</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 self-end">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8" onClick={(e) => e.stopPropagation()}>
|
||||
<MoreHorizontal className="w-4 h-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem asChild onClick={(e) => e.stopPropagation()}>
|
||||
<Link href={`/task/client-detail/${client.id}`}>View Client Detail</Link>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setShowSelectedData(client); setAction('EDIT') }} onClick={(e) => e.stopPropagation()}>
|
||||
Edit Client
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setShowSelectedData(client); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete Client
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 self-end">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8">
|
||||
<MoreHorizontal className="w-4 h-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={`/task/client-detail/${client.id}`}>View Client Detail</Link>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setShowSelectedData(client); setAction('EDIT') }}>Edit Client</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setShowSelectedData(client); setAction('DELETE') }} className="text-destructive">Delete Client</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card900>
|
||||
</CardContent>
|
||||
</Card900>
|
||||
</Link>
|
||||
</motion.div>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -31,11 +31,12 @@ type FormDataType = Yup.InferType<typeof validationSchema>;
|
||||
|
||||
type Props = {
|
||||
data?: IClient
|
||||
isRedirectToDetail?: boolean
|
||||
onCancel?: VoidFunction
|
||||
onSuccess?: VoidFunction;
|
||||
};
|
||||
|
||||
const FormClient: FC<Props> = ({ data, onSuccess, onCancel }) => {
|
||||
const FormClient: FC<Props> = ({ data, onSuccess, onCancel, isRedirectToDetail }) => {
|
||||
const [showEnduserForm, setShowEndUserForm] = useState(false)
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [currentFile, setCurrentFile] = useState<any | undefined>(undefined);
|
||||
@@ -146,10 +147,10 @@ const FormClient: FC<Props> = ({ 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}` })
|
||||
|
||||
@@ -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) {
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectLabel>Show by</SelectLabel>
|
||||
<SelectItem value="grid">Clients</SelectItem>
|
||||
<SelectItem value="table">Project Assignment</SelectItem>
|
||||
<SelectItem value="clients">Clients</SelectItem>
|
||||
<SelectItem value="assignments">Project Assignment</SelectItem>
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Button className="gap-2" onClick={() => setShowForm(true)}>
|
||||
<Plus className="w-4 h-4" /> Add Client
|
||||
</Button>
|
||||
{currentView === 'clients' ?
|
||||
<Button className="gap-2" onClick={() => setShowForm(true)}>
|
||||
<Plus className="w-4 h-4" /> Add Client
|
||||
</Button>
|
||||
:
|
||||
<Link href='task/project-assignment'>
|
||||
<Button className="gap-2">
|
||||
<Plus className="w-4 h-4" /> Create Project Assignment
|
||||
</Button>
|
||||
</Link>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<FilterComponent hideCategory />
|
||||
|
||||
{showForm && <FormClient onCancel={() => setShowForm(false)} onSuccess={() => { setShowForm(false); router.refresh() }} />}
|
||||
{showForm && <FormClient isRedirectToDetail onCancel={() => setShowForm(false)} onSuccess={() => { setShowForm(false); router.refresh() }} />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -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<string | null>(null);
|
||||
const [draftData, setDraftData] = useState<Partial<ITableData>>({});
|
||||
const [editingId, setEditingId] = useState<number | null>(null);
|
||||
const [draftData, setDraftData] = useState<Partial<any>>({});
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
const [showAddTeamDialog, setShowAddTeamDialog] = useState(false);
|
||||
const [deletedId, setDeletedId] = useState<string | null>(null);
|
||||
const [deletedId, setDeletedId] = useState<number | null>(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 (
|
||||
<>
|
||||
<AlertDialog open={true} >
|
||||
<AlertDialogContent className="min-w-full md:min-w-max">
|
||||
<AlertDialogContent className="min-w-full md:min-w-max py-7">
|
||||
<div className="flex flex-col sm:flex-row justify-between gap-3">
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Manage Team</AlertDialogTitle>
|
||||
@@ -113,7 +123,7 @@ export function ManageTeam({ assignmentId, onClose }: { assignmentId: number, on
|
||||
</AlertDialogHeader>
|
||||
<Button size='sm' variant='outline' onClick={() => setShowAddTeamDialog(true)}><UserPlus /> Add Team</Button>
|
||||
</div>
|
||||
<div className="rounded-md border bg-card overflow-x-auto my-3">
|
||||
<div className="rounded-md border bg-card overflow-x-auto my-5">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
@@ -144,7 +154,7 @@ export function ManageTeam({ assignmentId, onClose }: { assignmentId: number, on
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
:
|
||||
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
|
||||
<TableCell>
|
||||
<div className="flex items-center gap-3">
|
||||
<Avatar className="h-9 w-9">
|
||||
<AvatarImage src={row.avatar} alt={row.fullname} />
|
||||
<AvatarFallback>{row.fullname?.charAt(0)}</AvatarFallback>
|
||||
<AvatarImage src={`${process.env.BASE_URL_IMG}/${row.user.avatar}`} alt={row.user.fullname} />
|
||||
<AvatarFallback>{row.user.fullname?.charAt(0)}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="flex flex-col">
|
||||
<div className="flex items-center gap-1">
|
||||
<span className="font-medium text-sm leading-none">{row.fullname}</span>
|
||||
<Badge variant="secondary" className="ml-auto">{row.position?.name}</Badge>
|
||||
<span className="font-medium text-sm leading-none">{row.user.fullname}</span>
|
||||
<Badge variant="secondary" className="ml-auto">{row.user.position?.name}</Badge>
|
||||
</div>
|
||||
<span className="text-xs text-muted-foreground mt-1">{row.email}</span>
|
||||
<span className="text-xs text-muted-foreground mt-1">{row.user.email}</span>
|
||||
</div>
|
||||
</div>
|
||||
</TableCell>
|
||||
|
||||
@@ -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<Props> = ({ assignmentId, onClose }) => {
|
||||
const [editingId, setEditingId] = useState<string | null>(null);
|
||||
const [editingId, setEditingId] = useState<number | null>(null);
|
||||
const [draftData, setDraftData] = useState<any>({});
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
|
||||
@@ -34,14 +48,14 @@ const UpdateTimelineStatus: FC<Props> = ({ 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<Props> = ({ 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<Props> = ({ 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<Props> = ({ assignmentId, onClose }) => {
|
||||
<TableHead>Status</TableHead>
|
||||
<TableHead>Start Date</TableHead>
|
||||
<TableHead>End Date</TableHead>
|
||||
<TableHead>Note/Remarks</TableHead>
|
||||
<TableHead className="text-right">Action</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
@@ -124,21 +138,21 @@ const UpdateTimelineStatus: FC<Props> = ({ assignmentId, onClose }) => {
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
:
|
||||
existTimeline.map((row: any) => {
|
||||
existTimeline.map((row: IProjectAssignmentTimeline) => {
|
||||
const isEditing = editingId === row.id;
|
||||
const isOtherRowEditing = editingId !== null && editingId !== row.id;
|
||||
|
||||
return (
|
||||
<TableRow key={row.id}>
|
||||
<TableCell>
|
||||
<BadgeStatus status={row.name} />
|
||||
<BadgeStatus status={row.project_assignment_status.name} />
|
||||
</TableCell>
|
||||
|
||||
<TableCell>
|
||||
{isEditing ?
|
||||
<DatePicker date={draftData.start_date_assign as Date | undefined} setDate={(date) => handleDraftChange("start_date_assign", date as any)} />
|
||||
:
|
||||
<span className="text-sm">{row.start_date_assign}</span>
|
||||
<span className="text-sm">{row.start_date ? dayjs(row.start_date).format('MMM DD, YYYY') : null}</span>
|
||||
}
|
||||
</TableCell>
|
||||
|
||||
@@ -146,15 +160,7 @@ const UpdateTimelineStatus: FC<Props> = ({ assignmentId, onClose }) => {
|
||||
{isEditing ?
|
||||
<DatePicker date={draftData.end_date_assign as Date | undefined} setDate={(date) => handleDraftChange("end_date_assign", date as any)} />
|
||||
:
|
||||
<span className="text-sm">{row.end_date_assign}</span>
|
||||
}
|
||||
</TableCell>
|
||||
|
||||
<TableCell>
|
||||
{isEditing ?
|
||||
<Textarea placeholder="Add a note about this status change..." className="min-h-20 w-60" value={draftData.note} onChange={(e) => handleDraftChange("note", e.target.value)} />
|
||||
:
|
||||
<span className="text-sm">{row.note}</span>
|
||||
<span className="text-sm">{row.end_date ? dayjs(row.end_date).format('MMM DD, YYYY') : null}</span>
|
||||
}
|
||||
</TableCell>
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ type Props = {
|
||||
export default async function ClientsPage({ searchParams }: Props) {
|
||||
const params = await searchParams;
|
||||
|
||||
const view = params.view === 'table' ? 'table' : 'grid';
|
||||
const view = params.view === 'assignments' ? 'assignments' : 'clients';
|
||||
const query = (params.q || '').toLowerCase();
|
||||
const status = (params.status || '').toLowerCase();
|
||||
const sort = (params.sort || '').toLowerCase();
|
||||
@@ -35,7 +35,7 @@ export default async function ClientsPage({ searchParams }: Props) {
|
||||
|
||||
{/* Render the correct view based on the URL */}
|
||||
<Suspense fallback={<div className="animate-pulse h-96 bg-accent rounded-xl" />}>
|
||||
{view === 'grid' ?
|
||||
{view === 'clients' ?
|
||||
<ClientGrid clients={filteredClients} />
|
||||
:
|
||||
<AssignmentTable data={filterAssignments} />
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import fetchData from "@/lib/fetchData";
|
||||
import ProjectAssignmentForm from "../client-detail/[client_id]/project-assignments/ProjectAssignmentForm";
|
||||
|
||||
type Props = {
|
||||
searchParams: Promise<{ is_edit?: string; assignment_id?: string }>
|
||||
};
|
||||
|
||||
export default async function CreateAssignmentPage({ searchParams }: Props) {
|
||||
const isEdit = (await searchParams)!.is_edit
|
||||
const assignmentId = (await searchParams)!.assignment_id
|
||||
|
||||
return (
|
||||
<div className="max-w-4xl mx-auto p-6 sm:p-8 pt-6 pb-20">
|
||||
<ProjectAssignmentForm isEdit={isEdit ? true : false} assignmentId={assignmentId as any} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -12,7 +12,7 @@ export interface IProjectAssignment {
|
||||
client: Client
|
||||
end_user: EndUser
|
||||
project?: Project
|
||||
project_status: ProjectStatus
|
||||
project_assignment_status: ProjectStatus
|
||||
wo_code: string
|
||||
wo_description: string
|
||||
wo_name: string
|
||||
@@ -57,10 +57,15 @@ export interface ProjectStatus {
|
||||
|
||||
export interface ProjectAssignmentStatusDetail {
|
||||
id: number
|
||||
date_status_changed: string
|
||||
status: string
|
||||
status_remarks: any
|
||||
created_at?: string
|
||||
end_date?: string
|
||||
start_date?: string
|
||||
updated_at?: string
|
||||
project_assignment_status: ProjectAssignmentStatus
|
||||
}
|
||||
|
||||
export interface ProjectAssignmentStatus {
|
||||
id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface Status {
|
||||
@@ -71,6 +76,9 @@ export interface Status {
|
||||
|
||||
export interface ProjectAssignmentWorkOrderDetail {
|
||||
id: number
|
||||
assigned_date: string
|
||||
start_date: any
|
||||
end_date: any
|
||||
status: string
|
||||
created_at: string
|
||||
user: IUser
|
||||
}
|
||||
@@ -30,6 +30,7 @@ interface ComboboxProps {
|
||||
options: ComboboxOption[];
|
||||
value?: string | number;
|
||||
onChange: (value: string | number | undefined) => void;
|
||||
onSelect?: (option: ComboboxOption) => void;
|
||||
placeholder?: string;
|
||||
searchPlaceholder?: string;
|
||||
emptyText?: string;
|
||||
@@ -44,9 +45,10 @@ export function ComboboxCustomUI({
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
placeholder = "Pilih opsi...",
|
||||
searchPlaceholder = "Cari...",
|
||||
emptyText = "Tidak ditemukan.",
|
||||
onSelect,
|
||||
placeholder = "Select option...",
|
||||
searchPlaceholder = "Search...",
|
||||
emptyText = "No results found.",
|
||||
disabled = false,
|
||||
className,
|
||||
renderTrigger,
|
||||
@@ -96,6 +98,7 @@ export function ComboboxCustomUI({
|
||||
// Toggle selection: if already selected, clear it (undefined), else set new value
|
||||
onChange(isSelected ? undefined : option.value);
|
||||
setOpen(false);
|
||||
onSelect?.(option);
|
||||
}}
|
||||
>
|
||||
{renderOption ? (
|
||||
|
||||
Reference in New Issue
Block a user