@abgov/jsonforms-components 1.34.3 → 1.34.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.esm.js
CHANGED
|
@@ -6726,14 +6726,14 @@ const SearchBox = styled.div(_t$1 || (_t$1 = _$1`
|
|
|
6726
6726
|
const LabelDiv = styled.div(_t2 || (_t2 = _$1`
|
|
6727
6727
|
font-size: var(--fs-sl);
|
|
6728
6728
|
font-weight: var(--fw-bold);
|
|
6729
|
-
padding-left: 0.4rem;
|
|
6730
6729
|
padding-bottom: 0.5rem;
|
|
6731
6730
|
`));
|
|
6732
6731
|
|
|
6733
6732
|
const AddressInputs = ({
|
|
6734
6733
|
address,
|
|
6735
6734
|
handleInputChange,
|
|
6736
|
-
isAlbertaAddress
|
|
6735
|
+
isAlbertaAddress,
|
|
6736
|
+
postalCodeErrorMsg
|
|
6737
6737
|
}) => {
|
|
6738
6738
|
const provinces = [{
|
|
6739
6739
|
value: 'AB',
|
|
@@ -6802,6 +6802,7 @@ const AddressInputs = ({
|
|
|
6802
6802
|
})
|
|
6803
6803
|
}), jsx(GoAFormItem, {
|
|
6804
6804
|
label: "Postal Code",
|
|
6805
|
+
error: postalCodeErrorMsg,
|
|
6805
6806
|
children: jsx(GoAInput, {
|
|
6806
6807
|
name: "postalCode",
|
|
6807
6808
|
testId: "address-form-postal-code",
|
|
@@ -6809,7 +6810,8 @@ const AddressInputs = ({
|
|
|
6809
6810
|
placeholder: "A0A 0A0",
|
|
6810
6811
|
value: (address === null || address === void 0 ? void 0 : address.postalCode) || '',
|
|
6811
6812
|
onChange: (name, value) => handleInputChange(name, value),
|
|
6812
|
-
width: "100%"
|
|
6813
|
+
width: "100%",
|
|
6814
|
+
maxLength: 7
|
|
6813
6815
|
})
|
|
6814
6816
|
})]
|
|
6815
6817
|
}), jsx("br", {}), jsxs(GoAGrid, {
|
|
@@ -6998,13 +7000,17 @@ const mapSuggestionToAddress = suggestion => {
|
|
|
6998
7000
|
city,
|
|
6999
7001
|
province,
|
|
7000
7002
|
postalCode,
|
|
7001
|
-
country: '
|
|
7003
|
+
country: 'CA'
|
|
7002
7004
|
};
|
|
7003
7005
|
};
|
|
7006
|
+
const validatePostalCode = values => {
|
|
7007
|
+
const postalCodeRegex = /^[A-Za-z]\d[A-Za-z] \d[A-Za-z]\d$/;
|
|
7008
|
+
return postalCodeRegex.test(values);
|
|
7009
|
+
};
|
|
7004
7010
|
|
|
7005
7011
|
const ADDRESS_PATH = 'api/gateway/v1/address/v1/find';
|
|
7006
7012
|
const AddressLookUpControl = props => {
|
|
7007
|
-
var _a, _b, _c
|
|
7013
|
+
var _a, _b, _c;
|
|
7008
7014
|
const {
|
|
7009
7015
|
data,
|
|
7010
7016
|
path,
|
|
@@ -7016,7 +7022,7 @@ const AddressLookUpControl = props => {
|
|
|
7016
7022
|
const formCtx = useContext(JsonFormContext);
|
|
7017
7023
|
const formHost = formCtx === null || formCtx === void 0 ? void 0 : formCtx.formUrl;
|
|
7018
7024
|
const formUrl = `${formHost}/${ADDRESS_PATH}`;
|
|
7019
|
-
const autocompletion = ((_c = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _c === void 0 ? void 0 : _c.autocomplete)
|
|
7025
|
+
const autocompletion = ((_c = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _c === void 0 ? void 0 : _c.autocomplete) !== false;
|
|
7020
7026
|
const [open, setOpen] = useState(false);
|
|
7021
7027
|
const label = typeof (uischema === null || uischema === void 0 ? void 0 : uischema.label) === 'string' && uischema.label ? uischema.label : schema === null || schema === void 0 ? void 0 : schema.title;
|
|
7022
7028
|
const defaultAddress = {
|
|
@@ -7025,17 +7031,28 @@ const AddressLookUpControl = props => {
|
|
|
7025
7031
|
city: '',
|
|
7026
7032
|
province: isAlbertaAddress ? 'AB' : '',
|
|
7027
7033
|
postalCode: '',
|
|
7028
|
-
country: '
|
|
7034
|
+
country: 'CA'
|
|
7029
7035
|
};
|
|
7030
7036
|
const [address, setAddress] = useState(data || defaultAddress);
|
|
7031
7037
|
const [searchTerm, setSearchTerm] = useState('');
|
|
7032
7038
|
const [suggestions, setSuggestions] = useState([]);
|
|
7033
7039
|
const [loading, setLoading] = useState(false);
|
|
7040
|
+
const [postalCodeErrorMsg, setPostalCodeErrorMsg] = useState('');
|
|
7034
7041
|
const updateFormData = updatedAddress => {
|
|
7035
7042
|
setAddress(updatedAddress);
|
|
7036
7043
|
handleChange(path, updatedAddress);
|
|
7037
7044
|
};
|
|
7038
7045
|
const handleInputChange = (field, value) => {
|
|
7046
|
+
var _a, _b;
|
|
7047
|
+
if (field === 'postalCode') {
|
|
7048
|
+
const validatePc = validatePostalCode(value);
|
|
7049
|
+
if (!validatePc && value.length >= 5) {
|
|
7050
|
+
const postalCodeErrorMessage = (_b = (_a = schema.errorMessage) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.postalCode;
|
|
7051
|
+
setPostalCodeErrorMsg(postalCodeErrorMessage !== null && postalCodeErrorMessage !== void 0 ? postalCodeErrorMessage : '');
|
|
7052
|
+
} else {
|
|
7053
|
+
setPostalCodeErrorMsg('');
|
|
7054
|
+
}
|
|
7055
|
+
}
|
|
7039
7056
|
const newAddress = Object.assign(Object.assign({}, address), {
|
|
7040
7057
|
[field]: value
|
|
7041
7058
|
});
|
|
@@ -7064,6 +7081,7 @@ const AddressLookUpControl = props => {
|
|
|
7064
7081
|
}, [searchTerm, formUrl, isAlbertaAddress]);
|
|
7065
7082
|
const handleDropdownChange = value => __awaiter(void 0, void 0, void 0, function* () {
|
|
7066
7083
|
setSearchTerm(value);
|
|
7084
|
+
handleInputChange('addressLine1', value);
|
|
7067
7085
|
});
|
|
7068
7086
|
const handleSuggestionClick = suggestion => {
|
|
7069
7087
|
const suggestAddress = mapSuggestionToAddress(suggestion);
|
|
@@ -7076,18 +7094,18 @@ const AddressLookUpControl = props => {
|
|
|
7076
7094
|
label: label,
|
|
7077
7095
|
children: jsxs(SearchBox, {
|
|
7078
7096
|
children: [jsx(GoAInput, {
|
|
7079
|
-
leadingIcon:
|
|
7080
|
-
name: "
|
|
7097
|
+
leadingIcon: autocompletion ? 'search' : undefined,
|
|
7098
|
+
name: "addressLine1",
|
|
7081
7099
|
testId: "address-form-address1",
|
|
7082
7100
|
ariaLabel: 'address-form-address1',
|
|
7083
7101
|
placeholder: "Start typing the first line of your address",
|
|
7084
7102
|
value: (address === null || address === void 0 ? void 0 : address.addressLine1) || '',
|
|
7085
7103
|
onChange: (name, value) => handleDropdownChange(value),
|
|
7086
7104
|
width: "100%"
|
|
7087
|
-
}), loading && jsx(GoASkeleton, {
|
|
7105
|
+
}), loading && autocompletion && jsx(GoASkeleton, {
|
|
7088
7106
|
type: "text",
|
|
7089
7107
|
"data-testId": "loading"
|
|
7090
|
-
}, 1), suggestions && jsx("ul", {
|
|
7108
|
+
}, 1), suggestions && autocompletion && jsx("ul", {
|
|
7091
7109
|
className: "suggestions",
|
|
7092
7110
|
tabIndex: 0,
|
|
7093
7111
|
children: suggestions && autocompletion && open && suggestions.map((suggestion, index) => jsx("li", {
|
|
@@ -7099,7 +7117,8 @@ const AddressLookUpControl = props => {
|
|
|
7099
7117
|
}), jsx("br", {}), jsx(AddressInputs, {
|
|
7100
7118
|
address: address,
|
|
7101
7119
|
handleInputChange: handleInputChange,
|
|
7102
|
-
isAlbertaAddress: isAlbertaAddress
|
|
7120
|
+
isAlbertaAddress: isAlbertaAddress,
|
|
7121
|
+
postalCodeErrorMsg: postalCodeErrorMsg
|
|
7103
7122
|
})]
|
|
7104
7123
|
});
|
|
7105
7124
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abgov/jsonforms-components",
|
|
3
|
-
"version": "1.34.
|
|
3
|
+
"version": "1.34.4",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Government of Alberta - React renderers for JSON Forms based on the design system.",
|
|
6
6
|
"repository": "https://github.com/GovAlta/adsp-monorepo",
|
|
@@ -3,3 +3,4 @@ export declare const fetchAddressSuggestions: (formUrl: string, searchTerm: stri
|
|
|
3
3
|
export declare const filterAlbertaAddresses: (suggestions: Suggestion[]) => Suggestion[];
|
|
4
4
|
export declare const filterSuggestionsWithoutAddressCount: (suggestions: Suggestion[]) => Suggestion[];
|
|
5
5
|
export declare const mapSuggestionToAddress: (suggestion: Suggestion) => Address;
|
|
6
|
+
export declare const validatePostalCode: (values: string) => boolean;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { CellProps, WithClassname, ControlProps, RankedTester } from '@jsonforms/core';
|
|
3
3
|
import { WithInputProps } from './type';
|
|
4
4
|
export type GoAInputTextProps = CellProps & WithClassname & WithInputProps;
|
|
5
|
+
export declare const formatSin: (value: string) => string;
|
|
5
6
|
export declare const GoAInputText: (props: GoAInputTextProps) => JSX.Element;
|
|
6
7
|
export declare const GoATextControl: (props: ControlProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
8
|
export declare const GoATextControlTester: RankedTester;
|