mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:56:28 +00:00
Add project-assignment admin pages and UI updates
Add new admin Project Assignment area with Client, End User, and Project Management pages and components (tables, Export buttons, lazy-loaded pages). Introduce FormProject for creating/editing projects and export utilities to download Excel for each module. Update task types: IEndUser now includes code and a status object. Clean up FormClient by removing unused imports and inline end-user modal usage. Make BadgeStatus robust to missing status values. Add "Project Assignment" entry to the sidebar and import FolderGit2.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useCallback, useEffect, useRef, useState, type FC } from 'react';
|
||||
import { useCallback, useRef, useState, type FC } from 'react';
|
||||
import {
|
||||
AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle
|
||||
} from "@/components/ui/alert-dialog"
|
||||
@@ -9,16 +9,13 @@ import { IClient } from '../types';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { toast } from 'sonner';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { ImageIcon, Loader2, Plus, Upload, UploadIcon } from 'lucide-react';
|
||||
import { ImageIcon, Loader2, UploadIcon } from 'lucide-react';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useFetchWithAxios } from '@/lib/axios/useFetch';
|
||||
import { Combobox } from '@/components/ui/combobox';
|
||||
import Dropzone from 'react-dropzone';
|
||||
import { LazyImage } from '@/components/ui/lazy-image';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { serverApiCall } from '@/lib/server-api';
|
||||
import FormEndUser from './FormEndUser';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
@@ -37,11 +34,9 @@ type Props = {
|
||||
};
|
||||
|
||||
const FormClient: FC<Props> = ({ data, onSuccess, onCancel, isRedirectToDetail }) => {
|
||||
const [showEnduserForm, setShowEndUserForm] = useState(false)
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [currentFile, setCurrentFile] = useState<any | undefined>(undefined);
|
||||
|
||||
const { data: endUserList, mutate } = useFetchWithAxios('/end-user')
|
||||
|
||||
const existFile = data?.photo || null
|
||||
const dropzoneRef = useRef<any>(null);
|
||||
@@ -272,10 +267,6 @@ const FormClient: FC<Props> = ({ data, onSuccess, onCancel, isRedirectToDetail }
|
||||
</Form>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
||||
{showEnduserForm ?
|
||||
<FormEndUser onCancel={() => setShowEndUserForm(false)} onSuccess={() => { mutate(); setShowEndUserForm(false); }} /> : null
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,15 @@ import { IUser } from "@/app/admin/administration/user/component/type";
|
||||
|
||||
export type IEndUser = {
|
||||
id?: string;
|
||||
code?: string
|
||||
name: string;
|
||||
description: string;
|
||||
photo?: string
|
||||
status: {
|
||||
id: number
|
||||
code: string
|
||||
name: string
|
||||
}
|
||||
};
|
||||
|
||||
export type IClient = {
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
'use client'
|
||||
|
||||
import { FC, useState } from 'react';
|
||||
import { Icons } from '@/components/Icons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import { exportTable } from '@/lib/exportExcel';
|
||||
import dayjs from 'dayjs';
|
||||
import { IExcelJSColumnType } from '@/types/types';
|
||||
import { IUser } from '@/app/admin/administration/user/component/type';
|
||||
|
||||
type Props = {
|
||||
data: IUser[]
|
||||
}
|
||||
|
||||
const ExportComponent: FC<Props> = ({ data }) => {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
||||
const { data: session } = useSession()
|
||||
|
||||
const handleExport = async () => {
|
||||
setIsLoading(true)
|
||||
|
||||
const columns: IExcelJSColumnType[] = [
|
||||
{ header: 'No', key: 'number', width: 5, style: { numFmt: '0;[Red]0' } },
|
||||
{ header: 'Code', key: 'code', width: 15 },
|
||||
{ header: 'Name', key: 'name', width: 25 },
|
||||
{ header: 'Description', key: 'description', width: 25 },
|
||||
{ header: 'Total Project', key: 'total_project', width: 10 },
|
||||
{ header: 'Total WO', key: 'total_work_order', width: 10 },
|
||||
{ header: 'Total User Assigned', key: 'total_user_assigned', width: 10 },
|
||||
{ header: 'Status', key: 'status_name', width: 15 },
|
||||
]
|
||||
|
||||
const resBlob: any = await exportTable(session?.user.detail as IUser, data, columns, 'List of Clients')
|
||||
if (resBlob) {
|
||||
const url = URL.createObjectURL(resBlob);
|
||||
|
||||
// Create a link and trigger a click event to start the download
|
||||
const a = document.createElement("a");
|
||||
a.style.display = "none";
|
||||
a.href = url;
|
||||
a.download = `Client List - Export by ${session?.user.detail.nik} - ${dayjs().format('YYYYMMDD HH:mm:ss')}`; // Set the downloaded filename
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
|
||||
// Clean up by removing the temporary link and URL
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
setIsLoading(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<Button className='w-full sm:w-max' disabled={isLoading} onClick={handleExport}>
|
||||
{isLoading &&
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
}
|
||||
Download
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
export default ExportComponent;
|
||||
@@ -0,0 +1,202 @@
|
||||
'use client'
|
||||
|
||||
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
||||
import { MoreHorizontalIcon } from 'lucide-react';
|
||||
import { Table } from 'antd';
|
||||
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||
import { PlusCircledIcon } from '@radix-ui/react-icons';
|
||||
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { AlertDialogTrigger } from '@/components/ui/alert-dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
import Image from 'next/image';
|
||||
import { IClient } from '@/app/(dashboard)/task/types';
|
||||
import { LazyImage } from '@/components/ui/lazy-image';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
import FormClient from '@/app/(dashboard)/task/component/FormClient';
|
||||
import { ConfirmDeleteWithInput } from '@/components/modal/ConfirmDeleteWithInput';
|
||||
|
||||
type Props = {
|
||||
data: IClient[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const [filterData, setFilterData] = useState<IClient[]>([])
|
||||
const [action, setAction] = useState<'CREATE' | 'EDIT' | 'DELETE' | undefined>(undefined)
|
||||
const [selectedData, setSelectedData] = useState<IClient>()
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
setFilterData(data)
|
||||
}
|
||||
}, [data])
|
||||
|
||||
|
||||
|
||||
const handleSearch = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
const text = e.target.value
|
||||
if (text) {
|
||||
const newData = [...data!].filter(item => (
|
||||
item.name?.toLowerCase().includes(text.toLowerCase()) ||
|
||||
item.code?.toLowerCase().includes(text.toLowerCase()) ||
|
||||
item.description?.toLowerCase().includes(text.toLowerCase()) ||
|
||||
item.status_name?.toLowerCase().includes(text.toLowerCase())
|
||||
))
|
||||
setFilterData(newData)
|
||||
} else {
|
||||
setFilterData(data)
|
||||
}
|
||||
}
|
||||
|
||||
const handleClose = () => {
|
||||
setAction(undefined)
|
||||
setSelectedData(undefined)
|
||||
}
|
||||
|
||||
const Columns: ColumnsType<IClient> = [
|
||||
{
|
||||
title: 'No',
|
||||
dataIndex: 'key',
|
||||
render: (text, record, index) => index + 1
|
||||
},
|
||||
{
|
||||
title: 'Code',
|
||||
dataIndex: 'code',
|
||||
sorter: (a, b) => a.code.localeCompare(b.code)
|
||||
},
|
||||
{
|
||||
title: 'Client Name',
|
||||
dataIndex: 'name',
|
||||
sorter: (a, b) => a.name.localeCompare(b.name),
|
||||
render: (text, record) => (
|
||||
<div className='flex items-center space-x-2.5'>
|
||||
{record.photo ?
|
||||
<LazyImage className='w-8 h-8 rounded-md border dark:border-zinc-800 object-cover' alt='logo' src={record.photo} />
|
||||
:
|
||||
<Image alt='avatar' height={0} width={0} quality={50} src='/assets/ilustration.png' className='w-8 h-8 rounded-md border dark:border-zinc-800 object-cover' />
|
||||
}
|
||||
<p>{text}</p>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
{
|
||||
title: 'Description',
|
||||
dataIndex: 'description',
|
||||
sorter: (a, b) => a.description.localeCompare(b.description)
|
||||
},
|
||||
{
|
||||
title: 'Total Project',
|
||||
dataIndex: 'total_project',
|
||||
align: 'right'
|
||||
},
|
||||
{
|
||||
title: 'Total WO',
|
||||
dataIndex: 'total_work_order',
|
||||
align: 'right'
|
||||
},
|
||||
{
|
||||
title: 'Total User Assigned',
|
||||
dataIndex: 'total_user_assigned',
|
||||
align: 'right'
|
||||
},
|
||||
{
|
||||
title: 'Status',
|
||||
dataIndex: 'status_name',
|
||||
filters: [
|
||||
{
|
||||
text: 'ACTIVE',
|
||||
value: 'A',
|
||||
},
|
||||
{
|
||||
text: 'INACTIVE',
|
||||
value: 'N',
|
||||
},
|
||||
{
|
||||
text: 'DELETED',
|
||||
value: 'X',
|
||||
},
|
||||
],
|
||||
onFilter: (value, record) => record.status_name.indexOf(value as string) === 0,
|
||||
align: 'center',
|
||||
render: (text, record) => (
|
||||
<div className='flex justify-center text-white font-semibold text-xs'>
|
||||
<BadgeStatus status={record.status_name} />
|
||||
</div>
|
||||
)
|
||||
},
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
fixed: 'right',
|
||||
render: (_, record) => (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant='ghost' size="icon" onClick={e => e?.stopPropagation()}>
|
||||
<MoreHorizontalIcon />
|
||||
<span className="sr-only">Action Button</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" onClick={e => e?.stopPropagation()}>
|
||||
<DropdownMenuItem><Link href={`/task/client-detail/${record.id}`} className='w-full'>View Details</Link></DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit Client</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete Client
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
const tableProps: TableProps<IClient> = {
|
||||
bordered: false,
|
||||
size: 'large',
|
||||
showHeader: true,
|
||||
pagination: {
|
||||
pageSizeOptions: [5, 10, 20, 50],
|
||||
defaultPageSize: 10,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
size: 'middle' as any
|
||||
},
|
||||
scroll: { x: 'max-content' },
|
||||
tableLayout: 'auto',
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className='flex flex-col space-y-4'>
|
||||
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between space-y-2 sm:space-y-0">
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search data..." className="h-8 w-full sm:w-62.5" onChange={handleSearch} />
|
||||
</div>
|
||||
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost' onClick={() => { setAction('CREATE'); setSelectedData(undefined) }}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Client
|
||||
</Button>
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
rowKey='id'
|
||||
columns={Columns}
|
||||
dataSource={filterData || []}
|
||||
style={{ cursor: "pointer" }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{(action === 'CREATE' || action === 'EDIT') && <FormClient data={selectedData} onCancel={handleClose} onSuccess={() => { router.refresh(); handleClose() }} />}
|
||||
|
||||
{action === 'DELETE' ? <ConfirmDeleteWithInput endpoint={`/client/${selectedData?.id}`} onCancel={handleClose} onSuccess={() => { 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`}
|
||||
/> : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default ComponentPage;
|
||||
@@ -0,0 +1,38 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
const ExportComponent = lazy(() => import('./component/Export'));
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Client - Project Assignment | Admin",
|
||||
}
|
||||
export default async function ClientPage() {
|
||||
const data = await fetchData('/client')
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-col">
|
||||
<Card>
|
||||
<CardHeader className='flex flex-col md:flex-row items-center justify-between space-y-5 sm:space-y-0'>
|
||||
<div>
|
||||
<CardTitle>Client Management</CardTitle>
|
||||
<CardDescription className='mt-1'>Here's a list of clients that have been registered for project assignment!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data} />
|
||||
</Suspense>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={data} />
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
'use client'
|
||||
|
||||
import { FC, useState } from 'react';
|
||||
import { Icons } from '@/components/Icons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import { exportTable } from '@/lib/exportExcel';
|
||||
import dayjs from 'dayjs';
|
||||
import { IExcelJSColumnType } from '@/types/types';
|
||||
import { IUser } from '@/app/admin/administration/user/component/type';
|
||||
|
||||
type Props = {
|
||||
data: IUser[]
|
||||
}
|
||||
|
||||
const ExportComponent: FC<Props> = ({ data }) => {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
||||
const { data: session } = useSession()
|
||||
|
||||
const handleExport = async () => {
|
||||
setIsLoading(true)
|
||||
|
||||
const columns: IExcelJSColumnType[] = [
|
||||
{ header: 'No', key: 'number', width: 5, style: { numFmt: '0;[Red]0' } },
|
||||
{ header: 'Code', key: 'code', width: 15 },
|
||||
{ header: 'Name', key: 'name', width: 25 },
|
||||
{ header: 'Description', key: 'description', width: 25 },
|
||||
{ header: 'Status', key: 'status', value: 'status.name', width: 15 }
|
||||
]
|
||||
|
||||
const resBlob: any = await exportTable(session?.user.detail as IUser, data, columns, 'List of End Users')
|
||||
if (resBlob) {
|
||||
const url = URL.createObjectURL(resBlob);
|
||||
|
||||
// Create a link and trigger a click event to start the download
|
||||
const a = document.createElement("a");
|
||||
a.style.display = "none";
|
||||
a.href = url;
|
||||
a.download = `End User List - Export by ${session?.user.detail.nik} - ${dayjs().format('YYYYMMDD HH:mm:ss')}`; // Set the downloaded filename
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
|
||||
// Clean up by removing the temporary link and URL
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
setIsLoading(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<Button className='w-full sm:w-max' disabled={isLoading} onClick={handleExport}>
|
||||
{isLoading &&
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
}
|
||||
Download
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
export default ExportComponent;
|
||||
@@ -0,0 +1,183 @@
|
||||
'use client'
|
||||
|
||||
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
||||
import { MoreHorizontalIcon } from 'lucide-react';
|
||||
import { Table } from 'antd';
|
||||
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||
import { PlusCircledIcon } from '@radix-ui/react-icons';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import Image from 'next/image';
|
||||
import { IEndUser } from '@/app/(dashboard)/task/types';
|
||||
import { LazyImage } from '@/components/ui/lazy-image';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
import { ConfirmDeleteWithInput } from '@/components/modal/ConfirmDeleteWithInput';
|
||||
import FormEndUser from '@/app/(dashboard)/task/component/FormEndUser';
|
||||
|
||||
type Props = {
|
||||
data: IEndUser[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const [filterData, setFilterData] = useState<IEndUser[]>([])
|
||||
const [action, setAction] = useState<'CREATE' | 'EDIT' | 'DELETE' | undefined>(undefined)
|
||||
const [selectedData, setSelectedData] = useState<IEndUser>()
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
setFilterData(data)
|
||||
}
|
||||
}, [data])
|
||||
|
||||
|
||||
|
||||
const handleSearch = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
const text = e.target.value
|
||||
if (text) {
|
||||
const newData = [...data!].filter(item => (
|
||||
item.name?.toLowerCase().includes(text.toLowerCase()) ||
|
||||
item.code?.toLowerCase()?.includes(text.toLowerCase()) ||
|
||||
item.description?.toLowerCase().includes(text.toLowerCase()) ||
|
||||
item?.status.name.toLowerCase()?.includes(text.toLowerCase())
|
||||
))
|
||||
setFilterData(newData)
|
||||
} else {
|
||||
setFilterData(data)
|
||||
}
|
||||
}
|
||||
|
||||
const handleClose = () => {
|
||||
setAction(undefined)
|
||||
setSelectedData(undefined)
|
||||
}
|
||||
|
||||
const Columns: ColumnsType<IEndUser> = [
|
||||
{
|
||||
title: 'No',
|
||||
dataIndex: 'key',
|
||||
render: (text, record, index) => index + 1
|
||||
},
|
||||
{
|
||||
title: 'Code',
|
||||
dataIndex: 'code',
|
||||
sorter: (a, b) => a.code!.localeCompare(b.code!)
|
||||
},
|
||||
{
|
||||
title: 'End User Name',
|
||||
dataIndex: 'name',
|
||||
sorter: (a, b) => a.name.localeCompare(b.name),
|
||||
render: (text, record) => (
|
||||
<div className='flex items-center space-x-2.5'>
|
||||
{record.photo ?
|
||||
<LazyImage className='w-8 h-8 rounded-md border dark:border-zinc-800 object-cover' alt='logo' src={record.photo} />
|
||||
:
|
||||
<Image alt='avatar' height={0} width={0} quality={50} src='/assets/ilustration.png' className='w-8 h-8 rounded-md border dark:border-zinc-800 object-cover' />
|
||||
}
|
||||
<p>{text}</p>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
{
|
||||
title: 'Description',
|
||||
dataIndex: 'description',
|
||||
sorter: (a, b) => a.description.localeCompare(b.description)
|
||||
},
|
||||
{
|
||||
title: 'Status',
|
||||
dataIndex: 'status_name',
|
||||
filters: [
|
||||
{
|
||||
text: 'ACTIVE',
|
||||
value: 'A',
|
||||
},
|
||||
{
|
||||
text: 'INACTIVE',
|
||||
value: 'N',
|
||||
},
|
||||
{
|
||||
text: 'DELETED',
|
||||
value: 'X',
|
||||
},
|
||||
],
|
||||
onFilter: (value, record) => record.status.code?.indexOf(value as string) === 0,
|
||||
align: 'center',
|
||||
render: (text, record) => (
|
||||
<div className='flex justify-center text-white font-semibold text-xs'>
|
||||
<BadgeStatus status={record.status.name} />
|
||||
</div>
|
||||
)
|
||||
},
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
fixed: 'right',
|
||||
render: (_, record) => (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant='ghost' size="icon" onClick={e => e?.stopPropagation()}>
|
||||
<MoreHorizontalIcon />
|
||||
<span className="sr-only">Action Button</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" onClick={e => e?.stopPropagation()}>
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit End User</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete End User
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
const tableProps: TableProps<IEndUser> = {
|
||||
bordered: false,
|
||||
size: 'large',
|
||||
showHeader: true,
|
||||
pagination: {
|
||||
pageSizeOptions: [5, 10, 20, 50],
|
||||
defaultPageSize: 10,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
size: 'middle' as any
|
||||
},
|
||||
scroll: { x: 'max-content' },
|
||||
tableLayout: 'auto',
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className='flex flex-col space-y-4'>
|
||||
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between space-y-2 sm:space-y-0">
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search data..." className="h-8 w-full sm:w-62.5" onChange={handleSearch} />
|
||||
</div>
|
||||
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost' onClick={() => { setAction('CREATE'); setSelectedData(undefined) }}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New End User
|
||||
</Button>
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
rowKey='id'
|
||||
columns={Columns}
|
||||
dataSource={filterData || []}
|
||||
style={{ cursor: "pointer" }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{(action === 'CREATE' || action === 'EDIT') && <FormEndUser data={selectedData} onCancel={handleClose} onSuccess={() => { router.refresh(); handleClose() }} />}
|
||||
|
||||
{action === 'DELETE' ? <ConfirmDeleteWithInput endpoint={`/end-user/${selectedData?.id}`} onCancel={handleClose} onSuccess={() => { router.refresh(); handleClose() }}
|
||||
title={selectedData?.name!} description={`This action cannot be undone. This will permanently delete and remove End User ${selectedData?.name} from our servers.`}
|
||||
titleButton={`I understand the consequences, delete this End User`}
|
||||
/> : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default ComponentPage;
|
||||
@@ -0,0 +1,38 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
const ExportComponent = lazy(() => import('./component/Export'));
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "End User - Project Assignment | Admin",
|
||||
}
|
||||
export default async function EndUserPage() {
|
||||
const data = await fetchData('/end-user')
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-col">
|
||||
<Card>
|
||||
<CardHeader className='flex flex-col md:flex-row items-center justify-between space-y-5 sm:space-y-0'>
|
||||
<div>
|
||||
<CardTitle>End User Management</CardTitle>
|
||||
<CardDescription className='mt-1'>Here's a list of end users that have been registered for project assignment!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data} />
|
||||
</Suspense>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={data} />
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
'use client'
|
||||
|
||||
import { FC, useState } from 'react';
|
||||
import { Icons } from '@/components/Icons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import { exportTable } from '@/lib/exportExcel';
|
||||
import dayjs from 'dayjs';
|
||||
import { IExcelJSColumnType } from '@/types/types';
|
||||
import { IUser } from '@/app/admin/administration/user/component/type';
|
||||
|
||||
type Props = {
|
||||
data: IUser[]
|
||||
}
|
||||
|
||||
const ExportComponent: FC<Props> = ({ data }) => {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
||||
const { data: session } = useSession()
|
||||
|
||||
const handleExport = async () => {
|
||||
setIsLoading(true)
|
||||
|
||||
const columns: IExcelJSColumnType[] = [
|
||||
{ header: 'No', key: 'number', width: 5, style: { numFmt: '0;[Red]0' } },
|
||||
{ header: 'Code', key: 'code', value: 'project.code', width: 15 },
|
||||
{ header: 'Name', key: 'name', value: 'project.name', width: 25 },
|
||||
{ header: 'Client Name', key: 'client', value: 'client.name', width: 25 },
|
||||
{ header: 'End User Name', key: 'end_user', value: 'end_user.name', width: 25 },
|
||||
{ header: 'Year', key: 'year', value: 'project.year', width: 25 },
|
||||
{ header: 'Start Date', key: 'start_date', value: 'project.start_date', style: { numFmt: 'dd/mm/yyyy' }, width: 25 },
|
||||
{ header: 'End Date', key: 'end_date', value: 'project.end_date', style: { numFmt: 'dd/mm/yyyy' }, width: 25 },
|
||||
{ header: 'Description', key: 'description', value: 'project.description', width: 25 },
|
||||
{ header: 'Status', key: 'status', value: 'status.name', width: 15 }
|
||||
]
|
||||
|
||||
const resBlob: any = await exportTable(session?.user.detail as IUser, data, columns, 'List of Projects')
|
||||
if (resBlob) {
|
||||
const url = URL.createObjectURL(resBlob);
|
||||
|
||||
// Create a link and trigger a click event to start the download
|
||||
const a = document.createElement("a");
|
||||
a.style.display = "none";
|
||||
a.href = url;
|
||||
a.download = `Project List - Export by ${session?.user.detail.nik} - ${dayjs().format('YYYYMMDD HH:mm:ss')}`; // Set the downloaded filename
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
|
||||
// Clean up by removing the temporary link and URL
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
setIsLoading(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<Button className='w-full sm:w-max' disabled={isLoading} onClick={handleExport}>
|
||||
{isLoading &&
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
}
|
||||
Download
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
export default ExportComponent;
|
||||
@@ -0,0 +1,231 @@
|
||||
import { useState, type FC } from 'react';
|
||||
import {
|
||||
AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle
|
||||
} from "@/components/ui/alert-dialog"
|
||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form";
|
||||
import * as Yup from 'yup'
|
||||
import { yupResolver } from '@hookform/resolvers/yup';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { toast } from 'sonner';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { CheckCircle, Loader2 } from 'lucide-react';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { serverApiCall } from '@/lib/server-api';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { LazyImage } from '@/components/ui/lazy-image';
|
||||
import { useFetchWithAxios } from '@/lib/axios/useFetch';
|
||||
import { ComboboxCustomUI } from '@/components/ui/combobox-custom-ui';
|
||||
import { IClient, IEndUser } from '@/app/(dashboard)/task/types';
|
||||
import { DatePicker } from '@/components/ui/datepicker';
|
||||
import { IProjectAssignment } from '@/app/(dashboard)/task/type.assignment';
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
client_id: Yup.number().required(),
|
||||
end_user_id: Yup.number().required(),
|
||||
name: Yup.string().required(),
|
||||
code: Yup.string().required('Project code is required'),
|
||||
year: Yup.string().required('Year is required'),
|
||||
start_date: Yup.date().required('Start date is required'),
|
||||
end_date: Yup.date().nullable().min(Yup.ref('start_date'), 'End date cannot be before start date').default(null),
|
||||
description: Yup.string().optional().default(''),
|
||||
});
|
||||
|
||||
type FormDataType = Yup.InferType<typeof validationSchema>;
|
||||
|
||||
type Props = {
|
||||
data?: IProjectAssignment
|
||||
onCancel?: VoidFunction
|
||||
onSuccess?: VoidFunction;
|
||||
};
|
||||
|
||||
const FormProject: FC<Props> = ({ data, onSuccess, onCancel }) => {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const { data: clientList } = useFetchWithAxios('/client')
|
||||
const { data: endUserList } = useFetchWithAxios('/end-user')
|
||||
|
||||
const form = useForm<FormDataType>({
|
||||
resolver: yupResolver(validationSchema),
|
||||
defaultValues: {
|
||||
"name": data?.project?.name || '',
|
||||
client_id: data?.client.id || undefined,
|
||||
end_user_id: data?.end_user.id || undefined,
|
||||
code: data?.project?.code || '',
|
||||
year: data?.project?.year || '',
|
||||
start_date: data?.project?.start_date ? new Date(data.project.start_date) : undefined,
|
||||
end_date: data?.project?.end_date ? new Date(data.project.end_date) : null,
|
||||
'description': data?.project?.description || '',
|
||||
},
|
||||
});
|
||||
|
||||
const onSubmit = async (payload: FormDataType) => {
|
||||
setIsLoading(true);
|
||||
|
||||
let res: any
|
||||
if (data) {
|
||||
res = await serverApiCall('PUT', `/project/${data.id}`, payload)
|
||||
} else {
|
||||
res = await serverApiCall('POST', '/project', payload)
|
||||
}
|
||||
|
||||
setIsLoading(false)
|
||||
if (res.success) {
|
||||
toast.success('Project saved successfully')
|
||||
onSuccess!()
|
||||
} else {
|
||||
toast.error(`Fail to save project`, { description: `(${res.code || '-'}) ${res.message}` })
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<AlertDialog open={true}>
|
||||
<AlertDialogContent className='max-h-[90vh] overflow-y-auto'>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Project Information</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
Enter the basic details of the Project.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)}>
|
||||
<div className="grid grid-cols-1 gap-4 mb-6">
|
||||
<FormField control={form.control} name='name'
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Project Name <span className='text-red-600 font-bold'>*</span></FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} placeholder='e.g. PT ASDP Indonesia Ferry' />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField control={form.control} name='client_id'
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Client</FormLabel>
|
||||
<FormControl>
|
||||
<ComboboxCustomUI options={clientList && clientList.length > 0 ? clientList.map((item: IClient) => ({ label: item.name, value: item.id, originalData: item })) : []}
|
||||
value={field.value} onChange={field.onChange} placeholder='Select client' className='shrink'
|
||||
|
||||
// --- CUSTOM DROPDOWN OPTIONS ---
|
||||
renderOption={(option, isSelected) => {
|
||||
const item = option.originalData as IClient;
|
||||
return (
|
||||
<div className={`flex items-center justify-between w-full py-1 rounded-sm ${isSelected ? 'bg-zinc-800' : ''}`}>
|
||||
<div className="flex items-center gap-3">
|
||||
<LazyImage className='w-10 h-10 rounded-md border border-border' alt={item.name} src={item.photo ? item.photo : '/assets/ilustration.png'} />
|
||||
<div className="flex flex-col">
|
||||
<span className={`text-sm ${isSelected ? 'font-bold text-primary' : ''}`}>
|
||||
{item.name}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground truncate">
|
||||
{item.description}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{isSelected && <CheckCircle className="h-5 w-5 -translate-x-2" />}
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField control={form.control} name='end_user_id'
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>End User</FormLabel>
|
||||
<FormControl>
|
||||
<ComboboxCustomUI options={endUserList && endUserList.length > 0 ? endUserList.map((item: IEndUser) => ({ label: item.name, value: item.id, originalData: item })) : []}
|
||||
value={field.value} onChange={field.onChange} placeholder='Select end user' className='shrink'
|
||||
|
||||
// --- CUSTOM DROPDOWN OPTIONS ---
|
||||
renderOption={(option, isSelected) => {
|
||||
const item = option.originalData as IEndUser;
|
||||
return (
|
||||
<div className={`flex items-center justify-between w-full py-1 rounded-sm ${isSelected ? 'bg-zinc-800' : ''}`}>
|
||||
<div className="flex items-center gap-3">
|
||||
<LazyImage className='w-10 h-10 rounded-md border border-border' alt={item.name} src={item.photo ? item.photo : '/assets/ilustration.png'} />
|
||||
<div className="flex flex-col">
|
||||
<span className={`text-sm ${isSelected ? 'font-bold text-primary' : ''}`}>
|
||||
{item.name}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground truncate">
|
||||
{item.description}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{isSelected && <CheckCircle className="h-5 w-5 -translate-x-2" />}
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<div className="grid md:grid-cols-2 gap-4">
|
||||
<FormField control={form.control} name="code" render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Code</FormLabel>
|
||||
<FormControl><Input placeholder="e.g. 24016" {...field} /></FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
<FormField control={form.control} name="year" render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Year</FormLabel>
|
||||
<FormControl><Input placeholder="e.g. 2024" {...field} /></FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
</div>
|
||||
|
||||
<div className="grid md:grid-cols-2 gap-4">
|
||||
<FormField control={form.control} name="start_date" render={({ field }) => (
|
||||
<FormItem className="flex flex-col">
|
||||
<FormLabel>Start Date</FormLabel>
|
||||
<DatePicker date={field.value} setDate={field.onChange} />
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
<FormField control={form.control} name="end_date" render={({ field }) => (
|
||||
<FormItem className="flex flex-col">
|
||||
<FormLabel>End Date</FormLabel>
|
||||
<DatePicker date={field.value as Date | undefined} setDate={field.onChange} />
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
</div>
|
||||
|
||||
<FormField control={form.control} name="description" render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Description</FormLabel>
|
||||
<FormControl>
|
||||
<Textarea placeholder="Describe the scope..." className="min-h-30" {...field} value={field.value || ''} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
</div>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel onClick={onCancel} disabled={isLoading} type='button'>Cancel</AlertDialogCancel>
|
||||
<Button type="submit" disabled={isLoading}>
|
||||
{isLoading && <Loader2 className='animate-spin' />}
|
||||
Save Project
|
||||
</Button>
|
||||
</AlertDialogFooter>
|
||||
</form>
|
||||
</Form>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default FormProject;
|
||||
@@ -0,0 +1,203 @@
|
||||
'use client'
|
||||
|
||||
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
||||
import { MoreHorizontalIcon } from 'lucide-react';
|
||||
import { Table } from 'antd';
|
||||
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||
import { PlusCircledIcon } from '@radix-ui/react-icons';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
import { ConfirmDeleteWithInput } from '@/components/modal/ConfirmDeleteWithInput';
|
||||
import { IProjectAssignment } from '@/app/(dashboard)/task/type.assignment';
|
||||
import dayjs from 'dayjs';
|
||||
import FormProject from './FormProject';
|
||||
|
||||
type Props = {
|
||||
data: IProjectAssignment[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const [filterData, setFilterData] = useState<IProjectAssignment[]>([])
|
||||
const [action, setAction] = useState<'CREATE' | 'EDIT' | 'DELETE' | undefined>(undefined)
|
||||
const [selectedData, setSelectedData] = useState<IProjectAssignment>()
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
setFilterData(data)
|
||||
}
|
||||
}, [data])
|
||||
|
||||
|
||||
|
||||
const handleSearch = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
const text = e.target.value
|
||||
if (text) {
|
||||
const newData = [...data!].filter(item => (
|
||||
item.project?.name?.toLowerCase().includes(text.toLowerCase()) ||
|
||||
item.project?.code?.toLowerCase()?.includes(text.toLowerCase()) ||
|
||||
item.project?.description?.toLowerCase().includes(text.toLowerCase()) ||
|
||||
item.client.name?.toLowerCase().includes(text.toLowerCase()) ||
|
||||
item.end_user.name?.toLowerCase().includes(text.toLowerCase()) ||
|
||||
item?.status.name.toLowerCase()?.includes(text.toLowerCase())
|
||||
))
|
||||
setFilterData(newData)
|
||||
} else {
|
||||
setFilterData(data)
|
||||
}
|
||||
}
|
||||
|
||||
const handleClose = () => {
|
||||
setAction(undefined)
|
||||
setSelectedData(undefined)
|
||||
}
|
||||
|
||||
const Columns: ColumnsType<IProjectAssignment> = [
|
||||
{
|
||||
title: 'No',
|
||||
dataIndex: 'key',
|
||||
render: (text, record, index) => index + 1
|
||||
},
|
||||
{
|
||||
title: 'Code',
|
||||
dataIndex: 'project.code',
|
||||
sorter: (a, b) => a.project?.code?.localeCompare(b.project?.code!)!,
|
||||
render: (_, record) => <span>{record.project?.code}</span>
|
||||
},
|
||||
{
|
||||
title: 'Project Name',
|
||||
dataIndex: 'project.name',
|
||||
sorter: (a, b) => a.project?.name.localeCompare(b.project?.name!)!,
|
||||
render: (_, record) => <span>{record.project?.name}</span>
|
||||
},
|
||||
{
|
||||
title: 'Client',
|
||||
dataIndex: 'client.name',
|
||||
sorter: (a, b) => a.client?.name.localeCompare(b.client?.name!)!,
|
||||
render: (_, record) => <span>{record.client?.name}</span>
|
||||
},
|
||||
{
|
||||
title: 'End User',
|
||||
dataIndex: 'end_user.name',
|
||||
sorter: (a, b) => a.end_user?.name.localeCompare(b.end_user?.name!)!,
|
||||
render: (_, record) => <span>{record.end_user?.name}</span>
|
||||
},
|
||||
{
|
||||
title: 'Year',
|
||||
dataIndex: 'project.year',
|
||||
render: (_, record) => <span>{record.project?.year}</span>
|
||||
},
|
||||
{
|
||||
title: 'Start Date',
|
||||
dataIndex: 'project.start_date',
|
||||
render: (_, record) => record.project?.start_date ? <span>{dayjs(record.project.start_date).format('DD MMM YYYY')}</span> : <span>-</span>
|
||||
},
|
||||
{
|
||||
title: 'End Date',
|
||||
dataIndex: 'project.end_date',
|
||||
render: (_, record) => record.project?.end_date ? <span>{dayjs(record.project.end_date).format('DD MMM YYYY')}</span> : <span>-</span>
|
||||
},
|
||||
{
|
||||
title: 'Description',
|
||||
dataIndex: 'project.description',
|
||||
render: (_, record) => <span>{record.project?.description}</span>
|
||||
},
|
||||
{
|
||||
title: 'Status',
|
||||
dataIndex: 'status_name',
|
||||
filters: [
|
||||
{
|
||||
text: 'ACTIVE',
|
||||
value: 'A',
|
||||
},
|
||||
{
|
||||
text: 'INACTIVE',
|
||||
value: 'N',
|
||||
},
|
||||
{
|
||||
text: 'DELETED',
|
||||
value: 'X',
|
||||
},
|
||||
],
|
||||
onFilter: (value, record) => record.status.name?.indexOf(value as string) === 0,
|
||||
align: 'center',
|
||||
render: (text, record) => (
|
||||
<div className='flex justify-center text-white font-semibold text-xs'>
|
||||
<BadgeStatus status={record.status.name} />
|
||||
</div>
|
||||
)
|
||||
},
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
fixed: 'right',
|
||||
render: (_, record) => (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant='ghost' size="icon" onClick={e => e?.stopPropagation()}>
|
||||
<MoreHorizontalIcon />
|
||||
<span className="sr-only">Action Button</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" onClick={e => e?.stopPropagation()}>
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit Project</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete Project
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
const tableProps: TableProps<IProjectAssignment> = {
|
||||
bordered: false,
|
||||
size: 'small',
|
||||
showHeader: true,
|
||||
pagination: {
|
||||
pageSizeOptions: [5, 10, 20, 50],
|
||||
defaultPageSize: 10,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
size: 'middle' as any
|
||||
},
|
||||
scroll: { x: 'max-content' },
|
||||
tableLayout: 'auto',
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className='flex flex-col space-y-4'>
|
||||
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between space-y-2 sm:space-y-0">
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search data..." className="h-8 w-full sm:w-62.5" onChange={handleSearch} />
|
||||
</div>
|
||||
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost' onClick={() => { setAction('CREATE'); setSelectedData(undefined) }}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Project
|
||||
</Button>
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
rowKey='id'
|
||||
columns={Columns}
|
||||
dataSource={filterData || []}
|
||||
style={{ cursor: "pointer" }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{(action === 'CREATE' || action === 'EDIT') && <FormProject data={selectedData} onCancel={handleClose} onSuccess={() => { router.refresh(); handleClose() }} />}
|
||||
|
||||
{action === 'DELETE' ? <ConfirmDeleteWithInput endpoint={`/project/${selectedData?.id}`} onCancel={handleClose} onSuccess={() => { router.refresh(); handleClose() }}
|
||||
title={selectedData?.project?.name!} description={`This action cannot be undone. This will permanently delete and remove project ${selectedData?.project?.name} from our servers.`}
|
||||
titleButton={`I understand the consequences, delete this project`}
|
||||
/> : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default ComponentPage;
|
||||
@@ -0,0 +1,38 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
const ExportComponent = lazy(() => import('./component/Export'));
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Project - Project Assignment | Admin",
|
||||
}
|
||||
export default async function ProjectManagementPage() {
|
||||
const data = await fetchData('/project')
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-col">
|
||||
<Card>
|
||||
<CardHeader className='flex flex-col md:flex-row items-center justify-between space-y-5 sm:space-y-0'>
|
||||
<div>
|
||||
<CardTitle>Project Management</CardTitle>
|
||||
<CardDescription className='mt-1'>Here's a list of projects that have been registered for project assignment!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data} />
|
||||
</Suspense>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={data} />
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { Badge, STATUS_BADGE_MAP } from "@/components/ui/badge"
|
||||
|
||||
export default function BadgeStatus({ status, className }: { status: string, className?: string }) { // e.g. status = "UAT"
|
||||
return (
|
||||
<Badge variant={STATUS_BADGE_MAP[status?.toLowerCase()] || "default"} className={className}>
|
||||
<Badge variant={STATUS_BADGE_MAP[status ? status?.toLowerCase() : ''] || "default"} className={className}>
|
||||
{status}
|
||||
</Badge>
|
||||
)
|
||||
|
||||
+21
-2
@@ -1,4 +1,4 @@
|
||||
import { LayoutDashboard, Settings, MonitorSmartphone, Database, ShieldAlert, FileText, Circle, ScanFace, MenuSquare, CalendarX2 } from 'lucide-react'
|
||||
import { LayoutDashboard, Settings, MonitorSmartphone, Database, ShieldAlert, FileText, Circle, ScanFace, MenuSquare, CalendarX2, FolderGit2 } from 'lucide-react'
|
||||
|
||||
const SIDEBAR_MENU = [
|
||||
{
|
||||
@@ -106,10 +106,29 @@ const SIDEBAR_MENU = [
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
title: "Project Assignment",
|
||||
Icon: <FolderGit2 size={18} />,
|
||||
submenuId: 5,
|
||||
submenuItems: [
|
||||
{
|
||||
title: "Client",
|
||||
path: '/project-assignment/client'
|
||||
},
|
||||
{
|
||||
title: "End User",
|
||||
path: '/project-assignment/end-user'
|
||||
},
|
||||
{
|
||||
title: "Project Management",
|
||||
path: '/project-assignment/project-management'
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
title: "Information",
|
||||
Icon: <ShieldAlert size={18} />,
|
||||
submenuId: 5,
|
||||
submenuId: 6,
|
||||
submenuItems: [
|
||||
{
|
||||
title: "Master Status",
|
||||
|
||||
Reference in New Issue
Block a user