mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 21:36:28 +00:00
Add 'Promote to Project' flow for assignments
Introduce a promote-to-project workflow and related UI/logic changes. Key changes: - Add Promote button/link in AssignmentDetail, AssignmentGrid, and AssignmentList to open the ProjectAssignmentForm in promote mode. - Propagate isPromote flag through pages and ProjectAssignmentForm: lock type to Project, prevent selecting IM, adjust headings/labels, and show badges. - When promoting, set payload fields (project_id, im_id) accordingly and POST to create a Project from an existing IM. - Autofill project/work-order fields from existing project selection and fetch WO sequence when project selected. - Update validation messages, toasts, and minor UI/text sizing tweaks. - Update UpdateAdministrationStatus to read/write notes (project_assignment_status_notes) and use it as initial remark. - Extend IProjectAssignment type with im_id and project_assignment_status_notes. - Remove .env.production.local (deleted). Files changed: multiple components under app/(dashboard)/task and type.assignment.ts (see diff).
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
BASE_PATH = ""
|
||||
NEXT_PUBLIC_APP_URL="https://dev-hats.hisnutech.my.id"
|
||||
|
||||
BASE_URL_API = https://api-hats-dev.hisnutech.my.id/api/v1
|
||||
BASE_URL_IMG = https://api-hats.hisnutech.my.id/
|
||||
|
||||
NEXTAUTH_URL = https://dev-hats.hisnutech.my.id
|
||||
NEXTAUTH_URL_INTERNAL = http://36.66.3.44:7005
|
||||
|
||||
NEXTAUTH_SECRET = 4339d50684523526005c1fcb34be0bb1
|
||||
|
||||
FIREBASE_API_KEY = AIzaSyAEkZCHhnyatsNiZ2dpjeaz6JqXYknKKHk
|
||||
FIREBASE_APP_ID = "1:422528660020:web:db16e1cba4d357e32f1061"
|
||||
|
||||
DEVICE_CODE = "40001"
|
||||
NEXT_PUBLIC_HATS_SUPPORT_NAME = "Amalia"
|
||||
NEXT_PUBLIC_HATS_SUPPORT_PHONE = "6285214074002"
|
||||
NEXT_PUBLIC_APP_VERSION = "v1.2.0"
|
||||
NEXT_PUBLIC_MANAGER_USER_ID = '2'
|
||||
|
||||
NEXT_PUBLIC_S3_IMAGE_URL = https://cdn.hisnutech.my.id/public
|
||||
+13
-1
@@ -15,7 +15,7 @@ import Link from 'next/link';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import dayjs from 'dayjs';
|
||||
import {
|
||||
ArrowLeft, Briefcase, Calendar, ChevronDown, ClipboardCheck, Clock, ExternalLink, FileText,
|
||||
ArrowLeft, ArrowUpRight, Briefcase, Calendar, ChevronDown, ClipboardCheck, Clock, ExternalLink, FileText,
|
||||
FolderGit2, History, LayoutGrid, List, Mail, Phone, UserPlus, Users,
|
||||
} from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
@@ -146,6 +146,18 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col sm:flex-row gap-2.5 w-full md:w-auto">
|
||||
{!isWorkOrder && (
|
||||
<Button
|
||||
variant="outline"
|
||||
asChild
|
||||
className="w-full shrink-0 gap-2 border-his/40 text-his hover:bg-his/10 transition-transform active:scale-[0.98] md:w-auto"
|
||||
>
|
||||
<Link href={owner?.id ? `/task/client-detail/${owner.id}/project-assignments?is_edit=true&assignment_id=${assignment.id}&promote=true` : `/task/project-assignment?is_edit=true&assignment_id=${assignment.id}&promote=true`}>
|
||||
<ArrowUpRight className="h-4 w-4 text-his" />
|
||||
Promote to Project
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setAction('UPDATE_ADMIN_STATUS')}
|
||||
|
||||
+147
-73
@@ -1,13 +1,13 @@
|
||||
"use client"
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useRouter, useSearchParams } 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, CheckCircle2, RotateCcw, X, ChevronDown, FolderGit2
|
||||
Plus, CheckCircle2, RotateCcw, X, ChevronDown, FolderGit2, ArrowUpRight
|
||||
} from 'lucide-react';
|
||||
|
||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form';
|
||||
@@ -56,7 +56,7 @@ 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().required().min(yup.ref('startDate'), 'End date cannot be before start date'),
|
||||
endDate: yup.date().required('End date is 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')
|
||||
@@ -66,7 +66,7 @@ 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().required('Start date is required').min(yup.ref('startDate'), 'End date cannot be before start date'),
|
||||
endDate: yup.date().required('End date is 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()
|
||||
@@ -76,21 +76,22 @@ export const assignmentSchema = yup.object({
|
||||
// Infer the TypeScript type from the Yup schema
|
||||
export type AssignmentFormValues = yup.InferType<typeof assignmentSchema>;
|
||||
|
||||
export default function ProjectAssignmentForm({ client, clientId, isEdit, assignmentId }: { client?: IClient, clientId?: string, isEdit?: boolean, assignmentId?: string }) {
|
||||
const [existAssignment, setIsExistAssignment] = useState<IProjectAssignment | null>(null)
|
||||
export default function ProjectAssignmentForm(
|
||||
{ client, clientId, isEdit, assignmentId, isPromote }: { client?: IClient; clientId?: string; isEdit?: boolean; assignmentId?: string; isPromote?: boolean; }
|
||||
) {
|
||||
const router = useRouter();
|
||||
const [existAssignment, setIsExistAssignment] = useState<IProjectAssignment | null>(null);
|
||||
const [step, setStep] = useState<IStep>('type');
|
||||
const [loading, setIsLoading] = useState(false);
|
||||
const [isFullLoading, setIsFullLoading] = useState(false)
|
||||
const [isExistProject, setIsExistProject] = useState(false)
|
||||
const [isFullLoading, setIsFullLoading] = useState(false);
|
||||
const [isExistProject, setIsExistProject] = useState<any>(null);
|
||||
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 [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 [isSameAsProject, setIsSameAsProject] = useState(false);
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const form = useForm<AssignmentFormValues>({
|
||||
resolver: yupResolver(assignmentSchema),
|
||||
defaultValues: {
|
||||
@@ -130,18 +131,21 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
|
||||
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');
|
||||
|
||||
setIsExistProject(null);
|
||||
toast.warning('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');
|
||||
|
||||
toast.warning('Work order form cleared');
|
||||
};
|
||||
|
||||
// 3. Navigation & Validation Logic
|
||||
@@ -156,54 +160,61 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
|
||||
const currentStepIndex = steps.findIndex(s => s.id === step);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isEdit) return
|
||||
if (!isEdit) return;
|
||||
|
||||
async function getAssignmentDetail() {
|
||||
setIsFullLoading(true)
|
||||
const res: any = await serverApiCall('GET', `/project-assignment/${assignmentId}`)
|
||||
setIsFullLoading(true);
|
||||
const res: any = await serverApiCall('GET', `/project-assignment/${assignmentId}`);
|
||||
|
||||
console.log(res)
|
||||
if (res.success) {
|
||||
const data: IProjectAssignment = res.data.data
|
||||
form.setValue('type', data.project?.code ? 'Project' : 'IM')
|
||||
const data: IProjectAssignment = res.data.data;
|
||||
form.setValue('type', isPromote ? 'Project' : data.project?.code ? 'Project' : 'IM');
|
||||
|
||||
form.setValue('client_id', data.client.id)
|
||||
form.setValue('end_user_id', data.end_user.id)
|
||||
form.setValue('client_id', data.client?.id);
|
||||
form.setValue('end_user_id', data.end_user?.id);
|
||||
setSelectedClient(data.client as any);
|
||||
setSelectedEndUser(data.end_user as any);
|
||||
|
||||
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)
|
||||
form.setValue('endDate', data.project?.end_date || data.im_end_date)
|
||||
form.setValue('description', data.project?.description || data.im_description)
|
||||
form.setValue('name', data.project?.name || data.im_name || '');
|
||||
form.setValue('code', data.project?.code || data.im_code || '');
|
||||
form.setValue('year', String(data.project?.year || data.im_year || new Date().getFullYear()));
|
||||
const sDate = data.project?.start_date || data.im_start_date;
|
||||
const eDate = data.project?.end_date || data.im_end_date;
|
||||
form.setValue('startDate', sDate ? new Date(sDate) : undefined as any);
|
||||
form.setValue('endDate', eDate ? new Date(eDate) : undefined as any);
|
||||
form.setValue('description', data.project?.description || data.im_description || '');
|
||||
|
||||
form.setValue('workOrder.name' as any, data.wo_name)
|
||||
const defaultWoName = data.wo_name;
|
||||
form.setValue('workOrder.name' as any, data.wo_name);
|
||||
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)
|
||||
form.setValue('workOrder.code' as any, initialWoCode);
|
||||
const woSDate = data.wo_start_date;
|
||||
const woEDate = data.wo_end_date;
|
||||
form.setValue('workOrder.startDate' as any, woSDate ? new Date(woSDate) : undefined as any);
|
||||
form.setValue('workOrder.endDate' as any, woEDate ? new Date(woEDate) : undefined as any);
|
||||
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)) {
|
||||
if (defaultWoName.toLowerCase() === data.project?.name.toLowerCase()) {
|
||||
setIsSameAsProject(true);
|
||||
}
|
||||
|
||||
setStep('clients')
|
||||
|
||||
setIsExistAssignment(res.data.data)
|
||||
setStep(isPromote ? 'details' : 'clients');
|
||||
setIsExistAssignment(res.data.data);
|
||||
} else {
|
||||
toast.error('Fail to get detail assignment', {
|
||||
description: `(${res.code || '-'}) ${res.message}`
|
||||
})
|
||||
});
|
||||
}
|
||||
setIsFullLoading(false)
|
||||
setIsFullLoading(false);
|
||||
}
|
||||
|
||||
getAssignmentDetail()
|
||||
}, [isEdit, assignmentId])
|
||||
getAssignmentDetail();
|
||||
}, [isEdit, assignmentId, isPromote]);
|
||||
|
||||
const handleNext = async () => {
|
||||
let isStepValid = false;
|
||||
@@ -228,8 +239,14 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
|
||||
};
|
||||
|
||||
const handleBack = () => {
|
||||
if (step === 'clients') setStep('type');
|
||||
if (step === 'details') setStep('clients');
|
||||
if (step === 'clients') {
|
||||
if (isPromote) {
|
||||
toast.info('Assignment type is locked to Project during promotion');
|
||||
return;
|
||||
}
|
||||
setStep('type');
|
||||
}
|
||||
else if (step === 'details') setStep('clients');
|
||||
else if (step === 'work-orders') setStep('details');
|
||||
else if (step === 'review') setStep(assignmentType === 'Project' ? 'work-orders' : 'details');
|
||||
};
|
||||
@@ -246,7 +263,7 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
|
||||
: `${projectCode}-${rawWoCode}`;
|
||||
}
|
||||
|
||||
const newPayload = {
|
||||
const newPayload: any = {
|
||||
"client_id": Number(payload.client_id),
|
||||
"end_user_id": payload.end_user_id ? Number(payload.end_user_id) : null,
|
||||
|
||||
@@ -274,28 +291,52 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
|
||||
"project_assignment_status_id": isEdit ? existAssignment?.project_assignment_status?.id : 1,
|
||||
|
||||
"note": isEdit ? existAssignment?.note : "",
|
||||
};
|
||||
|
||||
if (existAssignment || isExistProject) {
|
||||
newPayload['project_id'] = isExistProject?.id || existAssignment?.project?.id
|
||||
}
|
||||
|
||||
let res: any
|
||||
if (isEdit) {
|
||||
res = await serverApiCall('PUT', `/project-assignment/${assignmentId}`, newPayload)
|
||||
if (isPromote && existAssignment) {
|
||||
newPayload['im_id'] = existAssignment?.im_id || existAssignment?.id
|
||||
}
|
||||
|
||||
let res: any;
|
||||
if (isPromote) {
|
||||
res = await serverApiCall('POST', '/project-assignment', newPayload);
|
||||
} else {
|
||||
res = await serverApiCall('POST', '/project-assignment', newPayload)
|
||||
if (isEdit) {
|
||||
res = await serverApiCall('PUT', `/project-assignment/${assignmentId}`, newPayload);
|
||||
} else {
|
||||
res = await serverApiCall('POST', '/project-assignment', newPayload);
|
||||
}
|
||||
}
|
||||
|
||||
setIsLoading(false)
|
||||
setIsLoading(false);
|
||||
if (res.success) {
|
||||
toast.success(`${payload.type} saved successfully`);
|
||||
toast.success(isPromote ? 'Internal Memo successfully promoted to Project' : `${payload.type} saved successfully`);
|
||||
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}` })
|
||||
toast.error(`Fail to save assignment`, { description: `(${res.code || '-'}) ${res.message}` });
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!isExistProject) return
|
||||
|
||||
async function getWOCode() {
|
||||
const res = await serverApiCall('GET', `/project-assignment/project-sequences?project_id=${isExistProject?.id}`)
|
||||
if (res.success) form.setValue('workOrder.code' as any, String((res.data as any)?.data))
|
||||
else form.setValue('workOrder.code' as any, "")
|
||||
}
|
||||
|
||||
getWOCode();
|
||||
}, [isExistProject])
|
||||
|
||||
return (
|
||||
<>
|
||||
<Form {...form}>
|
||||
@@ -308,8 +349,21 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
|
||||
<ArrowLeft className="w-5 h-5" />
|
||||
</Button>
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold">{isEdit ? 'Update' : 'Create Project'} Assignment</h1>
|
||||
<p className="text-muted-foreground">{clientId ? `For ${client?.name}` : 'Manage the creation and modification of assignment information'}</p>
|
||||
<div className="flex items-center gap-2.5">
|
||||
<h1 className="text-3xl font-bold">{isPromote ? 'Promote to Project' : isEdit ? 'Update Assignment' : 'Create Project Assignment'}</h1>
|
||||
{isPromote && (
|
||||
<Badge className="bg-his text-white font-medium text-xs px-2 py-0.5">
|
||||
Promote Action
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-muted-foreground">
|
||||
{isPromote
|
||||
? 'Convert this Internal Memo into a Project with Work Orders'
|
||||
: clientId
|
||||
? `For ${client?.name}`
|
||||
: 'Manage the creation and modification of assignment information'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -355,8 +409,13 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
|
||||
<FormItem>
|
||||
<div className="grid md:grid-cols-2 gap-6">
|
||||
<Card900 onClick={() => field.onChange('Project')}
|
||||
className={cn("cursor-pointer transition-all hover:border-his dark:hover:border-his duration-400", field.value === 'Project' && "ring-2 ring-his/10 border-his dark:ring-his/10 dark:border-his")}
|
||||
className={cn("cursor-pointer transition-all hover:border-his dark:hover:border-his duration-400 relative", field.value === 'Project' && "ring-2 ring-his/10 border-his dark:ring-his/10 dark:border-his")}
|
||||
>
|
||||
{isPromote && (
|
||||
<Badge className="absolute top-4 right-4 bg-his text-white text-[11px] font-medium">
|
||||
Locked for Promotion
|
||||
</Badge>
|
||||
)}
|
||||
<CardContent className="p-8 flex flex-col items-center text-center space-y-4">
|
||||
<div className="w-16 h-16 rounded-2xl bg-orange-500/10 text-orange-500 flex items-center justify-center">
|
||||
<Briefcase className="w-8 h-8" />
|
||||
@@ -370,9 +429,24 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
|
||||
</CardContent>
|
||||
</Card900>
|
||||
|
||||
<Card900 onClick={() => 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")}
|
||||
<Card900 onClick={() => {
|
||||
if (isPromote) {
|
||||
toast.info('Cannot select Internal Memo while promoting to Project');
|
||||
return;
|
||||
}
|
||||
field.onChange('IM');
|
||||
}}
|
||||
className={cn(
|
||||
"cursor-pointer transition-all hover:border-his dark:hover:border-his duration-400 relative",
|
||||
field.value === 'IM' && "ring-2 ring-his/10 border-his dark:ring-his/10 dark:border-his",
|
||||
isPromote && "opacity-40 cursor-not-allowed hover:border-border"
|
||||
)}
|
||||
>
|
||||
{isPromote && (
|
||||
<Badge variant="outline" className="absolute top-4 right-4 text-[10px] text-muted-foreground border-border/80">
|
||||
Unavailable
|
||||
</Badge>
|
||||
)}
|
||||
<CardContent className="p-8 flex flex-col items-center text-center space-y-4">
|
||||
<div className="w-16 h-16 rounded-2xl bg-purple-500/10 text-purple-500 flex items-center justify-center">
|
||||
<Clock className="w-8 h-8" />
|
||||
@@ -511,12 +585,12 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
|
||||
<div className="space-y-0.5">
|
||||
<div className="flex items-center gap-2">
|
||||
<FolderGit2 className="w-4 h-4 text-primary" />
|
||||
<span className="text-xs font-semibold text-foreground">Import Existing Project</span>
|
||||
<span className="text-sm font-semibold text-foreground">Import Existing Project</span>
|
||||
<Badge variant="outline" className="text-[10px] font-normal py-0 h-5 border-border/70 text-muted-foreground">
|
||||
Optional
|
||||
</Badge>
|
||||
</div>
|
||||
<p className="text-[11px] text-muted-foreground">
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Select an existing project for {selectedClient?.name || 'this client'} to autofill information, or create a new one below.
|
||||
</p>
|
||||
</div>
|
||||
@@ -553,7 +627,7 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
|
||||
form.setValue('description', p.description || '', { shouldValidate: true });
|
||||
|
||||
setOpenProjectSearch(false);
|
||||
setIsExistProject(true);
|
||||
setIsExistProject(p);
|
||||
toast.info(`Autofilled details from ${p.name}`);
|
||||
}}
|
||||
className="cursor-pointer py-2.5 px-3"
|
||||
@@ -561,11 +635,11 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
|
||||
<div className="flex items-start gap-2.5 w-full min-w-0">
|
||||
<FolderGit2 className="w-4 h-4 text-primary shrink-0 mt-0.5" />
|
||||
<div className="flex flex-col min-w-0 flex-1">
|
||||
<span className="font-medium text-xs text-foreground leading-snug wrap-break-word">
|
||||
<span className="font-medium text-sm text-foreground leading-snug wrap-break-word">
|
||||
{p.name}
|
||||
</span>
|
||||
<div className="flex items-center gap-2 mt-1 text-[11px] text-muted-foreground font-mono">
|
||||
<span className="px-1.5 py-0.2 rounded bg-muted/60 dark:bg-zinc-800 text-[10px]">
|
||||
<div className="flex items-center gap-2 mt-1 text-xs text-muted-foreground font-mono">
|
||||
<span className="pr-1.5 py-0.2 rounded bg-muted/60 dark:bg-zinc-800">
|
||||
# {p.code}
|
||||
</span>
|
||||
<span>•</span>
|
||||
@@ -624,7 +698,7 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
|
||||
form.setValue('description', p.description || '', { shouldValidate: true });
|
||||
|
||||
setOpenProjectSearch(false);
|
||||
setIsExistProject(true);
|
||||
setIsExistProject(p);
|
||||
toast.info(`Switched project to ${p.name}`);
|
||||
}}
|
||||
className="cursor-pointer py-2.5 px-3"
|
||||
@@ -632,12 +706,12 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
|
||||
<div className="flex items-start gap-2.5 w-full min-w-0">
|
||||
<FolderGit2 className="w-4 h-4 text-primary shrink-0 mt-0.5" />
|
||||
<div className="flex flex-col min-w-0 flex-1">
|
||||
<span className="font-medium text-xs text-foreground leading-snug wrap-break-word">
|
||||
<span className="font-mediums text-foreground leading-snug wrap-break-word">
|
||||
{p.name}
|
||||
</span>
|
||||
<div className="flex items-center gap-2 mt-1 text-[11px] text-muted-foreground font-mono">
|
||||
<span className="px-1.5 py-0.2 rounded bg-muted/60 dark:bg-zinc-800 text-[10px]">
|
||||
{p.code}
|
||||
<div className="flex items-center gap-2 mt-1 text-muted-foreground font-mono text-xs">
|
||||
<span className="pr-1.5 py-0.2 rounded bg-muted/60 dark:bg-zinc-800">
|
||||
# {p.code}
|
||||
</span>
|
||||
<span>•</span>
|
||||
<span>Year: {p.year}</span>
|
||||
@@ -655,10 +729,10 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-7 px-2 text-xs text-muted-foreground hover:text-destructive hover:bg-destructive/10"
|
||||
className="h-7 px-2 text-xs text-destructive hover:bg-destructive"
|
||||
onClick={handleClearProject}
|
||||
>
|
||||
<X className="w-3.5 h-3.5 mr-1" /> Clear / Create New
|
||||
<X className="w-3.5 h-3.5" /> Clear / Create New
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -683,7 +757,7 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p className="text-[11px] text-muted-foreground border-t border-border/50 pt-2">
|
||||
<p className="text-xs text-muted-foreground border-t border-border/50 pt-2">
|
||||
Fields below are locked and autofilled from this existing project. Click <strong className="text-foreground font-medium">Clear / Create New</strong> to enter new project details manually.
|
||||
</p>
|
||||
</div>
|
||||
@@ -878,7 +952,7 @@ export default function ProjectAssignmentForm({ client, clientId, isEdit, assign
|
||||
<p className="text-[11px] text-muted-foreground flex items-center gap-1.5">
|
||||
<span>Full work order code will be submitted as:</span>
|
||||
<span className="font-mono font-semibold text-foreground px-1.5 py-0.5 rounded bg-muted/60 dark:bg-zinc-900 border border-border/60">
|
||||
{projectCode}-{field.value?.trim() || '...'}
|
||||
# {projectCode}-{field.value?.trim() || '...'}
|
||||
</span>
|
||||
</p>
|
||||
<FormMessage />
|
||||
|
||||
@@ -8,14 +8,22 @@ type Props = {
|
||||
|
||||
export default async function CreateAssignmentPage({ params, searchParams }: Props) {
|
||||
const { client_id } = await params;
|
||||
const isEdit = (await searchParams)!.is_edit
|
||||
const assignmentId = (await searchParams)!.assignment_id
|
||||
const resolvedSearchParams = await searchParams;
|
||||
const isEdit = resolvedSearchParams?.is_edit;
|
||||
const assignmentId = resolvedSearchParams?.assignment_id;
|
||||
const isPromote = resolvedSearchParams?.promote === 'true' || resolvedSearchParams?.is_promote === 'true';
|
||||
|
||||
const client = await fetchData(`/client/${client_id}`)
|
||||
const client = await fetchData(`/client/${client_id}`);
|
||||
|
||||
return (
|
||||
<div className="max-w-4xl mx-auto p-6 sm:p-8 pt-6 pb-20">
|
||||
<ProjectAssignmentForm client={client} clientId={client_id} isEdit={isEdit ? true : false} assignmentId={assignmentId as any} />
|
||||
<ProjectAssignmentForm
|
||||
client={client}
|
||||
clientId={client_id}
|
||||
isEdit={isEdit ? true : false}
|
||||
assignmentId={assignmentId as any}
|
||||
isPromote={isPromote}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -85,10 +85,11 @@ export default function UpdateAdministrationStatus({
|
||||
}, [initialStatusId]);
|
||||
|
||||
useEffect(() => {
|
||||
const initialRemark = assignment?.project_assignment_status?.remark || assignment?.project_assignment_status?.description || assignment?.note || '';
|
||||
const initialRemark = assignment?.project_assignment_status_notes || assignment?.project_assignment_status?.remark || assignment?.project_assignment_status?.description || assignment?.note || '';
|
||||
setDescription(initialRemark);
|
||||
}, [assignment]);
|
||||
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!effectiveId) {
|
||||
@@ -105,9 +106,7 @@ export default function UpdateAdministrationStatus({
|
||||
try {
|
||||
const payload = {
|
||||
project_assignment_status_id: Number(selectedStatusId),
|
||||
remark: description.trim(),
|
||||
description: description.trim(),
|
||||
note: description.trim(),
|
||||
notes: description.trim(),
|
||||
};
|
||||
|
||||
const res = await serverApiCall('PUT', `/project-assignment/status/${effectiveId}`, payload);
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
Tooltip, TooltipContent, TooltipTrigger,
|
||||
} from '@/components/ui/tooltip';
|
||||
import { LazyImage } from '@/components/ui/lazy-image';
|
||||
import { Briefcase, Calendar, ExternalLink, MoreVertical, FolderGit2, FileText } from 'lucide-react';
|
||||
import { Briefcase, Calendar, ExternalLink, MoreVertical, FolderGit2, FileText, ArrowUpRight } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
import { formatAssignmentDate } from './AssignmentList';
|
||||
@@ -47,17 +47,18 @@ export default function AssignmentGrid({
|
||||
const assignmentDesc = assignment.wo_description || assignment.im_description || assignment.project?.description;
|
||||
const assignmentStatus = assignment.project_assignment_status?.name || assignment.project?.status;
|
||||
|
||||
const illustrationSrc = isProject
|
||||
? '/assets/illustrations/work_order.jpg'
|
||||
: '/assets/illustrations/internal_memo.jpg';
|
||||
const illustrationSrc = isProject ? '/assets/illustrations/work_order.jpg' : '/assets/illustrations/internal_memo.jpg';
|
||||
|
||||
const effectiveClientId = clientId || assignment.client?.id;
|
||||
const assignmentDetailUrl = effectiveClientId ? `/task/client-detail/${effectiveClientId}/${assignment.id}` : '#';
|
||||
const projectDetailUrl = effectiveClientId && assignment.project?.id
|
||||
? `/task/client-detail/${effectiveClientId}/project-detail/${assignment.project.id}`
|
||||
: null;
|
||||
const projectDetailUrl = effectiveClientId && assignment.project?.id ? `/task/client-detail/${effectiveClientId}/project-detail/${assignment.project.id}` : null;
|
||||
const editAssignmentUrl = effectiveClientId
|
||||
? `/task/client-detail/${effectiveClientId}/project-assignments?is_edit=true&assignment_id=${assignment.id}`
|
||||
: `/task/project-assignment?is_edit=true&assignment_id=${assignment.id}`;
|
||||
const promoteAssignmentUrl = !isProject
|
||||
? (effectiveClientId
|
||||
? `/task/client-detail/${effectiveClientId}/project-assignments?is_edit=true&assignment_id=${assignment.id}&promote=true`
|
||||
: `/task/project-assignment?is_edit=true&assignment_id=${assignment.id}&promote=true`)
|
||||
: null;
|
||||
|
||||
return (
|
||||
@@ -122,7 +123,14 @@ export default function AssignmentGrid({
|
||||
<MoreVertical className="w-4 h-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-48">
|
||||
<DropdownMenuContent align="end" className="w-48">{promoteAssignmentUrl && (
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={promoteAssignmentUrl} className="flex items-center gap-2 text-his font-medium">
|
||||
<ArrowUpRight className="w-4 h-4 text-his" />
|
||||
Promote to Project
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={assignmentDetailUrl}>View Assignment Details</Link>
|
||||
</DropdownMenuItem>
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
Tooltip, TooltipContent, TooltipTrigger,
|
||||
} from '@/components/ui/tooltip';
|
||||
import { LazyImage } from '@/components/ui/lazy-image';
|
||||
import { Briefcase, Calendar, MoreVertical, FolderGit2, FileText, BuildingComplex } from 'lucide-react';
|
||||
import { Briefcase, Calendar, MoreVertical, FolderGit2, FileText, BuildingComplex, ArrowUpRight } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
|
||||
@@ -59,11 +59,14 @@ export default function AssignmentList({
|
||||
|
||||
const effectiveClientId = clientId || assignment.client?.id;
|
||||
const assignmentDetailUrl = effectiveClientId ? `/task/client-detail/${effectiveClientId}/${assignment.id}` : '#';
|
||||
const projectDetailUrl = effectiveClientId && assignment.project?.id
|
||||
? `/task/client-detail/${effectiveClientId}/project-detail/${assignment.project.id}`
|
||||
: null;
|
||||
const projectDetailUrl = effectiveClientId && assignment.project?.id ? `/task/client-detail/${effectiveClientId}/project-detail/${assignment.project.id}` : null;
|
||||
const editAssignmentUrl = effectiveClientId
|
||||
? `/task/client-detail/${effectiveClientId}/project-assignments?is_edit=true&assignment_id=${assignment.id}`
|
||||
: `/task/project-assignment?is_edit=true&assignment_id=${assignment.id}`;
|
||||
const promoteAssignmentUrl = !isProject
|
||||
? (effectiveClientId
|
||||
? `/task/client-detail/${effectiveClientId}/project-assignments?is_edit=true&assignment_id=${assignment.id}&promote=true`
|
||||
: `/task/project-assignment?is_edit=true&assignment_id=${assignment.id}&promote=true`)
|
||||
: null;
|
||||
|
||||
return (
|
||||
@@ -234,6 +237,14 @@ export default function AssignmentList({
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-48">
|
||||
{promoteAssignmentUrl && (
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={promoteAssignmentUrl} className="flex items-center gap-2 text-his font-medium">
|
||||
<ArrowUpRight className="w-4 h-4 text-his" />
|
||||
Promote to Project
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={assignmentDetailUrl}>View Assignment Details</Link>
|
||||
</DropdownMenuItem>
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
import ProjectAssignmentForm from "../client-detail/[client_id]/project-assignments/ProjectAssignmentForm";
|
||||
|
||||
type Props = {
|
||||
searchParams: Promise<{ is_edit?: string; assignment_id?: string }>
|
||||
searchParams: Promise<{ is_edit?: string; assignment_id?: string; promote?: string; is_promote?: string }>
|
||||
};
|
||||
|
||||
export default async function CreateAssignmentPage({ searchParams }: Props) {
|
||||
const isEdit = (await searchParams)!.is_edit
|
||||
const assignmentId = (await searchParams)!.assignment_id
|
||||
const resolvedSearchParams = await searchParams;
|
||||
const isEdit = resolvedSearchParams?.is_edit;
|
||||
const assignmentId = resolvedSearchParams?.assignment_id;
|
||||
const isPromote = resolvedSearchParams?.promote === 'true' || resolvedSearchParams?.is_promote === 'true';
|
||||
|
||||
return (
|
||||
<div className="max-w-4xl mx-auto p-6 sm:p-8 pt-6 pb-20">
|
||||
<ProjectAssignmentForm isEdit={isEdit === 'true' ? true : false} assignmentId={assignmentId as any} />
|
||||
<ProjectAssignmentForm
|
||||
isEdit={isEdit === 'true' ? true : false}
|
||||
assignmentId={assignmentId as any}
|
||||
isPromote={isPromote}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { IUser } from "@/app/admin/administration/user/component/type"
|
||||
|
||||
export interface IProjectAssignment {
|
||||
id: number
|
||||
im_id?: any
|
||||
im_code?: any
|
||||
im_description?: any
|
||||
im_end_date?: any
|
||||
@@ -13,6 +14,7 @@ export interface IProjectAssignment {
|
||||
end_user: EndUser
|
||||
project?: Project
|
||||
project_assignment_status: ProjectStatus
|
||||
project_assignment_status_notes?: string
|
||||
wo_code: string
|
||||
wo_description: string
|
||||
wo_name: string
|
||||
|
||||
Reference in New Issue
Block a user