diff --git a/.env.development b/.env.development index 83ac4eb..cec6786 100644 --- a/.env.development +++ b/.env.development @@ -2,10 +2,8 @@ BASE_PATH = "" NEXT_PUBLIC_APP_URL="http://localhost:1209" # 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/ +BASE_URL_IMG = https://api-hats.hisnutech.my.id/ NEXTAUTH_URL = http://localhost:1209 # NEXTAUTH_URL = http://localhost:7090/super-apps/api/auth diff --git a/app/(dashboard)/components/PieChart.tsx b/app/(dashboard)/components/PieChart.tsx index f25722c..626c318 100644 --- a/app/(dashboard)/components/PieChart.tsx +++ b/app/(dashboard)/components/PieChart.tsx @@ -39,11 +39,11 @@ const PieChart: FC = ({ data }) => { } if (selectedDataPoints.length > 0) { - chart.toggleDataPointSelection(selectedDataPoints[0]) + chart?.toggleDataPointSelection(selectedDataPoints[0]) } }, mounted: (chart) => { - chart.windowResizeHandler(); + chart?.windowResizeHandler(); } }, }, diff --git a/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx index b2e017f..df5a646 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx @@ -43,7 +43,6 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro handleClose() } - console.log(assignmentLists) return ( <>
@@ -73,8 +72,8 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro

No Project Assignments

-

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

+ This client doesn't have any projects or internal memos yet. Try to change the filter or create one to get started.

@@ -87,13 +86,13 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro /* --- GRID VIEW --- */
{assignmentLists.map((assignment) => { - const isProject = assignment.project?.code + const isProject = assignment.wo_name const assignmentType = isProject ? 'Project' : 'IM' - const assignmentName = assignment.project?.name || assignment.im_name - 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 assignmentName = assignment.wo_name || assignment.im_name + 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 return ( @@ -107,29 +106,23 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro {isProject ? : }
- {isProject ? +
+

{assignmentName}

+ {!isProject ? {assignmentType} : null} + +
+ + {assignment.wo_name && e.stopPropagation()}>
-

{assignmentName}

+

Project Name: {assignment.project?.name}

- {assignmentType} -
- : -
-

{assignmentName}

- {assignmentType} - -
- } - - {assignment.wo_name && -

WO: {assignment.wo_name}

}

{assignmentDesc}

diff --git a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx index c508fdd..e2ecd60 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx @@ -36,9 +36,9 @@ export default function AssignmentDetail({ client, initialAssignment: assignment const assignmentName = assignment.project?.name || assignment.im_name const assignmentCode = assignment.project?.code || assignment.im_code const assignmentYear = assignment.project?.year || assignment.im_year - 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 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 handleClose = () => { @@ -110,7 +110,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
- +
diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx index 632c9f0..0f2dc95 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx @@ -262,7 +262,7 @@ export default async function ProjectDetailPage({ params, searchParams }: Props)
- +
{filterData() && filterData().length > 0 ? project.project_assignment.map((wo: any, i: number) => diff --git a/app/(dashboard)/task/component/AssignmentTable.tsx b/app/(dashboard)/task/component/AssignmentTable.tsx index 38de698..cc29df9 100644 --- a/app/(dashboard)/task/component/AssignmentTable.tsx +++ b/app/(dashboard)/task/component/AssignmentTable.tsx @@ -14,7 +14,12 @@ export default function AssignmentTable({ data }: { data: IProjectAssignment[] } if (data.length === 0) { return -

No project assignment found

+
+

No Project Assignment Found

+

+ Try to change the filter or create one to get started. +

+
} diff --git a/app/(dashboard)/task/component/ClientGrid.tsx b/app/(dashboard)/task/component/ClientGrid.tsx index 11bc12d..4a3330c 100644 --- a/app/(dashboard)/task/component/ClientGrid.tsx +++ b/app/(dashboard)/task/component/ClientGrid.tsx @@ -29,144 +29,152 @@ export default function ClientGrid({ clients }: { clients: IClient[] }) { setShowSelectedData(undefined) } - if (clients.length === 0) { - return ( -
- -

No client found

-
- ); - } return ( <> -
- {clients.map((client, i) => { - const imCount = 0 - const projectCount = client.total_project; - const woCount = client.total_work_order - const userCount = client.total_user_assigned + {clients.length === 0 ? +
+ +
+

No Client Found

+

+ Try to change the filter or create one to get started. +

+ +
+
: null + } - return ( - - - -
- -
-
-
-

{client.name}

-

{client.end_user_name}

+ {clients.length > 0 ? +
+ {clients.map((client, i) => { + const imCount = 0 + const projectCount = client.total_project; + const woCount = client.total_work_order + const userCount = client.total_user_assigned + + return ( + + + +
+ +
+
+
+

{client.name}

+

{client.end_user_name}

+
+ + +
- - -
-
-
-
- {/*

+

+
+ {/*

Currently managing a portfolio of {projectCount} projects and {imCount} internal memos. A dedicated team of {assignedEmployeeIds.length} experts is handling {woCount} work orders to ensure successful delivery for {client.endUser}.

*/} -

- {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 && - {projectCount} project{projectCount! > 1 ? 's' : ''} - } - {projectCount! > 0 && imCount > 0 && " and "} - {imCount > 0 && - {imCount} internal memo{imCount > 1 ? 's' : ''} - } - .{" "} - - )} - {woCount! > 0 && ( - <> - A dedicated team of{" "} - {userCount} experts is handling{" "} - {woCount} work order{woCount! > 1 ? 's' : ''}{" "}to ensure successful delivery for {client.end_user_name}. - - )} - - } -

-
+

+ {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 && + {projectCount} project{projectCount! > 1 ? 's' : ''} + } + {projectCount! > 0 && imCount > 0 && " and "} + {imCount > 0 && + {imCount} internal memo{imCount > 1 ? 's' : ''} + } + .{" "} + + )} + {woCount! > 0 && ( + <> + A dedicated team of{" "} + {userCount} experts is handling{" "} + {woCount} work order{woCount! > 1 ? 's' : ''}{" "}to ensure successful delivery for {client.end_user_name}. + + )} + + } +

+
-
-
- Assigned Team -
- {client.users?.slice(0, 5).map((user, key) => { - return ( -
- - - - - -

{user?.name}

-

{user?.position?.name}

-
-
+
+
+ Assigned Team +
+ {client.users?.slice(0, 5).map((user, key) => { + return ( +
+ + + + + +

{user?.name}

+

{user?.position?.name}

+
+
+
+ ); + })} + {client.users?.length! > 5 && +
+ +{client.users?.length! - 5}
- ); - })} - {client.users?.length! > 5 && -
- +{client.users?.length! - 5} -
- } - {client.users?.length === 0 && - No team assigned - } + } + {client.users?.length === 0 && + No team assigned + } +
+
+
+ + + + + + + View Client Detail + + { setShowSelectedData(client); setAction('EDIT') }}>Edit Client + { setShowSelectedData(client); setAction('DELETE') }} className="text-destructive">Delete Client + +
-
- - - - - - - View Client Detail - - { setShowSelectedData(client); setAction('EDIT') }}>Edit Client - { setShowSelectedData(client); setAction('DELETE') }} className="text-destructive">Delete Client - - -
-
- - - - ); - })} -
+ + + + ); + })} +
: null + } {action === 'EDIT' && { router.refresh(); handleClose() }} />} + {action === 'DELETE' ? { router.refresh(); handleClose() }} title={selectedData?.name!} description={`This action cannot be undone. This will permanently delete and remove client ${selectedData?.name} from our servers.`} titleButton={`I understand the consequences, delete this client`} diff --git a/app/(dashboard)/task/component/FilterComponent.tsx b/app/(dashboard)/task/component/FilterComponent.tsx index 1b40507..01229a3 100644 --- a/app/(dashboard)/task/component/FilterComponent.tsx +++ b/app/(dashboard)/task/component/FilterComponent.tsx @@ -1,7 +1,6 @@ "use client" import { Input } from '@/components/ui/input'; -import { MultiSelect } from '@/components/ui/multi-select'; // Assuming this is a custom component import { Search } from 'lucide-react'; import { usePathname, useRouter, useSearchParams } from 'next/navigation'; import { type FC, useEffect, useState } from 'react'; @@ -9,20 +8,22 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import useDebounce from '@/hooks/useDebounce'; -import { STATUS_LIST } from '../data'; +import { FilterModal } from './FilterModal'; type Props = { - hideStatus?: boolean + hideStatus?: boolean; + hideAssignedTo?: boolean; + hideDateFilters?: boolean; + hideCategory?: boolean; hideSort?: boolean }; -const FilterComponent: FC = ({ hideStatus, hideSort }) => { +const FilterComponent: FC = ({ hideStatus, hideAssignedTo, hideDateFilters, hideCategory, hideSort }) => { const router = useRouter(); const pathname = usePathname(); const searchParams = useSearchParams(); const currentQuery = searchParams?.get('q') || ''; - const currentStatus = searchParams?.get('status'); const currentSort = searchParams?.get('sort') || ''; const [searchText, setSearchText] = useState(currentQuery); @@ -41,18 +42,6 @@ const FilterComponent: FC = ({ hideStatus, hideSort }) => { router.replace(`${pathname}?${params.toString()}`, { scroll: false }); }, [debouncedSearchText, pathname, router]); // Remove searchParams from dependency array to prevent infinite loops - const handleStatusChange = (val: any[]) => { - const params = new URLSearchParams(searchParams!); - - if (val && val.length > 0) { - params.set('status', val.join(',')); - } else { - params.delete('status'); - } - - router.replace(`${pathname}?${params.toString()}`, { scroll: false }); - }; - const handleSortChange = (val: string) => { const params = new URLSearchParams(searchParams!); @@ -78,16 +67,7 @@ const FilterComponent: FC = ({ hideStatus, hideSort }) => { />
- {!hideStatus ? - ({ label: item, value: item }))} - maxCount={1} - /> : null - } +
{!hideSort ? diff --git a/app/(dashboard)/task/component/FilterModal.tsx b/app/(dashboard)/task/component/FilterModal.tsx new file mode 100644 index 0000000..5ea72c0 --- /dev/null +++ b/app/(dashboard)/task/component/FilterModal.tsx @@ -0,0 +1,219 @@ +"use client" + +import { useState, useEffect, type FC } from 'react'; +import { usePathname, useRouter, useSearchParams } from 'next/navigation'; +import { format, parseISO } from 'date-fns'; +import { ListFilter } from 'lucide-react'; +import type { DateRange } from 'react-day-picker'; + +import { + Select, SelectContent, SelectItem, SelectTrigger, SelectValue, +} from "@/components/ui/select" +import { + CardContent, CardDescription, CardFooter, CardHeader, CardTitle, +} from "@/components/ui/card" +import { + Popover, PopoverContent, PopoverTrigger, +} from "@/components/ui/popover" +import { ScrollArea } from '@/components/ui/scroll-area'; +import { Button } from '@/components/ui/button'; +import { Badge } from '@/components/ui/badge'; +import { Label } from '@/components/ui/label'; +import { DatePickerMultiMode } from '@/components/ui/datepicker-multi-mode'; +import { MultiSelect } from '@/components/ui/multi-select'; +import { useFetchWithAxios } from '@/lib/axios/useFetch'; + +import { ProjectStatus } from '../type.assignment'; +import { IUser } from '@/app/admin/administration/user/component/type'; + +interface Props { + hideStatus?: boolean; + hideAssignedTo?: boolean; + hideDateFilters?: boolean; + hideCategory?: boolean; +} + +export const FilterModal: FC = ({ hideStatus, hideAssignedTo, hideDateFilters, hideCategory }) => { + const [open, setOpen] = useState(false); + const router = useRouter(); + const pathname = usePathname(); + const searchParams = useSearchParams(); + + const { data: statusList } = useFetchWithAxios('/project-status'); + const { data: userList } = useFetchWithAxios('/user'); + + const [category, setCategory] = useState(); + const [statusFilter, setStatusFilter] = useState([]); + const [assignedToFilter, setAssignedToFilter] = useState([]); + const [projectDate, setProjectDate] = useState(); + const [woDate, setWoDate] = useState(); + const [imDate, setImDate] = useState(); + + // Set initial filter if values exist in URL + useEffect(() => { + if (open) { + setCategory(searchParams?.get('category') || undefined); + + const statusParam = searchParams?.get('status'); + console.log(statusParam) + setStatusFilter(statusParam ? statusParam.split(',') : []); + + const assignedToParam = searchParams?.get('users'); + setAssignedToFilter(assignedToParam ? assignedToParam.split(',') : []); + + const parseDateRange = (prefix: string): DateRange | undefined => { + const fromStr = searchParams?.get(`${prefix}_from`); + const toStr = searchParams?.get(`${prefix}_to`); + if (!fromStr) return undefined; + return { + from: parseISO(fromStr), + to: toStr ? parseISO(toStr) : undefined + }; + }; + + setProjectDate(parseDateRange('project_date')); + setWoDate(parseDateRange('wo_date')); + setImDate(parseDateRange('im_date')); + } + }, [open, searchParams]); + + + const handleApplyFilters = () => { + const params = new URLSearchParams(searchParams?.toString()); + + // Single string values + if (category) params.set('category', category); + else params.delete('category'); + + if (statusFilter.length > 0) params.set('status', statusFilter.join(',')); + else params.delete('status'); + + if (assignedToFilter.length > 0) params.set('users', assignedToFilter.join(',')); + else params.delete('users'); + + + // Helper to format DateRange into URL params + const applyDateRangeToParams = (range: DateRange | undefined, prefix: string) => { + if (range?.from) { + params.set(`${prefix}_from`, format(range.from, 'yyyy-MM-dd')); + if (range.to) { + params.set(`${prefix}_to`, format(range.to, 'yyyy-MM-dd')); + } else { + params.delete(`${prefix}_to`); + } + } else { + params.delete(`${prefix}_from`); + params.delete(`${prefix}_to`); + } + }; + + applyDateRangeToParams(projectDate, 'project_date'); + applyDateRangeToParams(woDate, 'wo_date'); + applyDateRangeToParams(imDate, 'im_date'); + + router.replace(`${pathname}?${params.toString()}`, { scroll: false }); + setOpen(false); + }; + + const handleClearFilters = () => { + // Clear local state + setCategory(undefined); + setStatusFilter([]); + setAssignedToFilter([]); + setProjectDate(undefined); + setWoDate(undefined); + setImDate(undefined); + + // Clear URL (or you can clear specific keys if you want to keep pagination params) + router.replace(pathname!, { scroll: false }); + }; + + // Calculate active filter count for the badge + const activeFilterCount = Array.from(searchParams!.keys()).filter(key => + ['category', 'status', 'users', 'project_date_from', 'wo_date_from', 'im_date_from'].includes(key) + ).length; + + return ( + + + + + + + Filter + Apply filters to customize the data shown. + + + + {!hideCategory ? +
+ + +
: null + } + {!hideStatus ? +
+ + 0 ? statusList.map((item: ProjectStatus) => ({ label: item.name, value: String(item.id) })) : []} + maxCount={1} + /> +
: null + } + {!hideDateFilters ? + <> +
+ + setProjectDate(d as DateRange | undefined)} mode='range' /> +
+
+ + setWoDate(d as DateRange | undefined)} mode='range' /> +
+
+ + setImDate(d as DateRange | undefined)} mode='range' /> +
+ : null + } + {!hideAssignedTo ? +
+ + 0 ? userList.map((item: IUser) => ({ label: item.name, value: String(item.id) })) : []} + maxCount={1} + /> +
: null + } +
+
+ + + + +
+
+ ); +} \ No newline at end of file diff --git a/app/(dashboard)/task/component/HomeTask.tsx b/app/(dashboard)/task/component/HomeTask.tsx index 08f108a..f2c23e5 100644 --- a/app/(dashboard)/task/component/HomeTask.tsx +++ b/app/(dashboard)/task/component/HomeTask.tsx @@ -3,19 +3,20 @@ import { useState } from 'react'; import { useRouter, usePathname, useSearchParams } from 'next/navigation'; -import { Plus, Search, LayoutGrid, List } from 'lucide-react'; +import { Plus } from 'lucide-react'; import { Button } from '@/components/ui/button'; -import { Input } from '@/components/ui/input'; -import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'; +// import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'; import FormClient from './FormClient'; import FilterComponent from './FilterComponent'; +import { + Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, +} from '@/components/ui/select'; interface ShellProps { currentView: 'grid' | 'table'; - currentQuery: string; } -export default function HomeTask({ currentView, currentQuery }: ShellProps) { +export default function HomeTask({ currentView }: ShellProps) { const router = useRouter(); const pathname = usePathname(); const searchParams = useSearchParams(); @@ -40,19 +41,31 @@ export default function HomeTask({ currentView, currentQuery }: ShellProps) {

- + {/* Clients Assignments - + */} +
- + {showForm && setShowForm(false)} onSuccess={() => { setShowForm(false); router.refresh() }} />} diff --git a/app/(dashboard)/task/page.tsx b/app/(dashboard)/task/page.tsx index 8c5199a..e1c7fcf 100644 --- a/app/(dashboard)/task/page.tsx +++ b/app/(dashboard)/task/page.tsx @@ -32,7 +32,7 @@ export default async function ClientsPage({ searchParams }: Props) {
{/* The Shell manages the Search Input, Tabs, and "Add Client" Modal */} - + {/* Render the correct view based on the URL */} }> diff --git a/components/ui/datepicker-multi-mode.tsx b/components/ui/datepicker-multi-mode.tsx new file mode 100644 index 0000000..95f8fdc --- /dev/null +++ b/components/ui/datepicker-multi-mode.tsx @@ -0,0 +1,155 @@ +"use client" + +import { useState } from "react"; +import { CalendarIcon } from "@radix-ui/react-icons"; +import { format } from "date-fns"; +import { cn } from "@/lib/utils"; +import { Button } from "@/components/ui/button"; +import { Calendar } from "@/components/ui/calendar"; +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover"; +import type { Matcher, DateRange } from "react-day-picker"; + +// 1. Base props shared across all modes +type BaseProps = { + placeholder?: string; + disabled?: boolean; + disabledDate?: Matcher | Matcher[] | undefined; + captionLayout?: "label" | "dropdown" | "dropdown-months" | "dropdown-years"; + formatDate?: string; + className?: string; +}; + +// 2. Strict typings for each specific mode to avoid `any` +export type DatePickerSingleProps = BaseProps & { + mode?: "single"; + date: Date | undefined; + setDate: (date: Date | undefined) => void; +}; + +export type DatePickerMultipleProps = BaseProps & { + mode: "multiple"; + date: Date[] | undefined; + setDate: (date: Date[] | undefined) => void; +}; + +export type DatePickerRangeProps = BaseProps & { + mode: "range"; + date: DateRange | undefined; + setDate: (date: DateRange | undefined) => void; +}; + +export type DatePickerProps = + | DatePickerSingleProps + | DatePickerMultipleProps + | DatePickerRangeProps; + +export function DatePickerMultiMode(props: DatePickerProps) { + const { + placeholder, + disabled, + disabledDate, + captionLayout, + formatDate = "PPP", + className + } = props; + + const [open, setOpen] = useState(false); + + // Dynamic text rendering based on the active mode + const renderTriggerText = () => { + if (!props.date) return {placeholder || "Pick a date"}; + + if (props.mode === "single" || !props.mode) { + return format(props.date as Date, formatDate); + } + + if (props.mode === "multiple") { + const dates = props.date as Date[]; + if (dates.length === 0) return {placeholder || "Pick a date"}; + if (dates.length === 1) return format(dates[0], formatDate); + if (dates.length <= 2) return dates.map(d => format(d, formatDate)).join(", "); + return {dates.length} dates selected; + } + + if (props.mode === "range") { + const rangeDate = props.date as DateRange; + if (rangeDate.from) { + if (rangeDate.to) { + return ( + <> + {format(rangeDate.from, formatDate)} - {format(rangeDate.to, formatDate)} + + ); + } + return format(rangeDate.from, formatDate); + } + } + + return {placeholder || "Pick a date"}; + }; + + // Conditional Calendar rendering to appease react-day-picker strict types + const renderCalendar = () => { + const commonProps = { + captionLayout: captionLayout || "dropdown", + disabled: disabledDate, + initialFocus: true, + endMonth: new Date(2050, 11), + }; + + if (props.mode === "multiple") { + return ( + + ); + } + + if (props.mode === "range") { + return ( + + ); + } + + // Default to single + return ( + { + props.setDate(selectedDate); + setOpen(false); // Only close automatically on single select mode + }} + /> + ); + }; + + return ( + + + + + + {renderCalendar()} + + + ); +} \ No newline at end of file