All files / lib/pages/Reward/Modal AddRewardCountModal.tsx

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

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                                                                                                                       
import { usePatchRewardQuantityMutation } from '@lib/api/mutations';
import { useGetBizMoneyQuery } from '@lib/api/queries';
import { Form, Input, Modal, ModalProps, message } from 'antd';
import styled from 'styled-components';
 
interface AddRewardCountModalProps {
  rewardId: string;
  type: string;
  modalData: ModalProps;
  closeModal: () => unknown;
}
 
export default function AddRewardCountModal({
  rewardId,
  type,
  modalData,
  closeModal
}: AddRewardCountModalProps) {
  const [form] = Form.useForm();
 
  const { data: bizMoney } = useGetBizMoneyQuery();
  const { mutateAsync: patchRewardCount } = usePatchRewardQuantityMutation(rewardId);
 
  const handleSubmit = async (values: { quantity: number }) => {
    try {
      const data = await patchRewardCount({ quantity: values.quantity });
 
      if (data.success) {
        message.success('보상 개수가 성공적으로 추가되었습니다.');
        form.resetFields();
        closeModal();
      }
    } catch (e) {
      console.error(e);
    }
  };
 
  return (
    <Modal {...modalData} onOk={form.submit} title="보상 개수 추가" okText="확인" cancelText="닫기">
      <Form form={form} onFinish={handleSubmit}>
        <Form.Item name="quantity">
          <Input placeholder="추가할 보상 개수를 입력해주세요." />
        </Form.Item>
        {type === 'GiftShow' && (
          <Description>
            기프티쇼 보상을 추가할 때는 잔여 비즈머니를 확인해주세요. <br /> 잔여 비즈머니:{' '}
            {bizMoney?.data?.bizMoney}원
          </Description>
        )}
      </Form>
    </Modal>
  );
}
 
const Description = styled.span`
  color: #888;
  font-size: 12px;
  display: block;
`;