mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat(webapp): add ability to redirect to list to mail dialogs
This commit is contained in:
@@ -13,7 +13,12 @@ const EstimateMailDialogContent = React.lazy(
|
||||
*/
|
||||
function EstimateMailDialog({
|
||||
dialogName,
|
||||
payload: { estimateId = null },
|
||||
payload: {
|
||||
estimateId = null,
|
||||
|
||||
// Redirect to the estimates list after mail submitting.
|
||||
redirectToEstimatesList = false,
|
||||
},
|
||||
isOpen,
|
||||
}) {
|
||||
return (
|
||||
@@ -29,6 +34,7 @@ function EstimateMailDialog({
|
||||
<EstimateMailDialogContent
|
||||
dialogName={dialogName}
|
||||
estimateId={estimateId}
|
||||
redirectToEstimatesList={redirectToEstimatesList}
|
||||
/>
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
|
||||
@@ -6,12 +6,14 @@ import { DialogContent } from '@/components';
|
||||
interface EstimateMailDialogBootValues {
|
||||
estimateId: number;
|
||||
mailOptions: any;
|
||||
redirectToEstimatesList: boolean;
|
||||
}
|
||||
|
||||
const EstimateMailDialagBoot = createContext<EstimateMailDialogBootValues>();
|
||||
|
||||
interface EstimateMailDialogBootProps {
|
||||
estimateId: number;
|
||||
redirectToEstimatesList?: boolean;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
@@ -20,6 +22,7 @@ interface EstimateMailDialogBootProps {
|
||||
*/
|
||||
function EstimateMailDialogBoot({
|
||||
estimateId,
|
||||
redirectToEstimatesList,
|
||||
...props
|
||||
}: EstimateMailDialogBootProps) {
|
||||
const { data: mailOptions, isLoading: isMailOptionsLoading } =
|
||||
@@ -29,6 +32,7 @@ function EstimateMailDialogBoot({
|
||||
saleEstimateId: estimateId,
|
||||
mailOptions,
|
||||
isMailOptionsLoading,
|
||||
redirectToEstimatesList,
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -4,14 +4,19 @@ import { EstimateMailDialogForm } from './EstimateMailDialogForm';
|
||||
interface EstimateMailDialogContentProps {
|
||||
dialogName: string;
|
||||
estimateId: number;
|
||||
redirectToEstimatesList?: boolean;
|
||||
}
|
||||
export default function EstimateMailDialogContent({
|
||||
dialogName,
|
||||
estimateId,
|
||||
redirectToEstimatesList,
|
||||
}: EstimateMailDialogContentProps) {
|
||||
return (
|
||||
<EstimateMailDialogBoot estimateId={estimateId}>
|
||||
<EstimateMailDialogForm />
|
||||
<EstimateMailDialogBoot
|
||||
estimateId={estimateId}
|
||||
redirectToEstimatesList={redirectToEstimatesList}
|
||||
>
|
||||
<EstimateMailDialogForm />
|
||||
</EstimateMailDialogBoot>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// @ts-nocheck
|
||||
import { Formik } from 'formik';
|
||||
import * as R from 'ramda';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useEstimateMailDialogBoot } from './EstimateMailDialogBoot';
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
@@ -12,7 +14,6 @@ import {
|
||||
transformMailFormToInitialValues,
|
||||
transformMailFormToRequest,
|
||||
} from '@/containers/SendMailNotification/utils';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { AppToaster } from '@/components';
|
||||
|
||||
const initialFormValues = {
|
||||
@@ -29,7 +30,10 @@ function EstimateMailDialogFormRoot({
|
||||
closeDialog,
|
||||
}) {
|
||||
const { mutateAsync: sendEstimateMail } = useSendSaleEstimateMail();
|
||||
const { mailOptions, saleEstimateId } = useEstimateMailDialogBoot();
|
||||
const { mailOptions, saleEstimateId, redirectToEstimatesList } =
|
||||
useEstimateMailDialogBoot();
|
||||
|
||||
const history = useHistory();
|
||||
|
||||
const initialValues = transformMailFormToInitialValues(
|
||||
mailOptions,
|
||||
@@ -48,8 +52,12 @@ function EstimateMailDialogFormRoot({
|
||||
});
|
||||
closeDialog(DialogsName.EstimateMail);
|
||||
setSubmitting(false);
|
||||
|
||||
if (redirectToEstimatesList) {
|
||||
history.push('/estimates');
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch(() => {
|
||||
setSubmitting(false);
|
||||
closeDialog(DialogsName.EstimateMail);
|
||||
AppToaster.show({
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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