mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
re-structure to monorepo.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
|
||||
import { NotifyInvoiceViaSMSFormProvider } from './NotifyInvoiceViaSMSFormProvider';
|
||||
import NotifyInvoiceViaSMSForm from './NotifyInvoiceViaSMSForm';
|
||||
|
||||
export default function NotifyInvoiceViaSMSDialogContent({
|
||||
// #ownProps
|
||||
dialogName,
|
||||
invoiceId,
|
||||
}) {
|
||||
return (
|
||||
<NotifyInvoiceViaSMSFormProvider
|
||||
invoiceId={invoiceId}
|
||||
dialogName={dialogName}
|
||||
>
|
||||
<NotifyInvoiceViaSMSForm />
|
||||
</NotifyInvoiceViaSMSFormProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import { pick } from 'lodash';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { AppToaster } from '@/components';
|
||||
|
||||
import NotifyViaSMSForm from '@/containers/NotifyViaSMS/NotifyViaSMSForm';
|
||||
import { useNotifyInvoiceViaSMSContext } from './NotifyInvoiceViaSMSFormProvider';
|
||||
import { transformErrors } from '@/containers/NotifyViaSMS/utils';
|
||||
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import { compose } from '@/utils';
|
||||
|
||||
const transformFormValuesToRequest = (values) => {
|
||||
return pick(values, ['notification_key']);
|
||||
};
|
||||
|
||||
// Momerize the notification types.
|
||||
const notificationTypes = [
|
||||
{
|
||||
key: 'details',
|
||||
label: intl.get('sms_notification.invoice_details.type'),
|
||||
},
|
||||
{
|
||||
key: 'reminder',
|
||||
label: intl.get('sms_notification.invoice_reminder.type'),
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Notify Invoice Via SMS Form.
|
||||
*/
|
||||
function NotifyInvoiceViaSMSForm({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const {
|
||||
createNotifyInvoiceBySMSMutate,
|
||||
invoiceId,
|
||||
invoiceSMSDetail,
|
||||
dialogName,
|
||||
notificationType,
|
||||
setNotificationType,
|
||||
} = useNotifyInvoiceViaSMSContext();
|
||||
|
||||
const [calloutCode, setCalloutCode] = React.useState([]);
|
||||
|
||||
// Handles the form submit.
|
||||
const handleFormSubmit = (values, { setSubmitting, setErrors }) => {
|
||||
setSubmitting(true);
|
||||
|
||||
// Handle request response success.
|
||||
const onSuccess = (response) => {
|
||||
AppToaster.show({
|
||||
message: intl.get('notify_invoice_via_sms.dialog.success_message'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setSubmitting(false);
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
// Handle request response errors.
|
||||
const onError = ({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
if (errors) {
|
||||
transformErrors(errors, { setErrors, setCalloutCode });
|
||||
}
|
||||
setSubmitting(false);
|
||||
};
|
||||
// Transformes the form values to request.
|
||||
const requestValues = transformFormValuesToRequest(values);
|
||||
|
||||
// Submits invoice SMS notification.
|
||||
createNotifyInvoiceBySMSMutate([invoiceId, requestValues])
|
||||
.then(onSuccess)
|
||||
.catch(onError);
|
||||
};
|
||||
// Handle the form cancel.
|
||||
const handleFormCancel = React.useCallback(() => {
|
||||
closeDialog(dialogName);
|
||||
}, [closeDialog, dialogName]);
|
||||
|
||||
const initialValues = {
|
||||
notification_key: notificationType,
|
||||
...invoiceSMSDetail,
|
||||
};
|
||||
// Handle form values change.
|
||||
const handleValuesChange = (values) => {
|
||||
if (values.notification_key !== notificationType) {
|
||||
setNotificationType(values.notification_key);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<NotifyViaSMSForm
|
||||
initialValues={initialValues}
|
||||
notificationTypes={notificationTypes}
|
||||
onSubmit={handleFormSubmit}
|
||||
onCancel={handleFormCancel}
|
||||
onValuesChange={handleValuesChange}
|
||||
calloutCodes={calloutCode}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions)(NotifyInvoiceViaSMSForm);
|
||||
@@ -0,0 +1,51 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { DialogContent } from '@/components';
|
||||
import { useCreateNotifyInvoiceBySMS, useInvoiceSMSDetail } from '@/hooks/query';
|
||||
|
||||
const NotifyInvoiceViaSMSContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Invoice SMS notification provider.
|
||||
*/
|
||||
function NotifyInvoiceViaSMSFormProvider({ invoiceId, dialogName, ...props }) {
|
||||
const [notificationType, setNotificationType] = React.useState('details');
|
||||
|
||||
// Retrieve the invoice sms notification message details.
|
||||
const { data: invoiceSMSDetail, isLoading: isInvoiceSMSDetailLoading } =
|
||||
useInvoiceSMSDetail(
|
||||
invoiceId,
|
||||
{
|
||||
notification_key: notificationType,
|
||||
},
|
||||
{
|
||||
enabled: !!invoiceId,
|
||||
keepPreviousData: true,
|
||||
},
|
||||
);
|
||||
// Create notfiy invoice by sms mutations.
|
||||
const { mutateAsync: createNotifyInvoiceBySMSMutate } =
|
||||
useCreateNotifyInvoiceBySMS();
|
||||
|
||||
// State provider.
|
||||
const provider = {
|
||||
invoiceId,
|
||||
invoiceSMSDetail,
|
||||
dialogName,
|
||||
createNotifyInvoiceBySMSMutate,
|
||||
|
||||
notificationType,
|
||||
setNotificationType,
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogContent isLoading={isInvoiceSMSDetailLoading}>
|
||||
<NotifyInvoiceViaSMSContext.Provider value={provider} {...props} />
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
const useNotifyInvoiceViaSMSContext = () =>
|
||||
React.useContext(NotifyInvoiceViaSMSContext);
|
||||
|
||||
export { NotifyInvoiceViaSMSFormProvider, useNotifyInvoiceViaSMSContext };
|
||||
@@ -0,0 +1,36 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
|
||||
import { Dialog, DialogSuspense, FormattedMessage as T } from '@/components';
|
||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||
import { compose } from '@/utils';
|
||||
|
||||
const NotifyInvoiceViaSMSDialogContent = React.lazy(
|
||||
() => import('./NotifyInvoiceViaSMSDialogContent'),
|
||||
);
|
||||
|
||||
function NotifyInvoiceViaSMSDialog({
|
||||
dialogName,
|
||||
payload: { invoiceId },
|
||||
isOpen,
|
||||
}) {
|
||||
return (
|
||||
<Dialog
|
||||
name={dialogName}
|
||||
title={<T id={'notify_via_sms.dialog.notify_via_sms'} />}
|
||||
isOpen={isOpen}
|
||||
canEscapeJeyClose={true}
|
||||
autoFocus={true}
|
||||
className={'dialog--notify-vis-sms'}
|
||||
>
|
||||
<DialogSuspense>
|
||||
<NotifyInvoiceViaSMSDialogContent
|
||||
dialogName={dialogName}
|
||||
invoiceId={invoiceId}
|
||||
/>
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogRedux())(NotifyInvoiceViaSMSDialog);
|
||||
Reference in New Issue
Block a user