1 import type { Ref } from 'react';
2 import { forwardRef } from 'react';
4 import type { VCardContact, VCardProperty } from '@proton/shared/lib/interfaces/contacts/VCard';
6 import type { ContactImageProps } from '../../modals/ContactImageModal';
7 import ContactFieldAdr from './ContactFieldAdr';
8 import ContactFieldDate from './ContactFieldDate';
9 import ContactFieldEmail from './ContactFieldEmail';
10 import ContactFieldFn from './ContactFieldFn';
11 import ContactFieldGender from './ContactFieldGender';
12 import ContactFieldImage from './ContactFieldImage';
13 import ContactFieldN from './ContactFieldN';
14 import ContactFieldNote from './ContactFieldNote';
15 import ContactFieldOrg from './ContactFieldOrg';
16 import ContactFieldString from './ContactFieldString';
17 import ContactFieldTel from './ContactFieldTel';
20 vCardContact: VCardContact;
21 vCardProperty: VCardProperty<any>;
22 onChangeVCard: (vCardProperty: VCardProperty) => void;
23 onSelectImage: (props: ContactImageProps) => void;
24 isSubmitted?: boolean;
27 const ContactFieldProperty = (
28 { vCardContact, vCardProperty, onChangeVCard, onSelectImage, isSubmitted = false, ...rest }: Props,
29 ref: Ref<HTMLInputElement>
31 const { field } = vCardProperty;
33 if (field === 'email') {
34 return <ContactFieldEmail vCardProperty={vCardProperty} onChange={onChangeVCard} {...rest} />;
37 if (field === 'tel') {
38 return <ContactFieldTel vCardProperty={vCardProperty} onChange={onChangeVCard} {...rest} />;
41 if (field === 'adr') {
42 return <ContactFieldAdr vCardProperty={vCardProperty} onChange={onChangeVCard} {...rest} />;
45 if (field === 'note') {
46 return <ContactFieldNote vCardProperty={vCardProperty} onChange={onChangeVCard} {...rest} />;
49 if (field === 'bday' || field === 'anniversary') {
50 return <ContactFieldDate vCardProperty={vCardProperty} onChange={onChangeVCard} {...rest} />;
53 if (field === 'photo' || field === 'logo') {
56 vCardProperty={vCardProperty}
57 onChange={onChangeVCard}
58 onSelectImage={onSelectImage}
68 vCardProperty={vCardProperty}
69 vCardContact={vCardContact}
70 onChange={onChangeVCard}
71 isSubmitted={isSubmitted}
77 if (field === 'gender') {
78 return <ContactFieldGender vCardProperty={vCardProperty} onChange={onChangeVCard} {...rest} />;
85 vCardContact={vCardContact}
86 isSubmitted={isSubmitted}
87 vCardProperty={vCardProperty}
88 onChangeVCard={onChangeVCard}
94 if (field === 'org') {
95 return <ContactFieldOrg vCardProperty={vCardProperty} onChange={onChangeVCard} {...rest} />;
98 return <ContactFieldString vCardProperty={vCardProperty} onChange={onChangeVCard} {...rest} />;
101 export default forwardRef(ContactFieldProperty);