@abgov/jsonforms-components 1.35.1 → 1.35.2
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
|
@@ -4,7 +4,7 @@ import { GoAFormItem, GoAInput, GoATextArea, GoACallout, GoAInputDate, GoAInputD
|
|
|
4
4
|
import styled from 'styled-components';
|
|
5
5
|
import axios from 'axios';
|
|
6
6
|
import get$1 from 'lodash/get';
|
|
7
|
-
import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, getAjv, isVisible, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl,
|
|
7
|
+
import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, getAjv, isVisible, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, isObjectControl, hasType, isControl, isCategorization, isLayout } from '@jsonforms/core';
|
|
8
8
|
import { withJsonFormsControlProps, withJsonFormsRendererProps, withJsonFormsEnumProps, withTranslateProps, useJsonForms, JsonFormsDispatch, withJsonFormsLayoutProps, withJsonFormsArrayLayoutProps, withJsonFormsCellProps } from '@jsonforms/react';
|
|
9
9
|
import { isEqual } from 'lodash';
|
|
10
10
|
import merge from 'lodash/merge';
|
|
@@ -6733,8 +6733,10 @@ const AddressInputs = ({
|
|
|
6733
6733
|
address,
|
|
6734
6734
|
handleInputChange,
|
|
6735
6735
|
isAlbertaAddress,
|
|
6736
|
-
|
|
6736
|
+
errors,
|
|
6737
|
+
handleOnBlur
|
|
6737
6738
|
}) => {
|
|
6739
|
+
var _a, _b;
|
|
6738
6740
|
const provinces = [{
|
|
6739
6741
|
value: 'AB',
|
|
6740
6742
|
label: 'Alberta'
|
|
@@ -6792,17 +6794,19 @@ const AddressInputs = ({
|
|
|
6792
6794
|
gap: "s",
|
|
6793
6795
|
children: [jsx(GoAFormItem, {
|
|
6794
6796
|
label: "City",
|
|
6797
|
+
error: (_a = errors === null || errors === void 0 ? void 0 : errors['municipality']) !== null && _a !== void 0 ? _a : '',
|
|
6795
6798
|
children: jsx(GoAInput, {
|
|
6796
6799
|
name: "city",
|
|
6797
6800
|
testId: "address-form-city",
|
|
6798
6801
|
ariaLabel: 'address-form-city',
|
|
6799
6802
|
value: (address === null || address === void 0 ? void 0 : address.city) || '',
|
|
6800
6803
|
onChange: (name, value) => handleInputChange(name, value),
|
|
6804
|
+
onBlur: (name, value) => handleOnBlur('municipality'),
|
|
6801
6805
|
width: "100%"
|
|
6802
6806
|
})
|
|
6803
6807
|
}), jsx(GoAFormItem, {
|
|
6804
6808
|
label: "Postal Code",
|
|
6805
|
-
error:
|
|
6809
|
+
error: (_b = errors === null || errors === void 0 ? void 0 : errors['postalCode']) !== null && _b !== void 0 ? _b : '',
|
|
6806
6810
|
children: jsx(GoAInput, {
|
|
6807
6811
|
name: "postalCode",
|
|
6808
6812
|
testId: "address-form-postal-code",
|
|
@@ -6810,6 +6814,7 @@ const AddressInputs = ({
|
|
|
6810
6814
|
placeholder: "A0A 0A0",
|
|
6811
6815
|
value: (address === null || address === void 0 ? void 0 : address.postalCode) || '',
|
|
6812
6816
|
onChange: (name, value) => handleInputChange(name, value),
|
|
6817
|
+
onBlur: (name, value) => handleOnBlur(name),
|
|
6813
6818
|
width: "100%",
|
|
6814
6819
|
maxLength: 7
|
|
6815
6820
|
})
|
|
@@ -7007,6 +7012,15 @@ const validatePostalCode = values => {
|
|
|
7007
7012
|
const postalCodeRegex = /^[A-Za-z]\d[A-Za-z] \d[A-Za-z]\d$/;
|
|
7008
7013
|
return postalCodeRegex.test(values);
|
|
7009
7014
|
};
|
|
7015
|
+
const handlePostalCodeValidation = (validatePc, message, value, errors) => {
|
|
7016
|
+
const newErrors = Object.assign({}, errors);
|
|
7017
|
+
if (!validatePc && value.length >= 4) {
|
|
7018
|
+
newErrors['postalCode'] = message;
|
|
7019
|
+
} else {
|
|
7020
|
+
delete newErrors['postalCode'];
|
|
7021
|
+
}
|
|
7022
|
+
return newErrors;
|
|
7023
|
+
};
|
|
7010
7024
|
|
|
7011
7025
|
let _ = t => t,
|
|
7012
7026
|
_t;
|
|
@@ -7192,7 +7206,7 @@ const HelpReviewContent = withJsonFormsControlProps(HelpContentReviewComponent);
|
|
|
7192
7206
|
|
|
7193
7207
|
const ADDRESS_PATH = 'api/gateway/v1/address/v1/find';
|
|
7194
7208
|
const AddressLookUpControl = props => {
|
|
7195
|
-
var _a, _b, _c;
|
|
7209
|
+
var _a, _b, _c, _d;
|
|
7196
7210
|
const {
|
|
7197
7211
|
data,
|
|
7198
7212
|
path,
|
|
@@ -7219,7 +7233,7 @@ const AddressLookUpControl = props => {
|
|
|
7219
7233
|
const [searchTerm, setSearchTerm] = useState('');
|
|
7220
7234
|
const [suggestions, setSuggestions] = useState([]);
|
|
7221
7235
|
const [loading, setLoading] = useState(false);
|
|
7222
|
-
const [
|
|
7236
|
+
const [errors, setErrors] = useState({});
|
|
7223
7237
|
const updateFormData = updatedAddress => {
|
|
7224
7238
|
setAddress(updatedAddress);
|
|
7225
7239
|
handleChange(path, updatedAddress);
|
|
@@ -7227,14 +7241,10 @@ const AddressLookUpControl = props => {
|
|
|
7227
7241
|
const handleInputChange = (field, value) => {
|
|
7228
7242
|
var _a, _b;
|
|
7229
7243
|
let newAddress;
|
|
7244
|
+
const postalCodeErrorMessage = (_b = (_a = schema.errorMessage) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.postalCode;
|
|
7230
7245
|
if (field === 'postalCode') {
|
|
7231
7246
|
const validatePc = validatePostalCode(value);
|
|
7232
|
-
|
|
7233
|
-
const postalCodeErrorMessage = (_b = (_a = schema.errorMessage) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.postalCode;
|
|
7234
|
-
setPostalCodeErrorMsg(postalCodeErrorMessage !== null && postalCodeErrorMessage !== void 0 ? postalCodeErrorMessage : '');
|
|
7235
|
-
} else {
|
|
7236
|
-
setPostalCodeErrorMsg('');
|
|
7237
|
-
}
|
|
7247
|
+
setErrors(handlePostalCodeValidation(validatePc, postalCodeErrorMessage ? postalCodeErrorMessage : '', value, errors));
|
|
7238
7248
|
if (value.length >= 4 && value.indexOf(' ') === -1) {
|
|
7239
7249
|
value = value.slice(0, 3) + ' ' + value.slice(3);
|
|
7240
7250
|
}
|
|
@@ -7275,19 +7285,32 @@ const AddressLookUpControl = props => {
|
|
|
7275
7285
|
});
|
|
7276
7286
|
fetchSuggestions();
|
|
7277
7287
|
}, [searchTerm, formUrl, isAlbertaAddress]);
|
|
7278
|
-
const handleDropdownChange = value =>
|
|
7288
|
+
const handleDropdownChange = value => {
|
|
7279
7289
|
setSearchTerm(value);
|
|
7280
7290
|
handleInputChange('addressLine1', value);
|
|
7281
|
-
}
|
|
7291
|
+
};
|
|
7282
7292
|
const handleSuggestionClick = suggestion => {
|
|
7283
7293
|
const suggestAddress = mapSuggestionToAddress(suggestion);
|
|
7284
7294
|
setAddress(suggestAddress);
|
|
7285
7295
|
handleChange(path, suggestAddress);
|
|
7286
7296
|
setSuggestions([]);
|
|
7297
|
+
setErrors({});
|
|
7298
|
+
};
|
|
7299
|
+
const handleRequiredFieldBlur = name => {
|
|
7300
|
+
const requiredFields = schema.required;
|
|
7301
|
+
if (!(data === null || data === void 0 ? void 0 : data[name]) || data[name] === '' || requiredFields.includes(name)) {
|
|
7302
|
+
const err = Object.assign({}, errors);
|
|
7303
|
+
err[name] = name === 'municipality' ? `city is required` : `${name} is required`;
|
|
7304
|
+
setErrors(err);
|
|
7305
|
+
} else {
|
|
7306
|
+
delete errors[name];
|
|
7307
|
+
}
|
|
7287
7308
|
};
|
|
7288
7309
|
return jsxs("div", {
|
|
7289
7310
|
children: [renderHelp(), jsx(GoAFormItem, {
|
|
7290
7311
|
label: label,
|
|
7312
|
+
error: (_d = errors === null || errors === void 0 ? void 0 : errors['addressLine1']) !== null && _d !== void 0 ? _d : '',
|
|
7313
|
+
"data-testId": "form-address-line1",
|
|
7291
7314
|
children: jsxs(SearchBox, {
|
|
7292
7315
|
children: [jsx(GoAInput, {
|
|
7293
7316
|
leadingIcon: autocompletion ? 'search' : undefined,
|
|
@@ -7297,6 +7320,7 @@ const AddressLookUpControl = props => {
|
|
|
7297
7320
|
placeholder: "Start typing the first line of your address",
|
|
7298
7321
|
value: (address === null || address === void 0 ? void 0 : address.addressLine1) || '',
|
|
7299
7322
|
onChange: (name, value) => handleDropdownChange(value),
|
|
7323
|
+
onBlur: (name, value) => handleRequiredFieldBlur(name),
|
|
7300
7324
|
width: "100%"
|
|
7301
7325
|
}), loading && autocompletion && jsx(GoASkeleton, {
|
|
7302
7326
|
type: "text",
|
|
@@ -7312,14 +7336,15 @@ const AddressLookUpControl = props => {
|
|
|
7312
7336
|
})
|
|
7313
7337
|
}), jsx("br", {}), jsx(AddressInputs, {
|
|
7314
7338
|
address: address,
|
|
7339
|
+
errors: errors,
|
|
7315
7340
|
handleInputChange: handleInputChange,
|
|
7316
7341
|
isAlbertaAddress: isAlbertaAddress,
|
|
7317
|
-
|
|
7342
|
+
handleOnBlur: handleRequiredFieldBlur
|
|
7318
7343
|
})]
|
|
7319
7344
|
});
|
|
7320
7345
|
};
|
|
7321
7346
|
|
|
7322
|
-
const AddressLookUpTester = rankWith(3,
|
|
7347
|
+
const AddressLookUpTester = rankWith(3, isObjectControl);
|
|
7323
7348
|
|
|
7324
7349
|
const GoATextCell = props => jsx(GoAInputText, Object.assign({}, props));
|
|
7325
7350
|
const GoATextCellTester = rankWith(1, isStringControl);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abgov/jsonforms-components",
|
|
3
|
-
"version": "1.35.
|
|
3
|
+
"version": "1.35.2",
|
|
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",
|
|
@@ -4,7 +4,8 @@ interface AddressInputsProps {
|
|
|
4
4
|
address: Address;
|
|
5
5
|
handleInputChange: (field: string, value: string) => void;
|
|
6
6
|
isAlbertaAddress?: boolean;
|
|
7
|
-
|
|
7
|
+
errors?: any;
|
|
8
|
+
handleOnBlur: (field: string) => void;
|
|
8
9
|
}
|
|
9
10
|
export declare const AddressInputs: React.FC<AddressInputsProps>;
|
|
10
11
|
export {};
|
|
@@ -4,3 +4,6 @@ export declare const filterAlbertaAddresses: (suggestions: Suggestion[]) => Sugg
|
|
|
4
4
|
export declare const filterSuggestionsWithoutAddressCount: (suggestions: Suggestion[]) => Suggestion[];
|
|
5
5
|
export declare const mapSuggestionToAddress: (suggestion: Suggestion) => Address;
|
|
6
6
|
export declare const validatePostalCode: (values: string) => boolean;
|
|
7
|
+
export declare const handlePostalCodeValidation: (validatePc: boolean, message: string, value: string, errors: Record<string, string>) => {
|
|
8
|
+
[x: string]: string;
|
|
9
|
+
};
|