valiadtion: add fingap valiation (to insurance)
server: extend calculate input object: add fingap
This commit is contained in:
parent
84de7a84e8
commit
e8b656132b
@ -75,6 +75,23 @@ function getInsuranceTableErrors({ $tables, $process }) {
|
||||
));
|
||||
}
|
||||
|
||||
function getFingapTableErrors({ $tables, $process }) {
|
||||
const { fingap } = $tables;
|
||||
const errors = fingap.validation.getErrors();
|
||||
const title = fingap.validation.params.err_title;
|
||||
|
||||
return errors.map(({ key, message }) => (
|
||||
<AlertWrapper>
|
||||
<Alert
|
||||
key={key}
|
||||
type={$process.has('Unlimited') ? 'warning' : 'error'}
|
||||
showIcon
|
||||
message={Message(title, message)}
|
||||
/>
|
||||
</AlertWrapper>
|
||||
));
|
||||
}
|
||||
|
||||
const Errors = observer(() => {
|
||||
const store = useStore();
|
||||
const { $calculation, $tables } = store;
|
||||
@ -92,8 +109,9 @@ const Errors = observer(() => {
|
||||
const elementsErrors = getElementsErrors(store);
|
||||
const paymentsErrors = getPaymentsTableErrors(store);
|
||||
const insuranceErrors = getInsuranceTableErrors(store);
|
||||
const fingapErrors = getFingapTableErrors(store);
|
||||
|
||||
const errors = [...elementsErrors, ...paymentsErrors, ...insuranceErrors];
|
||||
const errors = [...elementsErrors, ...paymentsErrors, ...insuranceErrors, ...fingapErrors];
|
||||
|
||||
return <Flex flexDirection="column">{errors}</Flex>;
|
||||
});
|
||||
|
||||
@ -10,3 +10,5 @@ export const RiskSchema = z.object({
|
||||
riskName: z.string(),
|
||||
sum: z.number(),
|
||||
});
|
||||
|
||||
export const FinGAPSchema = RiskSchema.array();
|
||||
|
||||
@ -21,11 +21,14 @@ export async function action({ store, trpcClient }: ProcessContext) {
|
||||
osago: toJS($tables.insurance.row('osago').getValues()),
|
||||
};
|
||||
|
||||
const fingap = $tables.fingap.getSelectedRisks();
|
||||
|
||||
const paymentRelations = toJS($tables.payments.values);
|
||||
const paymentSums = toJS($tables.payments.sums);
|
||||
|
||||
trpcClient.calculate
|
||||
.mutate({
|
||||
fingap,
|
||||
insurance: { values: insurance },
|
||||
payments: { sums: paymentSums, values: paymentRelations },
|
||||
values,
|
||||
|
||||
@ -112,11 +112,13 @@ export default function reactions({ store, apolloClient, queryClient }: ProcessC
|
||||
const discountRub = $calculation.$values.getValue('discountRub');
|
||||
const firstPaymentRub = $calculation.element('tbxFirstPaymentRub').getValue();
|
||||
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
|
||||
const hasPaymentsErrors = $tables.payments.validation.hasErrors;
|
||||
|
||||
return {
|
||||
discountRub,
|
||||
finGAPInsuranceCompany,
|
||||
firstPaymentRub,
|
||||
hasPaymentsErrors,
|
||||
leasingPeriod,
|
||||
paymentsValues,
|
||||
plPriceRub,
|
||||
@ -129,8 +131,13 @@ export default function reactions({ store, apolloClient, queryClient }: ProcessC
|
||||
discountRub,
|
||||
firstPaymentRub,
|
||||
leasingPeriod,
|
||||
hasPaymentsErrors,
|
||||
}) => {
|
||||
if (!finGAPInsuranceCompany || $tables.payments.validation.hasErrors) return;
|
||||
if (!finGAPInsuranceCompany || hasPaymentsErrors) {
|
||||
$tables.fingap.clear();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
data: { evo_addproduct_types },
|
||||
|
||||
@ -1,2 +1 @@
|
||||
export { default as common } from './common';
|
||||
export { default as validation } from './validation';
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
import type { ProcessContext } from '@/process/types';
|
||||
import ValidationHelper from '@/stores/validation/helper';
|
||||
import { reaction } from 'mobx';
|
||||
import { uid } from 'radash';
|
||||
|
||||
const key = uid(7);
|
||||
|
||||
export default function reactions({ store }: ProcessContext) {
|
||||
const { $tables } = store;
|
||||
|
||||
const helper = new ValidationHelper();
|
||||
reaction(
|
||||
() => {
|
||||
const hasPaymentsErrors = $tables.payments.validation.hasErrors;
|
||||
const finGAPInsuranceCompany = $tables.insurance.row('fingap').getValue('insuranceCompany');
|
||||
|
||||
return {
|
||||
finGAPInsuranceCompany,
|
||||
hasPaymentsErrors,
|
||||
};
|
||||
},
|
||||
({ hasPaymentsErrors, finGAPInsuranceCompany }) => {
|
||||
if (finGAPInsuranceCompany !== null && hasPaymentsErrors) {
|
||||
const removeError = $tables.fingap.setError({
|
||||
key,
|
||||
message: 'Неверно заполнены платежи',
|
||||
});
|
||||
helper.add(removeError);
|
||||
} else {
|
||||
helper.removeErrors();
|
||||
}
|
||||
|
||||
if (hasPaymentsErrors) {
|
||||
$tables.fingap.clear();
|
||||
}
|
||||
},
|
||||
{
|
||||
fireImmediately: true,
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -3,6 +3,7 @@
|
||||
/* eslint-disable zod/require-strict */
|
||||
import type { ValidationContext } from '../types';
|
||||
import type * as Insurance from '@/Components/Calculation/Form/Insurance/InsuranceTable/types';
|
||||
import { FinGAPSchema } from '@/config/schema/fingap';
|
||||
import { InsuranceSchema } from '@/config/schema/insurance';
|
||||
import ValuesSchema from '@/config/schema/values';
|
||||
import * as CRMTypes from '@/graphql/crm.types';
|
||||
@ -18,6 +19,7 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
|
||||
recalcWithRevision: true,
|
||||
})
|
||||
.extend({
|
||||
fingap: FinGAPSchema,
|
||||
insurance: InsuranceSchema,
|
||||
})
|
||||
|
||||
@ -31,6 +33,7 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
|
||||
insDecentral,
|
||||
insurance,
|
||||
brand: brandId,
|
||||
fingap: fingapRisks,
|
||||
},
|
||||
ctx
|
||||
) => {
|
||||
@ -118,6 +121,14 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
|
||||
});
|
||||
}
|
||||
|
||||
if (fingap.insuranceCompany && !fingapRisks?.length) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `Выберите риски`,
|
||||
path: ['fingap'],
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
!leasingWithoutKasko &&
|
||||
!insDecentral &&
|
||||
|
||||
@ -29,6 +29,7 @@ export function createValidationReaction<T extends ZodTypeAny>(
|
||||
if (shapeValues.includes('insurance'))
|
||||
return {
|
||||
...values,
|
||||
fingap: $tables.fingap.getSelectedRisks(),
|
||||
insurance: {
|
||||
values: {
|
||||
fingap: toJS($tables.insurance.row('fingap').getValues()),
|
||||
@ -54,11 +55,16 @@ export function createValidationReaction<T extends ZodTypeAny>(
|
||||
if (validationResult.success === false) {
|
||||
validationResult.error.errors.forEach(({ path, message }) => {
|
||||
(
|
||||
path as Array<Elements & ('eltKasko' | 'eltOsago' | 'insurance' | 'payments')>
|
||||
path as Array<
|
||||
Elements & ('eltKasko' | 'eltOsago' | 'fingap' | 'insurance' | 'payments')
|
||||
>
|
||||
).forEach((elementName) => {
|
||||
if (elementName === 'insurance') {
|
||||
const removeError = $tables.insurance.setError({ key, message });
|
||||
if (removeError) helper.add(removeError);
|
||||
} else if (elementName === 'fingap') {
|
||||
const removeError = $tables.fingap.setError({ key, message });
|
||||
if (removeError) helper.add(removeError);
|
||||
} else if (elementName === 'payments') {
|
||||
const removeError = $tables.payments.setError({ key, message });
|
||||
if (removeError) helper.add(removeError);
|
||||
|
||||
@ -25,6 +25,7 @@ const processes = [
|
||||
];
|
||||
|
||||
const titles = Object.assign(elementsTitles, {
|
||||
fingap: 'Таблица Safe Finance',
|
||||
insurance: 'Таблица страхования',
|
||||
payments: 'Таблица платежей',
|
||||
});
|
||||
@ -42,6 +43,7 @@ export async function validate({ input, context }: { context: Context; input: Ca
|
||||
const validationSchema = createValidationSchema(context);
|
||||
const validationResult = await validationSchema.safeParseAsync({
|
||||
...input.values,
|
||||
fingap: input.fingap,
|
||||
insurance: input.insurance,
|
||||
payments: input.payments,
|
||||
});
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { FinGAPSchema } from '@/config/schema/fingap';
|
||||
import { InsuranceSchema } from '@/config/schema/insurance';
|
||||
import PaymentsSchema from '@/config/schema/payments';
|
||||
import { ResultPaymentsSchema, ResultValuesSchema } from '@/config/schema/results';
|
||||
@ -9,6 +10,7 @@ export type Context = Pick<ProcessContext, 'apolloClient' | 'queryClient' | 'use
|
||||
|
||||
export const CalculateInputSchema = z
|
||||
.object({
|
||||
fingap: FinGAPSchema,
|
||||
insurance: InsuranceSchema,
|
||||
payments: PaymentsSchema,
|
||||
values: ValuesSchema,
|
||||
|
||||
@ -74,7 +74,6 @@ export const CreateQuoteInputDataSchema = CalculateInputSchema.extend({
|
||||
kasko: EltRowSchema.optional(),
|
||||
osago: EltRowSchema.optional(),
|
||||
}),
|
||||
fingap: RiskSchema.array(),
|
||||
});
|
||||
|
||||
export { CalculateOutputSchema as CreateQuoteOutputDataSchema } from '../calculate/types';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user