1 import { isValid } from 'date-fns';
3 import DateInput from '@proton/components/components/input/DateInput';
4 import { getDateFromVCardProperty } from '@proton/shared/lib/contacts/property';
5 import { getAllFieldLabels } from '@proton/shared/lib/helpers/contacts';
6 import type { VCardDateOrText, VCardProperty } from '@proton/shared/lib/interfaces/contacts/VCard';
9 vCardProperty: VCardProperty<VCardDateOrText>;
10 onChange: (vCardProperty: VCardProperty) => void;
13 const ContactFieldDate = ({ vCardProperty, onChange, ...rest }: Props) => {
14 const label = (getAllFieldLabels() as any)[vCardProperty.field] || '';
16 const date = getDateFromVCardProperty(vCardProperty);
18 const handleChange = (date?: Date) => {
19 if (!date || !isValid(date)) {
23 onChange({ ...vCardProperty, value: { ...vCardProperty.value, date } });
26 return <DateInput placeholder={label} value={date} onChange={handleChange} data-testid={label} {...rest} />;
29 export default ContactFieldDate;