Compare commits
4 Commits
dev
...
feature/lo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72560b3e8a | ||
|
|
524f0105e1 | ||
|
|
582310f59c | ||
|
|
1940f6e07d |
31
apps/web/Components/Calculation/addons/irr-addon.tsx
Normal file
31
apps/web/Components/Calculation/addons/irr-addon.tsx
Normal file
@ -0,0 +1,31 @@
|
||||
import { useStore } from '@/stores/hooks';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import styled from 'styled-components';
|
||||
import { LoadingOutlined } from 'ui/elements/icons';
|
||||
|
||||
const TextAddon = styled.span`
|
||||
font-size: 14px;
|
||||
`;
|
||||
|
||||
const formatter = Intl.NumberFormat('ru', {
|
||||
minimumFractionDigits: 2,
|
||||
}).format;
|
||||
|
||||
export const IRRAddon = observer(() => {
|
||||
const { $calculation, $process } = useStore();
|
||||
|
||||
if ($process.has('Tarif')) {
|
||||
return (
|
||||
<TextAddon>
|
||||
<LoadingOutlined rev="" />
|
||||
{' Подбирается тариф...'}
|
||||
</TextAddon>
|
||||
);
|
||||
}
|
||||
|
||||
const tarif = $calculation.element('selectTarif').getValue();
|
||||
if (!tarif) return <TextAddon>Тариф не найден</TextAddon>;
|
||||
|
||||
const { min, max } = $calculation.$values.getValue('irrInfo');
|
||||
return <TextAddon>{`${formatter(min)}% - ${formatter(max)}%`}</TextAddon>;
|
||||
});
|
||||
@ -1,3 +1,4 @@
|
||||
import { IRRAddon } from '../../addons/irr-addon';
|
||||
import { ProductAddon } from '../../addons/product-addon';
|
||||
import { buildLink } from '../../builders';
|
||||
import components from '../elements-components';
|
||||
@ -11,7 +12,6 @@ import { useErrors, useStore } from '@/stores/hooks';
|
||||
import { useIsFetching } from '@tanstack/react-query';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import type { ComponentProps } from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { Link, Tooltip } from 'ui/elements';
|
||||
import { LoadingOutlined } from 'ui/elements/icons';
|
||||
|
||||
@ -22,14 +22,6 @@ const defaultLinkProps: ComponentProps<typeof Link> = {
|
||||
type: 'link',
|
||||
};
|
||||
|
||||
const formatter = Intl.NumberFormat('ru', {
|
||||
minimumFractionDigits: 2,
|
||||
}).format;
|
||||
|
||||
const TextAddon = styled.span`
|
||||
font-size: 14px;
|
||||
`;
|
||||
|
||||
const overrideRender: Partial<Record<keyof typeof map, RenderProps>> = {
|
||||
btnCalculate: {
|
||||
render: () => {
|
||||
@ -55,7 +47,11 @@ const overrideRender: Partial<Record<keyof typeof map, RenderProps>> = {
|
||||
<Element
|
||||
{...props}
|
||||
loading={$process.has('Calculate') || $process.has('CreateKP')}
|
||||
disabled={$process.has('LoadKP') || (!$process.has('Unlimited') && hasErrors)}
|
||||
disabled={
|
||||
$process.has('LoadKP') ||
|
||||
(!$process.has('Unlimited') && hasErrors) ||
|
||||
$process.has('Tarif')
|
||||
}
|
||||
/>
|
||||
</Container>
|
||||
);
|
||||
@ -89,7 +85,11 @@ const overrideRender: Partial<Record<keyof typeof map, RenderProps>> = {
|
||||
<Element
|
||||
{...props}
|
||||
loading={$process.has('Calculate') || $process.has('CreateKP')}
|
||||
disabled={$process.has('LoadKP') || (!$process.has('Unlimited') && hasErrors)}
|
||||
disabled={
|
||||
$process.has('LoadKP') ||
|
||||
(!$process.has('Unlimited') && hasErrors) ||
|
||||
$process.has('Tarif')
|
||||
}
|
||||
/>
|
||||
</Container>
|
||||
);
|
||||
@ -334,11 +334,9 @@ const overrideRender: Partial<Record<keyof typeof map, RenderProps>> = {
|
||||
const { $calculation } = useStore();
|
||||
const { min, max } = $calculation.$values.getValue('irrInfo');
|
||||
|
||||
const addon = <TextAddon>{`${formatter(min)}% - ${formatter(max)}%`}</TextAddon>;
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Head htmlFor={elementName} title={title} addon={addon} />
|
||||
<Head htmlFor={elementName} title={title} addon={<IRRAddon />} />
|
||||
<Element {...props} min={min > 0 ? min : undefined} max={max > 0 ? max : undefined} />
|
||||
</Container>
|
||||
);
|
||||
|
||||
@ -36,6 +36,7 @@ export default function valuesReactions({ store, apolloClient, trpcClient }: Pro
|
||||
if (abortController) abortController.abort();
|
||||
abortController = new AbortController();
|
||||
|
||||
$process.add('Tarif');
|
||||
const { evo_tarif } = await trpcClient.getTarif.query(values, {
|
||||
signal: abortController.signal,
|
||||
});
|
||||
@ -44,7 +45,10 @@ export default function valuesReactions({ store, apolloClient, trpcClient }: Pro
|
||||
$calculation.element('selectTarif').setOptions(normalizeOptions([evo_tarif]));
|
||||
$calculation.element('selectTarif').setValue(evo_tarif.evo_tarifid);
|
||||
}
|
||||
|
||||
$process.delete('Tarif');
|
||||
} catch {
|
||||
$process.delete('Tarif');
|
||||
$calculation.element('selectTarif').resetOptions();
|
||||
}
|
||||
},
|
||||
|
||||
@ -74,6 +74,14 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
|
||||
|
||||
const { tarif: tarifId, parmentsDecreasePercent } = values;
|
||||
|
||||
if (!tarifId) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: 'Не заполнено поле',
|
||||
path: ['selectTarif'],
|
||||
});
|
||||
}
|
||||
|
||||
if (tarifId) {
|
||||
const {
|
||||
data: { evo_tarif },
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import type { ObservableSet } from 'mobx';
|
||||
import { observable } from 'mobx';
|
||||
|
||||
export type Process = 'Calculate' | 'CreateKP' | 'ELT' | 'LoadKP' | 'Unlimited';
|
||||
export type Process = 'Calculate' | 'CreateKP' | 'ELT' | 'LoadKP' | 'Tarif' | 'Unlimited';
|
||||
export type ProcessStore = ObservableSet<Process>;
|
||||
|
||||
export default function createProcessStore() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user