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,19 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { NotifyEstimateViaSMSFormProvider } from './NotifyEstimateViaSMSFormProvider';
|
||||
import NotifyEstimateViaSMSForm from './NotifyEstimateViaSMSForm';
|
||||
|
||||
export default function NotifyEstimateViaSMSDialogContent({
|
||||
// #ownProps
|
||||
dialogName,
|
||||
estimate,
|
||||
}) {
|
||||
return (
|
||||
<NotifyEstimateViaSMSFormProvider
|
||||
estimateId={estimate}
|
||||
dialogName={dialogName}
|
||||
>
|
||||
<NotifyEstimateViaSMSForm />
|
||||
</NotifyEstimateViaSMSFormProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { AppToaster } from '@/components';
|
||||
|
||||
import NotifyViaSMSForm from '@/containers/NotifyViaSMS/NotifyViaSMSForm';
|
||||
import { useEstimateViaSMSContext } from './NotifyEstimateViaSMSFormProvider';
|
||||
import { transformErrors } from '@/containers/NotifyViaSMS/utils';
|
||||
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import { compose } from '@/utils';
|
||||
|
||||
const notificationType = {
|
||||
key: 'sale-estimate-details',
|
||||
label: intl.get('sms_notification.estimate_details.type'),
|
||||
};
|
||||
|
||||
function NotifyEstimateViaSMSForm({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const {
|
||||
estimateId,
|
||||
dialogName,
|
||||
estimateSMSDetail,
|
||||
createNotifyEstimateBySMSMutate,
|
||||
} = useEstimateViaSMSContext();
|
||||
|
||||
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_estimate_via_sms.dialog.success_message'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
closeDialog(dialogName);
|
||||
setSubmitting(false);
|
||||
};
|
||||
// Handle request response errors.
|
||||
const onError = ({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
if (errors) {
|
||||
transformErrors(errors, { setErrors, setCalloutCode });
|
||||
}
|
||||
setSubmitting(false);
|
||||
};
|
||||
createNotifyEstimateBySMSMutate([estimateId, values])
|
||||
.then(onSuccess)
|
||||
.catch(onError);
|
||||
};
|
||||
|
||||
const initialValues = {
|
||||
...estimateSMSDetail,
|
||||
notification_key: notificationType.key,
|
||||
};
|
||||
// Handle the form cancel.
|
||||
const handleFormCancel = () => {
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
return (
|
||||
<NotifyViaSMSForm
|
||||
initialValues={initialValues}
|
||||
notificationTypes={[notificationType]}
|
||||
onCancel={handleFormCancel}
|
||||
onSubmit={handleFormSubmit}
|
||||
calloutCodes={calloutCode}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions)(NotifyEstimateViaSMSForm);
|
||||
@@ -0,0 +1,43 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { DialogContent } from '@/components';
|
||||
import {
|
||||
useEstimateSMSDetail,
|
||||
useCreateNotifyEstimateBySMS,
|
||||
} from '@/hooks/query';
|
||||
|
||||
const NotifyEstimateViaSMSContext = React.createContext();
|
||||
|
||||
function NotifyEstimateViaSMSFormProvider({
|
||||
estimateId,
|
||||
dialogName,
|
||||
...props
|
||||
}) {
|
||||
const { data: estimateSMSDetail, isLoading: isEstimateSMSDetailLoading } =
|
||||
useEstimateSMSDetail(estimateId, {
|
||||
enabled: !!estimateId,
|
||||
});
|
||||
|
||||
// Create notfiy estimate by sms mutations.
|
||||
const { mutateAsync: createNotifyEstimateBySMSMutate } =
|
||||
useCreateNotifyEstimateBySMS();
|
||||
|
||||
// State provider.
|
||||
const provider = {
|
||||
estimateId,
|
||||
dialogName,
|
||||
estimateSMSDetail,
|
||||
createNotifyEstimateBySMSMutate,
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogContent isLoading={isEstimateSMSDetailLoading}>
|
||||
<NotifyEstimateViaSMSContext.Provider value={provider} {...props} />
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
const useEstimateViaSMSContext = () =>
|
||||
React.useContext(NotifyEstimateViaSMSContext);
|
||||
|
||||
export { NotifyEstimateViaSMSFormProvider, useEstimateViaSMSContext };
|
||||
@@ -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 NotifyEstimateViaSMSDialogContent = React.lazy(
|
||||
() => import('./NotifyEstimateViaSMSDialogContent'),
|
||||
);
|
||||
|
||||
function NotifyEstimateViaSMSDialog({
|
||||
dialogName,
|
||||
payload: { estimateId },
|
||||
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>
|
||||
<NotifyEstimateViaSMSDialogContent
|
||||
dialogName={dialogName}
|
||||
estimate={estimateId}
|
||||
/>
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogRedux())(NotifyEstimateViaSMSDialog);
|
||||
Reference in New Issue
Block a user