Skip to content

Commit

Permalink
feat: Trade Policies (#68)
Browse files Browse the repository at this point in the history
* sales channel support

* upgrade deps
  • Loading branch information
tlgimenes authored May 31, 2022
1 parent 51c5001 commit 8e9d1f4
Show file tree
Hide file tree
Showing 11 changed files with 1,539 additions and 1,762 deletions.
3,073 changes: 1,460 additions & 1,613 deletions @generated/graphql/index.ts

Large diffs are not rendered by default.

16 changes: 1 addition & 15 deletions @generated/graphql/persisted.json
Original file line number Diff line number Diff line change
@@ -1,15 +1 @@
{
"UpdateSessionMutation": "mutation UpdateSessionMutation($session: IStoreSession!) {\n updateSession(session: $session) {\n channel\n }\n}\n",
"SearchSuggestionsQuery": "query SearchSuggestionsQuery($term: String!, $selectedFacets: [IStoreSelectedFacet!]) {\n search(first: 5, term: $term, selectedFacets: $selectedFacets) {\n suggestions {\n terms {\n value\n }\n products {\n id: productID\n slug\n sku\n brand {\n brandName: name\n name\n }\n name\n gtin\n isVariantOf {\n productGroupID\n name\n }\n image {\n url\n alternateName\n }\n offers {\n lowPrice\n offers {\n availability\n price\n listPrice\n quantity\n seller {\n identifier\n }\n }\n }\n }\n }\n }\n}\n",
"ProductGalleryQuery": "query ProductGalleryQuery($first: Int!, $after: String!, $sort: StoreSort!, $term: String!, $selectedFacets: [IStoreSelectedFacet!]!) {\n search(\n first: $first\n after: $after\n sort: $sort\n term: $term\n selectedFacets: $selectedFacets\n ) {\n products {\n pageInfo {\n totalCount\n }\n edges {\n node {\n id: productID\n slug\n sku\n brand {\n brandName: name\n name\n }\n name\n gtin\n isVariantOf {\n productGroupID\n name\n }\n image {\n url\n alternateName\n }\n offers {\n lowPrice\n offers {\n availability\n price\n listPrice\n quantity\n seller {\n identifier\n }\n }\n }\n }\n }\n }\n facets {\n key\n label\n type\n values {\n label\n value\n selected\n quantity\n }\n }\n }\n}\n",
"CollectionPageQuery": "query CollectionPageQuery {\n site {\n siteMetadata {\n titleTemplate\n title\n description\n }\n }\n}\n",
"ServerCollectionPageQuery": "query ServerCollectionPageQuery($slug: String!) {\n collection(slug: $slug) {\n seo {\n title\n description\n }\n breadcrumbList {\n itemListElement {\n item\n name\n position\n }\n }\n meta {\n selectedFacets {\n key\n value\n }\n }\n }\n}\n",
"ProductPageQuery": "query ProductPageQuery {\n site {\n siteMetadata {\n title\n description\n titleTemplate\n siteUrl\n }\n }\n}\n",
"ServerProductPageQuery": "query ServerProductPageQuery($id: String!) {\n product(locator: [{key: \"id\", value: $id}]) {\n id: productID\n slug\n seo {\n title\n description\n }\n brand {\n name\n }\n sku\n gtin\n name\n description\n breadcrumbList {\n itemListElement {\n item\n name\n position\n }\n }\n image {\n url\n alternateName\n }\n offers {\n lowPrice\n highPrice\n priceCurrency\n offers {\n availability\n price\n priceValidUntil\n priceCurrency\n itemCondition\n seller {\n identifier\n }\n listPrice\n }\n }\n isVariantOf {\n productGroupID\n name\n }\n additionalProperty {\n propertyID\n name\n value\n valueReference\n }\n }\n}\n",
"HomePageQuery": "query HomePageQuery {\n site {\n siteMetadata {\n title\n description\n titleTemplate\n }\n }\n}\n",
"SearchPageQuery": "query SearchPageQuery {\n site {\n siteMetadata {\n titleTemplate\n title\n description\n }\n }\n}\n",
"ValidateCartMutation": "mutation ValidateCartMutation($cart: IStoreCart!) {\n validateCart(cart: $cart) {\n order {\n orderNumber\n acceptedOffer {\n seller {\n identifier\n }\n quantity\n price\n listPrice\n itemOffered {\n sku\n name\n image {\n url\n alternateName\n }\n brand {\n name\n }\n isVariantOf {\n productGroupID\n name\n }\n gtin\n additionalProperty {\n propertyID\n name\n value\n valueReference\n }\n }\n }\n }\n messages {\n text\n status\n }\n }\n}\n",
"PersonQuery": "query PersonQuery {\n person {\n id\n email\n givenName\n familyName\n }\n}\n",
"BrowserProductQuery": "query BrowserProductQuery($locator: [IStoreSelectedFacet!]!) {\n product(locator: $locator) {\n id: productID\n sku\n name\n gtin\n description\n isVariantOf {\n productGroupID\n name\n }\n image {\n url\n alternateName\n }\n brand {\n name\n }\n offers {\n lowPrice\n offers {\n availability\n price\n listPrice\n seller {\n identifier\n }\n }\n }\n breadcrumbList {\n itemListElement {\n item\n name\n position\n }\n }\n additionalProperty {\n propertyID\n name\n value\n valueReference\n }\n }\n}\n",
"ProductsQuery": "query ProductsQuery($first: Int!, $after: String, $sort: StoreSort!, $term: String!, $selectedFacets: [IStoreSelectedFacet!]!) {\n search(\n first: $first\n after: $after\n sort: $sort\n term: $term\n selectedFacets: $selectedFacets\n ) {\n products {\n pageInfo {\n totalCount\n }\n edges {\n node {\n id: productID\n slug\n sku\n brand {\n brandName: name\n name\n }\n name\n gtin\n isVariantOf {\n productGroupID\n name\n }\n image {\n url\n alternateName\n }\n offers {\n lowPrice\n offers {\n availability\n price\n listPrice\n quantity\n seller {\n identifier\n }\n }\n }\n }\n }\n }\n }\n}\n"
}
{"SearchSuggestionsQuery":"query SearchSuggestionsQuery($term: String!, $selectedFacets: [IStoreSelectedFacet!]) {\n search(first: 5, term: $term, selectedFacets: $selectedFacets) {\n suggestions {\n terms {\n value\n }\n products {\n id: productID\n slug\n sku\n brand {\n brandName: name\n name\n }\n name\n gtin\n isVariantOf {\n productGroupID\n name\n }\n image {\n url\n alternateName\n }\n offers {\n lowPrice\n offers {\n availability\n price\n listPrice\n quantity\n seller {\n identifier\n }\n }\n }\n }\n }\n }\n}\n","ProductGalleryQuery":"query ProductGalleryQuery($first: Int!, $after: String!, $sort: StoreSort!, $term: String!, $selectedFacets: [IStoreSelectedFacet!]!) {\n search(\n first: $first\n after: $after\n sort: $sort\n term: $term\n selectedFacets: $selectedFacets\n ) {\n products {\n pageInfo {\n totalCount\n }\n edges {\n node {\n id: productID\n slug\n sku\n brand {\n brandName: name\n name\n }\n name\n gtin\n isVariantOf {\n productGroupID\n name\n }\n image {\n url\n alternateName\n }\n offers {\n lowPrice\n offers {\n availability\n price\n listPrice\n quantity\n seller {\n identifier\n }\n }\n }\n }\n }\n }\n facets {\n key\n label\n type\n values {\n label\n value\n selected\n quantity\n }\n }\n }\n}\n","CollectionPageQuery":"query CollectionPageQuery {\n site {\n siteMetadata {\n titleTemplate\n title\n description\n }\n }\n}\n","ServerCollectionPageQuery":"query ServerCollectionPageQuery($slug: String!) {\n collection(slug: $slug) {\n seo {\n title\n description\n }\n breadcrumbList {\n itemListElement {\n item\n name\n position\n }\n }\n meta {\n selectedFacets {\n key\n value\n }\n }\n }\n}\n","ProductPageQuery":"query ProductPageQuery {\n site {\n siteMetadata {\n title\n description\n titleTemplate\n siteUrl\n }\n }\n}\n","ServerProductPageQuery":"query ServerProductPageQuery($id: String!) {\n product(locator: [{key: \"id\", value: $id}]) {\n id: productID\n slug\n seo {\n title\n description\n }\n brand {\n name\n }\n sku\n gtin\n name\n description\n breadcrumbList {\n itemListElement {\n item\n name\n position\n }\n }\n image {\n url\n alternateName\n }\n offers {\n lowPrice\n highPrice\n priceCurrency\n offers {\n availability\n price\n priceValidUntil\n priceCurrency\n itemCondition\n seller {\n identifier\n }\n listPrice\n }\n }\n isVariantOf {\n productGroupID\n name\n }\n additionalProperty {\n propertyID\n name\n value\n valueReference\n }\n }\n}\n","HomePageQuery":"query HomePageQuery {\n site {\n siteMetadata {\n title\n description\n titleTemplate\n }\n }\n}\n","SearchPageQuery":"query SearchPageQuery {\n site {\n siteMetadata {\n titleTemplate\n title\n description\n }\n }\n}\n","ValidateCartMutation":"mutation ValidateCartMutation($cart: IStoreCart!) {\n validateCart(cart: $cart) {\n order {\n orderNumber\n acceptedOffer {\n seller {\n identifier\n }\n quantity\n price\n listPrice\n itemOffered {\n sku\n name\n image {\n url\n alternateName\n }\n brand {\n name\n }\n isVariantOf {\n productGroupID\n name\n }\n gtin\n additionalProperty {\n propertyID\n name\n value\n valueReference\n }\n }\n }\n }\n messages {\n text\n status\n }\n }\n}\n","BrowserProductQuery":"query BrowserProductQuery($locator: [IStoreSelectedFacet!]!) {\n product(locator: $locator) {\n id: productID\n sku\n name\n gtin\n description\n isVariantOf {\n productGroupID\n name\n }\n image {\n url\n alternateName\n }\n brand {\n name\n }\n offers {\n lowPrice\n offers {\n availability\n price\n listPrice\n seller {\n identifier\n }\n }\n }\n breadcrumbList {\n itemListElement {\n item\n name\n position\n }\n }\n additionalProperty {\n propertyID\n name\n value\n valueReference\n }\n }\n}\n","ProductsQuery":"query ProductsQuery($first: Int!, $after: String, $sort: StoreSort!, $term: String!, $selectedFacets: [IStoreSelectedFacet!]!) {\n search(\n first: $first\n after: $after\n sort: $sort\n term: $term\n selectedFacets: $selectedFacets\n ) {\n products {\n pageInfo {\n totalCount\n }\n edges {\n node {\n id: productID\n slug\n sku\n brand {\n brandName: name\n name\n }\n name\n gtin\n isVariantOf {\n productGroupID\n name\n }\n image {\n url\n alternateName\n }\n offers {\n lowPrice\n offers {\n availability\n price\n listPrice\n quantity\n seller {\n identifier\n }\n }\n }\n }\n }\n }\n }\n}\n","ValidateSession":"mutation ValidateSession($session: IStoreSession!, $search: String!) {\n validateSession(session: $session, search: $search) {\n locale\n channel\n country\n postalCode\n currency {\n code\n symbol\n }\n person {\n id\n email\n givenName\n familyName\n }\n }\n}\n"}
2 changes: 2 additions & 0 deletions gatsby-browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ErrorBoundary from 'src/sdk/error/ErrorBoundary'
import TestProvider from 'src/sdk/tests'
import { uiActions, uiEffects, uiInitialState } from 'src/sdk/ui'
import { ModalProvider } from 'src/sdk/ui/modal'
import { validateSession } from 'src/sdk/session/validate'
import type { GatsbyBrowser } from 'gatsby'

import storeConfig from './store.config'
Expand All @@ -32,6 +33,7 @@ export const wrapRootElement: GatsbyBrowser['wrapRootElement'] = ({
channel: storeConfig.channel,
locale: storeConfig.locale,
}}
onValidateSession={validateSession}
>
<CartProvider mode="optimistic" onValidateCart={validateCart}>
<ModalProvider>{element}</ModalProvider>
Expand Down
2 changes: 2 additions & 0 deletions gatsby-ssr.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CartProvider, SessionProvider, UIProvider } from '@faststore/sdk'
import { validateSession } from 'src/sdk/session/validate'
import type { ReactNode } from 'react'
import type { GatsbySSR } from 'gatsby'

Expand Down Expand Up @@ -26,6 +27,7 @@ export const wrapRootElement: GatsbySSR['wrapRootElement'] = ({ element }) => (
channel: storeConfig.channel,
locale: storeConfig.locale,
}}
onValidateSession={validateSession}
>
<CartProvider mode="optimistic" onValidateCart={validateCart}>
<ModalProvider>{element}</ModalProvider>
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
"@envelop/graphql-jit": "^1.1.1",
"@envelop/parser-cache": "^2.2.0",
"@envelop/validation-cache": "^2.2.0",
"@faststore/api": "^1.8.40",
"@faststore/sdk": "^1.8.40",
"@faststore/ui": "^1.8.40",
"@vtex/graphql-utils": "^1.8.40",
"@faststore/api": "^1.8.49",
"@faststore/sdk": "^1.8.49",
"@faststore/ui": "^1.8.49",
"@vtex/graphql-utils": "^1.8.42",
"gatsby": "^4.14.1",
"gatsby-plugin-gatsby-cloud": "^4.14.0",
"gatsby-plugin-manifest": "^4.14.0",
Expand Down Expand Up @@ -69,7 +69,7 @@
"@storybook/react": "^6.4.20",
"@testing-library/cypress": "^8.0.0",
"@types/cypress": "^1.1.3",
"@vtex/lighthouse-config": "^1.8.40",
"@vtex/lighthouse-config": "^1.8.42",
"@vtex/prettier-config": "1.0.0",
"@vtex/tsconfig": "0.6.0",
"autoprefixer": "^10.4.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
import { useSession } from '@faststore/sdk'
import { gql } from '@vtex/graphql-utils'
import { useRef, useState } from 'react'
import { request } from 'src/sdk/graphql/request'
import type {
UpdateSessionMutationMutation,
UpdateSessionMutationMutationVariables,
} from '@generated/graphql'
import InputText from 'src/components/ui/InputText'
import { validateSession } from 'src/sdk/session/validate'
import { useModal } from 'src/sdk/ui/modal/Provider'

export const UpdateSessionMutation = gql`
mutation UpdateSessionMutation($session: IStoreSession!) {
updateSession(session: $session) {
channel
}
}
`

export default function RegionalizationInput() {
const inputRef = useRef<HTMLInputElement>(null)
const { country, setSession, ...partialSession } = useSession()
const { setSession, ...session } = useSession()
const [errorMessage, setErrorMessage] = useState<string>('')
const { onModalClose } = useModal()

Expand All @@ -33,24 +20,15 @@ export default function RegionalizationInput() {
setErrorMessage('')

try {
const {
updateSession: { channel },
} = await request<
UpdateSessionMutationMutation,
UpdateSessionMutationMutationVariables
>(UpdateSessionMutation, {
session: {
channel: partialSession.channel,
postalCode: value,
country,
},
})

setSession({
const newSession = await validateSession({
...session,
postalCode: value,
channel: channel ?? partialSession.channel,
})

if (newSession) {
setSession(newSession)
}

onModalClose()
} catch (error) {
setErrorMessage('You entered an invalid Zip Code')
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/Button/ButtonSignIn.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Icon from 'src/components/ui/Icon'
import usePersonQuery from 'src/sdk/person/usePersonQuery'
import { ButtonLink } from 'src/components/ui/Button'
import { useSession } from '@faststore/sdk'

const ButtonSignIn = () => {
const person = usePersonQuery()
const { person } = useSession()

return (
<ButtonLink
Expand Down
76 changes: 0 additions & 76 deletions src/sdk/person/usePersonQuery.ts

This file was deleted.

38 changes: 38 additions & 0 deletions src/sdk/session/validate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { gql } from '@vtex/graphql-utils'
import type { Session } from '@faststore/sdk'

import type {
ValidateSessionMutation,
ValidateSessionMutationVariables,
} from '../../../@generated/graphql/index'
import { request } from '../graphql/request'

export const mutation = gql`
mutation ValidateSession($session: IStoreSession!, $search: String!) {
validateSession(session: $session, search: $search) {
locale
channel
country
postalCode
currency {
code
symbol
}
person {
id
email
givenName
familyName
}
}
}
`

export const validateSession = async (session: Session) => {
const data = await request<
ValidateSessionMutation,
ValidateSessionMutationVariables
>(mutation, { session, search: window.location.search })

return data.validateSession
}
2 changes: 1 addition & 1 deletion store.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
},

// Default channel
channel: '{"salesChannel":"1"}',
channel: '{"salesChannel":"1","regionId":""}',
locale: 'en-US',

// Production URLs
Expand Down
Loading

1 comment on commit 8e9d1f4

@vercel
Copy link

@vercel vercel bot commented on 8e9d1f4 May 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployment failed with the following error:

Resource is limited - try again in 8 minutes (more than 100, code: "api-deployments-free-per-day").

Please sign in to comment.