From 6ef19c826f1592e35678a4a6a1c6cb92219ebed4 Mon Sep 17 00:00:00 2001 From: Chika Date: Thu, 23 Jun 2022 17:06:08 +0300 Subject: [PATCH] store(insurance): support options per row --- .../Insurance/InsuranceTable/builders.tsx | 4 +- .../Form/Insurance/InsuranceTable/types.ts | 4 +- config/tables/insurance-table.ts | 139 +++++++++++++++--- stores/tables/insurance/hooks.js | 4 +- stores/tables/insurance/index.ts | 10 +- 5 files changed, 130 insertions(+), 31 deletions(-) diff --git a/Components/Calculation/Form/Insurance/InsuranceTable/builders.tsx b/Components/Calculation/Form/Insurance/InsuranceTable/builders.tsx index 9e70f3d..c0fd444 100644 --- a/Components/Calculation/Form/Insurance/InsuranceTable/builders.tsx +++ b/Components/Calculation/Form/Insurance/InsuranceTable/builders.tsx @@ -7,13 +7,13 @@ import type { Keys } from './types'; export function buildOptionComponent(key: string, Component: ComponentType, valueName: Keys) { return observer((props: T) => { const [value, setValue] = useInsuranceValue(key, valueName); - const options = useRowOptions(valueName); + const options = useRowOptions(key); const statuses = useRowStatuses(key); return ( []; }; +export type RowOptions = Omit & { key: string }; + export type RowStatuses = Omit, 'key'> & { key: string; }; diff --git a/config/tables/insurance-table.ts b/config/tables/insurance-table.ts index 433f87c..ef4f52a 100644 --- a/config/tables/insurance-table.ts +++ b/config/tables/insurance-table.ts @@ -1,28 +1,123 @@ /* eslint-disable object-curly-newline */ import type * as Insurance from 'Components/Calculation/Form/Insurance/InsuranceTable/types'; -export const defaultOptions: Insurance.Options = { - insured: [ - { - label: 'ЛП', - value: 100_000_000, - }, - { - label: 'ЛД', - value: 100_000_001, - }, - ], - insTerm: [ - { - label: '12 месяцев', - value: 100_000_000, - }, - { - label: 'Срок ДЛ', - value: 100_000_001, - }, - ], -}; +export const defaultOptions: Insurance.RowOptions[] = [ + { + key: 'osago', + insured: [ + { + label: 'ЛП', + value: 100_000_000, + }, + { + label: 'ЛД', + value: 100_000_001, + }, + ], + insTerm: [ + { + label: '12 месяцев', + value: 100_000_000, + }, + { + label: 'Срок ДЛ', + value: 100_000_001, + }, + ], + }, + { + key: 'kasko', + insured: [ + { + label: 'ЛП', + value: 100_000_000, + }, + { + label: 'ЛД', + value: 100_000_001, + }, + ], + insTerm: [ + { + label: '12 месяцев', + value: 100_000_000, + }, + { + label: 'Срок ДЛ', + value: 100_000_001, + }, + ], + }, + { + key: 'dgo', + insured: [ + { + label: 'ЛП', + value: 100_000_000, + }, + { + label: 'ЛД', + value: 100_000_001, + }, + ], + insTerm: [ + { + label: '12 месяцев', + value: 100_000_000, + }, + { + label: 'Срок ДЛ', + value: 100_000_001, + }, + ], + }, + { + key: 'ns', + insured: [ + { + label: 'ЛП', + value: 100_000_000, + }, + { + label: 'ЛД', + value: 100_000_001, + }, + ], + insTerm: [ + { + label: '12 месяцев', + value: 100_000_000, + }, + { + label: 'Срок ДЛ', + value: 100_000_001, + }, + ], + }, + { + key: 'finGAP', + insured: [ + { + label: 'ЛП', + value: 100_000_000, + }, + { + label: 'ЛД', + value: 100_000_001, + }, + ], + insTerm: [ + { + label: '12 месяцев', + value: 100_000_000, + }, + { + label: 'Срок ДЛ', + value: 100_000_001, + }, + ], + }, +]; export const defaultRows: Insurance.Row[] = [ { diff --git a/stores/tables/insurance/hooks.js b/stores/tables/insurance/hooks.js index e1e8d6c..1b2c008 100644 --- a/stores/tables/insurance/hooks.js +++ b/stores/tables/insurance/hooks.js @@ -14,10 +14,10 @@ export function useRowValue(key, valueName) { return [storeValue, setStoreValue]; } -export function useRowOptions(valueName) { +export function useRowOptions(key) { const { $tables } = useStore(); - const options = $tables.insurance.getRowOptions(valueName); + const options = $tables.insurance.getRowOptions(key); return options; } diff --git a/stores/tables/insurance/index.ts b/stores/tables/insurance/index.ts index 15442e7..219e6aa 100644 --- a/stores/tables/insurance/index.ts +++ b/stores/tables/insurance/index.ts @@ -7,14 +7,14 @@ import type RootStore from 'stores/root'; export interface InsuranceTableData { values: Insurance.Row[]; - options: Insurance.Options; + options: Insurance.RowOptions[]; statuses: Insurance.RowStatuses[]; } export default class InsuranceTable { root: RootStore; values: Insurance.Row[] = insuranceTableConfig.defaultRows; - options: Insurance.Options = insuranceTableConfig.defaultOptions; + options: Insurance.RowOptions[] = insuranceTableConfig.defaultOptions; statuses: Insurance.RowStatuses[] = insuranceTableConfig.defaultStatuses; constructor(rootStore: RootStore) { @@ -46,8 +46,10 @@ export default class InsuranceTable { } }; - getRowOptions(valueName: Insurance.Keys) { - return this.options[valueName]; + getRowOptions(key: string) { + const rowIndex = this.options.findIndex((x) => x.key === key); + + return this.options[rowIndex]; } getRowStatuses(key: string) {