brilliant-orangeB
Refine2y ago
3 replies
brilliant-orange

Refresh the page when closing the modal

export const PointsModal = ({ type, point_id, member_id }: PointsModalProps) => {
  const {
    register,
    setValue,
    formState: { errors },
    handleSubmit,
    reset,
    refineCore: { onFinish },
  } = useForm<IPointDetail, HttpError, Nullable<IPointDetail>>({
    refineCoreProps: {
      resource: 'points',
      action: 'create',
      redirect: 'list',
    },
  })

  const handleModalOpen = async () => {
    let available_points = 0
    try {
      const response = await fetch(`${process.env.NEXT_PUBLIC_PUBLIC_IP}/points/${member_id}`, {
        headers: {
          'Content-Type': 'application/json',
        },
      })

      if (response.status === 200) {
        const data = await response.json();
        available_points = data.data.available_points;
        setValue('available_points', available_points);
      }    
    } catch (error) {
      console.error('Error get customer point : ', error);
    }
  };

  const t = useTranslate()
  const isPay = type === 'pay'
  const pointType = isPay ? 'OP01002' : 'OP01004'
  const pointTypeName = isPay ? '적립' : '회수'

  const [open, setOpen] = useState(false)

  const onSubmit = (variables: Nullable<IPointDetail>) => {
    onFinish(variables).then(() => {
      reset()
    })
    handleClose()
  }
  const handleOpen = () => {
    handleModalOpen()
    setOpen(true)
  }
  const handleClose = () => {
    setOpen(false)
  }


How to refresh when I close the modal?
Was this page helpful?