mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
feat(webapp): the mail notifications dialogs
This commit is contained in:
@@ -1,27 +1,26 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import { Formik } from 'formik';
|
import { Formik } from 'formik';
|
||||||
import * as R from 'ramda';
|
import * as R from 'ramda';
|
||||||
import { castArray } from 'lodash';
|
|
||||||
import { useEstimateMailDialogBoot } from './EstimateMailDialogBoot';
|
import { useEstimateMailDialogBoot } from './EstimateMailDialogBoot';
|
||||||
import { transformToForm } from '@/utils';
|
|
||||||
import { DialogsName } from '@/constants/dialogs';
|
import { DialogsName } from '@/constants/dialogs';
|
||||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||||
import { useSendSaleEstimateMail } from '@/hooks/query';
|
import { useSendSaleEstimateMail } from '@/hooks/query';
|
||||||
import { EstimateMailDialogFormContent } from './EstimateMailDialogFormContent';
|
import { EstimateMailDialogFormContent } from './EstimateMailDialogFormContent';
|
||||||
|
import {
|
||||||
|
initialMailNotificationValues,
|
||||||
|
MailNotificationFormValues,
|
||||||
|
transformMailFormToInitialValues,
|
||||||
|
transformMailFormToRequest,
|
||||||
|
} from '@/containers/SendMailNotification/utils';
|
||||||
|
import { Intent } from '@blueprintjs/core';
|
||||||
|
import { AppToaster } from '@/components';
|
||||||
|
|
||||||
const initialFormValues = {
|
const initialFormValues = {
|
||||||
from: [],
|
...initialMailNotificationValues,
|
||||||
to: [],
|
|
||||||
subject: '',
|
|
||||||
body: '',
|
|
||||||
attachEstimate: true,
|
attachEstimate: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
interface EstimateMailFormValues {
|
interface EstimateMailFormValues extends MailNotificationFormValues {
|
||||||
from: string[];
|
|
||||||
to: string[];
|
|
||||||
subject: string;
|
|
||||||
body: string;
|
|
||||||
attachEstimate: boolean;
|
attachEstimate: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,21 +31,31 @@ function EstimateMailDialogFormRoot({
|
|||||||
const { mutateAsync: sendEstimateMail } = useSendSaleEstimateMail();
|
const { mutateAsync: sendEstimateMail } = useSendSaleEstimateMail();
|
||||||
const { mailOptions, saleEstimateId } = useEstimateMailDialogBoot();
|
const { mailOptions, saleEstimateId } = useEstimateMailDialogBoot();
|
||||||
|
|
||||||
const initialValues = {
|
const initialValues = transformMailFormToInitialValues(
|
||||||
...initialFormValues,
|
mailOptions,
|
||||||
...transformToForm(mailOptions, initialFormValues),
|
initialFormValues,
|
||||||
from: mailOptions.from ? castArray(mailOptions.from) : [],
|
);
|
||||||
to: mailOptions.to ? castArray(mailOptions.to) : [],
|
|
||||||
};
|
|
||||||
// Handle the form submitting.
|
// Handle the form submitting.
|
||||||
const handleSubmit = (values: EstimateMailFormValues, { setSubmitting }) => {
|
const handleSubmit = (values: EstimateMailFormValues, { setSubmitting }) => {
|
||||||
|
const reqValues = transformMailFormToRequest(values);
|
||||||
|
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
sendEstimateMail([saleEstimateId, values])
|
sendEstimateMail([saleEstimateId, reqValues])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: 'The mail notification has been sent successfully.',
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
closeDialog(DialogsName.EstimateMail);
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
|
closeDialog(DialogsName.EstimateMail);
|
||||||
|
AppToaster.show({
|
||||||
|
message: 'Something went wrong.',
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import styled from 'styled-components';
|
|||||||
import { FFormGroup, FSwitch } from '@/components';
|
import { FFormGroup, FSwitch } from '@/components';
|
||||||
import { MailNotificationForm } from '@/containers/SendMailNotification';
|
import { MailNotificationForm } from '@/containers/SendMailNotification';
|
||||||
import { saveInvoke } from '@/utils';
|
import { saveInvoke } from '@/utils';
|
||||||
|
import { useEstimateMailDialogBoot } from './EstimateMailDialogBoot';
|
||||||
|
|
||||||
interface EstimateMailDialogFormContentProps {
|
interface EstimateMailDialogFormContentProps {
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
@@ -14,6 +15,7 @@ export function EstimateMailDialogFormContent({
|
|||||||
onClose,
|
onClose,
|
||||||
}: EstimateMailDialogFormContentProps) {
|
}: EstimateMailDialogFormContentProps) {
|
||||||
const { isSubmitting } = useFormikContext();
|
const { isSubmitting } = useFormikContext();
|
||||||
|
const { mailOptions } = useEstimateMailDialogBoot();
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
saveInvoke(onClose);
|
saveInvoke(onClose);
|
||||||
@@ -22,8 +24,10 @@ export function EstimateMailDialogFormContent({
|
|||||||
return (
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
<div className={Classes.DIALOG_BODY}>
|
<div className={Classes.DIALOG_BODY}>
|
||||||
<MailNotificationForm fromAddresses={[]} toAddresses={[]} />
|
<MailNotificationForm
|
||||||
|
fromAddresses={mailOptions.from_addresses}
|
||||||
|
toAddresses={mailOptions.to_addresses}
|
||||||
|
/>
|
||||||
<AttachFormGroup name={'attachEstimate'} inline>
|
<AttachFormGroup name={'attachEstimate'} inline>
|
||||||
<FSwitch name={'attachEstimate'} label={'Attach Estimate'} />
|
<FSwitch name={'attachEstimate'} label={'Attach Estimate'} />
|
||||||
</AttachFormGroup>
|
</AttachFormGroup>
|
||||||
|
|||||||
@@ -1,28 +1,27 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import { Formik } from 'formik';
|
import { Formik } from 'formik';
|
||||||
import { castArray } from 'lodash';
|
|
||||||
import * as R from 'ramda';
|
import * as R from 'ramda';
|
||||||
|
import { Intent } from '@blueprintjs/core';
|
||||||
import { useInvoiceMailDialogBoot } from './InvoiceMailDialogBoot';
|
import { useInvoiceMailDialogBoot } from './InvoiceMailDialogBoot';
|
||||||
import { transformToForm } from '@/utils';
|
|
||||||
import { DialogsName } from '@/constants/dialogs';
|
import { DialogsName } from '@/constants/dialogs';
|
||||||
|
import { AppToaster } from '@/components';
|
||||||
import { useSendSaleInvoiceMail } from '@/hooks/query';
|
import { useSendSaleInvoiceMail } from '@/hooks/query';
|
||||||
import { InvoiceMailDialogFormContent } from './InvoiceMailDialogFormContent';
|
|
||||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||||
|
import { InvoiceMailDialogFormContent } from './InvoiceMailDialogFormContent';
|
||||||
import { InvoiceMailFormSchema } from './InvoiceMailDialogForm.schema';
|
import { InvoiceMailFormSchema } from './InvoiceMailDialogForm.schema';
|
||||||
|
import {
|
||||||
|
MailNotificationFormValues,
|
||||||
|
initialMailNotificationValues,
|
||||||
|
transformMailFormToRequest,
|
||||||
|
transformMailFormToInitialValues,
|
||||||
|
} from '@/containers/SendMailNotification/utils';
|
||||||
|
|
||||||
const initialFormValues = {
|
const initialFormValues = {
|
||||||
from: [],
|
...initialMailNotificationValues,
|
||||||
to: [],
|
|
||||||
subject: '',
|
|
||||||
body: '',
|
|
||||||
attachInvoice: true,
|
attachInvoice: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
interface InvoiceMailFormValues {
|
interface InvoiceMailFormValues extends MailNotificationFormValues {
|
||||||
from: string[];
|
|
||||||
to: string[];
|
|
||||||
subject: string;
|
|
||||||
body: string;
|
|
||||||
attachInvoice: boolean;
|
attachInvoice: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,20 +32,29 @@ function InvoiceMailDialogFormRoot({
|
|||||||
const { mailOptions, saleInvoiceId } = useInvoiceMailDialogBoot();
|
const { mailOptions, saleInvoiceId } = useInvoiceMailDialogBoot();
|
||||||
const { mutateAsync: sendInvoiceMail } = useSendSaleInvoiceMail();
|
const { mutateAsync: sendInvoiceMail } = useSendSaleInvoiceMail();
|
||||||
|
|
||||||
const initialValues = {
|
const initialValues = transformMailFormToInitialValues(
|
||||||
...initialFormValues,
|
mailOptions,
|
||||||
...transformToForm(mailOptions, initialFormValues),
|
initialFormValues,
|
||||||
from: mailOptions.from ? castArray(mailOptions.from) : [],
|
);
|
||||||
to: mailOptions.to ? castArray(mailOptions.to) : [],
|
|
||||||
};
|
|
||||||
// Handle the form submitting.
|
// Handle the form submitting.
|
||||||
const handleSubmit = (values: InvoiceMailFormValues, { setSubmitting }) => {
|
const handleSubmit = (values: InvoiceMailFormValues, { setSubmitting }) => {
|
||||||
|
const reqValues = transformMailFormToRequest(values);
|
||||||
|
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
sendInvoiceMail([saleInvoiceId, values])
|
sendInvoiceMail([saleInvoiceId, reqValues])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: 'The mail notification has been sent successfully.',
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
closeDialog(DialogsName.InvoiceMail);
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: 'Something went wrong.',
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import styled from 'styled-components';
|
|||||||
import { FFormGroup, FSwitch } from '@/components';
|
import { FFormGroup, FSwitch } from '@/components';
|
||||||
import { MailNotificationForm } from '@/containers/SendMailNotification';
|
import { MailNotificationForm } from '@/containers/SendMailNotification';
|
||||||
import { saveInvoke } from '@/utils';
|
import { saveInvoke } from '@/utils';
|
||||||
|
import { useInvoiceMailDialogBoot } from './InvoiceMailDialogBoot';
|
||||||
|
|
||||||
interface SendMailNotificationFormProps {
|
interface SendMailNotificationFormProps {
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
@@ -14,6 +15,7 @@ export function InvoiceMailDialogFormContent({
|
|||||||
onClose,
|
onClose,
|
||||||
}: SendMailNotificationFormProps) {
|
}: SendMailNotificationFormProps) {
|
||||||
const { isSubmitting } = useFormikContext();
|
const { isSubmitting } = useFormikContext();
|
||||||
|
const { mailOptions } = useInvoiceMailDialogBoot();
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
saveInvoke(onClose);
|
saveInvoke(onClose);
|
||||||
@@ -22,8 +24,10 @@ export function InvoiceMailDialogFormContent({
|
|||||||
return (
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
<div className={Classes.DIALOG_BODY}>
|
<div className={Classes.DIALOG_BODY}>
|
||||||
<MailNotificationForm fromAddresses={[]} toAddresses={[]} />
|
<MailNotificationForm
|
||||||
|
fromAddresses={mailOptions.from_addresses}
|
||||||
|
toAddresses={mailOptions.to_addresses}
|
||||||
|
/>
|
||||||
<AttachFormGroup name={'attachInvoice'} inline>
|
<AttachFormGroup name={'attachInvoice'} inline>
|
||||||
<FSwitch name={'attachInvoice'} label={'Attach Invoice'} />
|
<FSwitch name={'attachInvoice'} label={'Attach Invoice'} />
|
||||||
</AttachFormGroup>
|
</AttachFormGroup>
|
||||||
|
|||||||
@@ -1,27 +1,26 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import { Formik, FormikBag } from 'formik';
|
import { Formik, FormikBag } from 'formik';
|
||||||
import { castArray } from 'lodash';
|
|
||||||
import * as R from 'ramda';
|
import * as R from 'ramda';
|
||||||
|
import { Intent } from '@blueprintjs/core';
|
||||||
import { usePaymentMailDialogBoot } from './PaymentMailDialogBoot';
|
import { usePaymentMailDialogBoot } from './PaymentMailDialogBoot';
|
||||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||||
import { DialogsName } from '@/constants/dialogs';
|
import { DialogsName } from '@/constants/dialogs';
|
||||||
import { useSendPaymentReceiveMail } from '@/hooks/query';
|
import { useSendPaymentReceiveMail } from '@/hooks/query';
|
||||||
import { PaymentMailDialogFormContent } from './PaymentMailDialogFormContent';
|
import { PaymentMailDialogFormContent } from './PaymentMailDialogFormContent';
|
||||||
import { transformToForm } from '@/utils';
|
import {
|
||||||
|
MailNotificationFormValues,
|
||||||
|
initialMailNotificationValues,
|
||||||
|
transformMailFormToRequest,
|
||||||
|
transformMailFormToInitialValues,
|
||||||
|
} from '@/containers/SendMailNotification/utils';
|
||||||
|
import { AppToaster } from '@/components';
|
||||||
|
|
||||||
const initialFormValues = {
|
const initialFormValues = {
|
||||||
from: [],
|
...initialMailNotificationValues,
|
||||||
to: [],
|
|
||||||
subject: '',
|
|
||||||
body: '',
|
|
||||||
attachPayment: true,
|
attachPayment: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
interface PaymentMailFormValue {
|
interface PaymentMailFormValue extends MailNotificationFormValues {
|
||||||
from: string[];
|
|
||||||
to: string[];
|
|
||||||
subject: string;
|
|
||||||
body: string;
|
|
||||||
attachPayment: boolean;
|
attachPayment: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,24 +31,34 @@ export function PaymentMailDialogFormRoot({
|
|||||||
const { mailOptions, paymentId } = usePaymentMailDialogBoot();
|
const { mailOptions, paymentId } = usePaymentMailDialogBoot();
|
||||||
const { mutateAsync: sendPaymentMail } = useSendPaymentReceiveMail();
|
const { mutateAsync: sendPaymentMail } = useSendPaymentReceiveMail();
|
||||||
|
|
||||||
const initialValues = {
|
const initialValues = transformMailFormToInitialValues(
|
||||||
...initialFormValues,
|
mailOptions,
|
||||||
...transformToForm(mailOptions, initialFormValues),
|
initialFormValues,
|
||||||
from: mailOptions.from ? castArray(mailOptions.from) : [],
|
);
|
||||||
to: mailOptions.to ? castArray(mailOptions.to) : [],
|
|
||||||
};
|
|
||||||
// Handles the form submitting.
|
// Handles the form submitting.
|
||||||
const handleSubmit = (
|
const handleSubmit = (
|
||||||
values: PaymentMailFormValue,
|
values: PaymentMailFormValue,
|
||||||
{ setSubmitting }: FormikBag<PaymentMailFormValue>,
|
{ setSubmitting }: FormikBag<PaymentMailFormValue>,
|
||||||
) => {
|
) => {
|
||||||
|
const reqValues = transformMailFormToRequest(values);
|
||||||
|
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
sendPaymentMail([paymentId, values])
|
sendPaymentMail([paymentId, reqValues])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: 'The mail notification has been sent successfully.',
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
|
closeDialog(DialogsName.PaymentMail);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch(() => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: 'Something went wrong.',
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
|
closeDialog(DialogsName.PaymentMail);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import styled from 'styled-components';
|
|||||||
import { FFormGroup, FSwitch } from '@/components';
|
import { FFormGroup, FSwitch } from '@/components';
|
||||||
import { MailNotificationForm } from '@/containers/SendMailNotification';
|
import { MailNotificationForm } from '@/containers/SendMailNotification';
|
||||||
import { saveInvoke } from '@/utils';
|
import { saveInvoke } from '@/utils';
|
||||||
|
import { usePaymentMailDialogBoot } from './PaymentMailDialogBoot';
|
||||||
|
|
||||||
interface PaymentMailDialogFormContentProps {
|
interface PaymentMailDialogFormContentProps {
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
@@ -13,6 +14,7 @@ interface PaymentMailDialogFormContentProps {
|
|||||||
export function PaymentMailDialogFormContent({
|
export function PaymentMailDialogFormContent({
|
||||||
onClose,
|
onClose,
|
||||||
}: PaymentMailDialogFormContentProps) {
|
}: PaymentMailDialogFormContentProps) {
|
||||||
|
const { mailOptions } = usePaymentMailDialogBoot();
|
||||||
const { isSubmitting } = useFormikContext();
|
const { isSubmitting } = useFormikContext();
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
@@ -22,8 +24,10 @@ export function PaymentMailDialogFormContent({
|
|||||||
return (
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
<div className={Classes.DIALOG_BODY}>
|
<div className={Classes.DIALOG_BODY}>
|
||||||
<MailNotificationForm fromAddresses={[]} toAddresses={[]} />
|
<MailNotificationForm
|
||||||
|
fromAddresses={mailOptions.from_addresses}
|
||||||
|
toAddresses={mailOptions.to_addresses}
|
||||||
|
/>
|
||||||
<AttachFormGroup name={'attachPayment'} inline>
|
<AttachFormGroup name={'attachPayment'} inline>
|
||||||
<FSwitch name={'attachPayment'} label={'Attach Payment'} />
|
<FSwitch name={'attachPayment'} label={'Attach Payment'} />
|
||||||
</AttachFormGroup>
|
</AttachFormGroup>
|
||||||
|
|||||||
@@ -1,26 +1,25 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import { Formik, FormikBag } from 'formik';
|
import { Formik, FormikBag } from 'formik';
|
||||||
import { castArray } from 'lodash';
|
|
||||||
import * as R from 'ramda';
|
import * as R from 'ramda';
|
||||||
|
import { Intent } from '@blueprintjs/core';
|
||||||
import { useReceiptMailDialogBoot } from './ReceiptMailDialogBoot';
|
import { useReceiptMailDialogBoot } from './ReceiptMailDialogBoot';
|
||||||
import { transformToForm } from '@/utils';
|
|
||||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||||
import { DialogsName } from '@/constants/dialogs';
|
import { DialogsName } from '@/constants/dialogs';
|
||||||
import { useSendSaleReceiptMail } from '@/hooks/query';
|
import { useSendSaleReceiptMail } from '@/hooks/query';
|
||||||
import { ReceiptMailDialogFormContent } from './ReceiptMailDialogFormContent';
|
import { ReceiptMailDialogFormContent } from './ReceiptMailDialogFormContent';
|
||||||
|
import {
|
||||||
|
initialMailNotificationValues,
|
||||||
|
MailNotificationFormValues,
|
||||||
|
transformMailFormToInitialValues,
|
||||||
|
transformMailFormToRequest,
|
||||||
|
} from '@/containers/SendMailNotification/utils';
|
||||||
|
import { AppToaster } from '@/components';
|
||||||
|
|
||||||
const initialFormValues = {
|
const initialFormValues = {
|
||||||
from: [],
|
...initialMailNotificationValues,
|
||||||
to: [],
|
|
||||||
subject: '',
|
|
||||||
body: '',
|
|
||||||
attachReceipt: true,
|
attachReceipt: true,
|
||||||
};
|
};
|
||||||
interface ReceiptMailFormValues {
|
interface ReceiptMailFormValues extends MailNotificationFormValues {
|
||||||
from: string[];
|
|
||||||
to: string[];
|
|
||||||
subject: string;
|
|
||||||
body: string;
|
|
||||||
attachReceipt: boolean;
|
attachReceipt: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,26 +27,37 @@ function ReceiptMailDialogFormRoot({ closeDialog }) {
|
|||||||
const { mailOptions, saleReceiptId } = useReceiptMailDialogBoot();
|
const { mailOptions, saleReceiptId } = useReceiptMailDialogBoot();
|
||||||
const { mutateAsync: sendReceiptMail } = useSendSaleReceiptMail();
|
const { mutateAsync: sendReceiptMail } = useSendSaleReceiptMail();
|
||||||
|
|
||||||
const initialValues = {
|
// Transformes mail options to initial form values.
|
||||||
...initialFormValues,
|
const initialValues = transformMailFormToInitialValues(
|
||||||
...transformToForm(mailOptions, initialFormValues),
|
mailOptions,
|
||||||
from: mailOptions.from ? castArray(mailOptions.from) : [],
|
initialFormValues,
|
||||||
to: mailOptions.to ? castArray(mailOptions.to) : [],
|
);
|
||||||
};
|
// Handle the form submitting.
|
||||||
const handleSubmit = (
|
const handleSubmit = (
|
||||||
values: ReceiptMailFormValues,
|
values: ReceiptMailFormValues,
|
||||||
{ setSubmitting }: FormikBag<ReceiptMailFormValues>,
|
{ setSubmitting }: FormikBag<ReceiptMailFormValues>,
|
||||||
) => {
|
) => {
|
||||||
|
const reqValues = transformMailFormToRequest(values);
|
||||||
|
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
sendReceiptMail([saleReceiptId, values])
|
sendReceiptMail([saleReceiptId, reqValues])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: 'The mail notification has been sent successfully.',
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
closeDialog(DialogsName.ReceiptMail);
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch(() => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: 'Something went wrong.',
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
// Handle the close button click.
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
closeDialog(DialogsName.ReceiptMail);
|
closeDialog(DialogsName.ReceiptMail);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { Button, Classes, Intent } from '@blueprintjs/core';
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { FFormGroup, FSwitch } from '@/components';
|
import { FFormGroup, FSwitch } from '@/components';
|
||||||
import { MailNotificationForm } from '@/containers/SendMailNotification';
|
import { MailNotificationForm } from '@/containers/SendMailNotification';
|
||||||
|
import { useReceiptMailDialogBoot } from './ReceiptMailDialogBoot';
|
||||||
import { saveInvoke } from '@/utils';
|
import { saveInvoke } from '@/utils';
|
||||||
|
|
||||||
interface SendMailNotificationFormProps {
|
interface SendMailNotificationFormProps {
|
||||||
@@ -13,6 +14,7 @@ interface SendMailNotificationFormProps {
|
|||||||
export function ReceiptMailDialogFormContent({
|
export function ReceiptMailDialogFormContent({
|
||||||
onClose,
|
onClose,
|
||||||
}: SendMailNotificationFormProps) {
|
}: SendMailNotificationFormProps) {
|
||||||
|
const { mailOptions } = useReceiptMailDialogBoot();
|
||||||
const { isSubmitting } = useFormikContext();
|
const { isSubmitting } = useFormikContext();
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
@@ -22,8 +24,10 @@ export function ReceiptMailDialogFormContent({
|
|||||||
return (
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
<div className={Classes.DIALOG_BODY}>
|
<div className={Classes.DIALOG_BODY}>
|
||||||
<MailNotificationForm fromAddresses={[]} toAddresses={[]} />
|
<MailNotificationForm
|
||||||
|
fromAddresses={mailOptions.from_addresses}
|
||||||
|
toAddresses={mailOptions.to_addresses}
|
||||||
|
/>
|
||||||
<AttachFormGroup name={'attachReceipt:'} inline>
|
<AttachFormGroup name={'attachReceipt:'} inline>
|
||||||
<FSwitch name={'attachReceipt:'} label={'Attach Receipt'} />
|
<FSwitch name={'attachReceipt:'} label={'Attach Receipt'} />
|
||||||
</AttachFormGroup>
|
</AttachFormGroup>
|
||||||
|
|||||||
@@ -16,6 +16,14 @@ interface MailNotificationFormProps {
|
|||||||
toAddresses: SelectOptionProps[];
|
toAddresses: SelectOptionProps[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const commonAddressSelect = {
|
||||||
|
placeholder: '',
|
||||||
|
labelAccessor: '',
|
||||||
|
valueAccessor: 'mail',
|
||||||
|
tagAccessor: (item) => `<${item.label}> (${item.mail})`,
|
||||||
|
textAccessor: (item) => `<${item.label}> (${item.mail})`,
|
||||||
|
};
|
||||||
|
|
||||||
export function MailNotificationForm({
|
export function MailNotificationForm({
|
||||||
fromAddresses,
|
fromAddresses,
|
||||||
toAddresses,
|
toAddresses,
|
||||||
@@ -38,12 +46,12 @@ export function MailNotificationForm({
|
|||||||
<FMultiSelect
|
<FMultiSelect
|
||||||
items={fromAddresses}
|
items={fromAddresses}
|
||||||
name={'from'}
|
name={'from'}
|
||||||
placeholder=""
|
|
||||||
popoverProps={{ minimal: true, fill: true }}
|
popoverProps={{ minimal: true, fill: true }}
|
||||||
tagInputProps={{
|
tagInputProps={{
|
||||||
tagProps: { round: true, minimal: true, large: true },
|
tagProps: { round: true, minimal: true, large: true },
|
||||||
}}
|
}}
|
||||||
fill={true}
|
fill={true}
|
||||||
|
{...commonAddressSelect}
|
||||||
/>
|
/>
|
||||||
</FFormGroup>
|
</FFormGroup>
|
||||||
|
|
||||||
@@ -57,6 +65,7 @@ export function MailNotificationForm({
|
|||||||
tagProps: { round: true, minimal: true, large: true },
|
tagProps: { round: true, minimal: true, large: true },
|
||||||
}}
|
}}
|
||||||
fill={true}
|
fill={true}
|
||||||
|
{...commonAddressSelect}
|
||||||
/>
|
/>
|
||||||
</FFormGroup>
|
</FFormGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import './styles.scss';
|
|
||||||
import { Color } from '@tiptap/extension-color';
|
|
||||||
import ListItem from '@tiptap/extension-list-item';
|
|
||||||
import TextStyle from '@tiptap/extension-text-style';
|
|
||||||
import { EditorProvider } from '@tiptap/react';
|
|
||||||
import StarterKit from '@tiptap/starter-kit';
|
|
||||||
import { Box } from '@/components';
|
|
||||||
import styled from 'styled-components';
|
|
||||||
import { useUncontrolled } from '@/hooks/useUncontrolled';
|
|
||||||
|
|
||||||
const extensions = [
|
|
||||||
Color.configure({ types: [TextStyle.name, ListItem.name] }),
|
|
||||||
TextStyle.configure({ types: [ListItem.name] }),
|
|
||||||
StarterKit.configure({
|
|
||||||
bulletList: {
|
|
||||||
keepMarks: true,
|
|
||||||
keepAttributes: false,
|
|
||||||
},
|
|
||||||
orderedList: {
|
|
||||||
keepMarks: true,
|
|
||||||
keepAttributes: false,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
|
|
||||||
export interface RichEditorProps {
|
|
||||||
value?: string;
|
|
||||||
initialValue?: string;
|
|
||||||
onChange?: (value: string) => void;
|
|
||||||
className?: string;
|
|
||||||
}
|
|
||||||
export const RichEditor = ({
|
|
||||||
value,
|
|
||||||
initialValue,
|
|
||||||
onChange,
|
|
||||||
className,
|
|
||||||
}: RichEditorProps) => {
|
|
||||||
const [content, handleChange] = useUncontrolled({
|
|
||||||
value,
|
|
||||||
initialValue,
|
|
||||||
finalValue: '',
|
|
||||||
onChange,
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Root>
|
|
||||||
<EditorProvider
|
|
||||||
extensions={extensions}
|
|
||||||
content={content}
|
|
||||||
onBlur={handleChange}
|
|
||||||
/>
|
|
||||||
</Root>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const Root = styled(Box)`
|
|
||||||
padding: 15px;
|
|
||||||
border: 1px solid #dedfe9;
|
|
||||||
border-top: 0;
|
|
||||||
border-bottom-left-radius: 5px;
|
|
||||||
border-bottom-right-radius: 5px;
|
|
||||||
`;
|
|
||||||
@@ -1 +1 @@
|
|||||||
export * from './SendMailNotificationForm';
|
export * from './MailNotificationForm';
|
||||||
44
packages/webapp/src/containers/SendMailNotification/utils.ts
Normal file
44
packages/webapp/src/containers/SendMailNotification/utils.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import { castArray, first } from 'lodash';
|
||||||
|
import { transformToForm } from '@/utils';
|
||||||
|
|
||||||
|
export const initialMailNotificationValues = {
|
||||||
|
from: [],
|
||||||
|
to: [],
|
||||||
|
subject: '',
|
||||||
|
body: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface MailNotificationFormValues {
|
||||||
|
from: string[];
|
||||||
|
to: string[];
|
||||||
|
subject: string;
|
||||||
|
body: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const transformMailFormToRequest = (
|
||||||
|
values: MailNotificationFormValues,
|
||||||
|
) => {
|
||||||
|
return {
|
||||||
|
...values,
|
||||||
|
from: first(values.from),
|
||||||
|
to: values.to?.join(', '),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transformes the mail options response values to form initial values.
|
||||||
|
* @param {any} mailOptions
|
||||||
|
* @param {MailNotificationFormValues} initialValues
|
||||||
|
* @returns {MailNotificationFormValues}
|
||||||
|
*/
|
||||||
|
export const transformMailFormToInitialValues = (
|
||||||
|
mailOptions: any,
|
||||||
|
initialValues: MailNotificationFormValues,
|
||||||
|
): MailNotificationFormValues => {
|
||||||
|
return {
|
||||||
|
...initialValues,
|
||||||
|
...transformToForm(mailOptions, initialValues),
|
||||||
|
from: mailOptions.from ? castArray(mailOptions.from) : [],
|
||||||
|
to: mailOptions.to ? castArray(mailOptions.to) : [],
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -216,7 +216,7 @@ export function useSendSaleReceiptMail(props) {
|
|||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
(id, values) => apiRequest.post(`sales/receipts/${id}/mail`, values),
|
([id, values]) => apiRequest.post(`sales/receipts/${id}/mail`, values),
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
// Invalidate queries.
|
// Invalidate queries.
|
||||||
|
|||||||
Reference in New Issue
Block a user