mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22: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 InvoiceMailDialogContent = React.lazy(
|
||||
*/
|
||||
function InvoiceMailDialog({
|
||||
dialogName,
|
||||
payload: { invoiceId = null },
|
||||
payload: {
|
||||
invoiceId = null,
|
||||
|
||||
// Redirects to the invoices list.
|
||||
redirectToInvoicesList = false,
|
||||
},
|
||||
isOpen,
|
||||
}) {
|
||||
return (
|
||||
@@ -29,6 +34,7 @@ function InvoiceMailDialog({
|
||||
<InvoiceMailDialogContent
|
||||
dialogName={dialogName}
|
||||
invoiceId={invoiceId}
|
||||
redirectToInvoicesList={redirectToInvoicesList}
|
||||
/>
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
|
||||
@@ -6,12 +6,14 @@ import { DialogContent } from '@/components';
|
||||
interface InvoiceMailDialogBootValues {
|
||||
invoiceId: number;
|
||||
mailOptions: any;
|
||||
redirectToInvoicesList: boolean;
|
||||
}
|
||||
|
||||
const InvoiceMailDialagBoot = createContext<InvoiceMailDialogBootValues>();
|
||||
|
||||
interface InvoiceMailDialogBootProps {
|
||||
invoiceId: number;
|
||||
redirectToInvoicesList?: boolean;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
@@ -20,6 +22,7 @@ interface InvoiceMailDialogBootProps {
|
||||
*/
|
||||
function InvoiceMailDialogBoot({
|
||||
invoiceId,
|
||||
redirectToInvoicesList,
|
||||
...props
|
||||
}: InvoiceMailDialogBootProps) {
|
||||
const { data: mailOptions, isLoading: isMailOptionsLoading } =
|
||||
@@ -29,6 +32,7 @@ function InvoiceMailDialogBoot({
|
||||
saleInvoiceId: invoiceId,
|
||||
mailOptions,
|
||||
isMailOptionsLoading,
|
||||
redirectToInvoicesList,
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -4,13 +4,20 @@ import { InvoiceMailDialogForm } from './InvoiceMailDialogForm';
|
||||
interface InvoiceMailDialogContentProps {
|
||||
dialogName: string;
|
||||
invoiceId: number;
|
||||
|
||||
// Redirect to invoices list after submitting the message.
|
||||
redirectToInvoicesList?: boolean;
|
||||
}
|
||||
export default function InvoiceMailDialogContent({
|
||||
dialogName,
|
||||
invoiceId,
|
||||
redirectToInvoicesList,
|
||||
}: InvoiceMailDialogContentProps) {
|
||||
return (
|
||||
<InvoiceMailDialogBoot invoiceId={invoiceId}>
|
||||
<InvoiceMailDialogBoot
|
||||
invoiceId={invoiceId}
|
||||
redirectToInvoicesList={redirectToInvoicesList}
|
||||
>
|
||||
<InvoiceMailDialogForm />
|
||||
</InvoiceMailDialogBoot>
|
||||
);
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
transformMailFormToRequest,
|
||||
transformMailFormToInitialValues,
|
||||
} from '@/containers/SendMailNotification/utils';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
const initialFormValues = {
|
||||
...initialMailNotificationValues,
|
||||
@@ -29,7 +30,9 @@ function InvoiceMailDialogFormRoot({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const { mailOptions, saleInvoiceId } = useInvoiceMailDialogBoot();
|
||||
const history = useHistory();
|
||||
const { mailOptions, saleInvoiceId, redirectToInvoicesList } =
|
||||
useInvoiceMailDialogBoot();
|
||||
const { mutateAsync: sendInvoiceMail } = useSendSaleInvoiceMail();
|
||||
|
||||
const initialValues = transformMailFormToInitialValues(
|
||||
@@ -49,6 +52,11 @@ function InvoiceMailDialogFormRoot({
|
||||
});
|
||||
closeDialog(DialogsName.InvoiceMail);
|
||||
setSubmitting(false);
|
||||
|
||||
// Redirect to the dashboard if the option was enabled.
|
||||
if (redirectToInvoicesList) {
|
||||
history.push('/invoices');
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
AppToaster.show({
|
||||
|
||||
Reference in New Issue
Block a user