All files / lib/pages/UserScore/Modal index.tsx

0% Statements 0/10
0% Branches 0/2
0% Functions 0/2
0% Lines 0/10

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                                                                                                           
import { useDeleteUserScoreMutation } from '@lib/api/mutations';
import { Form, Input, Modal, ModalProps, message } from 'antd';
import React from 'react';
 
interface UserScoreDeleteModalProps {
  modalData: ModalProps;
  closeModal: () => unknown;
  userId: string;
}
 
export default function UserScoreDeleteModal({
  modalData,
  closeModal,
  userId
}: UserScoreDeleteModalProps) {
  const [form] = Form.useForm();
 
  const { mutateAsync: deleteUserScore } = useDeleteUserScoreMutation();
 
  const handleSubmit = async ({ note }: { note: string }) => {
    try {
      const data = await deleteUserScore({
        userId,
        note
      });
 
      if (data.success) {
        message.success('유저 점수 기록을 삭제했습니다.');
 
        closeModal();
      }
    } catch (e) {
      message.error('유저 점수 기록 삭제에 실패했습니다.');
    }
  };
 
  return (
    <Modal
      {...modalData}
      onOk={form.submit}
      title="정말 유저 점수 기록을 삭제하시겠어요?"
      okText="확인"
      okButtonProps={{ danger: true }}
      cancelText="닫기"
    >
      <Form form={form} onFinish={handleSubmit} labelCol={{ span: 24 }} wrapperCol={{ span: 24 }}>
        <Form.Item name="note" rules={[{ required: true, message: '필수로 입력해주세요' }]}>
          <Input placeholder="사유를 입력해주세요." />
        </Form.Item>
      </Form>
    </Modal>
  );
}