mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
feat: add notify via SMS Form.
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import React from 'react';
|
||||
|
||||
import { NotifyInvoiceViaSMSFormProvider } from './NotifyInvoiceViaSMSFormProvider';
|
||||
import NotifyInvoiceViaSMSForm from './NotifyInvoiceViaSMSForm';
|
||||
|
||||
export default function NotifyInvoiceViaSMSDialogContent({
|
||||
// #ownProps
|
||||
dialogName,
|
||||
invoice,
|
||||
}) {
|
||||
return (
|
||||
<NotifyInvoiceViaSMSFormProvider
|
||||
invoiceId={invoice}
|
||||
dialogName={dialogName}
|
||||
>
|
||||
<NotifyInvoiceViaSMSForm />
|
||||
</NotifyInvoiceViaSMSFormProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
|
||||
import NotifyViaSMSForm from '../../NotifyViaSMS/NotifyViaSMSForm';
|
||||
import { useNotifyInvoiceViaSMSContext } from './NotifyInvoiceViaSMSFormProvider';
|
||||
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Notify Invoice Via SMS Form.
|
||||
*/
|
||||
function NotifyInvoiceViaSMSForm({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const {
|
||||
createNotifyInvoiceBySMSMutate,
|
||||
invoiceId,
|
||||
invoiceSMSDetail,
|
||||
dialogName,
|
||||
} = useNotifyInvoiceViaSMSContext();
|
||||
|
||||
// Handles the form submit.
|
||||
const handleFormSubmit = (values, { setSubmitting, setErrors }) => {
|
||||
// Handle request response success.
|
||||
const onSuccess = (response) => {
|
||||
AppToaster.show({
|
||||
message: intl.get('notify_via_sms.dialog.success_message'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
// Handle request response errors.
|
||||
const onError = ({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
setSubmitting(false);
|
||||
};
|
||||
createNotifyInvoiceBySMSMutate([invoiceId, values])
|
||||
.then(onSuccess)
|
||||
.catch(onError);
|
||||
};
|
||||
|
||||
return (
|
||||
<NotifyViaSMSForm
|
||||
NotificationDetail={invoiceSMSDetail}
|
||||
NotificationName={dialogName}
|
||||
onSubmit={handleFormSubmit}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions)(NotifyInvoiceViaSMSForm);
|
||||
@@ -0,0 +1,35 @@
|
||||
import React from 'react';
|
||||
import { DialogContent } from 'components';
|
||||
import { useCreateNotifyInvoiceBySMS, useInvocieSMSDetails } from 'hooks/query';
|
||||
|
||||
const NotifyInvoiceViaSMSContext = React.createContext();
|
||||
|
||||
function NotifyInvoiceViaSMSFormProvider({ invoiceId, dialogName, ...props }) {
|
||||
const { data: invoiceSMSDetail, isLoading: isInvoiceSMSDetailLoading } =
|
||||
useInvocieSMSDetails(invoiceId, {
|
||||
enabled: !!invoiceId,
|
||||
});
|
||||
|
||||
// Create notfiy invoice by sms mutations.
|
||||
const { mutateAsync: createNotifyInvoiceBySMSMutate } =
|
||||
useCreateNotifyInvoiceBySMS();
|
||||
|
||||
// State provider.
|
||||
const provider = {
|
||||
invoiceId,
|
||||
invoiceSMSDetail,
|
||||
dialogName,
|
||||
createNotifyInvoiceBySMSMutate,
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogContent isLoading={isInvoiceSMSDetailLoading}>
|
||||
<NotifyInvoiceViaSMSContext.Provider value={provider} {...props} />
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
const useNotifyInvoiceViaSMSContext = () =>
|
||||
React.useContext(NotifyInvoiceViaSMSContext);
|
||||
|
||||
export { NotifyInvoiceViaSMSFormProvider, useNotifyInvoiceViaSMSContext };
|
||||
35
src/containers/Dialogs/NotifyInvoiceViaSMSDialog/index.js
Normal file
35
src/containers/Dialogs/NotifyInvoiceViaSMSDialog/index.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import React from 'react';
|
||||
|
||||
import { FormattedMessage as T } from 'components';
|
||||
import { Dialog, DialogSuspense } 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}
|
||||
invoice={invoiceId}
|
||||
/>
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
export default compose(withDialogRedux())(NotifyInvoiceViaSMSDialog);
|
||||
Reference in New Issue
Block a user