Skip to content

Commit

Permalink
add autoUpperCase rule for alphanumerical postalCode countries
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrizmaselli committed Jul 17, 2024
1 parent 5c03fb0 commit 67c09ba
Show file tree
Hide file tree
Showing 10 changed files with 350 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added
- implemented autoUpperCase rule for countries with alphanumeric postal codes, ensuring consistent uppercase formatting.

## [3.36.5] - 2024-07-02

### Fixed
Expand Down
5 changes: 5 additions & 0 deletions react/AddressContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class AddressContainer extends Component {
rules.fields &&
rules.fields.find((field) => field.name === 'postalCode')

// Convert postal code to uppercase if autoUpperCase is true
if (postalCodeField && postalCodeField.autoUpperCase) {
changedAddressFields.postalCode.value = changedAddressFields.postalCode.value.toUpperCase()
}

const diffFromPrev =
address.postalCode.value !== validatedAddress.postalCode.value

Expand Down
6 changes: 2 additions & 4 deletions react/country/GBR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const rules: PostalCodeRules = {
postalCodeAPI: false,
size: 'small',
autoComplete: 'nope',
autoUpperCase: true,
},
{
name: 'street',
Expand Down Expand Up @@ -128,10 +129,7 @@ const rules: PostalCodeRules = {

state: {
valueIn: 'long_name',
types: [
'postal_town',
'administrative_area_level_1'
],
types: ['postal_town', 'administrative_area_level_1'],
},

city: {
Expand Down
159 changes: 159 additions & 0 deletions react/country/GIB.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { POSTAL_CODE } from '../constants'
import type { PostalCodeRules } from '../types/rules'

const rules: PostalCodeRules = {
country: null,
abbr: null,
postalCodeFrom: POSTAL_CODE,
fields: [
{
hidden: true,
name: 'country',
maxLength: 100,
label: 'country',
size: 'medium',
},
{
name: 'postalCode',
maxLength: 50,
label: 'postalCode',
size: 'small',
autoComplete: 'nope',
postalCodeAPI: false,
autoUpperCase: true,
},
{
name: 'street',
label: 'addressLine1',
required: true,
size: 'xlarge',
},
{
hidden: true,
name: 'number',
maxLength: 750,
label: 'number',
size: 'small',
autoComplete: 'nope',
},
{
name: 'complement',
maxLength: 750,
label: 'addressLine2',
size: 'xlarge',
},
{
hidden: true,
name: 'reference',
maxLength: 750,
label: 'reference',
size: 'xlarge',
},
{
hidden: true,
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,
size: 'large',
},
{
name: 'receiverName',
elementName: 'receiver',
maxLength: 750,
label: 'receiverName',
size: 'xlarge',
required: true,
},
],
geolocation: {
postalCode: {
valueIn: 'long_name',
types: ['postal_code'],
required: false,
},

number: {
valueIn: 'long_name',
types: ['street_number'],
required: false,
notApplicable: true,
},

street: { valueIn: 'long_name', types: ['route'] },

neighborhood: {
valueIn: 'long_name',
types: [
'neighborhood',
'sublocality_level_1',
'sublocality_level_2',
'sublocality_level_3',
'sublocality_level_4',
'sublocality_level_5',
],
},

state: {
valueIn: 'long_name',
types: ['administrative_area_level_1'],
},

city: {
valueIn: 'long_name',
types: ['administrative_area_level_2', 'locality'],
},

receiverName: {
required: true,
},
},
summary: [
[
{
name: 'street',
},
{
delimiter: ' ',
name: 'number',
},
{
delimiter: ', ',
name: 'complement',
},
],
[
{
name: 'neighborhood',
delimiterAfter: ' - ',
},
{
name: 'city',
},
{
delimiter: ' - ',
name: 'state',
},
],
[
{
name: 'postalCode',
},
],
],
}

export default rules
1 change: 1 addition & 0 deletions react/country/IRL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const rules: PostalCodeRules = {
postalCodeAPI: true,
size: 'small',
autoComplete: 'nope',
autoUpperCase: true,
},
{
name: 'street',
Expand Down
159 changes: 159 additions & 0 deletions react/country/LTU.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { POSTAL_CODE } from '../constants'
import type { PostalCodeRules } from '../types/rules'

const rules: PostalCodeRules = {
country: null,
abbr: null,
postalCodeFrom: POSTAL_CODE,
fields: [
{
hidden: true,
name: 'country',
maxLength: 100,
label: 'country',
size: 'medium',
},
{
name: 'postalCode',
maxLength: 50,
label: 'postalCode',
size: 'small',
autoComplete: 'nope',
postalCodeAPI: false,
autoUpperCase: true,
},
{
name: 'street',
label: 'addressLine1',
required: true,
size: 'xlarge',
},
{
hidden: true,
name: 'number',
maxLength: 750,
label: 'number',
size: 'small',
autoComplete: 'nope',
},
{
name: 'complement',
maxLength: 750,
label: 'addressLine2',
size: 'xlarge',
},
{
hidden: true,
name: 'reference',
maxLength: 750,
label: 'reference',
size: 'xlarge',
},
{
hidden: true,
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,
size: 'large',
},
{
name: 'receiverName',
elementName: 'receiver',
maxLength: 750,
label: 'receiverName',
size: 'xlarge',
required: true,
},
],
geolocation: {
postalCode: {
valueIn: 'long_name',
types: ['postal_code'],
required: false,
},

number: {
valueIn: 'long_name',
types: ['street_number'],
required: false,
notApplicable: true,
},

street: { valueIn: 'long_name', types: ['route'] },

neighborhood: {
valueIn: 'long_name',
types: [
'neighborhood',
'sublocality_level_1',
'sublocality_level_2',
'sublocality_level_3',
'sublocality_level_4',
'sublocality_level_5',
],
},

state: {
valueIn: 'long_name',
types: ['administrative_area_level_1'],
},

city: {
valueIn: 'long_name',
types: ['administrative_area_level_2', 'locality'],
},

receiverName: {
required: true,
},
},
summary: [
[
{
name: 'street',
},
{
delimiter: ' ',
name: 'number',
},
{
delimiter: ', ',
name: 'complement',
},
],
[
{
name: 'neighborhood',
delimiterAfter: ' - ',
},
{
name: 'city',
},
{
delimiter: ' - ',
name: 'state',
},
],
[
{
name: 'postalCode',
},
],
],
}

export default rules
8 changes: 5 additions & 3 deletions react/country/MLT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const rules: PostalCodeRules = {
postalCodeAPI: false,
size: 'small',
autoComplete: 'nope',
autoUpperCase: true,
},
{
name: 'street',
Expand Down Expand Up @@ -140,8 +141,8 @@ const rules: PostalCodeRules = {
'Żebbuġ (Zebbug)',
'Zebbug (Zebbug-Gozo)',
'Zejtun (Zejtun)',
'Zurrieq (Zurrieq)'
],
'Zurrieq (Zurrieq)',
],
},
{
name: 'receiverName',
Expand Down Expand Up @@ -171,7 +172,8 @@ const rules: PostalCodeRules = {
types: ['route'],
handler: (address, googleAddress) => {
address.street = { value: (googleAddress as { name: string }).name }
return address

return address
},
},

Expand Down
Loading

0 comments on commit 67c09ba

Please sign in to comment.