({
isOpen,
onClose,
title,
}: DialogProps)
| 24 | } |
| 25 | |
| 26 | export default function NewPayoutDialog({ |
| 27 | isOpen, |
| 28 | onClose, |
| 29 | title, |
| 30 | }: DialogProps) { |
| 31 | if (!isOpen) return null; |
| 32 | const fieldName = title === 'Solana' ? 'solanaAddress' : 'upiId'; |
| 33 | |
| 34 | const [isLoading, setIsLoading] = useState<boolean>(false); |
| 35 | |
| 36 | const { |
| 37 | handleSubmit, |
| 38 | register, |
| 39 | formState: { errors }, |
| 40 | reset, |
| 41 | } = useForm<z.infer<typeof payoutMethodSchema>>({ |
| 42 | resolver: zodResolver(payoutMethodSchema), |
| 43 | }); |
| 44 | |
| 45 | const { execute: executeAddUpi } = useAction(addUpi, { |
| 46 | onSuccess: () => { |
| 47 | toast.success('UPI address added'); |
| 48 | setIsLoading(false); |
| 49 | reset(); |
| 50 | onClose(); |
| 51 | }, |
| 52 | onError: (error) => { |
| 53 | toast.error(error); |
| 54 | setIsLoading(false); |
| 55 | }, |
| 56 | }); |
| 57 | const { execute: executeAddSolanaAddress } = useAction(addSolanaAddress, { |
| 58 | onSuccess: () => { |
| 59 | toast.success('Solana address added'); |
| 60 | setIsLoading(false); |
| 61 | reset(); |
| 62 | onClose(); |
| 63 | }, |
| 64 | onError: (error) => { |
| 65 | toast.error(error); |
| 66 | setIsLoading(false); |
| 67 | }, |
| 68 | }); |
| 69 | |
| 70 | interface formData { |
| 71 | upiId?: string; |
| 72 | solanaAddress?: string; |
| 73 | } |
| 74 | |
| 75 | const onSubmit = (data: formData) => { |
| 76 | try { |
| 77 | setIsLoading(true); |
| 78 | switch (title) { |
| 79 | case 'UPI': |
| 80 | executeAddUpi({ upiId: data.upiId || '' }); |
| 81 | break; |
| 82 | case 'Solana': |
| 83 | executeAddSolanaAddress({ solanaAddress: data.solanaAddress || '' }); |
nothing calls this directly
no test coverage detected