All files / lib/pages/QuestionGroup/Modal CreateQuestionGroupModal.tsx

0% Statements 0/12
0% Branches 0/4
0% Functions 0/2
0% Lines 0/12

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                                                                                                               
import { usePostCreateQuestionGroupMutation } from '@lib/api/mutations';
import { CreateOrUpdateQuestionGroupRequestDto } from '@uniquegood/realworld-adventure-interface';
import { Form, Input, Modal, ModalProps, message } from 'antd';
import axios from 'axios';
 
type CreateQuestionGroupModalProps = {
  modalData: ModalProps;
  closeModal: () => unknown;
};
 
export default function CreateQuestionGroupModal({
  modalData,
  closeModal
}: CreateQuestionGroupModalProps) {
  const [form] = Form.useForm();
 
  const { mutateAsync: createQuestionGroup } = usePostCreateQuestionGroupMutation();
 
  const handleSubmit = async (values: CreateOrUpdateQuestionGroupRequestDto) => {
    try {
      const data = await createQuestionGroup(values);
 
      if (data.success) {
        message.success('랜덤 문제 그룹이 생성되었습니다.');
 
        closeModal();
      }
    } catch (e) {
      if (axios.isAxiosError(e)) {
        console.error(e);
 
        message.error(e.response?.data.message);
      }
    }
  };
 
  return (
    <Modal
      {...modalData}
      title="랜덤 문제 그룹 생성"
      okText="확인"
      cancelText="닫기"
      onOk={form.submit}
    >
      <Form form={form} onFinish={handleSubmit} preserve={false}>
        <Form.Item name="title" label="제목">
          <Input placeholder="제목을 입력해주세요." />
        </Form.Item>
        <Form.Item name="description" label="설명">
          <Input placeholder="내용을 입력해주세요." />
        </Form.Item>
      </Form>
    </Modal>
  );
}