fix(webapp): remove duplicated form submitting

This commit is contained in:
Ahmed Bouhuolia
2023-06-12 18:47:28 +02:00
parent 35ebb9c2aa
commit ff2b7563c8
11 changed files with 13 additions and 215 deletions

View File

@@ -27,7 +27,7 @@ export default function PaymentMadeFloatingActions() {
const history = useHistory();
// Formik context.
const { isSubmitting, resetForm } = useFormikContext();
const { isSubmitting, resetForm, submitForm } = useFormikContext();
// Payment made form context.
const { setSubmitPayload, paymentMadeId } = usePaymentMadeFormContext();
@@ -50,12 +50,15 @@ export default function PaymentMadeFloatingActions() {
// Handle submit & new button click.
const handleSubmitAndNewClick = (event) => {
setSubmitPayload({ redirect: false, resetForm: true });
submitForm();
};
// handle submit & continue editing button click.
// Handle submit & continue editing button click.
const handleSubmitContinueEditingBtnClick = (event) => {
setSubmitPayload({ redirect: false, publish: true });
submitForm()
};
return (
<div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}>
{/* ----------- Save and New ----------- */}

View File

@@ -87,18 +87,19 @@ function PaymentMadeForm({
message: intl.get('you_cannot_make_payment_with_zero_total_amount'),
intent: Intent.DANGER,
});
setSubmitting(false);
return;
}
// Transformes the form values to request body.
const form = transformFormToRequest(values);
// Triggers once the save request success.
const onSaved = (response) => {
const onSaved = () => {
AppToaster.show({
message: intl.get(
isNewMode
? 'the_payment_made_has_been_edited_successfully'
: 'the_payment_made_has_been_created_successfully',
? 'the_payment_made_has_been_created_successfully'
: 'the_payment_made_has_been_edited_successfully',
),
intent: Intent.SUCCESS,
});
@@ -116,7 +117,6 @@ function PaymentMadeForm({
if (errors) {
transformErrors(errors, { setFieldError });
}
setSubmitting(false);
};