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);
|
||||
}
|
||||
|
||||
const townId = $calculation.element('selectLegalClientRegion').getValue();
|
||||
const townId = $calculation.element('selectLegalClientTown').getValue();
|
||||
let evo_town: CRMTypes.GetTownQuery['evo_town'] = null;
|
||||
if (townId) {
|
||||
const { data } = await apolloClient.query({
|
||||
|
||||
@ -30,6 +30,13 @@ export default function reactions(context: ProcessContext) {
|
||||
'insAgeDrivers',
|
||||
'insExpDrivers',
|
||||
'vin',
|
||||
'brand',
|
||||
'model',
|
||||
'leaseObjectMotorPower',
|
||||
'leaseObjectPrice',
|
||||
'supplierDiscountRub',
|
||||
'leaseObjectYear',
|
||||
'leasingPeriod',
|
||||
]),
|
||||
}),
|
||||
async () => {
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import { createValidationSchema } from '../validation';
|
||||
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 complexity */
|
||||
import type { ValidationContext } from '../types';
|
||||
import titles from '@/Components/Calculation/config/elements-titles';
|
||||
import ValuesSchema from '@/config/schema/values';
|
||||
import * as CRMTypes from '@/graphql/crm.types';
|
||||
import { z } from 'zod';
|
||||
|
||||
export function createValidationSchema({ apolloClient }: ValidationContext) {
|
||||
return ValuesSchema.pick({
|
||||
brand: true,
|
||||
insDecentral: true,
|
||||
lead: true,
|
||||
leaseObjectCategory: true,
|
||||
leaseObjectMotorPower: true,
|
||||
leaseObjectPrice: true,
|
||||
leaseObjectType: true,
|
||||
leaseObjectUseFor: true,
|
||||
leaseObjectYear: true,
|
||||
leasingPeriod: true,
|
||||
leasingWithoutKasko: true,
|
||||
legalClientRegion: true,
|
||||
maxMass: true,
|
||||
model: true,
|
||||
objectRegistration: true,
|
||||
opportunity: true,
|
||||
supplierDiscountRub: true,
|
||||
townRegistration: true,
|
||||
withTrailer: true,
|
||||
}).superRefine(
|
||||
async (
|
||||
{
|
||||
@ -30,9 +40,80 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
|
||||
lead: leadid,
|
||||
opportunity: opportunityid,
|
||||
objectRegistration,
|
||||
brand,
|
||||
model,
|
||||
leaseObjectMotorPower,
|
||||
leaseObjectPrice,
|
||||
leaseObjectYear,
|
||||
leasingPeriod,
|
||||
supplierDiscountRub,
|
||||
},
|
||||
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) {
|
||||
const {
|
||||
data: { evo_leasingobject_type },
|
||||
|
||||
@ -9,7 +9,8 @@ import { uid } from 'radash';
|
||||
import type { ZodTypeAny } from 'zod';
|
||||
|
||||
export function createValidationReaction<T extends ZodTypeAny>(
|
||||
createValidationSchema: (context: ProcessContext) => T
|
||||
createValidationSchema: (context: ProcessContext) => T,
|
||||
opts?: { fireImmediately: boolean }
|
||||
) {
|
||||
const key = uid(7);
|
||||
|
||||
@ -80,6 +81,7 @@ export function createValidationReaction<T extends ZodTypeAny>(
|
||||
{
|
||||
delay: 1,
|
||||
equals: comparer.structural,
|
||||
fireImmediately: opts?.fireImmediately,
|
||||
wait: 100,
|
||||
}
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user