From ef8f187c818e605db75bb11a71aa4804b5f4cff1 Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Tue, 7 May 2024 16:26:47 +0800 Subject: [PATCH] Copy table header --- .../ApplicationTable/ApplicationTableImpl.tsx | 6 + .../Table/ApplicationTable/TableHeader.tsx | 144 ++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 components/Table/ApplicationTable/TableHeader.tsx diff --git a/components/Table/ApplicationTable/ApplicationTableImpl.tsx b/components/Table/ApplicationTable/ApplicationTableImpl.tsx index 1024f17..190cc11 100644 --- a/components/Table/ApplicationTable/ApplicationTableImpl.tsx +++ b/components/Table/ApplicationTable/ApplicationTableImpl.tsx @@ -10,6 +10,7 @@ import { TableContainer } from '@/styles/table.styles'; import { ColumnsType, Key } from 'antd/es/table/interface'; import { VolunteerLogTableContext } from './ApplicationTable'; import { LOCALE_DATE_FORMAT } from '@/utils/constants'; +import TableHeader from './TableHeader'; const ApplicationTableImpl = () => { const { @@ -113,6 +114,11 @@ const ApplicationTableImpl = () => { return ( <> +
void; + mutate: () => void; + status: string; +}) => { + const { rowSelection, errorMessage, successMessage } = useContext( + VolunteerLogTableContext + ); + + const [statusOptions, setStatusOptions] = useState([]); + + useEffect(() => { + setStatusOptions( + Object.values(VolunteerLogStatus).map(value => ({ value, label: value })) + ); + }, []); + + const handleApprove = () => { + if (rowSelection.selectedRowKeys.length === 0) { + errorMessage('No rows selected'); + return; + } + + fetch('/api/volunteer-logs/approved', { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(rowSelection.selectedRowKeys), + }) + .then(response => { + if (!response.ok) { + throw new Error('Failed to approve hours'); + } + return response.json(); + }) + .then(data => { + if (data.status === 'error') { + errorMessage(data.message); + } else { + successMessage(data.message); + } + }) + .then(() => mutate()) + .catch(err => { + errorMessage('Sorry an error occurred'); + console.error(err); + }); + }; + + const handleReject = () => { + if (rowSelection.selectedRowKeys.length === 0) { + errorMessage('No rows selected'); + return; + } + fetch('/api/volunteer-logs/rejected', { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(rowSelection.selectedRowKeys), + }) + .then(response => { + if (!response.ok) { + throw new Error('Failed to reject hours'); + } + return response.json(); + }) + .then(data => { + if (data.status === 'error') { + errorMessage(data.message); + } else { + successMessage(data.message); + } + }) + .then(() => mutate()) + .catch(err => { + errorMessage('Sorry an error occurred'); + console.error(err); + }); + }; + + return ( + <> + + + Choose status: +