Settings: refactor layout

Unlimited: add selectUser to Settings
This commit is contained in:
vchikalkin 2023-05-19 12:53:32 +03:00
parent 9eb86fc24f
commit 04d8a89b3e
6 changed files with 62 additions and 10 deletions

View File

@ -16,9 +16,23 @@ export const mainRows: FormTabRows = [
],
];
export const unlimitedMainRows: FormTabRows = [
{ title: 'Выбор Интереса/ЛС' },
[['selectUser'], defaultRowStyle],
[['selectLead'], defaultRowStyle],
[['selectOpportunity'], defaultRowStyle],
[['cbxRecalcWithRevision'], defaultRowStyle],
[['selectQuote'], defaultRowStyle],
[
['btnCalculate', 'btnCreateKPMini'],
{
gridTemplateColumns: ['1fr 0.15fr'],
},
],
];
export const paramsRows: FormTabRows = [
{ title: 'Параметры расчета' },
[['labelIrrInfo'], defaultRowStyle],
[['radioCalcType'], defaultRowStyle],
[['tbxIRR_Perc'], defaultRowStyle],
[['tbxTotalPayments'], defaultRowStyle],
@ -26,7 +40,6 @@ export const paramsRows: FormTabRows = [
export const unlimitedParamsRows: FormTabRows = [
{ title: 'Параметры расчета' },
[['labelIrrInfo'], defaultRowStyle],
[['radioCalcType'], defaultRowStyle],
[['tbxIRR_Perc', 'tbxPi'], { gridTemplateColumns: '1fr 1fr' }],
[['tbxTotalPayments'], defaultRowStyle],

View File

@ -20,7 +20,9 @@ const Wrapper = styled(Background)`
export default function Settings() {
const { $process } = useStore();
const mainRows = renderFormRows(config.mainRows);
const mainRows = $process.has('Unlimited')
? renderFormRows(config.unlimitedMainRows)
: renderFormRows(config.mainRows);
const paramsRows = $process.has('Unlimited')
? renderFormRows(config.unlimitedParamsRows)
: renderFormRows(config.paramsRows);

View File

@ -20,6 +20,10 @@ const defaultLinkProps: ComponentProps<typeof Link> = {
type: 'link',
};
const formatter = Intl.NumberFormat('ru', {
minimumFractionDigits: 2,
}).format;
const overrideRender: Partial<Record<keyof typeof map, RenderProps>> = {
selectHighSeasonStart: {
render: () => {
@ -181,6 +185,40 @@ const overrideRender: Partial<Record<keyof typeof map, RenderProps>> = {
},
},
tbxIRR_Perc: {
render: () => {
const elementName = 'tbxIRR_Perc';
const title = titles.tbxIRR_Perc;
const valueName = map.tbxIRR_Perc;
const Component = components.tbxIRR_Perc;
const props = elementsProps.tbxIRR_Perc;
const { builder } = types.tbxIRR_Perc();
const Element = builder(Component, {
elementName,
valueName,
});
const RenderedComponent = observer(() => {
const { $calculation } = useStore();
const { min, max } = $calculation.$values.getValue('irrInfo');
return (
<Container>
<Head
htmlFor={elementName}
title={title}
addon={`${formatter(min)}% - ${formatter(max)}%`}
/>
<Element {...props} min={min} max={max} />
</Container>
);
});
return <RenderedComponent />;
},
},
tbxVehicleTaxInYear: {
render: () => {
const elementName = 'tbxVehicleTaxInYear';

View File

@ -65,7 +65,7 @@ const defaultValues: CalculationValues = {
insUnlimitDrivers: true,
insurance: true,
IRR_Perc: 20,
irrInfo: '-',
irrInfo: { min: 0, max: 0 },
kpUrl: null,
lastPaymentPerc: 1,
lastPaymentRedemption: true,

View File

@ -142,7 +142,10 @@ const ValuesSchema = z.object({
depreciationGroup: z.string().nullable(),
discountRub: z.number(),
insKaskoPriceLeasePeriod: z.number(),
irrInfo: z.string().nullable(),
irrInfo: z.object({
min: z.number(),
max: z.number(),
}),
leaseObjectRiskName: z.string().nullable(),
plPriceRub: z.number(),
registrationDescription: z.string().nullable(),

View File

@ -2,10 +2,6 @@ import helper from '../lib/helper';
import type { ProcessContext } from '@/process/types';
import { reaction } from 'mobx';
export const formatter = Intl.NumberFormat('ru', {
minimumFractionDigits: 2,
}).format;
export default function reactions({ store, apolloClient }: ProcessContext) {
const { $calculation } = store;
@ -38,7 +34,7 @@ export default function reactions({ store, apolloClient }: ProcessContext) {
async (values) => {
const { min, max } = await getIrr(values);
$calculation.element('labelIrrInfo').setValue(`${formatter(min)}% - ${formatter(max)}%`);
$calculation.element('labelIrrInfo').setValue({ max, min });
}
);
}