Compare commits
1 Commits
dev
...
fix/dyn-30
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 Errors = observer(() => {
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
const { $calculation, $tables } = store;
|
const { $calculation, $tables } = store;
|
||||||
@ -92,8 +109,9 @@ const Errors = observer(() => {
|
|||||||
const elementsErrors = getElementsErrors(store);
|
const elementsErrors = getElementsErrors(store);
|
||||||
const paymentsErrors = getPaymentsTableErrors(store);
|
const paymentsErrors = getPaymentsTableErrors(store);
|
||||||
const insuranceErrors = getInsuranceTableErrors(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>;
|
return <Flex flexDirection="column">{errors}</Flex>;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -10,3 +10,5 @@ export const RiskSchema = z.object({
|
|||||||
riskName: z.string(),
|
riskName: z.string(),
|
||||||
sum: z.number(),
|
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()),
|
osago: toJS($tables.insurance.row('osago').getValues()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fingap = $tables.fingap.getSelectedRisks();
|
||||||
|
|
||||||
const paymentRelations = toJS($tables.payments.values);
|
const paymentRelations = toJS($tables.payments.values);
|
||||||
const paymentSums = toJS($tables.payments.sums);
|
const paymentSums = toJS($tables.payments.sums);
|
||||||
|
|
||||||
trpcClient.calculate
|
trpcClient.calculate
|
||||||
.mutate({
|
.mutate({
|
||||||
|
fingap,
|
||||||
insurance: { values: insurance },
|
insurance: { values: insurance },
|
||||||
payments: { sums: paymentSums, values: paymentRelations },
|
payments: { sums: paymentSums, values: paymentRelations },
|
||||||
values,
|
values,
|
||||||
|
|||||||
@ -112,11 +112,13 @@ export default function reactions({ store, apolloClient, queryClient }: ProcessC
|
|||||||
const discountRub = $calculation.$values.getValue('discountRub');
|
const discountRub = $calculation.$values.getValue('discountRub');
|
||||||
const firstPaymentRub = $calculation.element('tbxFirstPaymentRub').getValue();
|
const firstPaymentRub = $calculation.element('tbxFirstPaymentRub').getValue();
|
||||||
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
|
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
|
||||||
|
const hasPaymentsErrors = $tables.payments.validation.hasErrors;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
discountRub,
|
discountRub,
|
||||||
finGAPInsuranceCompany,
|
finGAPInsuranceCompany,
|
||||||
firstPaymentRub,
|
firstPaymentRub,
|
||||||
|
hasPaymentsErrors,
|
||||||
leasingPeriod,
|
leasingPeriod,
|
||||||
paymentsValues,
|
paymentsValues,
|
||||||
plPriceRub,
|
plPriceRub,
|
||||||
@ -129,8 +131,13 @@ export default function reactions({ store, apolloClient, queryClient }: ProcessC
|
|||||||
discountRub,
|
discountRub,
|
||||||
firstPaymentRub,
|
firstPaymentRub,
|
||||||
leasingPeriod,
|
leasingPeriod,
|
||||||
|
hasPaymentsErrors,
|
||||||
}) => {
|
}) => {
|
||||||
if (!finGAPInsuranceCompany || $tables.payments.validation.hasErrors) return;
|
if (!finGAPInsuranceCompany || hasPaymentsErrors) {
|
||||||
|
$tables.fingap.clear();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: { evo_addproduct_types },
|
data: { evo_addproduct_types },
|
||||||
|
|||||||
@ -1,2 +1 @@
|
|||||||
export { default as common } from './common';
|
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 */
|
/* eslint-disable zod/require-strict */
|
||||||
import type { ValidationContext } from '../types';
|
import type { ValidationContext } from '../types';
|
||||||
import type * as Insurance from '@/Components/Calculation/Form/Insurance/InsuranceTable/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 { InsuranceSchema } from '@/config/schema/insurance';
|
||||||
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';
|
||||||
@ -18,6 +19,7 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
|
|||||||
recalcWithRevision: true,
|
recalcWithRevision: true,
|
||||||
})
|
})
|
||||||
.extend({
|
.extend({
|
||||||
|
fingap: FinGAPSchema,
|
||||||
insurance: InsuranceSchema,
|
insurance: InsuranceSchema,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -31,6 +33,7 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
|
|||||||
insDecentral,
|
insDecentral,
|
||||||
insurance,
|
insurance,
|
||||||
brand: brandId,
|
brand: brandId,
|
||||||
|
fingap: fingapRisks,
|
||||||
},
|
},
|
||||||
ctx
|
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 (
|
if (
|
||||||
!leasingWithoutKasko &&
|
!leasingWithoutKasko &&
|
||||||
!insDecentral &&
|
!insDecentral &&
|
||||||
|
|||||||
@ -29,6 +29,7 @@ export function createValidationReaction<T extends ZodTypeAny>(
|
|||||||
if (shapeValues.includes('insurance'))
|
if (shapeValues.includes('insurance'))
|
||||||
return {
|
return {
|
||||||
...values,
|
...values,
|
||||||
|
fingap: $tables.fingap.getSelectedRisks(),
|
||||||
insurance: {
|
insurance: {
|
||||||
values: {
|
values: {
|
||||||
fingap: toJS($tables.insurance.row('fingap').getValues()),
|
fingap: toJS($tables.insurance.row('fingap').getValues()),
|
||||||
@ -54,11 +55,16 @@ export function createValidationReaction<T extends ZodTypeAny>(
|
|||||||
if (validationResult.success === false) {
|
if (validationResult.success === false) {
|
||||||
validationResult.error.errors.forEach(({ path, message }) => {
|
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) => {
|
).forEach((elementName) => {
|
||||||
if (elementName === 'insurance') {
|
if (elementName === 'insurance') {
|
||||||
const removeError = $tables.insurance.setError({ key, message });
|
const removeError = $tables.insurance.setError({ key, message });
|
||||||
if (removeError) helper.add(removeError);
|
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') {
|
} else if (elementName === 'payments') {
|
||||||
const removeError = $tables.payments.setError({ key, message });
|
const removeError = $tables.payments.setError({ key, message });
|
||||||
if (removeError) helper.add(removeError);
|
if (removeError) helper.add(removeError);
|
||||||
|
|||||||
@ -25,6 +25,7 @@ const processes = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
const titles = Object.assign(elementsTitles, {
|
const titles = Object.assign(elementsTitles, {
|
||||||
|
fingap: 'Таблица Safe Finance',
|
||||||
insurance: 'Таблица страхования',
|
insurance: 'Таблица страхования',
|
||||||
payments: 'Таблица платежей',
|
payments: 'Таблица платежей',
|
||||||
});
|
});
|
||||||
@ -42,6 +43,7 @@ export async function validate({ input, context }: { context: Context; input: Ca
|
|||||||
const validationSchema = createValidationSchema(context);
|
const validationSchema = createValidationSchema(context);
|
||||||
const validationResult = await validationSchema.safeParseAsync({
|
const validationResult = await validationSchema.safeParseAsync({
|
||||||
...input.values,
|
...input.values,
|
||||||
|
fingap: input.fingap,
|
||||||
insurance: input.insurance,
|
insurance: input.insurance,
|
||||||
payments: input.payments,
|
payments: input.payments,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { FinGAPSchema } from '@/config/schema/fingap';
|
||||||
import { InsuranceSchema } from '@/config/schema/insurance';
|
import { InsuranceSchema } from '@/config/schema/insurance';
|
||||||
import PaymentsSchema from '@/config/schema/payments';
|
import PaymentsSchema from '@/config/schema/payments';
|
||||||
import { ResultPaymentsSchema, ResultValuesSchema } from '@/config/schema/results';
|
import { ResultPaymentsSchema, ResultValuesSchema } from '@/config/schema/results';
|
||||||
@ -9,6 +10,7 @@ export type Context = Pick<ProcessContext, 'apolloClient' | 'queryClient' | 'use
|
|||||||
|
|
||||||
export const CalculateInputSchema = z
|
export const CalculateInputSchema = z
|
||||||
.object({
|
.object({
|
||||||
|
fingap: FinGAPSchema,
|
||||||
insurance: InsuranceSchema,
|
insurance: InsuranceSchema,
|
||||||
payments: PaymentsSchema,
|
payments: PaymentsSchema,
|
||||||
values: ValuesSchema,
|
values: ValuesSchema,
|
||||||
|
|||||||
@ -74,7 +74,6 @@ export const CreateQuoteInputDataSchema = CalculateInputSchema.extend({
|
|||||||
kasko: EltRowSchema.optional(),
|
kasko: EltRowSchema.optional(),
|
||||||
osago: EltRowSchema.optional(),
|
osago: EltRowSchema.optional(),
|
||||||
}),
|
}),
|
||||||
fingap: RiskSchema.array(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export { CalculateOutputSchema as CreateQuoteOutputDataSchema } from '../calculate/types';
|
export { CalculateOutputSchema as CreateQuoteOutputDataSchema } from '../calculate/types';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user