1 import type { ChangeEvent } from 'react';
2 import { useState } from 'react';
4 import { c } from 'ttag';
6 import { Input } from '@proton/atoms';
7 import type { VCardAddress, VCardProperty } from '@proton/shared/lib/interfaces/contacts/VCard';
8 import generateUID from '@proton/utils/generateUID';
11 vCardProperty: VCardProperty<VCardAddress>;
12 onChange: (vCardProperty: VCardProperty) => void;
14 const ContactFieldAdr = ({ vCardProperty, onChange }: Props) => {
15 const [uid] = useState(generateUID('contact-adr'));
18 (part: keyof VCardAddress) =>
19 ({ target }: ChangeEvent<HTMLInputElement>) => {
20 onChange({ ...vCardProperty, value: { ...vCardProperty.value, [part]: target.value } });
23 const address = vCardProperty.value || {};
27 <div className="mb-2">
30 value={address.streetAddress || ''}
31 placeholder={c('Label').t`Street address`}
32 onChange={handleChange('streetAddress')}
36 {address.extendedAddress ? (
37 <div className="mb-2">
39 id={`${uid}-extended`}
40 value={address.extendedAddress || ''}
41 placeholder={c('Label').t`Extended address`}
42 onChange={handleChange('extendedAddress')}
43 data-testid="extended"
47 <div className="mb-2 flex gap-2">
49 id={`${uid}-postalCode`}
50 value={address.postalCode || ''}
51 placeholder={c('Label').t`Postal code`}
52 onChange={handleChange('postalCode')}
53 data-testid="postalCode"
56 id={`${uid}-locality`}
57 value={address.locality || ''}
58 placeholder={c('Label').t`City`}
59 onChange={handleChange('locality')}
64 {address.postOfficeBox ? (
65 <div className="mb-2">
68 value={address.postOfficeBox || ''}
69 placeholder={c('Label').t`Post office box`}
70 onChange={handleChange('postOfficeBox')}
75 <div className="mb-2 flex gap-2">
78 value={address.region || ''}
79 placeholder={c('Label').t`Region`}
80 onChange={handleChange('region')}
85 value={address.country || ''}
86 placeholder={c('Label').t`Country`}
87 onChange={handleChange('country')}
95 export default ContactFieldAdr;