createLead validation

This commit is contained in:
Chika 2020-09-28 17:03:05 +03:00
parent 941859c80b
commit af1027bcaf
4 changed files with 79 additions and 12 deletions

View File

@ -2,9 +2,16 @@ import { Form, Input as AntInput } from 'antd';
import { Status } from 'core/types/statuses';
import React from 'react';
const TextArea = ({ value, setCurrentValue, status, ...props }) => {
const TextArea = ({
value,
setCurrentValue,
status,
validateStatus,
message,
...props
}) => {
return (
<Form.Item>
<Form.Item validateStatus={validateStatus} help={message}>
<AntInput.TextArea
{...props}
autoSize={{ minRows: 5, maxRows: 8 }}

View File

@ -1,9 +1,51 @@
import { openNotification } from 'client/Elements/Notification';
import CalculationStore from 'client/stores/CalculationStore';
import { TAction } from 'core/types/effect';
const actions: TAction = {
createLead: () => {
console.log('createLead action');
const {
contactClient,
contact,
newClient,
account,
commentLead,
phoneNumber,
} = CalculationStore.values;
if (!contactClient && !contact) {
CalculationStore.setValidation('selectContactClient', false);
CalculationStore.setValidation('tbxContact', false);
openNotification({
type: 'error',
title: 'Ошибка во время создания интереса',
description: 'Не указан контакт клиента!',
})();
}
if (!newClient && !account) {
CalculationStore.setValidation('tbxNewClient', false);
CalculationStore.setValidation('selectAccount', false);
openNotification({
type: 'error',
title: 'Ошибка во время создания интереса',
description: 'Не указан клиент!',
})();
}
if (!commentLead) {
CalculationStore.setValidation('tbxCommentLead', false);
openNotification({
type: 'error',
title: 'Ошибка во время создания интереса',
description: 'Не указан комментарий к интересу!',
})();
}
if (contact && !phoneNumber) {
CalculationStore.setValidation('tbxPhoneNumber', false);
openNotification({
type: 'error',
title: 'Ошибка во время создания интереса',
description: 'Не указан телефон контактного лица',
})();
}
},
};

View File

@ -1,11 +1,32 @@
import { IAutorunEffect } from 'core/types/effect';
const autorunEffects: IAutorunEffect[] = [
// calculationStore => () => {
// if (parseInt(calculationStore.values.price) > 25) {
// calculationStore.setValue('one', 100500);
// }
// }
calculationStore => () => {
const { contactClient, contact } = calculationStore.values;
if (contactClient || contact) {
calculationStore.setValidation('selectContactClient', true);
calculationStore.setValidation('tbxContact', true);
}
},
calculationStore => () => {
const { newClient, account } = calculationStore.values;
if (newClient || account) {
calculationStore.setValidation('tbxNewClient', true);
calculationStore.setValidation('selectAccount', true);
}
},
calculationStore => () => {
const { commentLead } = calculationStore.values;
if (commentLead) {
calculationStore.setValidation('tbxCommentLead', true);
}
},
calculationStore => () => {
const { phoneNumber } = calculationStore.values;
if (phoneNumber) {
calculationStore.setValidation('tbxPhoneNumber', true);
}
},
];
export default autorunEffects;

View File

@ -7,10 +7,7 @@ type TCommonStore = typeof CommonStore;
export type ActionsNames = 'createLead';
export type TAction = {
[actionName in ActionsNames]?: (
CalculationStore: ICalculationStore,
CommonStore?: TCommonStore,
) => void;
[actionName in ActionsNames]?: () => void;
};
export interface IAutorunEffect {