1 import { type FC, useCallback } from 'react';
2 import { useSelector } from 'react-redux';
4 import { getExtraFieldOption } from '@proton/pass/components/Form/Field/ExtraFieldGroup/ExtraField';
5 import { FieldsetCluster } from '@proton/pass/components/Form/Field/Layout/FieldsetCluster';
6 import { TextAreaReadonly } from '@proton/pass/components/Form/legacy/TextAreaReadonly';
7 import { UpsellRef } from '@proton/pass/constants';
8 import { selectExtraFieldLimits } from '@proton/pass/store/selectors';
9 import type { UnsafeItemExtraField } from '@proton/pass/types';
10 import { isEmptyString } from '@proton/pass/utils/string/is-empty-string';
12 import { OTPValueControl } from './OTPValueControl';
13 import { UpgradeControl } from './UpgradeControl';
14 import { ValueControl } from './ValueControl';
16 type ExtraFieldsControlProps = {
17 extraFields: UnsafeItemExtraField[];
22 export const ExtraFieldsControl: FC<ExtraFieldsControlProps> = ({ extraFields, itemId, shareId }) => {
23 const { needsUpgrade } = useSelector(selectExtraFieldLimits);
25 const getControlByType = useCallback(
26 ({ fieldName, type, data }: UnsafeItemExtraField, index: number) => {
27 const { icon } = getExtraFieldOption(type);
28 const key = `${index}-${fieldName}`;
32 <UpgradeControl icon={icon} key={key} label={fieldName} upsellRef={UpsellRef.LIMIT_EXTRA_FIELD} />
38 return isEmptyString(data.totpUri) ? (
39 <ValueControl icon={icon} key={key} label={fieldName} value={undefined} />
41 <OTPValueControl key={key} label={fieldName} payload={{ totpUri: data.totpUri, type: 'uri' }} />
50 hidden={type === 'hidden'}
62 <FieldsetCluster mode="read" as="div">
63 {extraFields.map((extraField, index) => getControlByType(extraField, index))}