insurance/store: minor refactor names
This commit is contained in:
parent
18bff9cd11
commit
5d65e85f57
@ -2,9 +2,13 @@ import { observer } from 'mobx-react-lite';
|
||||
import type { ComponentType } from 'react';
|
||||
import { useRowOptions, useRowStatuses } from 'stores/tables/insurance/hooks';
|
||||
import { useInsuranceValue } from './hooks';
|
||||
import type { Keys } from './types';
|
||||
import type { Values } from './types';
|
||||
|
||||
export function buildOptionComponent<T>(key: string, Component: ComponentType<T>, valueName: Keys) {
|
||||
export function buildOptionComponent<T>(
|
||||
key: string,
|
||||
Component: ComponentType<T>,
|
||||
valueName: Values
|
||||
) {
|
||||
return observer((props: T) => {
|
||||
const [value, setValue] = useInsuranceValue(key, valueName);
|
||||
const options = useRowOptions(key);
|
||||
@ -22,7 +26,11 @@ export function buildOptionComponent<T>(key: string, Component: ComponentType<T>
|
||||
});
|
||||
}
|
||||
|
||||
export function buildValueComponent<T>(key: string, Component: ComponentType<T>, valueName: Keys) {
|
||||
export function buildValueComponent<T>(
|
||||
key: string,
|
||||
Component: ComponentType<T>,
|
||||
valueName: Values
|
||||
) {
|
||||
return observer((props: T) => {
|
||||
const [value, setValue] = useInsuranceValue(key, valueName);
|
||||
const statuses = useRowStatuses(key);
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
import type { BaseOption, Status } from 'Elements/types';
|
||||
|
||||
export type Keys = 'osago' | 'kasko' | 'dgo' | 'ns' | 'finGAP';
|
||||
|
||||
export type RowValues = {
|
||||
key: string;
|
||||
key: Keys;
|
||||
policyType: string;
|
||||
insuranceCompany: string | null;
|
||||
insured: 100_000_000 | 100_000_001 | null;
|
||||
@ -9,14 +11,12 @@ export type RowValues = {
|
||||
insTerm: 100_000_000 | 100_000_001 | null;
|
||||
};
|
||||
|
||||
export type Keys = keyof RowValues;
|
||||
export type Values = Exclude<keyof RowValues, 'key'>;
|
||||
|
||||
type Options = {
|
||||
[ValueName in keyof RowValues]?: BaseOption<RowValues[ValueName]>[];
|
||||
};
|
||||
|
||||
export type RowOptions = Omit<Options, 'key'> & { key: string };
|
||||
|
||||
export type RowStatuses = Omit<Record<Keys, Status>, 'key'> & {
|
||||
key: string;
|
||||
export type RowOptions = {
|
||||
[ValueName in Values]?: BaseOption<RowValues[ValueName]>[];
|
||||
} & { key: Keys };
|
||||
|
||||
export type RowStatuses = Record<Values, Status> & {
|
||||
key: Keys;
|
||||
};
|
||||
|
||||
@ -35,33 +35,41 @@ export default class InsuranceTable {
|
||||
this.statuses = initialStatuses;
|
||||
};
|
||||
|
||||
getRowValue(key: string, valueName: Insurance.Keys) {
|
||||
getRowValue(key: Insurance.Keys, valueName: Insurance.Values) {
|
||||
const rowIndex = this.values.findIndex((x) => x.key === key);
|
||||
|
||||
return this.values[rowIndex][valueName];
|
||||
}
|
||||
|
||||
setRowValues = (key: string, row: Partial<Insurance.RowValues>) => {
|
||||
setRowValues = (key: Insurance.Keys, rowValues: Partial<Insurance.RowValues>) => {
|
||||
const rowIndex = this.values.findIndex((x) => x.key === key);
|
||||
|
||||
if (rowIndex >= 0) {
|
||||
mergeWith(this.values[rowIndex], row);
|
||||
mergeWith(this.values[rowIndex], rowValues);
|
||||
}
|
||||
};
|
||||
|
||||
getRowOptions(key: string) {
|
||||
getRowOptions(key: Insurance.Keys) {
|
||||
const rowIndex = this.options.findIndex((x) => x.key === key);
|
||||
|
||||
return this.options[rowIndex];
|
||||
}
|
||||
|
||||
getRowStatuses(key: string) {
|
||||
setRowOptions = (key: Insurance.Keys, rowOptions: Partial<Insurance.RowOptions>) => {
|
||||
const rowIndex = this.options.findIndex((x) => x.key === key);
|
||||
|
||||
if (rowIndex >= 0) {
|
||||
mergeWith(this.options[rowIndex], rowOptions);
|
||||
}
|
||||
};
|
||||
|
||||
getRowStatuses(key: Insurance.Keys) {
|
||||
const rowIndex = this.values.findIndex((x) => x.key === key);
|
||||
|
||||
return this.statuses[rowIndex];
|
||||
}
|
||||
|
||||
setRowStatuses = (key: string, rowStatuses: Insurance.RowStatuses) => {
|
||||
setRowStatuses = (key: Insurance.Keys, rowStatuses: Insurance.RowStatuses) => {
|
||||
const rowIndex = this.values.findIndex((x) => x.key === key);
|
||||
|
||||
if (rowIndex >= 0) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user