Skip to content

Commit

Permalink
Merge pull request #12 from vtex-apps/hook-types
Browse files Browse the repository at this point in the history
Add strong types to address rules hook return value
  • Loading branch information
lucasecdb authored Feb 19, 2021
2 parents 61cbaf1 + 7fb6ea5 commit 4028501
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Strongly type return value of `useAddressRules`.

## [0.6.0] - 2021-02-18
### Added
Expand Down
5 changes: 3 additions & 2 deletions react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"devDependencies": {
"@types/node": "^12.7.5",
"@types/react": "^16.9.2",
"vtex.checkout-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.46.0/public/@types/vtex.checkout-graphql",
"vtex.render-runtime": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.124.3/public/@types/vtex.render-runtime"
"vtex.checkout-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.56.1/public/@types/vtex.checkout-graphql",
"vtex.country-data-settings": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.country-data-settings@0.3.0/public/@types/vtex.country-data-settings",
"vtex.render-runtime": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.126.11/public/@types/vtex.render-runtime"
}
}
25 changes: 22 additions & 3 deletions react/useAddressRules.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
import { useMemo } from 'react'
import { useQuery } from 'react-apollo'
import {
CountryData,
DisplayData,
AddressFieldsData,
LocationSelectData,
} from 'vtex.country-data-settings'

import addressRulesQuery from './graphql/addressRulesQuery.gql'

interface RulesQuery {
allCountriesData: CountryData[]
}

const useAddressRules = () => {
const { data } = useQuery(addressRulesQuery)
const { data } = useQuery<RulesQuery>(addressRulesQuery)

const addressRules = useMemo(
() =>
data?.allCountriesData.reduce(
(rules: any, countryData: any) => ({
data?.allCountriesData?.reduce<
Record<
string,
{
display: DisplayData
fields: AddressFieldsData
locationSelect?: LocationSelectData | null
}
>
>(
(rules, countryData) => ({
...rules,
[countryData.countryISO]: {
display: countryData.display,
Expand Down
16 changes: 10 additions & 6 deletions react/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,14 @@ tslib@^1.10.0, tslib@^1.9.3:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

"vtex.checkout-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.46.0/public/@types/vtex.checkout-graphql":
version "0.46.0"
resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.46.0/public/@types/vtex.checkout-graphql#9a530005a9a190fda003221b6b0d94430b0527dd"
"vtex.checkout-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.56.1/public/@types/vtex.checkout-graphql":
version "0.56.1"
resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.56.1/public/@types/vtex.checkout-graphql#c1153ec5faf232f92abfe495f867019bfb7d510f"

"vtex.render-runtime@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.124.3/public/@types/vtex.render-runtime":
version "8.124.3"
resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.124.3/public/@types/vtex.render-runtime#8158e34bd24b4a51cb5d463eeef4e37af626c2d5"
"vtex.country-data-settings@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.country-data-settings@0.3.0/public/@types/vtex.country-data-settings":
version "0.3.0"
resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.country-data-settings@0.3.0/public/@types/vtex.country-data-settings#3225ad842acdb749c9283b10daa8af3f05785abf"

"vtex.render-runtime@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.126.11/public/@types/vtex.render-runtime":
version "8.126.11"
resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.126.11/public/@types/vtex.render-runtime#aceb734766093b56954ec19a074574b4c2c95242"

0 comments on commit 4028501

Please sign in to comment.