diff --git a/src/components/common/table/Table.tsx b/src/components/common/table/Table.tsx index d6537526..5f53ceba 100644 --- a/src/components/common/table/Table.tsx +++ b/src/components/common/table/Table.tsx @@ -2,10 +2,12 @@ import { useEffect, useState } from 'react'; import TableStatus from './TableStatus'; import TableButtons from './TableButtons'; import Pagination from '../Pagination'; +import Modal from '../Modal'; import formatWorkTime from '@/utils/formatWorkTime'; import { getNoticeApplications, getUserApplications, + putNoticeApplications, } from '@/api/applicationApi'; interface UserProps { @@ -32,6 +34,53 @@ export default function Table(props: UserProps | NoticeProps) { ); const [page, setPage] = useState(1); const [totalPage, setTotalPage] = useState(1); + const [modal, setModal] = useState<{ + isOpen: boolean; + status: 'accepted' | 'rejected'; + dataIndex: number; + }>({ + isOpen: false, + status: 'accepted', + dataIndex: 0, + }); + + const closeModal = () => + setModal((prev) => { + return { ...prev, isOpen: false }; + }); + + const clickButton = (dataIndex: number, status: 'accepted' | 'rejected') => { + setModal({ + isOpen: true, + status, + dataIndex, + }); + }; + + const handleModalClick = async () => { + closeModal(); + if (mode === 'user') return; + + setDatas((prev) => { + prev[modal.dataIndex][3] = modal.status; + return prev; + }); + try { + await putNoticeApplications( + props.shopId, + props.noticeId, + datas[modal.dataIndex][4] ?? '', + { + status: modal.status, + }, + ); + } catch { + setDatas((prev) => { + prev[modal.dataIndex][3] = 'pending'; + return prev; + }); + } + }; useEffect(() => { (async () => { @@ -97,68 +146,77 @@ export default function Table(props: UserProps | NoticeProps) { }, [mode, page]); return ( -
| - {headers[0]} - | -- {headers[1]} - | -- {headers[2]} - | -- {headers[3]} - | -||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
-
- {data[0]}
-
- |
-
-
- {data[1]}
-
- |
-
-
- {data[2]}
-
- |
-
-
- {mode === 'notice' && data[3] === 'pending' ? (
-
- |
+ <>
+
| + {headers[0]} + | ++ {headers[1]} + | ++ {headers[2]} + | ++ {headers[3]} + |
|---|