@abgov/jsonforms-components 1.35.0 → 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, scopeEndsWith, hasType, isControl, isCategorization, isLayout } from '@jsonforms/core';
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
- postalCodeErrorMsg
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: postalCodeErrorMsg,
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,25 +7233,29 @@ const AddressLookUpControl = props => {
7219
7233
  const [searchTerm, setSearchTerm] = useState('');
7220
7234
  const [suggestions, setSuggestions] = useState([]);
7221
7235
  const [loading, setLoading] = useState(false);
7222
- const [postalCodeErrorMsg, setPostalCodeErrorMsg] = useState('');
7236
+ const [errors, setErrors] = useState({});
7223
7237
  const updateFormData = updatedAddress => {
7224
7238
  setAddress(updatedAddress);
7225
7239
  handleChange(path, updatedAddress);
7226
7240
  };
7227
7241
  const handleInputChange = (field, value) => {
7228
7242
  var _a, _b;
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;
7229
7245
  if (field === 'postalCode') {
7230
7246
  const validatePc = validatePostalCode(value);
7231
- if (!validatePc && value.length >= 5) {
7232
- const postalCodeErrorMessage = (_b = (_a = schema.errorMessage) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.postalCode;
7233
- setPostalCodeErrorMsg(postalCodeErrorMessage !== null && postalCodeErrorMessage !== void 0 ? postalCodeErrorMessage : '');
7234
- } else {
7235
- setPostalCodeErrorMsg('');
7247
+ setErrors(handlePostalCodeValidation(validatePc, postalCodeErrorMessage ? postalCodeErrorMessage : '', value, errors));
7248
+ if (value.length >= 4 && value.indexOf(' ') === -1) {
7249
+ value = value.slice(0, 3) + ' ' + value.slice(3);
7236
7250
  }
7251
+ newAddress = Object.assign(Object.assign({}, address), {
7252
+ [field]: value.toUpperCase()
7253
+ });
7254
+ } else {
7255
+ newAddress = Object.assign(Object.assign({}, address), {
7256
+ [field]: value
7257
+ });
7237
7258
  }
7238
- const newAddress = Object.assign(Object.assign({}, address), {
7239
- [field]: value
7240
- });
7241
7259
  setAddress(newAddress);
7242
7260
  updateFormData(newAddress);
7243
7261
  };
@@ -7267,19 +7285,32 @@ const AddressLookUpControl = props => {
7267
7285
  });
7268
7286
  fetchSuggestions();
7269
7287
  }, [searchTerm, formUrl, isAlbertaAddress]);
7270
- const handleDropdownChange = value => __awaiter(void 0, void 0, void 0, function* () {
7288
+ const handleDropdownChange = value => {
7271
7289
  setSearchTerm(value);
7272
7290
  handleInputChange('addressLine1', value);
7273
- });
7291
+ };
7274
7292
  const handleSuggestionClick = suggestion => {
7275
7293
  const suggestAddress = mapSuggestionToAddress(suggestion);
7276
7294
  setAddress(suggestAddress);
7277
7295
  handleChange(path, suggestAddress);
7278
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
+ }
7279
7308
  };
7280
7309
  return jsxs("div", {
7281
7310
  children: [renderHelp(), jsx(GoAFormItem, {
7282
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",
7283
7314
  children: jsxs(SearchBox, {
7284
7315
  children: [jsx(GoAInput, {
7285
7316
  leadingIcon: autocompletion ? 'search' : undefined,
@@ -7289,6 +7320,7 @@ const AddressLookUpControl = props => {
7289
7320
  placeholder: "Start typing the first line of your address",
7290
7321
  value: (address === null || address === void 0 ? void 0 : address.addressLine1) || '',
7291
7322
  onChange: (name, value) => handleDropdownChange(value),
7323
+ onBlur: (name, value) => handleRequiredFieldBlur(name),
7292
7324
  width: "100%"
7293
7325
  }), loading && autocompletion && jsx(GoASkeleton, {
7294
7326
  type: "text",
@@ -7304,14 +7336,15 @@ const AddressLookUpControl = props => {
7304
7336
  })
7305
7337
  }), jsx("br", {}), jsx(AddressInputs, {
7306
7338
  address: address,
7339
+ errors: errors,
7307
7340
  handleInputChange: handleInputChange,
7308
7341
  isAlbertaAddress: isAlbertaAddress,
7309
- postalCodeErrorMsg: postalCodeErrorMsg
7342
+ handleOnBlur: handleRequiredFieldBlur
7310
7343
  })]
7311
7344
  });
7312
7345
  };
7313
7346
 
7314
- const AddressLookUpTester = rankWith(3, and(scopeEndsWith('mailingAddress')));
7347
+ const AddressLookUpTester = rankWith(3, isObjectControl);
7315
7348
 
7316
7349
  const GoATextCell = props => jsx(GoAInputText, Object.assign({}, props));
7317
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.0",
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
- postalCodeErrorMsg?: string;
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
+ };