Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | 'use client';
import useModalState from '@lib/hooks/useModalState';
import { Button, Table, Tooltip, message } from 'antd';
import styled from 'styled-components';
import { ColumnsType } from 'antd/es/table';
import { AdventureCampaignResponseDto } from '@uniquegood/realworld-adventure-interface';
import { useGetCampaignsQuery } from '@lib/api/queries';
import { useDeleteCampaignMutation } from '@lib/api/mutations';
import React from 'react';
import dayjs from 'dayjs';
import { useRouter } from 'next/navigation';
import ConfirmDeleteModal from '@lib/components/ConfirmDeleteModal';
import CreateModal from './Modal/CreateModal';
import ModifyModal from './Modal/ModifyModal';
export default function CampaignPage() {
const router = useRouter();
const {
openModal: openCreateModal,
closeModal: closeCreateModal,
modal: createModal
} = useModalState();
const {
openModal: openModifyModal,
closeModal: closeModifyModal,
modal: modifyModal
} = useModalState();
const {
openModal: openConfirmModal,
closeModal: closeConfirmModal,
modal: confirmModal
} = useModalState();
const { data, isLoading } = useGetCampaignsQuery();
const { mutateAsync } = useDeleteCampaignMutation();
const [currentCampaignId, setCurrentCampaignId] = React.useState('');
const columns: ColumnsType<AdventureCampaignResponseDto> = [
{
key: 'id',
dataIndex: 'id',
title: 'ID',
width: 200,
ellipsis: true,
render: (value) => (
<Tooltip title={value}>
<span style={{ cursor: 'pointer' }}>{value}</span>
</Tooltip>
),
onCell: (record) => ({
onClick: async (e) => {
e.stopPropagation();
await navigator.clipboard.writeText(record.id);
message.success(`ID가 복사되었습니다. [${record.id}]`);
}
})
},
{
key: 'title',
dataIndex: 'title',
title: '이름'
},
{
key: 'description',
dataIndex: 'description',
title: '설명'
},
{
key: 'isActive',
dataIndex: 'isActive',
title: '활성화 여부',
render: (value) => (value ? '활성화' : '비활성화')
},
{
key: 'startAt',
dataIndex: 'startAt',
title: '시작일',
render: (value) => (value ? dayjs(value).format('YYYY-MM-DD HH:mm') : '-')
},
{
key: 'endAt',
dataIndex: 'endAt',
title: '종료일',
render: (value) => (value ? dayjs(value).format('YYYY-MM-DD HH:mm') : '-')
},
{
title: '동작',
width: 250,
render: (record) => (
<>
<Button
size="small"
style={{ marginRight: 4 }}
onClick={(e) => {
e.stopPropagation();
router.push(`/campaigns/${record.id}/question-groups`);
}}
>
랜덤 문제 그룹 관리
</Button>
<Button
danger
size="small"
onClick={(e) => {
e.stopPropagation();
openConfirmModal({
title: '정말로 삭제하시겠어요?',
onOk: async () => {
const { success } = await mutateAsync(record.id);
if (success) {
message.success('캠페인이 삭제되었습니다.');
closeConfirmModal();
} else {
message.error('캠페인 삭제에 실패하였습니다.');
}
}
});
}}
>
삭제
</Button>
</>
)
}
];
return (
<>
<HeaderContainer>
<h1>캠페인 관리</h1>
<HeaderControllerContainer>
<Button onClick={() => openCreateModal({})}>캠페인 생성</Button>
</HeaderControllerContainer>
</HeaderContainer>
<Table
dataSource={data?.data}
columns={columns}
pagination={false}
loading={isLoading}
rowKey="id"
onRow={(record) => ({
onClick: (e) => {
e.stopPropagation();
setCurrentCampaignId(record.id);
openModifyModal({});
}
})}
/>
<CreateModal modalData={createModal} closeModal={closeCreateModal} />
<ModifyModal
modalData={modifyModal}
closeModal={closeModifyModal}
campaignId={currentCampaignId}
/>
<ConfirmDeleteModal modalData={confirmModal} />
</>
);
}
const HeaderContainer = styled.div`
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
`;
const HeaderControllerContainer = styled.div`
display: grid;
grid-auto-flow: column;
grid-auto-columns: min-content;
gap: 8px;
`;
|