mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
feat(webapp): showing up mail popup once saving invoice, receipt and estimate
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Dialog, DialogSuspense } from '@/components';
|
||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||
import { compose } from '@/utils';
|
||||
|
||||
const ReceiptFormMailDeliverDialogContent = React.lazy(
|
||||
() => import('./ReceiptFormMailDeliverDialogContent'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Receipt mail dialog.
|
||||
*/
|
||||
function ReceiptFormMailDeliverDialog({
|
||||
dialogName,
|
||||
payload: { receiptId = null },
|
||||
isOpen,
|
||||
}) {
|
||||
return (
|
||||
<Dialog
|
||||
name={dialogName}
|
||||
title={'Receipt Mail'}
|
||||
isOpen={isOpen}
|
||||
canEscapeJeyClose={false}
|
||||
isCloseButtonShown={false}
|
||||
autoFocus={true}
|
||||
style={{ width: 600 }}
|
||||
>
|
||||
<DialogSuspense>
|
||||
<ReceiptFormMailDeliverDialogContent
|
||||
dialogName={dialogName}
|
||||
receiptId={receiptId}
|
||||
/>
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogRedux())(ReceiptFormMailDeliverDialog);
|
||||
@@ -0,0 +1,40 @@
|
||||
// @ts-nocheck
|
||||
import * as R from 'ramda';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import ReceiptMailDialogContent from '../../ReceiptMailDialog/ReceiptMailDialogContent';
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
|
||||
interface ReceiptFormDeliverDialogContent {
|
||||
receiptId: number;
|
||||
}
|
||||
|
||||
function ReceiptFormDeliverDialogContentRoot({
|
||||
receiptId,
|
||||
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}: ReceiptFormDeliverDialogContent) {
|
||||
const history = useHistory();
|
||||
|
||||
const handleSubmit = () => {
|
||||
history.push('/receipts');
|
||||
closeDialog(DialogsName.ReceiptFormMailDeliver);
|
||||
};
|
||||
const handleCancel = () => {
|
||||
history.push('/receipts');
|
||||
closeDialog(DialogsName.ReceiptFormMailDeliver);
|
||||
};
|
||||
|
||||
return (
|
||||
<ReceiptMailDialogContent
|
||||
receiptId={receiptId}
|
||||
onFormSubmit={handleSubmit}
|
||||
onCancelClick={handleCancel}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default R.compose(withDialogActions)(
|
||||
ReceiptFormDeliverDialogContentRoot,
|
||||
);
|
||||
@@ -34,12 +34,20 @@ import {
|
||||
transformFormValuesToRequest,
|
||||
resetFormState,
|
||||
} from './utils';
|
||||
import { ReceiptSyncAutoExRateToForm, ReceiptSyncIncrementSettingsToForm } from './components';
|
||||
import {
|
||||
ReceiptSyncAutoExRateToForm,
|
||||
ReceiptSyncIncrementSettingsToForm,
|
||||
} from './components';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
|
||||
/**
|
||||
* Receipt form.
|
||||
*/
|
||||
function ReceiptForm({
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
|
||||
// #withSettings
|
||||
receiptNextNumber,
|
||||
receiptNumberPrefix,
|
||||
@@ -84,10 +92,7 @@ function ReceiptForm({
|
||||
}),
|
||||
};
|
||||
// Handle the form submit.
|
||||
const handleFormSubmit = (
|
||||
values,
|
||||
{ setErrors, setSubmitting, resetForm },
|
||||
) => {
|
||||
const handleFormSubmit = (values, { setErrors, setSubmitting }) => {
|
||||
const entries = values.entries.filter(
|
||||
(item) => item.item_id && item.quantity,
|
||||
);
|
||||
@@ -124,6 +129,11 @@ function ReceiptForm({
|
||||
if (submitPayload.resetForm) {
|
||||
resetFormState();
|
||||
}
|
||||
if (submitPayload.deliverMail) {
|
||||
openDialog(DialogsName.ReceiptFormMailDeliver, {
|
||||
receiptId: response.data.id,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Handle the request error.
|
||||
@@ -179,6 +189,7 @@ function ReceiptForm({
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogActions,
|
||||
withDashboardActions,
|
||||
withSettings(({ receiptSettings }) => ({
|
||||
receiptNextNumber: receiptSettings?.nextNumber,
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
import React from 'react';
|
||||
import { useFormikContext } from 'formik';
|
||||
import ReceiptNumberDialog from '@/containers/Dialogs/ReceiptNumberDialog';
|
||||
import ReceiptFormMailDeliverDialog from './Dialogs/ReceiptFormMailDeliverDialog';
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
|
||||
/**
|
||||
* Receipt form dialogs.
|
||||
@@ -27,6 +29,9 @@ export default function ReceiptFormDialogs() {
|
||||
dialogName={'receipt-number-form'}
|
||||
onConfirm={handleReceiptNumberFormConfirm}
|
||||
/>
|
||||
<ReceiptFormMailDeliverDialog
|
||||
dialogName={DialogsName.ReceiptFormMailDeliver}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ export default function ReceiptFormFloatingActions() {
|
||||
|
||||
// Handle submit & close button click.
|
||||
const handleSubmitCloseBtnClick = (event) => {
|
||||
setSubmitPayload({ redirect: true, status: true });
|
||||
setSubmitPayload({ redirect: false, deliverMail: true, status: true });
|
||||
submitForm();
|
||||
};
|
||||
|
||||
|
||||
@@ -4,21 +4,16 @@ import { Dialog, DialogSuspense } from '@/components';
|
||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||
import { compose } from '@/utils';
|
||||
|
||||
const ReceiptMailDialogContent = React.lazy(
|
||||
() => import('./ReceiptMailDialogContent'),
|
||||
const ReceiptMailDialogBody = React.lazy(
|
||||
() => import('./ReceiptMailDialogBody'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Invoice mail dialog.
|
||||
* Receipt mail dialog.
|
||||
*/
|
||||
function ReceiptMailDialog({
|
||||
dialogName,
|
||||
payload: {
|
||||
receiptId = null,
|
||||
|
||||
// Redirects to receipts list after mail submitting.
|
||||
redirectToReceiptsList = false,
|
||||
},
|
||||
payload: { receiptId = null },
|
||||
isOpen,
|
||||
}) {
|
||||
return (
|
||||
@@ -31,11 +26,7 @@ function ReceiptMailDialog({
|
||||
style={{ width: 600 }}
|
||||
>
|
||||
<DialogSuspense>
|
||||
<ReceiptMailDialogContent
|
||||
dialogName={dialogName}
|
||||
receiptId={receiptId}
|
||||
redirectToReceiptsList={redirectToReceiptsList}
|
||||
/>
|
||||
<ReceiptMailDialogBody receiptId={receiptId} />
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// @ts-nocheck
|
||||
import * as R from 'ramda';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import ReceiptMailDialogContent, {
|
||||
ReceiptMailDialogContentProps,
|
||||
} from './ReceiptMailDialogContent';
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
|
||||
interface ReceiptMailDialogBodyProps extends ReceiptMailDialogContentProps {}
|
||||
|
||||
function ReceiptMailDialogBodyRoot({
|
||||
receiptId,
|
||||
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}: ReceiptMailDialogBodyProps) {
|
||||
const handleCancelClick = () => {
|
||||
closeDialog(DialogsName.ReceiptMail);
|
||||
};
|
||||
const handleSubmitClick = () => {
|
||||
closeDialog(DialogsName.ReceiptMail);
|
||||
};
|
||||
|
||||
return (
|
||||
<ReceiptMailDialogContent
|
||||
receiptId={receiptId}
|
||||
onFormSubmit={handleSubmitClick}
|
||||
onCancelClick={handleCancelClick}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default R.compose(withDialogActions)(ReceiptMailDialogBodyRoot);
|
||||
@@ -2,22 +2,22 @@ import React from 'react';
|
||||
import { ReceiptMailDialogBoot } from './ReceiptMailDialogBoot';
|
||||
import { ReceiptMailDialogForm } from './ReceiptMailDialogForm';
|
||||
|
||||
interface ReceiptMailDialogContentProps {
|
||||
dialogName: string;
|
||||
export interface ReceiptMailDialogContentProps {
|
||||
receiptId: number;
|
||||
redirectToReceiptsList?: boolean;
|
||||
onFormSubmit?: () => void;
|
||||
onCancelClick?: () => void;
|
||||
}
|
||||
export default function ReceiptMailDialogContent({
|
||||
dialogName,
|
||||
receiptId,
|
||||
redirectToReceiptsList = false,
|
||||
onFormSubmit,
|
||||
onCancelClick
|
||||
}: ReceiptMailDialogContentProps) {
|
||||
return (
|
||||
<ReceiptMailDialogBoot
|
||||
receiptId={receiptId}
|
||||
redirectToReceiptsList={redirectToReceiptsList}
|
||||
>
|
||||
<ReceiptMailDialogForm />
|
||||
<ReceiptMailDialogBoot receiptId={receiptId}>
|
||||
<ReceiptMailDialogForm
|
||||
onFormSubmit={onFormSubmit}
|
||||
onCancelClick={onCancelClick}
|
||||
/>
|
||||
</ReceiptMailDialogBoot>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
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,12 +23,18 @@ interface ReceiptMailFormValues extends MailNotificationFormValues {
|
||||
attachReceipt: boolean;
|
||||
}
|
||||
|
||||
function ReceiptMailDialogFormRoot({ closeDialog }) {
|
||||
const { mailOptions, saleReceiptId, redirectToReceiptsList } =
|
||||
useReceiptMailDialogBoot();
|
||||
const { mutateAsync: sendReceiptMail } = useSendSaleReceiptMail();
|
||||
interface ReceiptMailDialogFormProps {
|
||||
onFormSubmit?: () => void;
|
||||
onCancelClick?: () => void;
|
||||
}
|
||||
|
||||
const history = useHistory();
|
||||
export function ReceiptMailDialogForm({
|
||||
// #props
|
||||
onFormSubmit,
|
||||
onCancelClick,
|
||||
}: ReceiptMailDialogFormProps) {
|
||||
const { mailOptions, saleReceiptId } = useReceiptMailDialogBoot();
|
||||
const { mutateAsync: sendReceiptMail } = useSendSaleReceiptMail();
|
||||
|
||||
// Transformes mail options to initial form values.
|
||||
const initialValues = transformMailFormToInitialValues(
|
||||
@@ -50,12 +55,8 @@ function ReceiptMailDialogFormRoot({ closeDialog }) {
|
||||
message: 'The mail notification has been sent successfully.',
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
closeDialog(DialogsName.ReceiptMail);
|
||||
setSubmitting(false);
|
||||
|
||||
if (redirectToReceiptsList) {
|
||||
history.push('/receipts');
|
||||
}
|
||||
onFormSubmit && onFormSubmit(values);
|
||||
})
|
||||
.catch(() => {
|
||||
AppToaster.show({
|
||||
@@ -67,7 +68,7 @@ function ReceiptMailDialogFormRoot({ closeDialog }) {
|
||||
};
|
||||
// Handle the close button click.
|
||||
const handleClose = () => {
|
||||
closeDialog(DialogsName.ReceiptMail);
|
||||
onCancelClick && onCancelClick();
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -76,7 +77,3 @@ function ReceiptMailDialogFormRoot({ closeDialog }) {
|
||||
</Formik>
|
||||
);
|
||||
}
|
||||
|
||||
export const ReceiptMailDialogForm = R.compose(withDialogActions)(
|
||||
ReceiptMailDialogFormRoot,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user