"use client"; import { useState } from 'react'; import { useRouter, useSearchParams } from 'next/navigation'; import { Users } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { IClient } from '../../types'; import dynamic from 'next/dynamic'; const ClientGrid = dynamic(() => import('./ClientGrid'), { ssr: false, loading: () => (
{[1, 2, 3, 4, 5, 6].map((i) => (
))}
), }); const ClientList = dynamic(() => import('./ClientList'), { ssr: false, loading: () => (
{[1, 2, 3, 4].map((i) => (
))}
), }); const FormClient = dynamic(() => import('./FormClient'), { ssr: false }); const ConfirmDeleteWithInput = dynamic( () => import('@/components/modal/ConfirmDeleteWithInput').then((mod) => mod.ConfirmDeleteWithInput), { ssr: false } ); interface ClientProps { clients: IClient[]; initialLayout?: 'grid' | 'list'; actions: string[]; } export default function Client({ clients, actions, initialLayout = 'grid' }: ClientProps) { const router = useRouter(); const searchParams = useSearchParams(); const layout = searchParams?.get('layout') === 'list' ? 'list' : initialLayout; const [action, setAction] = useState<'EDIT' | 'DELETE' | undefined>(undefined); const [selectedData, setSelectedData] = useState(); const handleClose = () => { setAction(undefined); setSelectedData(undefined); }; const handleEdit = (client: IClient) => { setSelectedData(client); setAction('EDIT'); }; const handleDelete = (client: IClient) => { setSelectedData(client); setAction('DELETE'); }; return ( <> {clients.length === 0 ? (

No Client Found

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

{actions?.includes('CREATE') && }
) : null} {clients.length > 0 && layout === 'list' ? : null} {clients.length > 0 && layout === 'grid' ? : null} {action === 'EDIT' && ( { router.refresh(); handleClose(); }} /> )} {action === 'DELETE' && selectedData ? { 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} ); }