feat: SMS notification handle errors.

This commit is contained in:
a.bouhuolia
2021-11-09 13:49:16 +02:00
parent 3039e43767
commit 9e5fddf294
6 changed files with 45 additions and 18 deletions

View File

@@ -1,16 +1,14 @@
import { Intent } from '@blueprintjs/core';
import { AppToaster } from 'components';
import intl from 'react-intl-universal';
export const transformErrors = (errors, { setErrors }) => {
export const transformErrors = (errors, { setErrors, setCalloutCode }) => {
if (errors.some((e) => e.type === 'CUSTOMER_SMS_NOTIFY_PHONE_INVALID')) {
AppToaster.show({
message: intl.get('notify_via_sms.dialog.error_message'),
intent: Intent.DANGER,
setCalloutCode([200]);
setErrors({
customer_phone_number: 'The personal phone number is invalid.',
});
}
if (errors.find((error) => error.type === 'CUSTOMER_HAS_NO_PHONE_NUMBER')) {
setCalloutCode([100]);
setErrors({
customer_phone_number: intl.get(
'notify_via_sms.dialog.customer_no_phone_error_message',
@@ -19,7 +17,6 @@ export const transformErrors = (errors, { setErrors }) => {
}
};
export const getSMSUnits = (message, threshold = 140) => {
return Math.ceil(message.length / threshold);
};
};