Skip to content

Commit

Permalink
fix: close form on successful proposal submission
Browse files Browse the repository at this point in the history
  • Loading branch information
helmturner committed Jun 26, 2024
1 parent cd75179 commit e2901b0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/features/voting/ProposalFormButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default function AddProposalButton({
}) {
const session = useSession();
const [loading, setLoading] = useState(false);
const [open, setOpen] = useState(false);

const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
Expand Down Expand Up @@ -92,15 +93,19 @@ export default function AddProposalButton({
type: undefined,
isDraft: true,
});

// Stay open after draft submit, in case the user wants to create another
if (!isDraft) setOpen(false);

return isDraft ? 'Draft Saved' : 'Proposal Submitted!';
}, [form]);
}, [form, setOpen]);

const error = useCallback(
(err: unknown) => {
form.reset({ ...form.getValues(), isDraft: true });

return err instanceof TypeError ?
new ProposalFormFetchError().render()
new ProposalFormFetchError().render()
: new ProposalFormError(err).render();
},
[form],
Expand All @@ -119,7 +124,7 @@ export default function AddProposalButton({
);

return (
<Dialog>
<Dialog open={open} onOpenChange={setOpen}>
<ProtectedTrigger type="dialog">{renderTrigger()}</ProtectedTrigger>

<DialogContent>
Expand Down

0 comments on commit e2901b0

Please sign in to comment.