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 8addd5b..8748c27 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
@@ -5,13 +5,19 @@ import { useRouter } from 'next/navigation';
import { useForm } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup';
import { motion, AnimatePresence } from 'motion/react';
-import { ArrowLeft, ArrowRight, Save, Briefcase, Clock, Search, Check, CheckCircle, Plus, Building2, CheckCircle2 } from 'lucide-react';
+import {
+ ArrowLeft, ArrowRight, Save, Briefcase, Clock, Search, Check, CheckCircle,
+ Plus, CheckCircle2, RotateCcw, X, ChevronDown, FolderGit2
+} from 'lucide-react';
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
-import { Textarea } from '@/components/ui/textarea';
-import { Card, CardContent, CardHeader, CardTitle, CardDescription, Card900 } from '@/components/ui/card';
+import { Checkbox } from '@/components/ui/checkbox';
+import {
+ InputGroup, InputGroupAddon, InputGroupInput, InputGroupText, InputGroupTextarea
+} from '@/components/ui/input-group';
+import { CardContent, CardHeader, CardTitle, CardDescription, Card900 } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Separator } from '@/components/ui/separator';
import {
@@ -50,8 +56,8 @@ export const assignmentSchema = yup.object({
code: yup.string().required('Project code is required'),
year: yup.string().required('Year is required'),
startDate: yup.date().required('Start date is required'),
- endDate: yup.date().nullable().min(yup.ref('startDate'), 'End date cannot be before start date').default(null),
- description: yup.string().optional().nullable().default(''),
+ endDate: yup.date().required().min(yup.ref('startDate'), 'End date cannot be before start date'),
+ description: yup.string().optional().nullable().max(500, 'Description cannot exceed 500 characters').default(''),
// Work Orders Step (Conditional based on 'type')
workOrder: yup.object().when('type', {
@@ -60,8 +66,8 @@ export const assignmentSchema = yup.object({
name: yup.string().required('Work order name is required'),
code: yup.string().required('Work order code is required'),
startDate: yup.date().required('Start date is required'),
- endDate: yup.date().nullable().default(null),
- description: yup.string().optional().nullable().default(''),
+ endDate: yup.date().required().min(yup.ref('startDate'), 'End date cannot be before start date'),
+ description: yup.string().optional().nullable().max(500, 'Description cannot exceed 500 characters').default(''),
}),
otherwise: (schema) => schema.nullable().notRequired()
})
@@ -81,6 +87,7 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
const [showClientForm, setShowClientForm] = useState(false)
const [selectedClient, setSelectedClient] = useState(client || null)
const [selectedEndUser, setSelectedEndUser] = useState(null)
+ const [isSameAsProject, setIsSameAsProject] = useState(false);
const router = useRouter();
@@ -109,6 +116,34 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
const { data: endUserList, mutate: mutateEndUserList } = useFetchWithAxios('/end-user')
const { data: projectList, mutate: mutateProjectList } = useFetchWithAxios(`/client/project/${formValues.client_id}`)
+ // Sync work order name when "Same as Project Name" is enabled
+ useEffect(() => {
+ if (isSameAsProject) {
+ form.setValue('workOrder.name' as any, formValues.name || '', { shouldValidate: true });
+ }
+ }, [isSameAsProject, formValues.name, form]);
+
+ const handleClearProject = () => {
+ form.setValue('name', '', { shouldValidate: false });
+ form.setValue('code', '', { shouldValidate: false });
+ form.setValue('year', new Date().getFullYear().toString(), { shouldValidate: false });
+ form.setValue('startDate', undefined as any, { shouldValidate: false });
+ form.setValue('endDate', undefined as any, { shouldValidate: false });
+ form.setValue('description', '', { shouldValidate: false });
+ setIsExistProject(false);
+ toast.info('Project form cleared');
+ };
+
+ const handleClearWorkOrder = () => {
+ setIsSameAsProject(false);
+ form.setValue('workOrder.name' as any, '', { shouldValidate: false });
+ form.setValue('workOrder.code' as any, '', { shouldValidate: false });
+ form.setValue('workOrder.startDate' as any, undefined as any, { shouldValidate: false });
+ form.setValue('workOrder.endDate' as any, undefined as any, { shouldValidate: false });
+ form.setValue('workOrder.description' as any, '', { shouldValidate: false });
+ toast.info('Work order form cleared');
+ };
+
// 3. Navigation & Validation Logic
const steps: { id: IStep; label: string }[] = [
{ id: 'type', label: 'Type' },
@@ -142,11 +177,20 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
form.setValue('description', data.project?.description || data.im_description)
form.setValue('workOrder.name' as any, data.wo_name)
- form.setValue('workOrder.code' as any, data.wo_code)
+ let initialWoCode = data.wo_code || '';
+ const prjCode = data.project?.code || data.im_code || '';
+ if (prjCode && initialWoCode.startsWith(`${prjCode}-`)) {
+ initialWoCode = initialWoCode.slice(prjCode.length + 1);
+ }
+ form.setValue('workOrder.code' as any, initialWoCode)
form.setValue('workOrder.startDate' as any, data.wo_start_date)
form.setValue('workOrder.endDate' as any, data.wo_end_date)
form.setValue('workOrder.description' as any, data.wo_description)
+ if (data.wo_name && (data.project?.name || data.im_name) && data.wo_name === (data.project?.name || data.im_name)) {
+ setIsSameAsProject(true);
+ }
+
setStep('clients')
setIsExistAssignment(res.data.data)
@@ -193,6 +237,15 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
const onSubmit = async (payload: AssignmentFormValues) => {
setIsLoading(true);
+ const projectCode = payload.code?.trim() || '';
+ const rawWoCode = ((payload.workOrder as any)?.code || '').trim();
+ let finalWoCode = '';
+ if (rawWoCode) {
+ finalWoCode = rawWoCode.startsWith(`${projectCode}-`)
+ ? rawWoCode
+ : `${projectCode}-${rawWoCode}`;
+ }
+
const newPayload = {
"client_id": Number(payload.client_id),
"end_user_id": payload.end_user_id ? Number(payload.end_user_id) : null,
@@ -211,8 +264,8 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
"project_end_date": assignmentType === 'Project' ? payload.endDate ? dayjs(payload.endDate).format('YYYY-MM-DD') : '' : '',
"project_description": assignmentType === 'Project' ? payload.description : '',
- "wo_code": (payload.workOrder as any).code,
- "wo_name": (payload.workOrder as any).name,
+ "wo_code": assignmentType === 'Project' ? finalWoCode : '',
+ "wo_name": (payload.workOrder as any)?.name || '',
"wo_start_date": (payload.workOrder as any).startDate ? dayjs((payload.workOrder as any).startDate).format('YYYY-MM-DD') : '',
"wo_end_date": (payload.workOrder as any).endDate ? dayjs((payload.workOrder as any).endDate).format('YYYY-MM-DD') : '',
"wo_description": (payload.workOrder as any).description,
@@ -301,7 +354,7 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
(
- field.onChange('Project')}
+ 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")}
>
@@ -315,9 +368,9 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
-
+
- field.onChange('IM')}
+ 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")}
>
@@ -331,7 +384,7 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
-
+
@@ -401,7 +454,7 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
renderOption={(option, isSelected) => {
const user = option.originalData as IEndUser;
return (
-
+
@@ -435,65 +488,221 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
{/* STEP 3: DETAILS */}
{step === 'details' && (
-
- {assignmentType === 'IM' ? 'Internal Memo' : 'Project'} Details
- Provide the basic information for this assignment.
+
+
+ {assignmentType === 'IM' ? 'Internal Memo' : 'Project'} Details
+ Provide the basic information for this assignment.
+
+
+ {/* Existing Project Selector / Linked Hero Card */}
+ {assignmentType === 'Project' && (
+ !isExistProject ? (
+
+
+
+
+ Import Existing Project
+
+ Optional
+
+
+
+ Select an existing project for {selectedClient?.name || 'this client'} to autofill information, or create a new one below.
+
+
+
+
+
+
+
+
+
+
+ No existing projects found.
+
+ {projectList?.map((p: IProject) => (
+ {
+ form.setValue('name', p.name!, { shouldValidate: true });
+ form.setValue('code', p.code!, { shouldValidate: true });
+ form.setValue('year', String(p.year), { shouldValidate: true });
+ form.setValue('startDate', new Date(p.start_date!), { shouldValidate: true });
+ form.setValue('endDate', new Date(p.end_date!), { shouldValidate: true });
+ form.setValue('description', p.description || '', { shouldValidate: true });
+
+ setOpenProjectSearch(false);
+ setIsExistProject(true);
+ toast.info(`Autofilled details from ${p.name}`);
+ }}
+ className="cursor-pointer py-2.5 px-3"
+ >
+
+
+
+
+ {p.name}
+
+
+
+ # {p.code}
+
+ •
+ Year: {p.year}
+
+
+
+
+ ))}
+
+
+
+
+
+
+ ) : (
+
+
+
+
+
+ Existing Project Linked
+
+
+ Code: # {formValues.code}
+
+
+
+
+
+
+
+
+
+
+
+ No existing projects found.
+
+ {projectList?.map((p: IProject) => (
+ {
+ form.setValue('name', p.name!, { shouldValidate: true });
+ form.setValue('code', p.code!, { shouldValidate: true });
+ form.setValue('year', String(p.year), { shouldValidate: true });
+ form.setValue('startDate', new Date(p.start_date!), { shouldValidate: true });
+ form.setValue('endDate', new Date(p.end_date!), { shouldValidate: true });
+ form.setValue('description', p.description || '', { shouldValidate: true });
+
+ setOpenProjectSearch(false);
+ setIsExistProject(true);
+ toast.info(`Switched project to ${p.name}`);
+ }}
+ className="cursor-pointer py-2.5 px-3"
+ >
+
+
+
+
+ {p.name}
+
+
+
+ {p.code}
+
+ •
+ Year: {p.year}
+
+
+
+
+ ))}
+
+
+
+
+
+
+
+
+
+
+
+ {formValues.name}
+
+
+ Year: {formValues.year}
+ {formValues.startDate && (
+ <>
+ •
+
+ Timeline:{" "}
+
+ {dayjs(formValues.startDate).format('DD MMM YYYY')} - {formValues.endDate ? dayjs(formValues.endDate).format('DD MMM YYYY') : 'Ongoing'}
+
+
+ >
+ )}
+
+
+
+
+ Fields below are locked and autofilled from this existing project. Click Clear / Create New to enter new project details manually.
+
+
+ )
+ )}
+
(
{assignmentType === 'Project' ? "Project" : "Internal Memo"} Name
-
-
-
-
-
- {assignmentType === 'Project' && (
-
-
-
-
-
-
-
-
-
- No projects found.
-
- {projectList.map((p: IProject) => (
- {
- form.setValue('name', p.name!, { shouldValidate: true });
- form.setValue('code', p.code!, { shouldValidate: true });
- form.setValue('year', String(p.year), { shouldValidate: true });
- form.setValue('startDate', new Date(p.start_date!), { shouldValidate: true });
- form.setValue('endDate', new Date(p.end_date!), { shouldValidate: true });
- form.setValue('description', p.description!, { shouldValidate: true });
-
- setOpenProjectSearch(false);
- setIsExistProject(true)
- toast.info(`Autofilled details from ${p.name}`);
- }}
- >
-
- {p?.name!}
-
- ))}
-
-
-
-
-
-
- )}
-
-
+
+
+
)}
@@ -533,70 +742,198 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
)} />
-
(
-
- Description
-
-
-
-
-
- )} />
+ {
+ const charCount = field.value?.length || 0;
+ const maxLen = 500;
+ return (
+
+ Description (Optional)
+
+
+
+
+
+ {maxLen - charCount} characters left
+
+
+
+
+
+
+ );
+ }} />
)}
{/* STEP 4: WORK ORDERS */}
{step === 'work-orders' && (
-
-
-
Work Order
-
Define the initial task for this project.
-
-
-
-
-
- (
-
- WO Start Date
-
-
-
- )} />
- (
-
- WO End Date
-
-
-
- )} />
-
- (
-
- WO Description
-
+ );
+ }}
+ />
+
+ {/* Dates (Start and End) */}
+
+ (
+
+ WO Start Date
+
)} />
-
-
-
+ (
+
+ WO End Date
+
+
+
+ )} />
+
+
+ {/* Description with character counter */}
+ {
+ const charCount = field.value?.length || 0;
+ const maxLen = 500;
+ return (
+
+ WO Description (Optional)
+
+
+
+
+
+ {maxLen - charCount} characters left
+
+
+
+
+
+
+ );
+ }} />
+
+
)}
{/* STEP 5: REVIEW */}
@@ -608,7 +945,7 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
-
+
Project Assignment Overview
{formValues.type}
@@ -682,42 +1019,84 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
- {(formValues.workOrder as any)?.name && (
-
-
-
-
-
-
-
-
-
-
-
+ {formValues.type === 'Project' && (formValues.workOrder as any)?.name && (() => {
+ const rawWoCode = ((formValues.workOrder as any)?.code || '').trim();
+ const prjCode = formValues.code?.trim() || '';
+ const fullWoCode = rawWoCode
+ ? (prjCode && !rawWoCode.startsWith(`${prjCode}-`) ? `${prjCode}-${rawWoCode}` : rawWoCode)
+ : '-';
+ const woStart = (formValues.workOrder as any)?.startDate
+ ? dayjs((formValues.workOrder as any).startDate).format('DD MMM YYYY')
+ : null;
+ const woEnd = (formValues.workOrder as any)?.endDate
+ ? dayjs((formValues.workOrder as any).endDate).format('DD MMM YYYY')
+ : null;
+ const scheduleStr = woStart && woEnd
+ ? `${woStart} - ${woEnd}`
+ : woStart
+ ? `From ${woStart}`
+ : 'Not specified';
+
+ return (
+
+
+
+
+ Work Order Detail
+
+
+
+ Initial Assignment
+
+
+
+
+ {/* Top Section: Badges, Schedule & Title */}
+
+
+
+
+
+ Work Order
+
+
+ Code: {fullWoCode}
+
+
+
+
+ Schedule:
+ {scheduleStr}
+
-
-
{(formValues.workOrder as any).name}
-
{(formValues.workOrder as any).description}
+
+
+
+
+ {(formValues.workOrder as any).name}
+
-
-
-
-
{(formValues.workOrder as any).code || '-'}
-
-
-
-
- {(formValues.workOrder as any).startDate ? new Date((formValues.workOrder as any).startDate).toLocaleDateString('en-US', { month: 'short', day: 'numeric' }) : '-'} — {(formValues.workOrder as any).endDate ? new Date((formValues.workOrder as any).endDate).toLocaleDateString('en-US', { month: 'short', day: 'numeric' }) : '-'}
+
+ {/* Bottom Section: Description (if available) */}
+ {(formValues.workOrder as any).description && (
+
+
+
+ {(formValues.workOrder as any).description}
-
+ )}
-
- )}
+ );
+ })()}
-
+
diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-assignments/loading.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-assignments/loading.tsx
new file mode 100644
index 0000000..0f81a1e
--- /dev/null
+++ b/app/(dashboard)/task/client-detail/[client_id]/project-assignments/loading.tsx
@@ -0,0 +1,74 @@
+export default function Loading() {
+ return (
+
+ {/* Header: Back link and Title Skeleton */}
+
+
+ {/* Stepper Progress Skeleton */}
+
+ {/* Progress bar line */}
+
+
+ {/* Step Circles & Labels */}
+
+ {Array.from({ length: 5 }).map((_, i) => (
+
+ ))}
+
+
+
+ {/* Main Form Content Skeleton (Card900 style) */}
+
+ {/* Card Title & Action button */}
+
+
+ {/* 2-Col Selection / Input fields placeholder */}
+
+
+
+ {/* Bottom Navigation Sticky Bar Skeleton */}
+
+
+ );
+}
diff --git a/components/ui/checkbox.tsx b/components/ui/checkbox.tsx
new file mode 100644
index 0000000..d2e9a1a
--- /dev/null
+++ b/components/ui/checkbox.tsx
@@ -0,0 +1,32 @@
+"use client"
+
+import * as React from "react"
+import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
+import { Check } from "lucide-react"
+
+import { cn } from "@/lib/utils"
+
+function Checkbox({
+ className,
+ ...props
+}: React.ComponentProps
) {
+ return (
+
+
+
+
+
+ )
+}
+
+export { Checkbox }
diff --git a/components/ui/input-group.tsx b/components/ui/input-group.tsx
new file mode 100644
index 0000000..99c0996
--- /dev/null
+++ b/components/ui/input-group.tsx
@@ -0,0 +1,164 @@
+"use client"
+
+import * as React from "react"
+import { cva, type VariantProps } from "class-variance-authority"
+import { cn } from "@/lib/utils"
+
+import { Button } from "@/components/ui/button"
+
+function InputGroup({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+
+ )
+}
+
+const inputGroupAddonVariants = cva(
+ "flex select-none text-muted-foreground group-data-[disabled=true]/input-group:opacity-50 shrink-0",
+ {
+ variants: {
+ align: {
+ "inline-start":
+ "order-first h-full px-3.5 bg-muted/40 dark:bg-zinc-900 border-r border-input text-xs font-mono font-medium text-foreground/80 flex items-center justify-center",
+ "inline-end":
+ "order-last h-full px-3.5 bg-muted/40 dark:bg-zinc-900 border-l border-input text-xs font-mono font-medium text-foreground/80 flex items-center justify-center",
+ "block-start":
+ "order-first w-full justify-start px-3 py-2 border-b border-input bg-muted/20 dark:bg-zinc-900/40 text-xs",
+ "block-end":
+ "order-last w-full flex items-center justify-between px-3 py-1.5 border-t border-input bg-muted/20 dark:bg-zinc-900/40 text-xs",
+ },
+ },
+ defaultVariants: {
+ align: "inline-start",
+ },
+ }
+)
+
+function InputGroupAddon({
+ className,
+ align = "inline-start",
+ ...props
+}: React.ComponentProps<"div"> & VariantProps) {
+ return (
+ {
+ if ((e.target as HTMLElement).closest("button")) {
+ return
+ }
+ e.currentTarget.parentElement?.querySelector("input, textarea")?.focus()
+ }}
+ {...props}
+ />
+ )
+}
+
+const inputGroupButtonVariants = cva(
+ "flex items-center gap-2 text-sm shadow-none",
+ {
+ variants: {
+ size: {
+ xs: "h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-2 has-[>svg]:px-2 [&>svg:not([class*='size-'])]:size-3.5",
+ sm: "h-8 gap-1.5 rounded-md px-2.5 has-[>svg]:px-2.5",
+ "icon-xs":
+ "size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0",
+ "icon-sm": "size-8 p-0 has-[>svg]:p-0",
+ },
+ },
+ defaultVariants: {
+ size: "xs",
+ },
+ }
+)
+
+function InputGroupButton({
+ className,
+ type = "button",
+ variant = "ghost",
+ size = "xs",
+ ...props
+}: Omit, "size"> &
+ VariantProps) {
+ return (
+
+ )
+}
+
+function InputGroupText({ className, ...props }: React.ComponentProps<"span">) {
+ return (
+
+ )
+}
+
+function InputGroupInput({
+ className,
+ ...props
+}: React.ComponentProps<"input">) {
+ return (
+
+ )
+}
+
+function InputGroupTextarea({
+ className,
+ ...props
+}: React.ComponentProps<"textarea">) {
+ return (
+
+ )
+}
+
+export {
+ InputGroup,
+ InputGroupAddon,
+ InputGroupButton,
+ InputGroupText,
+ InputGroupInput,
+ InputGroupTextarea,
+}