diff --git a/.env.development b/.env.development index 9d5490a..83ac4eb 100644 --- a/.env.development +++ b/.env.development @@ -1,13 +1,11 @@ BASE_PATH = "" NEXT_PUBLIC_APP_URL="http://localhost:1209" -# BASE_URL_API = https://hats-his.nutech-integrasi.com/presence-api/api/v1 -# BASE_URL_IMG = https://hats-his.nutech-integrasi.com/presence-api/ +# BASE_URL_API = https://api-hats.hisnutech.my.id/api/v1 +# BASE_URL_IMG = https://api-hats.hisnutech.my.id/ -# BASE_URL_API = https://his.nutech-integrasi.com/presence-api/api/v1 -# BASE_URL_IMG = https://his.nutech-integrasi.com/presence-api/ -BASE_URL_API = https://api-hats.hisnutech.my.id/api/v1 -BASE_URL_IMG = https://api-hats.hisnutech.my.id/ +BASE_URL_API = https://api-hats-dev.hisnutech.my.id/api/v1 +BASE_URL_IMG = https://api-hats-dev.hisnutech.my.id/ NEXTAUTH_URL = http://localhost:1209 # NEXTAUTH_URL = http://localhost:7090/super-apps/api/auth @@ -19,5 +17,7 @@ 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.1.2" -NEXT_PUBLIC_MANAGER_USER_ID = '2' \ No newline at end of file +NEXT_PUBLIC_APP_VERSION = "v1.2.0" +NEXT_PUBLIC_MANAGER_USER_ID = '2' + +NEXT_PUBLIC_S3_IMAGE_URL = https://cdn.hisnutech.my.id/public \ No newline at end of file diff --git a/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx new file mode 100644 index 0000000..6b103f4 --- /dev/null +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx @@ -0,0 +1,305 @@ +// app/task/client-detail/[clientId]/project-assignments-client.tsx +"use client" + +import { useState } from 'react'; +import { motion } from 'motion/react'; +import { Briefcase, Clock, Users, MoreVertical, Check, Calendar as CalendarIcon, LayoutGrid, Table as TableIcon } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import { Card, Card900, CardContent } from '@/components/ui/card'; +import { Badge } from '@/components/ui/badge'; +import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'; +import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; +import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; +import Link from 'next/link'; +import { DUMMY_EMPLOYEES } from '../../../types'; +import { LazyImage } from '@/components/ui/lazy-image'; +import { IProjectAssignment } from '../../../type.assignment'; +import ManageEmployee from '../../../component/ManageEmployee'; +import { useRouter } from 'next/navigation'; +import FormUpdateStatus from '../../../component/FormUpdateStatus'; + +interface Props { + clientId: string; + initialAssignments: IProjectAssignment[]; +} + +export default function ClientDetailComponent({ clientId, initialAssignments }: Props) { + const [viewMode, setViewMode] = useState<'grid' | 'table'>('grid'); + const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | undefined>() + const [selectedData, setSelectedData] = useState() + + const router = useRouter() + + // Call Server Action (this will automatically refresh the server data if you use revalidatePath in the action) + const handleClose = () => { + setSelectedData(undefined) + setAction(undefined) + } + + const handleSuccess = () => { + router.refresh() + handleClose() + } + + return ( + <> +
+

Project Assignments

+
+ setViewMode(v as 'grid' | 'table')}> + + + + + + + {initialAssignments.length} Total + +
+
+ + {/* --- EMPTY STATE --- */} + {initialAssignments.length === 0 ? + + +
+ +
+
+

No Project Assignments

+

+ This client doesn't have any projects or internal memos yet. Create one to get started. +

+
+ + + +
+
+ : viewMode === 'grid' ? + + /* --- GRID VIEW --- */ +
+ {initialAssignments.map((assignment) => { + const isProject = assignment.project.code + + const assignmentType = isProject ? 'Project' : 'IM' + const assignmentStartDate = assignment.project.start_date || assignment.im_start_date + const assignmentEndDate = assignment.project.end_date || assignment.im_end_date + const assignmentDesc = assignment.project.description || assignment.im_description + const assignmentStatus = assignment.project.status || assignment.project_status.name + + return ( + + + +
+
+
+ {isProject ? : } +
+
+
+

{assignment.project.name || assignment.im_name}

+ + {assignmentType} + + + {assignmentStatus} + +
+ + {assignment.wo_code && ( +

+ WO: {assignment.wo_name} +

+ )} + +

+ {assignmentDesc} +

+ +
+
+ + + {assignmentStartDate ? new Date(assignmentStartDate).toLocaleDateString() : 'N/A'} - + {assignmentEndDate ? new Date(assignmentEndDate).toLocaleDateString() : 'N/A'} + +
+
+ +
+ {assignment?.users?.slice(0, 3).map(empId => { + const emp = DUMMY_EMPLOYEES.find(e => e.id === empId); + return ( +
+ + + + + +
+

{emp?.name}

+

{emp?.role}

+
+
+
+
+ ); + })} + {assignment.project_assignment_work_order_detail?.length > 3 && ( +
+ +{assignment.project_assignment_work_order_detail?.length - 3} +
+ )} + {!assignment.project_assignment_work_order_detail && No employees assigned} +
+
+
+
+
+ + + + + + + View Details Assignment + + + Edit Assignment + + { setSelectedData(assignment); setAction('MANAGE_EMPLOYEE') }}>Manage Employees + { setSelectedData(assignment); setAction('UPDATE_STATUS') }}>Update Assignment Status + Delete + + +
+
+
+
+ ) + })} +
+ : + + /* --- TABLE VIEW --- */ + +
+ + + + IM Name + IM Code + Description + IM Year + IM Start + IM End + Project Name + Project Code + Description + Year + Proj Start + Proj End + Work Order + WO Code + WO Start + WO End + Status + + + + + {initialAssignments.map((assignment) => { + return ( + + {assignment.im_name} + {assignment.im_code || '-'} + + {assignment.im_description} + + {assignment.im_year || '-'} + + {assignment.im_start_date ? new Date(assignment.im_start_date).toLocaleDateString() : '-'} + + + {assignment.im_end_date ? new Date(assignment.im_end_date).toLocaleDateString() : '-'} + + {assignment.project.name} + {assignment.project.code || '-'} + + {assignment.project.description} + + {assignment.project.year || '-'} + + {assignment.project.start_date ? new Date(assignment.project.start_date).toLocaleDateString() : '-'} + + + {assignment.project.end_date ? new Date(assignment.project.end_date).toLocaleDateString() : '-'} + + {assignment.wo_name || '-'} + {assignment.wo_code || '-'} + + {assignment.wo_start_date ? new Date(assignment.wo_start_date).toLocaleDateString() : '-'} + + + {assignment.wo_end_date ? new Date(assignment.wo_end_date).toLocaleDateString() : '-'} + + + + {assignment.status.name} + + + + + + + + + + View Details + + + Edit Assignment + + { setSelectedData(assignment); setAction('MANAGE_EMPLOYEE') }}>Manage Employees + { setSelectedData(assignment); setAction('UPDATE_STATUS') }}>Update Assignment Status + Delete + + + + + ); + })} + +
+
+
+ } + + {action === 'MANAGE_EMPLOYEE' ? + + : null + } + + {action === 'UPDATE_STATUS' ? + + : null + } + + ); +} \ No newline at end of file diff --git a/app/(dashboard)/task/client-detail/[client_id]/(main)/page.dummy.tsx b/app/(dashboard)/task/client-detail/[client_id]/(main)/page.dummy.tsx new file mode 100644 index 0000000..b47ee23 --- /dev/null +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/page.dummy.tsx @@ -0,0 +1,514 @@ +"use client" + +import { motion } from 'motion/react'; +import { ArrowLeft, Plus, Briefcase, Clock, Users, MoreVertical, Check, Calendar as CalendarIcon, LayoutGrid, Table as TableIcon } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; +import { Badge } from '@/components/ui/badge'; +import { Separator } from '@/components/ui/separator'; +import { Label } from '@/components/ui/label'; +import { Input } from '@/components/ui/input'; +import { Textarea } from '@/components/ui/textarea'; +import { + DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, +} from '@/components/ui/dropdown-menu'; +import { + Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogFooter, +} from '@/components/ui/dialog'; +import { + Select, SelectContent, SelectItem, SelectTrigger, SelectValue, +} from '@/components/ui/select'; +import { + Tooltip, TooltipContent, TooltipTrigger, +} from '@/components/ui/tooltip'; +import { + Table, TableBody, TableCell, TableHead, TableHeader, TableRow, +} from "@/components/ui/table"; +import { + Tabs, TabsList, TabsTrigger, +} from "@/components/ui/tabs"; +import { use, useState } from 'react'; +import { toast } from 'sonner'; +import { cn } from '@/lib/utils'; +import { DUMMY_EMPLOYEES, IProjectAssignment } from '../../../types'; +import { useAppState } from '@/hooks/useDummyTaskData'; +import { useRouter } from 'next/navigation'; +import Link from 'next/link'; + +type Props = { + params: Promise<{ client_id: string | undefined }> +}; + +export default function ClientDetailPage({ params }: Props) { + + const [viewMode, setViewMode] = useState<'grid' | 'table'>('grid'); + const [statusForm, setStatusForm] = useState({ + status: 'Active' as IProjectAssignment['status'], + note: '', + date: new Date().toISOString().split('T')[0] + }); + + // const { id } = await params; + const { client_id } = use(params); + const router = useRouter() + const { clients, assignments, updateAssignment } = useAppState(); + + + const [editingEmployeesAssignment, setEditingEmployeesAssignment] = useState(null); + const [selectedEmployeeIds, setSelectedEmployeeIds] = useState([]); + + const [updatingStatusAssignment, setUpdatingStatusAssignment] = useState(null); + + const client = clients.find((c) => c.id === client_id); + const clientAssignments = assignments.filter((a) => a.clientId === client_id); + + const handleOpenEmployeeDialog = (assignment: IProjectAssignment) => { + setEditingEmployeesAssignment(assignment); + setSelectedEmployeeIds(assignment.assignedEmployees); + }; + + const handleOpenStatusDialog = (assignment: IProjectAssignment) => { + setUpdatingStatusAssignment(assignment); + setStatusForm({ + status: assignment.status, + note: '', + date: new Date().toISOString().split('T')[0] + }); + }; + + const toggleEmployee = (empId: string) => { + setSelectedEmployeeIds(prev => + prev.includes(empId) ? prev.filter(i => i !== empId) : [...prev, empId] + ); + }; + + const handleSaveEmployees = () => { + if (editingEmployeesAssignment) { + updateAssignment(editingEmployeesAssignment.id, { + assignedEmployees: selectedEmployeeIds + }); + toast.success('Team updated successfully'); + setEditingEmployeesAssignment(null); + } + }; + + const handleSaveStatus = () => { + if (updatingStatusAssignment) { + updateAssignment(updatingStatusAssignment.id, { + status: statusForm.status + }); + // In a real app we would save the note and date to a history log + toast.success(`Status updated to ${statusForm.status}`); + setUpdatingStatusAssignment(null); + } + }; + + if (!client) { + return ( +
+

Client not found

+ +
+ ); + } + + return ( + +
+
+ + {client.name} + +
+ +

{client.name}

+

End User: {client.endUser}

+
+
+
+ + + +
+
+ +
+
+
+

Project Assignments

+
+ setViewMode(v as 'grid' | 'table')}> + + + + + + + + + + + {clientAssignments.length} Total + +
+
+ + {clientAssignments.length === 0 ? ( + + +
+ +
+
+

No Project Assignments

+

+ This client doesn't have any projects or internal memos yet. Create one to get started. +

+
+ + + +
+
+ ) : viewMode === 'grid' ? ( +
+ {clientAssignments?.map((assignment) => ( + + +
+
+
+ {assignment.type === 'Project' ? : } +
+
+
+

{assignment.name}

+ + {assignment.type} + + + {assignment.status} + +
+ + {assignment.workOrder && ( +

+ WO: {assignment.workOrder.name} +

+ )} + +

+ {assignment.description} +

+ +
+
+ + + {assignment.startDate ? new Date(assignment.startDate).toLocaleDateString() : 'N/A'} - + {assignment.endDate ? new Date(assignment.endDate).toLocaleDateString() : 'N/A'} + +
+
+ +
+ {assignment.assignedEmployees.slice(0, 3).map(empId => { + const emp = DUMMY_EMPLOYEES.find(e => e.id === empId); + return ( +
+ + + {emp?.name} + + +
+

{emp?.name}

+

{emp?.role}

+
+
+
+
+ ); + })} + {assignment.assignedEmployees.length > 3 && ( +
+ +{assignment.assignedEmployees.length - 3} +
+ )} + {assignment.assignedEmployees.length === 0 && No employees assigned} +
+
+
+
+
+ + + + + + + View Details + + Edit Assignment + handleOpenEmployeeDialog(assignment)}> + Manage Employees + + Archive + + +
+
+
+ ))} +
+ ) : ( + +
+ + + + Project Name + Project Code + Description + Year + Proj Start + Proj End + Work Order + WO Code + WO Start + WO End + Status + + + + + {clientAssignments.map((assignment) => { + const wo = assignment.workOrder; + return ( + + {assignment.name} + {assignment.code || '-'} + + {assignment.description} + + {assignment.year || '-'} + + {assignment.startDate ? new Date(assignment.startDate).toLocaleDateString() : '-'} + + + {assignment.endDate ? new Date(assignment.endDate).toLocaleDateString() : '-'} + + {wo?.name || '-'} + {wo?.code || '-'} + + {wo?.startDate ? new Date(wo.startDate).toLocaleDateString() : '-'} + + + {wo?.endDate ? new Date(wo.endDate).toLocaleDateString() : '-'} + + + + {assignment.status} + + + + + + + + + + View Details + + Edit Assignment + handleOpenEmployeeDialog(assignment)}> + Manage Employees + + Archive + + + + + ); + })} + +
+
+
+ )} +
+ +
+ + + Client Info + + +
+ +

{client.name}

+
+
+ +

{client.endUser}

+
+ +
+ +

{new Date(client?.createdAt)?.toLocaleDateString()}

+
+
+
+ + + + Quick Stats + + +
+ Total Projects + {clientAssignments.filter(a => a.type === 'Project').length} +
+
+ Total IMs + {clientAssignments.filter(a => a.type === 'IM').length} +
+
+ Total WOs + + {clientAssignments.reduce((acc, curr) => acc + curr.workOrders?.length, 0)} + +
+
+
+
+
+ + {/* Employee Management Dialog */} + !open && setEditingEmployeesAssignment(null)}> + + + Manage Team + + Assign or remove employees for {editingEmployeesAssignment?.name} + + +
+ {DUMMY_EMPLOYEES.map((emp) => ( +
toggleEmployee(emp.id)} + > +
+ {emp.name} + {selectedEmployeeIds.includes(emp.id) && ( +
+ +
+ )} +
+
+

{emp.name}

+

{emp.role}

+
+
+ ))} +
+ + + + +
+
+ + {/* Status Update Dialog */} + !open && setUpdatingStatusAssignment(null)}> + + + Update Status + + Update the current status for {updatingStatusAssignment?.name} + + +
+
+ + +
+
+ +
+ setStatusForm({ ...statusForm, date: e.target.value })} + /> +
+
+
+ +