feat: add notify by sms .

This commit is contained in:
elforjani13
2021-11-07 20:11:15 +02:00
parent 7706d2992c
commit 4d89f1e0e0
17 changed files with 141 additions and 75 deletions

View File

@@ -14,32 +14,36 @@ function NotifyEstimateViaSMSForm({
// #withDialogActions
closeDialog,
}) {
const { dialogName, estimateId } = useEstimateViaSMSContext();
const {
estimateId,
dialogName,
estimateSMSDetail,
createNotifyEstimateBySMSMutate,
} = useEstimateViaSMSContext();
// 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'),
message: intl.get('notify_estimate_via_sms.dialog.success_message'),
intent: Intent.SUCCESS,
});
closeDialog(dialogName);
};
// Handle request response errors.
const onError = ({
response: {
data: { errors },
},
}) => {
const onError = () => {
setSubmitting(false);
};
createNotifyEstimateBySMSMutate([estimateId, values])
.then(onSuccess)
.then(onError);
};
return (
<NotifyViaSMSForm
NotificationDetail={{}}
NotificationDetail={estimateSMSDetail}
NotificationName={dialogName}
onSubmit={handleFormSubmit}
/>

View File

@@ -1,6 +1,9 @@
import React from 'react';
import { DialogContent } from 'components';
// import { } from 'hooks/query';
import {
useEstimateSMSDetail,
useCreateNotifyEstimateBySMS,
} from 'hooks/query';
const NotifyEstimateViaSMSContext = React.createContext();
@@ -9,16 +12,25 @@ function NotifyEstimateViaSMSFormProvider({
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={}
>
<DialogContent isLoading={isEstimateSMSDetailLoading}>
<NotifyEstimateViaSMSContext.Provider value={provider} {...props} />
</DialogContent>
);