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>
);

View File

@@ -1,12 +1,12 @@
import React from 'react';
import { DialogContent } from 'components';
import { useCreateNotifyInvoiceBySMS, useInvocieSMSDetails } from 'hooks/query';
import { useCreateNotifyInvoiceBySMS, useInvoiceSMSDetail } from 'hooks/query';
const NotifyInvoiceViaSMSContext = React.createContext();
function NotifyInvoiceViaSMSFormProvider({ invoiceId, dialogName, ...props }) {
const { data: invoiceSMSDetail, isLoading: isInvoiceSMSDetailLoading } =
useInvocieSMSDetails(invoiceId, {
useInvoiceSMSDetail(invoiceId, {
enabled: !!invoiceId,
});

View File

@@ -1,6 +1,9 @@
import React from 'react';
import { DialogContent } from 'components';
// import { useCreateNotifyInvoiceBySMS, useInvocieSMSDetails } from 'hooks/query';
import {
useCreateNotifyPaymentReceiveBySMS,
usePaymentReceiveSMSDetail,
} from 'hooks/query';
const NotifyPaymentReceiveViaSMSContext = React.createContext();
@@ -9,16 +12,27 @@ function NotifyPaymentReceiveViaFormProvider({
dialogName,
...props
}) {
// Create notfiy receipt via sms mutations.
const { mutateAsync: createNotifyPaymentReceivetBySMSMutate } =
useCreateNotifyPaymentReceiveBySMS();
const {
data: paymentReceiveMSDetail,
isLoading: isPaymentReceiveSMSDetailLoading,
} = usePaymentReceiveSMSDetail(paymentReceiveId, {
enabled: !!paymentReceiveId,
});
// State provider.
const provider = {
paymentReceiveId,
dialogName,
paymentReceiveMSDetail,
createNotifyPaymentReceivetBySMSMutate,
};
return (
<DialogContent
// isLoading={}
>
<DialogContent isLoading={isPaymentReceiveSMSDetailLoading}>
<NotifyPaymentReceiveViaSMSContext.Provider value={provider} {...props} />
</DialogContent>
);

View File

@@ -17,33 +17,38 @@ function NotifyPaymentReceiveViaSMSForm({
// #withDialogActions
closeDialog,
}) {
const { dialogName, paymentReceiveId } =
useNotifyPaymentReceiveViaSMSContext();
const {
dialogName,
paymentReceiveId,
paymentReceiveMSDetail,
createNotifyPaymentReceivetBySMSMutate,
} = useNotifyPaymentReceiveViaSMSContext();
// 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_payment_receive_via_sms.dialog.success_message',
),
intent: Intent.SUCCESS,
});
closeDialog(dialogName);
};
// Handle request response errors.
const onError = ({
response: {
data: { errors },
},
}) => {
const onError = ({}) => {
setSubmitting(false);
};
createNotifyPaymentReceivetBySMSMutate([paymentReceiveId, values])
.then(onSuccess)
.catch(onError);
};
return (
<NotifyViaSMSForm
NotificationDetail={{}}
NotificationDetail={paymentReceiveMSDetail}
NotificationName={dialogName}
onSubmit={handleFormSubmit}
/>

View File

@@ -25,7 +25,7 @@ function NotifyPaymentReciveViaSMSDialog({
<DialogSuspense>
<NotifyPaymentReceiveViaSMSDialogContent
dialogName={dialogName}
paymnetReceive={paymentReceiveId}
paymentReceive={paymentReceiveId}
/>
</DialogSuspense>
</Dialog>

View File

@@ -17,32 +17,36 @@ function NotifyReceiptViaSMSForm({
// #withDialogActions
closeDialog,
}) {
const { dialogName, receiptId } = useNotifyReceiptViaSMSContext();
const {
dialogName,
receiptId,
receiptSMSDetail,
createNotifyReceiptBySMSMutate,
} = useNotifyReceiptViaSMSContext();
// 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_receipt_via_sms.dialog.success_message'),
intent: Intent.SUCCESS,
});
closeDialog(dialogName);
};
// Handle request response errors.
const onError = ({
response: {
data: { errors },
},
}) => {
const onError = ({}) => {
setSubmitting(false);
};
createNotifyReceiptBySMSMutate([receiptId, values])
.then(onSuccess)
.catch(onError);
};
return (
<NotifyViaSMSForm
NotificationDetail={{}}
NotificationDetail={receiptSMSDetail}
NotificationName={dialogName}
onSubmit={handleFormSubmit}
/>

View File

@@ -1,22 +1,29 @@
import React from 'react';
import { DialogContent } from 'components';
// import { useCreateNotifyInvoiceBySMS, useInvocieSMSDetails } from 'hooks/query';
import { useCreateNotifyReceiptBySMS, useReceiptSMSDetail } from 'hooks/query';
const NotifyReceiptViaSMSContext = React.createContext();
function NotifyReceiptViaSMSFormProvider({ receiptId, dialogName, ...props }) {
// Create notfiy receipt via sms mutations.
const { mutateAsync: createNotifyReceiptBySMSMutate } =
useCreateNotifyReceiptBySMS();
const { data: receiptSMSDetail, isLoading: isReceiptSMSDetailLoading } =
useReceiptSMSDetail(receiptId, {
enabled: !!receiptId,
});
// State provider.
const provider = {
receiptId,
dialogName,
receiptSMSDetail,
createNotifyReceiptBySMSMutate,
};
return (
<DialogContent
// isLoading={}
>
<DialogContent isLoading={isReceiptSMSDetailLoading}>
<NotifyReceiptViaSMSContext.Provider value={provider} {...props} />
</DialogContent>
);

View File

@@ -11,7 +11,7 @@ import { transformToForm, saveInvoke } from 'utils';
const defaultInitialValues = {
customer_name: '',
customer_personal_phone: '',
customer_phone_number: '',
sms_message: '',
};

View File

@@ -4,7 +4,7 @@ import { DATATYPES_LENGTH } from 'common/dataTypes';
const Schema = Yup.object().shape({
customer_name: Yup.string().required(),
customer_personal_phone: Yup.number().required(),
customer_phone_number: Yup.number().required(),
sms_message: Yup.string().required().trim().max(DATATYPES_LENGTH.TEXT),
});

View File

@@ -31,15 +31,15 @@ function NotifyViaSMSFormFields() {
</FastField>
{/* ----------- Phone number ----------- */}
<FastField name={'customer_personal_phone'}>
<FastField name={'customer_phone_number'}>
{({ form, field, meta: { error, touched } }) => (
<FormGroup
label={<T id={'phone_number'} />}
labelInfo={<FieldRequiredHint />}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="customer_personal_phone" />}
helperText={<ErrorMessage name="customer_phone_number" />}
className={classNames(
'form-group--customer_personal_phone',
'form-group--customer_phone_number',
CLASSES.FILL,
)}
>

View File

@@ -195,30 +195,31 @@ export function useCreateNotifyEstimateBySMS(props) {
const apiRequest = useApiRequest();
return useMutation(
(id) => apiRequest.post(`sales/estimates/${id}/notify-by-sms`),
([id, values]) =>
apiRequest.post(`sales/estimates/${id}/notify-by-sms`, values),
{
onSuccess: (res, id) => {
onSuccess: (res, [id, values]) => {
// Invalidate
queryClient.invalidateQueries([t.NOTIFY_SALE_ESTIMATE_BY_SMS, id]);
// Common invalidate queries.
commonInvalidateQueries(queryClient);
// Invalidate sale estimate.
queryClient.invalidateQueries([t.NOTIFY_SALE_ESTIMATE_BY_SMS, id]);
},
...props,
},
);
}
export function useEstimateSMS(estimateId, props, requestProps) {
export function useEstimateSMSDetail(estimateId, props, requestProps) {
return useRequestQuery(
[t.SALE_ESTIMATE_SMS, estimateId],
[t.SALE_ESTIMATE_SMS_DETAIL, estimateId],
{
method: 'get',
url: `sales/estimates/${estimateId}/sms-details`,
...requestProps,
},
{
select: (res) => res.data,
select: (res) => res.data.data,
defaultData: {},
...props,
},

View File

@@ -239,9 +239,10 @@ export function useCreateNotifyInvoiceBySMS(props) {
const apiRequest = useApiRequest();
return useMutation(
(id) => apiRequest.post(`sales/invoices/${id}/notify-by-sms`),
([id, values]) =>
apiRequest.post(`sales/invoices/${id}/notify-by-sms`, values),
{
onSuccess: (res, id) => {
onSuccess: (res, [id, values]) => {
// Invalidate
queryClient.invalidateQueries([t.NOTIFY_SALE_INVOICE_BY_SMS, id]);
@@ -253,9 +254,9 @@ export function useCreateNotifyInvoiceBySMS(props) {
);
}
export function useInvocieSMSDetails(invoiceId, props, requestProps) {
export function useInvoiceSMSDetail(invoiceId, props, requestProps) {
return useRequestQuery(
[t.SALE_INVOICE_SMS, invoiceId],
[t.SALE_INVOICE_SMS_DETAIL, invoiceId],
{
method: 'get',
url: `sales/invoices/${invoiceId}/sms-details`,

View File

@@ -180,9 +180,10 @@ export function useCreateNotifyPaymentReceiveBySMS(props) {
const apiRequest = useApiRequest();
return useMutation(
(id) => apiRequest.post(`sales/payment_receives/${id}/notify-by-sms`),
([id, values]) =>
apiRequest.post(`sales/payment_receives/${id}/notify-by-sms`, values),
{
onSuccess: (res, id) => {
onSuccess: (res, [id, values]) => {
// Invalidate
queryClient.invalidateQueries([t.NOTIFY_PAYMENT_RECEIVE_BY_SMS, id]);
@@ -194,12 +195,20 @@ export function useCreateNotifyPaymentReceiveBySMS(props) {
);
}
export function usePaymentReceiveSMS(id, props, requestProps) {
export function usePaymentReceiveSMSDetail(
paymentReceiveId,
props,
requestProps,
) {
return useRequestQuery(
[t.PAYMENT_RECEIVE_SMS, id],
{ method: 'get', url: `sales/payment_receives/${id}/sms-details`, ...requestProps },
[t.PAYMENT_RECEIVE_SMS_DETAIL, paymentReceiveId],
{
select: (res) => res.data,
method: 'get',
url: `sales/payment_receives/${paymentReceiveId}/sms-details`,
...requestProps,
},
{
select: (res) => res.data.data,
defaultData: {},
...props,
},

View File

@@ -168,9 +168,10 @@ export function useCreateNotifyReceiptBySMS(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
(id) => apiRequest.post(`sales/receipts/${id}/notify-by-sms`),
([id, values]) =>
apiRequest.post(`sales/receipts/${id}/notify-by-sms`, values),
{
onSuccess: (res, id) => {
onSuccess: (res, [id, values]) => {
queryClient.invalidateQueries([t.NOTIFY_SALE_RECEIPT_BY_SMS, id]);
// Invalidate queries.
@@ -181,12 +182,16 @@ export function useCreateNotifyReceiptBySMS(props) {
);
}
export function useReceiptSMS(receiptId, props, requestProps) {
export function useReceiptSMSDetail(receiptId, props, requestProps) {
return useRequestQuery(
[t.SALE_RECEIPT_SMS, receiptId],
{ method: 'get', url: `sales/receipts/${receiptId}/sms-details`, ...requestProps },
[t.SALE_RECEIPT_SMS_DETAIL, receiptId],
{
select: (res) => res.data,
method: 'get',
url: `sales/receipts/${receiptId}/sms-details`,
...requestProps,
},
{
select: (res) => res.data.data,
defaultData: {},
...props,
},

View File

@@ -51,14 +51,14 @@ const ITEMS = {
const SALE_ESTIMATES = {
SALE_ESTIMATES: 'SALE_ESTIMATES',
SALE_ESTIMATE: 'SALE_ESTIMATE',
SALE_ESTIMATE_SMS: 'SALE_ESTIMATE_SMS',
SALE_ESTIMATE_SMS_DETAIL: 'SALE_ESTIMATE_SMS_DETAIL',
NOTIFY_SALE_ESTIMATE_BY_SMS: 'NOTIFY_SALE_ESTIMATE_BY_SMS',
};
const SALE_RECEIPTS = {
SALE_RECEIPTS: 'SALE_RECEIPTS',
SALE_RECEIPT: 'SALE_RECEIPT',
SALE_RECEIPT_SMS: 'SALE_RECEIPT_SMS',
SALE_RECEIPT_SMS_DETAIL: 'SALE_RECEIPT_SMS_DETAIL',
NOTIFY_SALE_RECEIPT_BY_SMS: 'NOTIFY_SALE_RECEIPT_BY_SMS',
};
@@ -83,7 +83,7 @@ const PAYMENT_RECEIVES = {
PAYMENT_RECEIVE: 'PAYMENT_RECEIVE',
PAYMENT_RECEIVE_NEW_ENTRIES: 'PAYMENT_RECEIVE_NEW_ENTRIES',
PAYMENT_RECEIVE_EDIT_PAGE: 'PAYMENT_RECEIVE_EDIT_PAGE',
PAYMENT_RECEIVE_SMS: 'PAYMENT_RECEIVE_SMS',
PAYMENT_RECEIVE_SMS_DETAIL: 'PAYMENT_RECEIVE_SMS_DETAIL',
NOTIFY_PAYMENT_RECEIVE_BY_SMS: 'NOTIFY_PAYMENT_RECEIVE_BY_SMS',
};
@@ -91,7 +91,7 @@ const SALE_INVOICES = {
SALE_INVOICES: 'SALE_INVOICES',
SALE_INVOICE: 'SALE_INVOICE',
SALE_INVOICES_DUE: 'SALE_INVOICES_DUE',
SALE_INVOICE_SMS: 'SALE_INVOICE_SMS',
SALE_INVOICE_SMS_DETAIL: 'SALE_INVOICE_SMS_DETAIL',
NOTIFY_SALE_INVOICE_BY_SMS: 'NOTIFY_SALE_INVOICE_BY_SMS',
BAD_DEBT: 'BAD_DEBT',
CANCEL_BAD_DEBT: 'CANCEL_BAD_DEBT',

View File

@@ -1430,7 +1430,10 @@
"notify_via_sms.dialog.send_notification_to":"Send notification to",
"notify_via_sms.dialog.message_text":"Message Text",
"notify_via_sms.dialog.notify_via_sms":"Notify vis SMS",
"notify_via_sms.dialog.success_message":"To notify have been successfully",
"notify_invoice_via_sms.dialog.success_message":"The sale invoice sms notification has been sent successfully",
"notify_estimate_via_sms.dialog.success_message":"The sale estimate sms notification has been sent successfully",
"notify_receipt_via_sms.dialog.success_message":"The sale receipt sms notification has been sent successfully",
"notify_payment_receive_via_sms.dialog.success_message":"The payment notification has been sent successfully.",
"send": "Send",
"sms_integration.label":"SMS Integration",
"sms_integration.label.overview":"Overview",
@@ -1441,4 +1444,5 @@
"sms_message.label_auto":"Auto",
"sms_message":"SMS message",
"sms_message.dialog.success_message":"Sms notification settings has been updated successfully."
}
}