From 1d7c65c2116b6bd6f5b9429b1e7ab9e1ad383555 Mon Sep 17 00:00:00 2001 From: georgelimadev Date: Thu, 6 Jul 2023 08:08:50 -0300 Subject: [PATCH 1/2] Adding VIR country rules for address-form --- CHANGELOG.md | 4 ++ react/country/VIR.js | 141 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 react/country/VIR.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b77cc4b..10de5945 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added + +- Virgin Islands (US) country rules. + ## [4.22.2] - 2023-06-27 ### Fixed diff --git a/react/country/VIR.js b/react/country/VIR.js new file mode 100644 index 00000000..8d1bf7ef --- /dev/null +++ b/react/country/VIR.js @@ -0,0 +1,141 @@ +import { POSTAL_CODE } from '../constants' + +export default { + country: 'VIR', + abbr: 'VI', + postalCodeFrom: POSTAL_CODE, + fields: [ + { + hidden: true, + name: 'country', + maxLength: 100, + label: 'country', + size: 'medium', + }, + { + name: 'postalCode', + maxLength: 50, + fixedLabel: 'ZIP', + required: true, + mask: '99999-9999', + regex: '^008(01|02|03|04|05|20|21|22|23|24|30|31|40|41|50|51)-\d{0,4}$', + // Asserts zipcode starts with 008, then contains one of the local accepted area values, then followed by hyphen and 4 digits. + postalCodeAPI: true, + forgottenURL: 'https://tools.usps.com/go/ZipLookupAction!input.action', + size: 'small', + autoComplete: 'nope', + }, + { + name: 'number', + maxLength: 750, + label: 'number', + hidden: true, + defaultValue: 'N/A', + autoComplete: 'nope', + }, + { + name: 'street', + label: 'addressLine1', + required: true, + size: 'xlarge', + }, + { + name: 'complement', + maxLength: 750, + label: 'addressLine2', + size: 'xlarge', + }, + { + hidden: false, + name: 'neighborhood', + maxLength: 100, + label: 'neighborhood', + size: 'large', + }, + { + name: 'city', + maxLength: 100, + label: 'city', + required: true, + size: 'large', + }, + { + name: 'state', + maxLength: 100, + label: 'state', + required: true, + hidden: true, + size: 'large', + optionsPairs: [ + { label: 'Virgin Islands', value: 'USVI' }, + ], + defaultValue: 'USVI' + }, + { + hidden: true, + name: 'reference', + maxLength: 750, + label: 'reference', + size: 'xlarge', + }, + { + name: 'receiverName', + elementName: 'receiver', + maxLength: 750, + label: 'receiverName', + size: 'xlarge', + required: true, + }, + ], + geolocation: { + postalCode: { + valueIn: 'long_name', + types: ['postal_code'], + required: false, + }, + + street: { + valueIn: 'long_name', + types: ['route'], + handler: (address, googleAddress) => { + address.street = { value: googleAddress.name } + + return address + }, + }, + + neighborhood: { + valueIn: 'long_name', + types: [ + 'neighborhood', + 'sublocality_level_1', + 'sublocality_level_2', + 'sublocality_level_3', + 'sublocality_level_4', + 'sublocality_level_5', + ], + }, + + state: { + valueIn: 'short_name', + types: ['administrative_area_level_1'], + }, + + city: { + valueIn: 'long_name', + types: ['locality'], + }, + + receiverName: { + required: true, + }, + }, + summary: [ + [{ name: 'street' }, { delimiter: ', ', name: 'complement' }], + [ + { name: 'city' }, + { delimiter: ', ', name: 'state' }, + { delimiter: ' ', name: 'postalCode' }, + ], + ], +} From b5c6459dd764a4afe63a298fab186b6bc8b69591 Mon Sep 17 00:00:00 2001 From: georgelimadev Date: Fri, 14 Jul 2023 13:31:14 -0300 Subject: [PATCH 2/2] fixing geolocation rules for number field --- react/country/VIR.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/react/country/VIR.js b/react/country/VIR.js index 8d1bf7ef..672e1a60 100644 --- a/react/country/VIR.js +++ b/react/country/VIR.js @@ -94,6 +94,13 @@ export default { required: false, }, + number: { + valueIn: 'long_name', + types: ['street_number'], + required: false, + notApplicable: true, + }, + street: { valueIn: 'long_name', types: ['route'],