feat(webapp): add ability to redirect to list to mail dialogs

This commit is contained in:
Ahmed Bouhuolia
2024-01-24 20:03:04 +02:00
parent c8e7a2c7d9
commit 9d4e7cec9e
16 changed files with 112 additions and 19 deletions

View File

@@ -13,7 +13,12 @@ const PaymentMailDialogContent = React.lazy(
*/
function PaymentMailDialog({
dialogName,
payload: { paymentReceiveId = null },
payload: {
paymentReceiveId = null,
// Redirects to the payments list on mail submitting.
redirectToPaymentsList = false,
},
isOpen,
}) {
return (
@@ -29,6 +34,7 @@ function PaymentMailDialog({
<PaymentMailDialogContent
dialogName={dialogName}
paymentReceiveId={paymentReceiveId}
redirectToPaymentsList={redirectToPaymentsList}
/>
</DialogSuspense>
</Dialog>

View File

@@ -13,6 +13,7 @@ const PaymentMailDialogBootContext =
interface PaymentMailDialogBootProps {
paymentReceiveId: number;
redirectToPaymentsList: boolean;
children: React.ReactNode;
}
@@ -29,7 +30,8 @@ function PaymentMailDialogBoot({
const provider = {
mailOptions,
isMailOptionsLoading,
paymentReceiveId
paymentReceiveId,
redirectToPaymentsList
};
return (

View File

@@ -4,13 +4,18 @@ import { PaymentMailDialogForm } from './PaymentMailDialogForm';
interface PaymentMailDialogContentProps {
dialogName: string;
paymentReceiveId: number;
redirectToPaymentsList: boolean;
}
export default function PaymentMailDialogContent({
dialogName,
paymentReceiveId,
redirectToPaymentsList,
}: PaymentMailDialogContentProps) {
return (
<PaymentMailDialogBoot paymentReceiveId={paymentReceiveId}>
<PaymentMailDialogBoot
paymentReceiveId={paymentReceiveId}
redirectToPaymentsList={redirectToPaymentsList}
>
<PaymentMailDialogForm />
</PaymentMailDialogBoot>
);

View File

@@ -3,7 +3,6 @@ import { Formik, FormikBag } from 'formik';
import * as R from 'ramda';
import { Intent } from '@blueprintjs/core';
import { usePaymentMailDialogBoot } from './PaymentMailDialogBoot';
import withDialogActions from '@/containers/Dialog/withDialogActions';
import { DialogsName } from '@/constants/dialogs';
import { useSendPaymentReceiveMail } from '@/hooks/query';
import { PaymentMailDialogFormContent } from './PaymentMailDialogFormContent';
@@ -14,6 +13,8 @@ import {
transformMailFormToInitialValues,
} from '@/containers/SendMailNotification/utils';
import { AppToaster } from '@/components';
import { useHistory } from 'react-router-dom';
import withDialogActions from '@/containers/Dialog/withDialogActions';
const initialFormValues = {
...initialMailNotificationValues,
@@ -28,9 +29,12 @@ export function PaymentMailDialogFormRoot({
// #withDialogActions
closeDialog,
}) {
const { mailOptions, paymentReceiveId } = usePaymentMailDialogBoot();
const { mailOptions, paymentReceiveId, redirectToPaymentsList } =
usePaymentMailDialogBoot();
const { mutateAsync: sendPaymentMail } = useSendPaymentReceiveMail();
const history = useHistory();
const initialValues = transformMailFormToInitialValues(
mailOptions,
initialFormValues,
@@ -51,6 +55,11 @@ export function PaymentMailDialogFormRoot({
});
setSubmitting(false);
closeDialog(DialogsName.PaymentMail);
// Redirects to payments list if the option is enabled.
if (redirectToPaymentsList) {
history.push('/payment-receives');
}
})
.catch(() => {
AppToaster.show({