Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0125· OpenAIAi2 WildChat-4.8M (AI2)

import { memo } from 'react'; import { useFormContext } from 'react-hook-form'; import {…

  1. User

    import { memo } from 'react'; import { useFormContext } from 'react-hook-form'; import { Select, useFormValueSelector } from '@sber-efsdf-ui/ufs-form-components';

    import { Box, Flex, Text } from '@atomic-ui/react';

    import type { BaseIndicatorTypeLabel, InterestRatesFormState, TermIndexesType, } from '$entities/rates'; import type { WithRateParametersProps } from '../../../model'; import { baseIndicatorSelector, withRateParameters } from '../../../model';

    interface BaseIndicatorParamsProps extends WithRateParametersProps { baseIndicatorKindItems: Labeled[]; termIndexTypeItems: Labeled[]; defaultValue?: Labeled; disabled?: boolean; }

    export const EnhancedBaseIndicatorParams = memo( ({ baseIndicatorKindItems, termIndexTypeItems, defaultValue, activePeriodIndex, rateIndex, disabled = false, }: BaseIndicatorParamsProps) => { const { resetField } = useFormContext();

    	const { kind } = useFormValueSelector(
    		(formState: InterestRatesFormState) =>
    			baseIndicatorSelector({ formState, activePeriodIndex, rateIndex }),
    		[activePeriodIndex, rateIndex],
    	);
    
    	const handleChange = () => {
    		resetField(
    			`INTEREST_RATES.${rateIndex}.periods.${activePeriodIndex}.baseIndicator.termIndex`,
    		);
    	};
    
    	return (
    		<Flex direction="column" gap={4} w="50%">
    			<Text fontWeight="semibold" typography="16_24">
    				Базовый индикатор (БИ)
    			</Text>
    
    			<Box w="full">
    				<Select<InterestRatesFormState, Labeled<BaseIndicatorTypeLabel>>
    					title="Наименование индикатора"
    					placeholder="Наименование индикатора"
    					fieldName={`INTEREST_RATES.${rateIndex}.periods.${activePeriodIndex}.baseIndicator.kind`}
    					items={baseIndicatorKindItems}
    					labelExtractor={(item) => item.name}
    					onChange={handleChange}
    					defaultValue={defaultValue}
    					showClearIcon={false}
    					disabled={disabled}
    				/>
    			</Box>
    
    			{kind && kind?.id !== 'CBR_KEY_RATE' && (
    				<Box w="full">
    					<Select<InterestRatesFormState, Labeled<TermIndexesType>>
    						title="Индекс срока"
    						placeholder="Индекс срока"
    						fieldName={`INTEREST_RATES.${rateIndex}.periods.${activePeriodIndex}.baseIndicator.termIndex`}
    						items={termIndexTypeItems}
    						labelExtractor={(item) => item.name}
    						showClearIcon={false}
    					/>
    				</Box>
    			)}
    		</Flex>
    	);
    },
    

    );

    export const BaseIndicatorParams = withRateParameters(EnhancedBaseIndicatorParams);

  2. Assistant

    The code provided is a React component that renders a form with select inputs for base indicator kind and term index type. The component receives props such as baseIndicatorKindItems, termIndexTypeItems, defaultValue, activePeriodIndex, rateIndex, and disabled. It uses the useFormContext and useFormValueSelector hooks from react-hook-form to access form values and reset fields when the base indicator kind is changed.

    The component renders a Select component for base indicator kind and term index type based on the values in the props. It also conditionally renders the term index select input if the base indicator kind is not CBR_KEY_RATE.

    The BaseIndicatorParams component is a higher-order component that enhances the EnhancedBaseIndicatorParams component with rate parameters.

    Overall, this code snippet is a well-structured and organized React component for handling base indicator parameters in a form.

import { memo } from 'react'; import { useFormContext }… · The Chat Archive