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({
|
onPersist({
|
||||||
primaryPhoneCountryCode: newCountry,
|
primaryPhoneCountryCode: newCountry,
|
||||||
primaryPhoneCallingCode: newCallingCode,
|
primaryPhoneCallingCode: newCallingCode,
|
||||||
primaryPhoneNumber: defaultValue?.primaryPhoneNumber || '',
|
primaryPhoneNumber: defaultValue?.primaryPhoneNumber ?? '',
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleNumberChange = (number: string | number | null) => {
|
const handleNumberChange = (number: string | number | null) => {
|
||||||
onPersist({
|
onPersist({
|
||||||
primaryPhoneCountryCode: defaultValue?.primaryPhoneCountryCode || '',
|
primaryPhoneCountryCode: defaultValue?.primaryPhoneCountryCode ?? '',
|
||||||
primaryPhoneCallingCode: defaultValue?.primaryPhoneCallingCode || '',
|
primaryPhoneCallingCode: defaultValue?.primaryPhoneCallingCode ?? '',
|
||||||
primaryPhoneNumber: number ? `${number}` : '',
|
primaryPhoneNumber: number ? `${number}` : '',
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -58,7 +58,6 @@ export const FormPhoneFieldInput = ({
|
|||||||
selectedCountryCode={defaultValue?.primaryPhoneCountryCode || ''}
|
selectedCountryCode={defaultValue?.primaryPhoneCountryCode || ''}
|
||||||
onPersist={handleCountryChange}
|
onPersist={handleCountryChange}
|
||||||
readonly={readonly}
|
readonly={readonly}
|
||||||
VariablePicker={VariablePicker}
|
|
||||||
/>
|
/>
|
||||||
<FormNumberFieldInput
|
<FormNumberFieldInput
|
||||||
label="Phone Number"
|
label="Phone Number"
|
||||||
|
|||||||
@ -104,9 +104,9 @@ export const SelectEmptyCountryCode: Story = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const WithVariables: Story = {
|
export const WithVariablesAsDefaultValues: Story = {
|
||||||
args: {
|
args: {
|
||||||
label: 'Enter phone...',
|
label: 'Phone',
|
||||||
defaultValue: {
|
defaultValue: {
|
||||||
primaryPhoneCountryCode: '{{a.countryCode}}',
|
primaryPhoneCountryCode: '{{a.countryCode}}',
|
||||||
primaryPhoneNumber: '{{a.phoneNumber}}',
|
primaryPhoneNumber: '{{a.phoneNumber}}',
|
||||||
@ -124,7 +124,7 @@ export const WithVariables: Story = {
|
|||||||
|
|
||||||
const variablePickers = await canvas.findAllByText('VariablePicker');
|
const variablePickers = await canvas.findAllByText('VariablePicker');
|
||||||
|
|
||||||
expect(variablePickers).toHaveLength(2);
|
expect(variablePickers).toHaveLength(1);
|
||||||
|
|
||||||
for (const variablePicker of variablePickers) {
|
for (const variablePicker of variablePickers) {
|
||||||
expect(variablePicker).toBeVisible();
|
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 = {
|
export const Disabled: Story = {
|
||||||
args: {
|
args: {
|
||||||
label: 'Enter phone...',
|
label: 'Phone',
|
||||||
readonly: true,
|
readonly: true,
|
||||||
VariablePicker: () => <div>VariablePicker</div>,
|
VariablePicker: () => <div>VariablePicker</div>,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user