Skip to content

Commit

Permalink
Add email composite field (#9061)
Browse files Browse the repository at this point in the history
Same as links, only adding primary email
  • Loading branch information
thomtrp authored Dec 13, 2024
1 parent 32e7eb7 commit 5961d26
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FormAddressFieldInput } from '@/object-record/record-field/form-types/components/FormAddressFieldInput';
import { FormBooleanFieldInput } from '@/object-record/record-field/form-types/components/FormBooleanFieldInput';
import { FormEmailsFieldInput } from '@/object-record/record-field/form-types/components/FormEmailsFieldInput';
import { FormFullNameFieldInput } from '@/object-record/record-field/form-types/components/FormFullNameFieldInput';
import { FormLinksFieldInput } from '@/object-record/record-field/form-types/components/FormLinksFieldInput';
import { FormNumberFieldInput } from '@/object-record/record-field/form-types/components/FormNumberFieldInput';
Expand All @@ -9,12 +10,14 @@ import { VariablePickerComponent } from '@/object-record/record-field/form-types
import { FieldDefinition } from '@/object-record/record-field/types/FieldDefinition';
import {
FieldAddressValue,
FieldEmailsValue,
FieldFullNameValue,
FieldLinksValue,
FieldMetadata,
} from '@/object-record/record-field/types/FieldMetadata';
import { isFieldAddress } from '@/object-record/record-field/types/guards/isFieldAddress';
import { isFieldBoolean } from '@/object-record/record-field/types/guards/isFieldBoolean';
import { isFieldEmails } from '@/object-record/record-field/types/guards/isFieldEmails';
import { isFieldFullName } from '@/object-record/record-field/types/guards/isFieldFullName';
import { isFieldLinks } from '@/object-record/record-field/types/guards/isFieldLinks';
import { isFieldNumber } from '@/object-record/record-field/types/guards/isFieldNumber';
Expand Down Expand Up @@ -88,5 +91,12 @@ export const FormFieldInput = ({
onPersist={onPersist}
VariablePicker={VariablePicker}
/>
) : isFieldEmails(field) ? (
<FormEmailsFieldInput
label={field.label}
defaultValue={defaultValue as FieldEmailsValue | undefined}
onPersist={onPersist}
VariablePicker={VariablePicker}
/>
) : null;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { FormFieldInputContainer } from '@/object-record/record-field/form-types/components/FormFieldInputContainer';
import { FormNestedFieldInputContainer } from '@/object-record/record-field/form-types/components/FormNestedFieldInputContainer';
import { FormTextFieldInput } from '@/object-record/record-field/form-types/components/FormTextFieldInput';
import { VariablePickerComponent } from '@/object-record/record-field/form-types/types/VariablePickerComponent';
import { FieldEmailsValue } from '@/object-record/record-field/types/FieldMetadata';
import { InputLabel } from '@/ui/input/components/InputLabel';

type FormEmailsFieldInputProps = {
label?: string;
defaultValue?: FieldEmailsValue;
onPersist: (value: FieldEmailsValue) => void;
VariablePicker?: VariablePickerComponent;
readonly?: boolean;
};

export const FormEmailsFieldInput = ({
label,
defaultValue,
onPersist,
readonly,
VariablePicker,
}: FormEmailsFieldInputProps) => {
const handleChange = (email: string) => {
onPersist({
primaryEmail: email,
additionalEmails: [],
});
};

return (
<FormFieldInputContainer>
{label ? <InputLabel>{label}</InputLabel> : null}
<FormNestedFieldInputContainer>
<FormTextFieldInput
label="Primary Email"
defaultValue={defaultValue?.primaryEmail}
onPersist={handleChange}
placeholder={'Primary Email'}
readonly={readonly}
VariablePicker={VariablePicker}
/>
</FormNestedFieldInputContainer>
</FormFieldInputContainer>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Meta, StoryObj } from '@storybook/react';
import { within } from '@storybook/test';
import { FormEmailsFieldInput } from '../FormEmailsFieldInput';

const meta: Meta<typeof FormEmailsFieldInput> = {
title: 'UI/Data/Field/Form/Input/FormEmailsFieldInput',
component: FormEmailsFieldInput,
args: {},
argTypes: {},
};

export default meta;

type Story = StoryObj<typeof FormEmailsFieldInput>;

export const Default: Story = {
args: {
label: 'Emails',
defaultValue: {
primaryEmail: '[email protected]',
additionalEmails: [],
},
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);

await canvas.findByText('Emails');
await canvas.findByText('Primary Email');
await canvas.findByText('[email protected]');
},
};

0 comments on commit 5961d26

Please sign in to comment.