mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
feat(webapp): add ability to redirect to list to mail dialogs
This commit is contained in:
@@ -13,7 +13,12 @@ const ReceiptMailDialogContent = React.lazy(
|
||||
*/
|
||||
function ReceiptMailDialog({
|
||||
dialogName,
|
||||
payload: { receiptId = null },
|
||||
payload: {
|
||||
receiptId = null,
|
||||
|
||||
// Redirects to receipts list after mail submitting.
|
||||
redirectToReceiptsList = false,
|
||||
},
|
||||
isOpen,
|
||||
}) {
|
||||
return (
|
||||
@@ -29,6 +34,7 @@ function ReceiptMailDialog({
|
||||
<ReceiptMailDialogContent
|
||||
dialogName={dialogName}
|
||||
receiptId={receiptId}
|
||||
redirectToReceiptsList={redirectToReceiptsList}
|
||||
/>
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
|
||||
@@ -6,6 +6,7 @@ import { DialogContent } from '@/components';
|
||||
interface ReceiptMailDialogBootValues {
|
||||
receiptId: number;
|
||||
mailOptions: any;
|
||||
redirectToReceiptsList: boolean;
|
||||
}
|
||||
|
||||
const ReceiptMailDialogBootContext =
|
||||
@@ -14,6 +15,7 @@ const ReceiptMailDialogBootContext =
|
||||
interface ReceiptMailDialogBootProps {
|
||||
receiptId: number;
|
||||
children: React.ReactNode;
|
||||
redirectToReceiptsList?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -21,6 +23,7 @@ interface ReceiptMailDialogBootProps {
|
||||
*/
|
||||
function ReceiptMailDialogBoot({
|
||||
receiptId,
|
||||
redirectToReceiptsList = false,
|
||||
...props
|
||||
}: ReceiptMailDialogBootProps) {
|
||||
const { data: mailOptions, isLoading: isMailOptionsLoading } =
|
||||
@@ -30,6 +33,7 @@ function ReceiptMailDialogBoot({
|
||||
saleReceiptId: receiptId,
|
||||
mailOptions,
|
||||
isMailOptionsLoading,
|
||||
redirectToReceiptsList,
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -3,15 +3,20 @@ import { ReceiptMailDialogBoot } from './ReceiptMailDialogBoot';
|
||||
import { ReceiptMailDialogForm } from './ReceiptMailDialogForm';
|
||||
|
||||
interface ReceiptMailDialogContentProps {
|
||||
dialogName: string
|
||||
dialogName: string;
|
||||
receiptId: number;
|
||||
redirectToReceiptsList?: boolean;
|
||||
}
|
||||
export default function ReceiptMailDialogContent({
|
||||
dialogName,
|
||||
receiptId,
|
||||
redirectToReceiptsList = false,
|
||||
}: ReceiptMailDialogContentProps) {
|
||||
return (
|
||||
<ReceiptMailDialogBoot receiptId={receiptId}>
|
||||
<ReceiptMailDialogBoot
|
||||
receiptId={receiptId}
|
||||
redirectToReceiptsList={redirectToReceiptsList}
|
||||
>
|
||||
<ReceiptMailDialogForm />
|
||||
</ReceiptMailDialogBoot>
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { Formik, FormikBag } from 'formik';
|
||||
import * as R from 'ramda';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useReceiptMailDialogBoot } from './ReceiptMailDialogBoot';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
@@ -24,9 +25,12 @@ interface ReceiptMailFormValues extends MailNotificationFormValues {
|
||||
}
|
||||
|
||||
function ReceiptMailDialogFormRoot({ closeDialog }) {
|
||||
const { mailOptions, saleReceiptId } = useReceiptMailDialogBoot();
|
||||
const { mailOptions, saleReceiptId, redirectToReceiptsList } =
|
||||
useReceiptMailDialogBoot();
|
||||
const { mutateAsync: sendReceiptMail } = useSendSaleReceiptMail();
|
||||
|
||||
const history = useHistory();
|
||||
|
||||
// Transformes mail options to initial form values.
|
||||
const initialValues = transformMailFormToInitialValues(
|
||||
mailOptions,
|
||||
@@ -48,6 +52,10 @@ function ReceiptMailDialogFormRoot({ closeDialog }) {
|
||||
});
|
||||
closeDialog(DialogsName.ReceiptMail);
|
||||
setSubmitting(false);
|
||||
|
||||
if (redirectToReceiptsList) {
|
||||
history.push('/receipts');
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
AppToaster.show({
|
||||
|
||||
Reference in New Issue
Block a user