Disable variables for the country code in the form phone field (#9897)
Fixes https://discord.com/channels/1130383047699738754/1333820080651501691 We disable the variable picker for the country code for now. We'll implement a proper solution later.
This commit is contained in:
committed by
GitHub
parent
7536a5a9a0
commit
5a34f6bfa7
@ -38,14 +38,14 @@ export const FormPhoneFieldInput = ({
|
||||
onPersist({
|
||||
primaryPhoneCountryCode: newCountry,
|
||||
primaryPhoneCallingCode: newCallingCode,
|
||||
primaryPhoneNumber: defaultValue?.primaryPhoneNumber || '',
|
||||
primaryPhoneNumber: defaultValue?.primaryPhoneNumber ?? '',
|
||||
});
|
||||
};
|
||||
|
||||
const handleNumberChange = (number: string | number | null) => {
|
||||
onPersist({
|
||||
primaryPhoneCountryCode: defaultValue?.primaryPhoneCountryCode || '',
|
||||
primaryPhoneCallingCode: defaultValue?.primaryPhoneCallingCode || '',
|
||||
primaryPhoneCountryCode: defaultValue?.primaryPhoneCountryCode ?? '',
|
||||
primaryPhoneCallingCode: defaultValue?.primaryPhoneCallingCode ?? '',
|
||||
primaryPhoneNumber: number ? `${number}` : '',
|
||||
});
|
||||
};
|
||||
@ -58,7 +58,6 @@ export const FormPhoneFieldInput = ({
|
||||
selectedCountryCode={defaultValue?.primaryPhoneCountryCode || ''}
|
||||
onPersist={handleCountryChange}
|
||||
readonly={readonly}
|
||||
VariablePicker={VariablePicker}
|
||||
/>
|
||||
<FormNumberFieldInput
|
||||
label="Phone Number"
|
||||
|
||||
@ -104,9 +104,9 @@ export const SelectEmptyCountryCode: Story = {
|
||||
},
|
||||
};
|
||||
|
||||
export const WithVariables: Story = {
|
||||
export const WithVariablesAsDefaultValues: Story = {
|
||||
args: {
|
||||
label: 'Enter phone...',
|
||||
label: 'Phone',
|
||||
defaultValue: {
|
||||
primaryPhoneCountryCode: '{{a.countryCode}}',
|
||||
primaryPhoneNumber: '{{a.phoneNumber}}',
|
||||
@ -124,7 +124,7 @@ export const WithVariables: Story = {
|
||||
|
||||
const variablePickers = await canvas.findAllByText('VariablePicker');
|
||||
|
||||
expect(variablePickers).toHaveLength(2);
|
||||
expect(variablePickers).toHaveLength(1);
|
||||
|
||||
for (const variablePicker of variablePickers) {
|
||||
expect(variablePicker).toBeVisible();
|
||||
@ -132,9 +132,52 @@ export const WithVariables: Story = {
|
||||
},
|
||||
};
|
||||
|
||||
export const SelectingVariables: Story = {
|
||||
args: {
|
||||
label: 'Phone',
|
||||
VariablePicker: ({ onVariableSelect }) => {
|
||||
return (
|
||||
<button
|
||||
onClick={() => {
|
||||
onVariableSelect('{{test}}');
|
||||
}}
|
||||
>
|
||||
Add variable
|
||||
</button>
|
||||
);
|
||||
},
|
||||
onPersist: fn(),
|
||||
},
|
||||
play: async ({ canvasElement, args }) => {
|
||||
const canvas = within(canvasElement);
|
||||
|
||||
const countryCodeDefaultValue = await canvas.findByText('No country');
|
||||
expect(countryCodeDefaultValue).toBeVisible();
|
||||
|
||||
const phoneNumberDefaultValue =
|
||||
await canvas.findByPlaceholderText('Enter phone number');
|
||||
expect(phoneNumberDefaultValue).toHaveDisplayValue('');
|
||||
|
||||
const phoneNumberVariablePicker = await canvas.findByText('Add variable');
|
||||
|
||||
await userEvent.click(phoneNumberVariablePicker);
|
||||
|
||||
const phoneNumberVariable = await canvas.findByText('test');
|
||||
expect(phoneNumberVariable).toBeVisible();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(args.onPersist).toHaveBeenCalledWith({
|
||||
primaryPhoneNumber: '{{test}}',
|
||||
primaryPhoneCountryCode: '',
|
||||
primaryPhoneCallingCode: '',
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export const Disabled: Story = {
|
||||
args: {
|
||||
label: 'Enter phone...',
|
||||
label: 'Phone',
|
||||
readonly: true,
|
||||
VariablePicker: () => <div>VariablePicker</div>,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user