diff --git a/Components/Calculation/Form/Insurance/InsuranceTable/builders.tsx b/Components/Calculation/Form/Insurance/InsuranceTable/builders.tsx index d0d715a..9e70f3d 100644 --- a/Components/Calculation/Form/Insurance/InsuranceTable/builders.tsx +++ b/Components/Calculation/Form/Insurance/InsuranceTable/builders.tsx @@ -1,6 +1,6 @@ import { observer } from 'mobx-react-lite'; import type { ComponentType } from 'react'; -import { useRowOptions } from 'stores/tables/insurance/hooks'; +import { useRowOptions, useRowStatuses } from 'stores/tables/insurance/hooks'; import { useInsuranceValue } from './hooks'; import type { Keys } from './types'; @@ -8,15 +8,25 @@ export function buildOptionComponent(key: string, Component: ComponentType return observer((props: T) => { const [value, setValue] = useInsuranceValue(key, valueName); const options = useRowOptions(valueName); + const statuses = useRowStatuses(key); - return ; + return ( + + ); }); } export function buildValueComponent(key: string, Component: ComponentType, valueName: Keys) { return observer((props: T) => { const [value, setValue] = useInsuranceValue(key, valueName); + const statuses = useRowStatuses(key); - return ; + return ; }); } diff --git a/Components/Calculation/Form/Insurance/InsuranceTable/types.ts b/Components/Calculation/Form/Insurance/InsuranceTable/types.ts index 131c2e3..ac613be 100644 --- a/Components/Calculation/Form/Insurance/InsuranceTable/types.ts +++ b/Components/Calculation/Form/Insurance/InsuranceTable/types.ts @@ -1,4 +1,4 @@ -import type { BaseOption } from 'Elements/types'; +import type { BaseOption, Status } from 'Elements/types'; export type Row = { key: string; @@ -14,3 +14,7 @@ export type Keys = keyof Row; export type Options = { [Key in keyof Row]?: BaseOption[]; }; + +export type RowStatuses = Omit, 'key'> & { + key: string; +}; diff --git a/config/tables/insurance-table.ts b/config/tables/insurance-table.ts index 128d4ba..433f87c 100644 --- a/config/tables/insurance-table.ts +++ b/config/tables/insurance-table.ts @@ -66,3 +66,46 @@ export const defaultRows: Insurance.Row[] = [ insTerm: null, }, ]; + +export const defaultStatuses: Insurance.RowStatuses[] = [ + { + key: 'osago', + insTerm: 'Disabled', + insCost: 'Default', + insuranceCompany: 'Default', + insured: 'Default', + policyType: 'Default', + }, + { + key: 'kasko', + insTerm: 'Disabled', + insCost: 'Default', + insuranceCompany: 'Default', + insured: 'Default', + policyType: 'Default', + }, + { + key: 'dgo', + insuranceCompany: 'Disabled', + insured: 'Disabled', + insTerm: 'Disabled', + insCost: 'Default', + policyType: 'Default', + }, + { + key: 'ns', + insuranceCompany: 'Disabled', + insured: 'Disabled', + insTerm: 'Disabled', + insCost: 'Default', + policyType: 'Default', + }, + { + key: 'finGAP', + insCost: 'Disabled', + insuranceCompany: 'Default', + insured: 'Default', + insTerm: 'Default', + policyType: 'Default', + }, +]; diff --git a/pages/index.tsx b/pages/index.tsx index a769461..81ec930 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -38,6 +38,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => insurance: { values: insuranceTableConfig.defaultRows, options: insuranceTableConfig.defaultOptions, + statuses: insuranceTableConfig.defaultStatuses, }, }, }, diff --git a/stores/index.js b/stores/index.js index f6385a2..b93752d 100644 --- a/stores/index.js +++ b/stores/index.js @@ -23,6 +23,7 @@ export function initializeStore(initialData) { _store.$tables.insurance.hydrate({ values: tables.insurance.values, options: tables.insurance.options, + statuses: tables.insurance.statuses, }); } } diff --git a/stores/tables/insurance/hooks.js b/stores/tables/insurance/hooks.js index 715bfbf..e1e8d6c 100644 --- a/stores/tables/insurance/hooks.js +++ b/stores/tables/insurance/hooks.js @@ -21,3 +21,11 @@ export function useRowOptions(valueName) { return options; } + +export function useRowStatuses(key) { + const { $tables } = useStore(); + + const statuses = $tables.insurance.getRowStatuses(key); + + return statuses; +} diff --git a/stores/tables/insurance/index.ts b/stores/tables/insurance/index.ts index 6d71bfe..1f6e623 100644 --- a/stores/tables/insurance/index.ts +++ b/stores/tables/insurance/index.ts @@ -7,21 +7,28 @@ import type RootStore from 'stores/root'; export interface InsuranceTableData { values: Insurance.Row[]; options: Insurance.Options; + statuses: Insurance.RowStatuses[]; } export default class InsuranceTable { root: RootStore; values: Insurance.Row[] = []; options: Insurance.Options = {}; + statuses: Insurance.RowStatuses[] = []; constructor(rootStore: RootStore) { this.root = rootStore; makeAutoObservable(this); } - hydrate = ({ values: initialValues, options: initialOptions }: InsuranceTableData) => { + hydrate = ({ + values: initialValues, + options: initialOptions, + statuses: initialStatuses, + }: InsuranceTableData) => { this.values = initialValues; this.options = initialOptions; + this.statuses = initialStatuses; }; getRowValue(key: string, valueName: Insurance.Keys) { @@ -41,4 +48,18 @@ export default class InsuranceTable { getRowOptions(valueName: Insurance.Keys) { return this.options[valueName]; } + + getRowStatuses(key: string) { + const rowIndex = this.values.findIndex((x) => x.key === key); + + return this.statuses[rowIndex]; + } + + setRowStatuses = (key: string, rowStatuses: Insurance.RowStatuses) => { + const rowIndex = this.values.findIndex((x) => x.key === key); + + if (rowIndex >= 0) { + mergeWith(this.statuses[rowIndex], rowStatuses); + } + }; }