Merge branch 'release-stable' of github.com:KieIO/grocery-vercel-commerce into feature/m3-viewed-product

This commit is contained in:
DatNguyen
2021-10-18 14:38:40 +07:00
53 changed files with 1215 additions and 180 deletions

View File

@@ -38,7 +38,6 @@ export default function getAllProductsOperation({
const { data } = await config.fetch<GetAllProductsQuery>(query, {
variables,
})
return {
products: data.search.items.map((item) => normalizeSearchResult(item)),
totalItems: data.search.totalItems as number,

View File

@@ -1,3 +1,6 @@
import { FacetValue, UpdateAddressInput } from './schema.d';
import { ResetPassword } from './schema.d';
import { requestPasswordReset } from '@framework/schema';
import { FacetValue } from './schema.d';
export type Maybe<T> = T | null
export type Exact<T extends { [key: string]: unknown }> = {
@@ -304,6 +307,11 @@ export type MutationResetPasswordArgs = {
}
export type Address = Node & {
updateCustomerAddress:
| {
__typename?: 'Address'
id: Scalars['ID']
}
__typename?: 'Address'
id: Scalars['ID']
createdAt: Scalars['DateTime']
@@ -322,6 +330,9 @@ export type Address = Node & {
customFields?: Maybe<Scalars['JSON']>
}
export type Asset = Node & {
__typename?: 'Asset'
id: Scalars['ID']
@@ -1459,6 +1470,11 @@ export type CustomerListOptions = {
}
export type Customer = Node & {
updateCustomer:
| {
__typename?: 'Customer'
id: Scalars['ID']
}
__typename?: 'Customer'
id: Scalars['ID']
createdAt: Scalars['DateTime']
@@ -1466,7 +1482,7 @@ export type Customer = Node & {
title?: Maybe<Scalars['String']>
firstName: Scalars['String']
lastName: Scalars['String']
phoneNumber?: Maybe<Scalars['String']>
phoneNumber?: Maybe<Scalars['String']>
emailAddress: Scalars['String']
addresses?: Maybe<Array<Address>>
orders: OrderList
@@ -3126,6 +3142,36 @@ export type LoginMutation = { __typename?: 'Mutation' } & {
>)
}
export type ResetPasswordMutation = { __typename?: 'Mutation' } & {
resetPassword:
| ({ __typename: 'CurrentUser' } & Pick<CurrentUser, 'id'>)
| ({ __typename: 'PasswordResetTokenInvalidError' } & Pick<
PasswordResetTokenInvalidError,
'errorCode' | 'message'
>)
| ({ __typename: 'PasswordResetTokenExpiredError' } & Pick<
PasswordResetTokenExpiredError,
'errorCode' | 'message'
>)
| ({ __typename: 'NativeAuthStrategyError' } & Pick<
NativeAuthStrategyError,
'errorCode' | 'message'
>)
}
export type SignupMutation = { __typename?: 'Mutation' } & {
registerCustomerAccount:
| ({ __typename: 'Success' } & Pick<Success, 'success'>)
| ({ __typename: 'MissingPasswordError' } & Pick<
MissingPasswordError,
'errorCode' | 'message'
>)
| ({ __typename: 'NativeAuthStrategyError' } & Pick<
NativeAuthStrategyError,
'errorCode' | 'message'
>)
}
export type VerifyCustomerAccountVariables = Exact<{
token: Scalars['String']
password?: Maybe<Scalars['String']>
@@ -3179,8 +3225,9 @@ export type SignupMutationVariables = Exact<{
input: RegisterCustomerInput
}>
export type SignupMutation = { __typename?: 'Mutation' } & {
registerCustomerAccount:
export type RequestPasswordReset = { __typename?: 'Mutation' } & {
requestPasswordReset:
| ({ __typename: 'Success' } & Pick<Success, 'success'>)
| ({ __typename: 'MissingPasswordError' } & Pick<
MissingPasswordError,
@@ -3192,17 +3239,48 @@ export type SignupMutation = { __typename?: 'Mutation' } & {
>)
}
export type ActiveCustomerQueryVariables = Exact<{ [key: string]: never }>
export type ActiveCustomerQuery = { __typename?: 'Query' } & {
activeCustomer?: Maybe<
{ __typename?: 'Customer' } & Pick<
Customer,
'id' | 'firstName' | 'lastName' | 'emailAddress'
Favorite,
'id' | 'firstName' | 'lastName' | 'emailAddress' | 'addresses' | 'phoneNumber'| 'orders'
>
>
}
export type QueryFavorite = {
options: FavoriteListOptions
}
export type FavoriteListOptions = {
skip?: Maybe<Scalars['Int']>
take?: Maybe<Scalars['Int']>
}
export type FavoriteList = PaginatedList & {
items: [Favorite!]!
totalItems: Int!
}
type Favorite = Node & {
id: ID!
createdAt: DateTime!
updatedAt: DateTime!
product: Product
customer: Customer!
}
type FavouriteOption = Customer & {
favorites(options: FavoriteListOptions): FavoriteList!
}
export type GetAllProductPathsQueryVariables = Exact<{
first?: Maybe<Scalars['Int']>
}>

View File

@@ -0,0 +1,14 @@
export const requestPasswordReset = /* GraphQL */ `
mutation RequestPasswordReset($emailAddress: String!) {
requestPasswordReset(emailAddress: $emailAddress) {
__typename
...on Success{
success
}
...on ErrorResult{
errorCode
message
}
}
}
`

View File

@@ -0,0 +1,15 @@
export const resetPasswordMutation = /* GraphQL */ `
mutation resetPassword($token: String!,$password: String!){
resetPassword(token: $token,password: $password){
__typename
...on CurrentUser{
id
identifier
}
...on ErrorResult{
errorCode
message
}
}
}
`

View File

@@ -0,0 +1,9 @@
export const toggleWishlistMutation = /* GraphQL */ `
mutation toggleFavorite($productId:ID!){
toggleFavorite(productId:$productId){
items{
id
}
}
}
`

View File

@@ -0,0 +1,14 @@
export const updateCustomerAddress = /* GraphQL */ `
mutation updateCustomerAddress($input: UpdateAddressInput!){
updateCustomerAddress(input: $input){
__typename
...on Address{
id
streetLine1
city
postalCode
province
}
}
}
`

View File

@@ -0,0 +1,13 @@
export const updateCustomer = /* GraphQL */ `
mutation updateCustomer($input: UpdateCustomerInput!){
updateCustomer(input:$input){
__typename
...on Customer{
id
firstName
lastName
phoneNumber
}
}
}
`

View File

@@ -1,6 +1,6 @@
import { Cart } from '@commerce/types/cart'
import { ProductCard, Product } from '@commerce/types/product'
import { CartFragment, SearchResultFragment } from '../schema'
import { CartFragment, SearchResultFragment,Favorite } from '../schema'
export function normalizeSearchResult(item: SearchResultFragment): ProductCard {
return {
@@ -23,6 +23,18 @@ export function normalizeSearchResult(item: SearchResultFragment): ProductCard {
}
}
export function normalizeFavoriteProductResult(item: Favorite) {
return {
id: item.product.id,
name: item.product.name,
slug: item.product.slug,
imageSrc: item.product.assets[0].preview ? item.product.assets[0].preview + '?w=800&mode=crop' : '',
price: item.product.variants[0].priceWithTax as number / 100,
currencyCode: item.product.variants[0].currencyCode,
}
}
export function normalizeCart(order: CartFragment): Cart {
return {
id: order.id.toString(),

View File

@@ -1,10 +1,24 @@
export const activeCustomerQuery = /* GraphQL */ `
query activeCustomer {
activeCustomer {
id
firstName
lastName
emailAddress
query activeCustomer {
activeCustomer {
id
firstName
lastName
emailAddress
favorites{
items{
product{
id
}
}
}
phoneNumber
addresses{
streetLine1
city
province
postalCode
}
}
}
`

View File

@@ -0,0 +1,28 @@
export const getFavoriteProductQuery = /* GraphQL */ `
query activeCustomer($options: FavoriteListOptions) {
activeCustomer {
id
firstName
lastName
emailAddress
favorites(options: $options){
items{
product{
id
name
slug
assets{
source
preview
}
variants{
priceWithTax
currencyCode
}
}
}
totalItems
}
}
}
`

View File

@@ -0,0 +1,19 @@
export const getUserOrderQuery = /* GraphQL */ `
query activeCustomer {
activeCustomer {
orders{
items{
lines{
productVariant{
name
}
quantity
}
total
state
code
}
}
}
}
`

View File

@@ -0,0 +1,16 @@
export const userInfoQuery = /* GraphQL */ `
query activeCustomer{
activeCustomer{
lastName
firstName
emailAddress
phoneNumber
addresses{
streetLine1
city
province
postalCode
}
}
}
`