From 22ece3c96ea489d5adb754d99dd69060716f7f02 Mon Sep 17 00:00:00 2001 From: Jonathan Weyermann Date: Mon, 4 Nov 2024 15:46:00 -0700 Subject: [PATCH] fix(postal code) - allow submission, disable submitted postal codes --- .../Controls/AddressLookup/AddressInputs.tsx | 17 +++++++++++++---- .../AddressLookup/AddressLookUpControl.tsx | 12 ++++++++---- .../src/lib/Controls/AddressLookup/types.ts | 4 ++-- .../src/lib/Controls/AddressLookup/utils.ts | 4 ++-- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/libs/jsonforms-components/src/lib/Controls/AddressLookup/AddressInputs.tsx b/libs/jsonforms-components/src/lib/Controls/AddressLookup/AddressInputs.tsx index d15d402ad..47b1e6a04 100644 --- a/libs/jsonforms-components/src/lib/Controls/AddressLookup/AddressInputs.tsx +++ b/libs/jsonforms-components/src/lib/Controls/AddressLookup/AddressInputs.tsx @@ -7,6 +7,7 @@ interface AddressInputsProps { address: Address; handleInputChange: (field: string, value: string) => void; isAlbertaAddress?: boolean; + readOnly?: boolean; // eslint-disable-next-line errors?: any; handleOnBlur: (field: string) => void; @@ -16,6 +17,7 @@ export const AddressInputs: React.FC = ({ address, handleInputChange, isAlbertaAddress, + readOnly, errors, handleOnBlur, }: AddressInputsProps): JSX.Element => { @@ -41,6 +43,8 @@ export const AddressInputs: React.FC = ({ = ({ handleInputChange(name, value)} onBlur={(name, value) => handleOnBlur('municipality')} width="100%" @@ -66,6 +72,8 @@ export const AddressInputs: React.FC = ({ name="postalCode" testId="address-form-postal-code" ariaLabel={'address-form-postal-code'} + disabled={readOnly} + readonly={readOnly} placeholder="A0A 0A0" value={address?.postalCode || ''} onChange={(name, value) => handleInputChange(name, value)} @@ -81,10 +89,11 @@ export const AddressInputs: React.FC = ({ {isAlbertaAddress && Alberta} {!isAlbertaAddress && ( handleInputChange('province', value)} relative={true} width="25ch" diff --git a/libs/jsonforms-components/src/lib/Controls/AddressLookup/AddressLookUpControl.tsx b/libs/jsonforms-components/src/lib/Controls/AddressLookup/AddressLookUpControl.tsx index 8c4a6ae3f..93b0150bc 100644 --- a/libs/jsonforms-components/src/lib/Controls/AddressLookup/AddressLookUpControl.tsx +++ b/libs/jsonforms-components/src/lib/Controls/AddressLookup/AddressLookUpControl.tsx @@ -22,7 +22,7 @@ type AddressLookUpProps = ControlProps; const ADDRESS_PATH = 'api/gateway/v1/address/v1/find'; export const AddressLookUpControl = (props: AddressLookUpProps): JSX.Element => { - const { data, path, schema, handleChange, uischema } = props; + const { data, path, schema, enabled, handleChange, uischema, rootSchema } = props; const isAlbertaAddress = schema?.properties?.subdivisionCode?.const === 'AB'; const formCtx = useContext(JsonFormContext); @@ -35,8 +35,8 @@ export const AddressLookUpControl = (props: AddressLookUpProps): JSX.Element => const defaultAddress = { addressLine1: '', addressLine2: '', - city: '', - province: isAlbertaAddress ? 'AB' : '', + municipality: '', + subdivisionCode: isAlbertaAddress ? 'AB' : '', postalCode: '', country: 'CA', }; @@ -121,15 +121,18 @@ export const AddressLookUpControl = (props: AddressLookUpProps): JSX.Element => delete errors[name]; } }; + const readOnly = uischema?.options?.componentProps?.readOnly ?? false; return (
{renderHelp()} { return { addressLine1, addressLine2, - city, - province, + municipality: city, + subdivisionCode: province, postalCode, country: 'CA', };