elt: extend validation
extend reset reaction triggers fix make-request/osago
This commit is contained in:
parent
2bea56fa87
commit
bb6a3986b1
@ -46,7 +46,7 @@ export async function makeEltOsagoRequest(
|
|||||||
({ evo_region } = data);
|
({ evo_region } = data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const townId = $calculation.element('selectLegalClientRegion').getValue();
|
const townId = $calculation.element('selectLegalClientTown').getValue();
|
||||||
let evo_town: CRMTypes.GetTownQuery['evo_town'] = null;
|
let evo_town: CRMTypes.GetTownQuery['evo_town'] = null;
|
||||||
if (townId) {
|
if (townId) {
|
||||||
const { data } = await apolloClient.query({
|
const { data } = await apolloClient.query({
|
||||||
|
|||||||
@ -30,6 +30,13 @@ export default function reactions(context: ProcessContext) {
|
|||||||
'insAgeDrivers',
|
'insAgeDrivers',
|
||||||
'insExpDrivers',
|
'insExpDrivers',
|
||||||
'vin',
|
'vin',
|
||||||
|
'brand',
|
||||||
|
'model',
|
||||||
|
'leaseObjectMotorPower',
|
||||||
|
'leaseObjectPrice',
|
||||||
|
'supplierDiscountRub',
|
||||||
|
'leaseObjectYear',
|
||||||
|
'leasingPeriod',
|
||||||
]),
|
]),
|
||||||
}),
|
}),
|
||||||
async () => {
|
async () => {
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
import { createValidationSchema } from '../validation';
|
import { createValidationSchema } from '../validation';
|
||||||
import { createValidationReaction } from '@/process/tools';
|
import { createValidationReaction } from '@/process/tools';
|
||||||
|
|
||||||
export const validation = createValidationReaction(createValidationSchema);
|
export const validation = createValidationReaction(createValidationSchema, {
|
||||||
|
fireImmediately: true,
|
||||||
|
});
|
||||||
|
|||||||
@ -1,22 +1,32 @@
|
|||||||
/* eslint-disable sonarjs/cognitive-complexity */
|
/* eslint-disable sonarjs/cognitive-complexity */
|
||||||
/* eslint-disable complexity */
|
/* eslint-disable complexity */
|
||||||
import type { ValidationContext } from '../types';
|
import type { ValidationContext } from '../types';
|
||||||
|
import titles from '@/Components/Calculation/config/elements-titles';
|
||||||
import ValuesSchema from '@/config/schema/values';
|
import ValuesSchema from '@/config/schema/values';
|
||||||
import * as CRMTypes from '@/graphql/crm.types';
|
import * as CRMTypes from '@/graphql/crm.types';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
export function createValidationSchema({ apolloClient }: ValidationContext) {
|
export function createValidationSchema({ apolloClient }: ValidationContext) {
|
||||||
return ValuesSchema.pick({
|
return ValuesSchema.pick({
|
||||||
|
brand: true,
|
||||||
insDecentral: true,
|
insDecentral: true,
|
||||||
lead: true,
|
lead: true,
|
||||||
leaseObjectCategory: true,
|
leaseObjectCategory: true,
|
||||||
|
leaseObjectMotorPower: true,
|
||||||
|
leaseObjectPrice: true,
|
||||||
leaseObjectType: true,
|
leaseObjectType: true,
|
||||||
leaseObjectUseFor: true,
|
leaseObjectUseFor: true,
|
||||||
|
leaseObjectYear: true,
|
||||||
|
leasingPeriod: true,
|
||||||
leasingWithoutKasko: true,
|
leasingWithoutKasko: true,
|
||||||
legalClientRegion: true,
|
legalClientRegion: true,
|
||||||
|
maxMass: true,
|
||||||
|
model: true,
|
||||||
objectRegistration: true,
|
objectRegistration: true,
|
||||||
opportunity: true,
|
opportunity: true,
|
||||||
|
supplierDiscountRub: true,
|
||||||
townRegistration: true,
|
townRegistration: true,
|
||||||
|
withTrailer: true,
|
||||||
}).superRefine(
|
}).superRefine(
|
||||||
async (
|
async (
|
||||||
{
|
{
|
||||||
@ -30,9 +40,80 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
|
|||||||
lead: leadid,
|
lead: leadid,
|
||||||
opportunity: opportunityid,
|
opportunity: opportunityid,
|
||||||
objectRegistration,
|
objectRegistration,
|
||||||
|
brand,
|
||||||
|
model,
|
||||||
|
leaseObjectMotorPower,
|
||||||
|
leaseObjectPrice,
|
||||||
|
leaseObjectYear,
|
||||||
|
leasingPeriod,
|
||||||
|
supplierDiscountRub,
|
||||||
},
|
},
|
||||||
ctx
|
ctx
|
||||||
) => {
|
) => {
|
||||||
|
if (!brand) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: 'Не заполенно поле ' + titles.selectBrand,
|
||||||
|
path: ['eltKasko', 'eltOsago'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!model) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: 'Не заполнено поле ' + titles.selectModel,
|
||||||
|
path: ['eltKasko', 'eltOsago'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!leaseObjectPrice) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: 'Не заполнено поле ' + titles.tbxLeaseObjectPrice,
|
||||||
|
path: ['eltKasko', 'eltOsago'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!supplierDiscountRub) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: 'Не заполнено поле ' + titles.tbxSupplierDiscountRub,
|
||||||
|
path: ['eltKasko', 'eltOsago'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!leasingPeriod) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: 'Не заполнено поле ' + titles.tbxLeasingPeriod,
|
||||||
|
path: ['eltKasko', 'eltOsago'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!leaseObjectYear) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: 'Не заполнено поле ' + titles.tbxLeaseObjectYear,
|
||||||
|
path: ['eltKasko', 'eltOsago'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!leaseObjectMotorPower) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: 'Не заполнено поле ' + titles.tbxLeaseObjectMotorPower,
|
||||||
|
path: ['eltKasko', 'eltOsago'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!leaseObjectUseFor) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: 'Не заполнено поле ' + titles.selectLeaseObjectUseFor,
|
||||||
|
path: ['eltKasko', 'eltOsago'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (leaseObjectTypeId) {
|
if (leaseObjectTypeId) {
|
||||||
const {
|
const {
|
||||||
data: { evo_leasingobject_type },
|
data: { evo_leasingobject_type },
|
||||||
|
|||||||
@ -9,7 +9,8 @@ import { uid } from 'radash';
|
|||||||
import type { ZodTypeAny } from 'zod';
|
import type { ZodTypeAny } from 'zod';
|
||||||
|
|
||||||
export function createValidationReaction<T extends ZodTypeAny>(
|
export function createValidationReaction<T extends ZodTypeAny>(
|
||||||
createValidationSchema: (context: ProcessContext) => T
|
createValidationSchema: (context: ProcessContext) => T,
|
||||||
|
opts?: { fireImmediately: boolean }
|
||||||
) {
|
) {
|
||||||
const key = uid(7);
|
const key = uid(7);
|
||||||
|
|
||||||
@ -80,6 +81,7 @@ export function createValidationReaction<T extends ZodTypeAny>(
|
|||||||
{
|
{
|
||||||
delay: 1,
|
delay: 1,
|
||||||
equals: comparer.structural,
|
equals: comparer.structural,
|
||||||
|
fireImmediately: opts?.fireImmediately,
|
||||||
wait: 100,
|
wait: 100,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user