mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
Lazy-load modal components and fix promote flow
Replace eager modal/action component imports with dynamic (client-only) imports and add a shared ModalActionLoader UI for loading states. Use dynamic imports for ManageTeam, UpdateAdministrationStatus, UpdateTechnicalStatus, and ConfirmDeleteWithInput. Add ConvertedAssignmentBadge to assignment detail. Update ProjectAssignmentForm: replace useSearchParams with useRouter, prevent pre-filling project/work order fields when promoting (isPromote), adjust step handling, and skip project selector when promoting. Minor refactor to improve client-side performance and UX. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -8,14 +8,40 @@ import { Badge } from '@/components/ui/badge';
|
||||
import Link from 'next/link';
|
||||
import { IProjectAssignment } from '../../../type.assignment';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import dynamic from 'next/dynamic';
|
||||
import FilterComponent from '../../../component/FilterComponent';
|
||||
import { ConfirmDeleteWithInput } from '@/components/modal/ConfirmDeleteWithInput';
|
||||
import UpdateTechnicalStatus from '../../../component/UpdateTechnicalStatus';
|
||||
import UpdateAdministrationStatus from '../../../component/UpdateAdministrationStatus';
|
||||
import { ManageTeam } from '../../../component/ManageTeam';
|
||||
import AssignmentGrid from '../../../component/project-assignment/AssignmentGrid';
|
||||
import AssignmentList from '../../../component/project-assignment/AssignmentList';
|
||||
|
||||
const ModalActionLoader = () => (
|
||||
<div className="fixed inset-0 z-50 bg-black/50 backdrop-blur-xs flex items-center justify-center animate-in fade-in duration-150">
|
||||
<div className="bg-popover border border-border/80 rounded-2xl p-5 shadow-2xl flex items-center gap-3">
|
||||
<span className="w-4 h-4 border-2 border-his border-t-transparent rounded-full animate-spin shrink-0" />
|
||||
<span className="text-xs font-medium text-foreground">Loading action...</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
const ManageTeam = dynamic(
|
||||
() => import('../../../component/ManageTeam').then((mod) => mod.ManageTeam),
|
||||
{ ssr: false, loading: () => <ModalActionLoader /> }
|
||||
);
|
||||
|
||||
const UpdateAdministrationStatus = dynamic(
|
||||
() => import('../../../component/UpdateAdministrationStatus'),
|
||||
{ ssr: false, loading: () => <ModalActionLoader /> }
|
||||
);
|
||||
|
||||
const UpdateTechnicalStatus = dynamic(
|
||||
() => import('../../../component/UpdateTechnicalStatus'),
|
||||
{ ssr: false, loading: () => <ModalActionLoader /> }
|
||||
);
|
||||
|
||||
const ConfirmDeleteWithInput = dynamic(
|
||||
() => import('@/components/modal/ConfirmDeleteWithInput').then((mod) => mod.ConfirmDeleteWithInput),
|
||||
{ ssr: false, loading: () => <ModalActionLoader /> }
|
||||
);
|
||||
|
||||
interface Props {
|
||||
clientId: string;
|
||||
assignmentLists: IProjectAssignment[];
|
||||
|
||||
+27
-3
@@ -22,14 +22,37 @@ import { Button } from '@/components/ui/button';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { LazyImage } from '@/components/ui/lazy-image';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
import dynamic from 'next/dynamic';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { IClient, CLIENT_FALLBACK_IMAGE, END_USER_FALLBACK_IMAGE } from '../../../types';
|
||||
import { IProjectAssignment, ProjectAssignmentWorkOrderDetail } from '../../../type.assignment';
|
||||
import { ManageTeam } from '../../../component/ManageTeam';
|
||||
import UpdateTechnicalStatus from '../../../component/UpdateTechnicalStatus';
|
||||
import UpdateAdministrationStatus from '../../../component/UpdateAdministrationStatus';
|
||||
import ConvertedAssignmentBadge from '../../../component/project-assignment/ConvertedAssignmentBadge';
|
||||
import Reveal from '@/components/ui/reveal';
|
||||
|
||||
const ModalActionLoader = () => (
|
||||
<div className="fixed inset-0 z-50 bg-black/50 backdrop-blur-xs flex items-center justify-center animate-in fade-in duration-150">
|
||||
<div className="bg-popover border border-border/80 rounded-2xl p-5 shadow-2xl flex items-center gap-3">
|
||||
<span className="w-4 h-4 border-2 border-his border-t-transparent rounded-full animate-spin shrink-0" />
|
||||
<span className="text-xs font-medium text-foreground">Loading action...</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
const ManageTeam = dynamic(
|
||||
() => import('../../../component/ManageTeam').then((mod) => mod.ManageTeam),
|
||||
{ ssr: false, loading: () => <ModalActionLoader /> }
|
||||
);
|
||||
|
||||
const UpdateAdministrationStatus = dynamic(
|
||||
() => import('../../../component/UpdateAdministrationStatus'),
|
||||
{ ssr: false, loading: () => <ModalActionLoader /> }
|
||||
);
|
||||
|
||||
const UpdateTechnicalStatus = dynamic(
|
||||
() => import('../../../component/UpdateTechnicalStatus'),
|
||||
{ ssr: false, loading: () => <ModalActionLoader /> }
|
||||
);
|
||||
|
||||
interface Props {
|
||||
client: IClient | undefined;
|
||||
initialAssignment: IProjectAssignment;
|
||||
@@ -125,6 +148,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
{isWorkOrder ? <Briefcase className="h-3 w-3" /> : <FileText className="h-3 w-3" />}
|
||||
{assignmentType}
|
||||
</Badge>
|
||||
<ConvertedAssignmentBadge assignment={assignment} clientId={owner?.id} />
|
||||
{assignmentStatus ? <BadgeStatus status={assignmentStatus} /> : null}
|
||||
{assignmentCode ? (
|
||||
<span className="rounded-lg border border-border bg-muted/50 px-2 py-0.5 font-mono text-xs text-muted-foreground">
|
||||
|
||||
+29
-26
@@ -1,7 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { yupResolver } from '@hookform/resolvers/yup';
|
||||
import { motion, AnimatePresence } from 'motion/react';
|
||||
@@ -176,34 +176,37 @@ export default function ProjectAssignmentForm(
|
||||
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', 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 || '');
|
||||
if (!isPromote) {
|
||||
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 || '');
|
||||
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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 (defaultWoName.toLowerCase() === data.project?.name.toLowerCase()) {
|
||||
setIsSameAsProject(true);
|
||||
if (defaultWoName?.toLowerCase() === data.project?.name?.toLowerCase()) {
|
||||
setIsSameAsProject(true);
|
||||
}
|
||||
} else {
|
||||
setStep(isPromote ? 'details' : 'clients');
|
||||
}
|
||||
|
||||
setStep(isPromote ? 'details' : 'clients');
|
||||
setIsExistAssignment(res.data.data);
|
||||
} else {
|
||||
toast.error('Fail to get detail assignment', {
|
||||
@@ -579,7 +582,7 @@ export default function ProjectAssignmentForm(
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
{/* Existing Project Selector / Linked Hero Card */}
|
||||
{assignmentType === 'Project' && (
|
||||
{!isPromote && assignmentType === 'Project' && (
|
||||
!isExistProject ? (
|
||||
<div className="p-4 rounded-xl border border-border/80 bg-zinc-200/25 dark:bg-zinc-800/90 space-y-3">
|
||||
<div className="space-y-0.5">
|
||||
|
||||
+25
-3
@@ -17,14 +17,36 @@ import { LazyImage } from '@/components/ui/lazy-image';
|
||||
import StatusTimeline from './StatusTimeline';
|
||||
import AssignedPeople from './AssignedPeople';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
import dynamic from 'next/dynamic';
|
||||
import { IProjectAssignment } from '@/app/(dashboard)/task/type.assignment';
|
||||
import UpdateTimelineStatus from '@/app/(dashboard)/task/component/UpdateTechnicalStatus';
|
||||
import UpdateAdministrationStatus from '@/app/(dashboard)/task/component/UpdateAdministrationStatus';
|
||||
import { ManageTeam } from '@/app/(dashboard)/task/component/ManageTeam';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { COMPLETE_STATUS_LIST, ONPROGRESS_STATUS_LIST } from '@/app/(dashboard)/task/data';
|
||||
import { avatarSrc, formatDate, formatSpan } from './format';
|
||||
|
||||
const ModalActionLoader = () => (
|
||||
<div className="fixed inset-0 z-50 bg-black/50 backdrop-blur-xs flex items-center justify-center animate-in fade-in duration-150">
|
||||
<div className="bg-popover border border-border/80 rounded-2xl p-5 shadow-2xl flex items-center gap-3">
|
||||
<span className="w-4 h-4 border-2 border-his border-t-transparent rounded-full animate-spin shrink-0" />
|
||||
<span className="text-xs font-medium text-foreground">Loading action...</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
const UpdateTimelineStatus = dynamic(
|
||||
() => import('@/app/(dashboard)/task/component/UpdateTechnicalStatus'),
|
||||
{ ssr: false, loading: () => <ModalActionLoader /> }
|
||||
);
|
||||
|
||||
const UpdateAdministrationStatus = dynamic(
|
||||
() => import('@/app/(dashboard)/task/component/UpdateAdministrationStatus'),
|
||||
{ ssr: false, loading: () => <ModalActionLoader /> }
|
||||
);
|
||||
|
||||
const ManageTeam = dynamic(
|
||||
() => import('@/app/(dashboard)/task/component/ManageTeam').then((mod) => mod.ManageTeam),
|
||||
{ ssr: false, loading: () => <ModalActionLoader /> }
|
||||
);
|
||||
|
||||
interface WorkOrderCardProps {
|
||||
workOrder: IProjectAssignment;
|
||||
index: number;
|
||||
|
||||
Reference in New Issue
Block a user