feat: setCustomerForOrder

:%s
This commit is contained in:
lytrankieio123
2021-10-18 17:38:08 +07:00
parent d846574b94
commit 8a2e06a0fa
14 changed files with 384 additions and 242 deletions

View File

@@ -306,9 +306,52 @@ export type MutationResetPasswordArgs = {
password: Scalars['String'] password: Scalars['String']
} }
export type ActiveOrderCustomerFragment = Pick<Order, 'id'> & {
customer?: Maybe<Pick<Customer, 'id' | 'emailAddress' | 'firstName' | 'lastName'>>;
lines: Array<Pick<OrderLine, 'id'>>;
};
export type SetCustomerForOrderMutationVariables = Exact<{
input: CreateCustomerInput;
}>;
export type SetCustomerForOrderMutation = { __typename?: 'Mutation' } & {
setCustomerForOrder:
| ({ __typename: 'ActiveOrderCustomerFragment' } & Pick<ActiveOrderCustomerFragment, 'customer', 'lines'>)
| ({ __typename: 'AlreadyLoggedInError' } & Pick<
AlreadyLoggedInError,
'errorCode' | 'message'
>)
| ({ __typename: 'EmailAddressConflictError' } & Pick<
EmailAddressConflictError,
'errorCode' | 'message'
>)
| ({ __typename: 'NoActiveOrderError' } & Pick<
NoActiveOrderError,
'errorCode' | 'message'
>)
}
export type SetCustomerForOrderMutation = { __typename?: 'Mutation' } & {
setCustomerForOrder:
| ({ __typename: 'ActiveOrderCustomerFragment' } & Pick<ActiveOrderCustomerFragment, 'customer', 'lines'>)
| ({ __typename: 'AlreadyLoggedInError' } & Pick<
AlreadyLoggedInError,
'errorCode' | 'message'
>)
| ({ __typename: 'EmailAddressConflictError' } & Pick<
EmailAddressConflictError,
'errorCode' | 'message'
>)
| ({ __typename: 'NoActiveOrderError' } & Pick<
NoActiveOrderError,
'errorCode' | 'message'
>)
}
export type Address = Node & { export type Address = Node & {
updateCustomerAddress: updateCustomerAddress:
| { | {
__typename?: 'Address' __typename?: 'Address'
id: Scalars['ID'] id: Scalars['ID']
} }
@@ -1471,7 +1514,7 @@ export type CustomerListOptions = {
export type Customer = Node & { export type Customer = Node & {
updateCustomer: updateCustomer:
| { | {
__typename?: 'Customer' __typename?: 'Customer'
id: Scalars['ID'] id: Scalars['ID']
} }
@@ -1482,7 +1525,7 @@ export type Customer = Node & {
title?: Maybe<Scalars['String']> title?: Maybe<Scalars['String']>
firstName: Scalars['String'] firstName: Scalars['String']
lastName: Scalars['String'] lastName: Scalars['String']
phoneNumber?: Maybe<Scalars['String']> phoneNumber?: Maybe<Scalars['String']>
emailAddress: Scalars['String'] emailAddress: Scalars['String']
addresses?: Maybe<Array<Address>> addresses?: Maybe<Array<Address>>
orders: OrderList orders: OrderList
@@ -3017,56 +3060,56 @@ export type CartFragment = { __typename?: 'Order' } & Pick<
| 'totalWithTax' | 'totalWithTax'
| 'currencyCode' | 'currencyCode'
> & { > & {
customer?: Maybe<{ __typename?: 'Customer' } & Pick<Customer, 'id'>> customer?: Maybe<{ __typename?: 'Customer' } & Pick<Customer, 'id'>>
lines: Array< lines: Array<
{ __typename?: 'OrderLine' } & Pick< { __typename?: 'OrderLine' } & Pick<
OrderLine, OrderLine,
| 'id'
| 'quantity'
| 'linePriceWithTax'
| 'discountedLinePriceWithTax'
| 'unitPriceWithTax'
| 'discountedUnitPriceWithTax'
> & {
featuredAsset?: Maybe<
{ __typename?: 'Asset' } & Pick<Asset, 'id' | 'preview'>
>
discounts: Array<
{ __typename?: 'Discount' } & Pick<
Discount,
'description' | 'amount'
>
>
productVariant: { __typename?: 'ProductVariant' } & Pick<
ProductVariant,
| 'id' | 'id'
| 'quantity' | 'name'
| 'linePriceWithTax' | 'sku'
| 'discountedLinePriceWithTax' | 'price'
| 'unitPriceWithTax' | 'priceWithTax'
| 'discountedUnitPriceWithTax' | 'stockLevel'
> & { | 'productId'
featuredAsset?: Maybe< > & { product: { __typename?: 'Product' } & Pick<Product, 'slug'> }
{ __typename?: 'Asset' } & Pick<Asset, 'id' | 'preview'> }
> >
discounts: Array< }
{ __typename?: 'Discount' } & Pick<
Discount,
'description' | 'amount'
>
>
productVariant: { __typename?: 'ProductVariant' } & Pick<
ProductVariant,
| 'id'
| 'name'
| 'sku'
| 'price'
| 'priceWithTax'
| 'stockLevel'
| 'productId'
> & { product: { __typename?: 'Product' } & Pick<Product, 'slug'> }
}
>
}
export type SearchResultFragment = { __typename?: 'SearchResult' } & Pick< export type SearchResultFragment = { __typename?: 'SearchResult' } & Pick<
SearchResult, SearchResult,
'productId' | 'sku' | 'productName' | 'description' | 'slug' | 'sku' | 'currencyCode' 'productId' | 'sku' | 'productName' | 'description' | 'slug' | 'sku' | 'currencyCode'
| 'productAsset' | 'price' | 'priceWithTax' | 'currencyCode' | 'productAsset' | 'price' | 'priceWithTax' | 'currencyCode'
| 'collectionIds' | 'productVariantId' | 'facetValueIds' | "productVariantName" | 'collectionIds' | 'productVariantId' | 'facetValueIds' | "productVariantName"
> & { > & {
productAsset?: Maybe< productAsset?: Maybe<
{ __typename?: 'SearchResultAsset' } & Pick< { __typename?: 'SearchResultAsset' } & Pick<
SearchResultAsset, SearchResultAsset,
'id' | 'preview' 'id' | 'preview'
>
> >
priceWithTax: >
| ({ __typename?: 'PriceRange' } & Pick<PriceRange, 'min' | 'max'>) priceWithTax:
| ({ __typename?: 'SinglePrice' } & Pick<SinglePrice, 'value'>) | ({ __typename?: 'PriceRange' } & Pick<PriceRange, 'min' | 'max'>)
} | ({ __typename?: 'SinglePrice' } & Pick<SinglePrice, 'value'>)
}
export type AddItemToOrderMutationVariables = Exact<{ export type AddItemToOrderMutationVariables = Exact<{
variantId: Scalars['ID'] variantId: Scalars['ID']
@@ -3075,23 +3118,23 @@ export type AddItemToOrderMutationVariables = Exact<{
export type AddItemToOrderMutation = { __typename?: 'Mutation' } & { export type AddItemToOrderMutation = { __typename?: 'Mutation' } & {
addItemToOrder: addItemToOrder:
| ({ __typename: 'Order' } & CartFragment) | ({ __typename: 'Order' } & CartFragment)
| ({ __typename: 'OrderModificationError' } & Pick< | ({ __typename: 'OrderModificationError' } & Pick<
OrderModificationError, OrderModificationError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
| ({ __typename: 'OrderLimitError' } & Pick< | ({ __typename: 'OrderLimitError' } & Pick<
OrderLimitError, OrderLimitError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
| ({ __typename: 'NegativeQuantityError' } & Pick< | ({ __typename: 'NegativeQuantityError' } & Pick<
NegativeQuantityError, NegativeQuantityError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
| ({ __typename: 'InsufficientStockError' } & Pick< | ({ __typename: 'InsufficientStockError' } & Pick<
InsufficientStockError, InsufficientStockError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
} }
export type AdjustOrderLineMutationVariables = Exact<{ export type AdjustOrderLineMutationVariables = Exact<{
@@ -3101,23 +3144,23 @@ export type AdjustOrderLineMutationVariables = Exact<{
export type AdjustOrderLineMutation = { __typename?: 'Mutation' } & { export type AdjustOrderLineMutation = { __typename?: 'Mutation' } & {
adjustOrderLine: adjustOrderLine:
| ({ __typename: 'Order' } & CartFragment) | ({ __typename: 'Order' } & CartFragment)
| ({ __typename: 'OrderModificationError' } & Pick< | ({ __typename: 'OrderModificationError' } & Pick<
OrderModificationError, OrderModificationError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
| ({ __typename: 'OrderLimitError' } & Pick< | ({ __typename: 'OrderLimitError' } & Pick<
OrderLimitError, OrderLimitError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
| ({ __typename: 'NegativeQuantityError' } & Pick< | ({ __typename: 'NegativeQuantityError' } & Pick<
NegativeQuantityError, NegativeQuantityError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
| ({ __typename: 'InsufficientStockError' } & Pick< | ({ __typename: 'InsufficientStockError' } & Pick<
InsufficientStockError, InsufficientStockError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
} }
export type LoginMutationVariables = Exact<{ export type LoginMutationVariables = Exact<{
@@ -3127,49 +3170,49 @@ export type LoginMutationVariables = Exact<{
export type LoginMutation = { __typename?: 'Mutation' } & { export type LoginMutation = { __typename?: 'Mutation' } & {
login: login:
| ({ __typename: 'CurrentUser' } & Pick<CurrentUser, 'id'>) | ({ __typename: 'CurrentUser' } & Pick<CurrentUser, 'id'>)
| ({ __typename: 'InvalidCredentialsError' } & Pick< | ({ __typename: 'InvalidCredentialsError' } & Pick<
InvalidCredentialsError, InvalidCredentialsError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
| ({ __typename: 'NotVerifiedError' } & Pick< | ({ __typename: 'NotVerifiedError' } & Pick<
NotVerifiedError, NotVerifiedError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
| ({ __typename: 'NativeAuthStrategyError' } & Pick< | ({ __typename: 'NativeAuthStrategyError' } & Pick<
NativeAuthStrategyError, NativeAuthStrategyError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
} }
export type ResetPasswordMutation = { __typename?: 'Mutation' } & { export type ResetPasswordMutation = { __typename?: 'Mutation' } & {
resetPassword: resetPassword:
| ({ __typename: 'CurrentUser' } & Pick<CurrentUser, 'id'>) | ({ __typename: 'CurrentUser' } & Pick<CurrentUser, 'id'>)
| ({ __typename: 'PasswordResetTokenInvalidError' } & Pick< | ({ __typename: 'PasswordResetTokenInvalidError' } & Pick<
PasswordResetTokenInvalidError, PasswordResetTokenInvalidError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
| ({ __typename: 'PasswordResetTokenExpiredError' } & Pick< | ({ __typename: 'PasswordResetTokenExpiredError' } & Pick<
PasswordResetTokenExpiredError, PasswordResetTokenExpiredError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
| ({ __typename: 'NativeAuthStrategyError' } & Pick< | ({ __typename: 'NativeAuthStrategyError' } & Pick<
NativeAuthStrategyError, NativeAuthStrategyError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
} }
export type SignupMutation = { __typename?: 'Mutation' } & { export type SignupMutation = { __typename?: 'Mutation' } & {
registerCustomerAccount: registerCustomerAccount:
| ({ __typename: 'Success' } & Pick<Success, 'success'>) | ({ __typename: 'Success' } & Pick<Success, 'success'>)
| ({ __typename: 'MissingPasswordError' } & Pick< | ({ __typename: 'MissingPasswordError' } & Pick<
MissingPasswordError, MissingPasswordError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
| ({ __typename: 'NativeAuthStrategyError' } & Pick< | ({ __typename: 'NativeAuthStrategyError' } & Pick<
NativeAuthStrategyError, NativeAuthStrategyError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
} }
export type VerifyCustomerAccountVariables = Exact<{ export type VerifyCustomerAccountVariables = Exact<{
@@ -3179,27 +3222,27 @@ export type VerifyCustomerAccountVariables = Exact<{
export type VerifyCustomerAccountMutation = { __typename?: 'Mutation' } & { export type VerifyCustomerAccountMutation = { __typename?: 'Mutation' } & {
verifyCustomerAccount: verifyCustomerAccount:
| ({ __typename: 'CurrentUser' } & Pick<CurrentUser, 'id'>) | ({ __typename: 'CurrentUser' } & Pick<CurrentUser, 'id'>)
| ({ __typename: 'VerificationTokenInvalidError' } & Pick< | ({ __typename: 'VerificationTokenInvalidError' } & Pick<
VerificationTokenInvalidError, VerificationTokenInvalidError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
| ({ __typename: 'VerificationTokenExpiredError' } & Pick< | ({ __typename: 'VerificationTokenExpiredError' } & Pick<
VerificationTokenExpiredError, VerificationTokenExpiredError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
| ({ __typename: 'MissingPasswordError' } & Pick< | ({ __typename: 'MissingPasswordError' } & Pick<
MissingPasswordError, MissingPasswordError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
| ({ __typename: 'PasswordAlreadySetError' } & Pick< | ({ __typename: 'PasswordAlreadySetError' } & Pick<
PasswordAlreadySetError, PasswordAlreadySetError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
| ({ __typename: 'NativeAuthStrategyError' } & Pick< | ({ __typename: 'NativeAuthStrategyError' } & Pick<
NativeAuthStrategyError, NativeAuthStrategyError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
} }
export type LogoutMutationVariables = Exact<{ [key: string]: never }> export type LogoutMutationVariables = Exact<{ [key: string]: never }>
@@ -3214,11 +3257,11 @@ export type RemoveOrderLineMutationVariables = Exact<{
export type RemoveOrderLineMutation = { __typename?: 'Mutation' } & { export type RemoveOrderLineMutation = { __typename?: 'Mutation' } & {
removeOrderLine: removeOrderLine:
| ({ __typename: 'Order' } & CartFragment) | ({ __typename: 'Order' } & CartFragment)
| ({ __typename: 'OrderModificationError' } & Pick< | ({ __typename: 'OrderModificationError' } & Pick<
OrderModificationError, OrderModificationError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
} }
export type SignupMutationVariables = Exact<{ export type SignupMutationVariables = Exact<{
@@ -3228,15 +3271,15 @@ export type SignupMutationVariables = Exact<{
export type RequestPasswordReset = { __typename?: 'Mutation' } & { export type RequestPasswordReset = { __typename?: 'Mutation' } & {
requestPasswordReset: requestPasswordReset:
| ({ __typename: 'Success' } & Pick<Success, 'success'>) | ({ __typename: 'Success' } & Pick<Success, 'success'>)
| ({ __typename: 'MissingPasswordError' } & Pick< | ({ __typename: 'MissingPasswordError' } & Pick<
MissingPasswordError, MissingPasswordError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
| ({ __typename: 'NativeAuthStrategyError' } & Pick< | ({ __typename: 'NativeAuthStrategyError' } & Pick<
NativeAuthStrategyError, NativeAuthStrategyError,
'errorCode' | 'message' 'errorCode' | 'message'
>) >)
} }
@@ -3248,7 +3291,7 @@ export type ActiveCustomerQuery = { __typename?: 'Query' } & {
{ __typename?: 'Customer' } & Pick< { __typename?: 'Customer' } & Pick<
Customer, Customer,
Favorite, Favorite,
'id' | 'firstName' | 'lastName' | 'emailAddress' | 'addresses' | 'phoneNumber'| 'orders' 'id' | 'firstName' | 'lastName' | 'emailAddress' | 'addresses' | 'phoneNumber' | 'orders'
> >
> >
} }
@@ -3267,7 +3310,7 @@ export type FavoriteList = PaginatedList & {
totalItems: Int! totalItems: Int!
} }
type Favorite = Node & { type Favorite = Node & {
id: ID! id: ID!
createdAt: DateTime! createdAt: DateTime!
updatedAt: DateTime! updatedAt: DateTime!
@@ -3277,7 +3320,7 @@ type Favorite = Node & {
type FavouriteOption = Customer & { type FavouriteOption = Customer & {
favorites(options: FavoriteListOptions): FavoriteList! favorites(options: FavoriteListOptions): FavoriteList!
} }
@@ -3308,13 +3351,13 @@ export type GetAllFacetsQuery = { __typename?: 'Query' } & {
{ __typename?: 'Facet' } & Pick< { __typename?: 'Facet' } & Pick<
Facet, Facet,
'id' | 'name' | 'code' | 'values' 'id' | 'name' | 'code' | 'values'
> >
& { & {
parent?: Maybe<{ __typename?: 'Facet' } & Pick<Facet, 'id'>> parent?: Maybe<{ __typename?: 'Facet' } & Pick<Facet, 'id'>>
children?: Maybe< children?: Maybe<
Array<{ __typename?: 'Facet' } & Pick<Facet, 'id'>> Array<{ __typename?: 'Facet' } & Pick<Facet, 'id'>>
> >
} }
>, >,
'totalItems' 'totalItems'
} }
@@ -3327,11 +3370,11 @@ export type GetAllCollectionsQuery = { __typename?: 'Query' } & {
Collection, Collection,
'id' | 'name' | 'slug' 'id' | 'name' | 'slug'
> & { > & {
parent?: Maybe<{ __typename?: 'Collection' } & Pick<Collection, 'id'>> parent?: Maybe<{ __typename?: 'Collection' } & Pick<Collection, 'id'>>
children?: Maybe< children?: Maybe<
Array<{ __typename?: 'Collection' } & Pick<Collection, 'id'>> Array<{ __typename?: 'Collection' } & Pick<Collection, 'id'>>
> >
} }
>, >,
'totalItems' 'totalItems'
} }
@@ -3352,15 +3395,15 @@ export type GetCollectionsQuery = { __typename?: 'Query' } & {
Collection, Collection,
'id' | 'name' | 'description' | 'slug' 'id' | 'name' | 'description' | 'slug'
> & { > & {
productVariants: { __typename?: 'ProductVariantList' } & Pick< productVariants: { __typename?: 'ProductVariantList' } & Pick<
ProductVariantList, ProductVariantList,
'totalItems' 'totalItems'
> >
parent?: Maybe<{ __typename?: 'Collection' } & Pick<Collection, 'id'>> parent?: Maybe<{ __typename?: 'Collection' } & Pick<Collection, 'id'>>
children?: Maybe< children?: Maybe<
Array<{ __typename?: 'Collection' } & Pick<Collection, 'id'>> Array<{ __typename?: 'Collection' } & Pick<Collection, 'id'>>
> >
} }
> >
} }
} }
@@ -3375,60 +3418,60 @@ export type GetProductQuery = { __typename?: 'Query' } & {
Product, Product,
'id' | 'name' | 'slug' | 'description' 'id' | 'name' | 'slug' | 'description'
> & { > & {
assets: Array< assets: Array<
{ __typename?: 'Asset' } & Pick<Asset, 'id' | 'preview' | 'name'> { __typename?: 'Asset' } & Pick<Asset, 'id' | 'preview' | 'name'>
> >
variants: Array< variants: Array<
{ __typename?: 'ProductVariant' } & Pick< { __typename?: 'ProductVariant' } & Pick<
ProductVariant, ProductVariant,
'id' | 'priceWithTax' | 'currencyCode' | 'price' | "name" 'id' | 'priceWithTax' | 'currencyCode' | 'price' | "name"
> & { > & {
options: Array< options: Array<
{ __typename?: 'ProductOption' } & Pick< { __typename?: 'ProductOption' } & Pick<
ProductOption, ProductOption,
'id' | 'name' | 'code' | 'groupId' 'id' | 'name' | 'code' | 'groupId'
> & { > & {
group: { __typename?: 'ProductOptionGroup' } & Pick< group: { __typename?: 'ProductOptionGroup' } & Pick<
ProductOptionGroup, ProductOptionGroup,
'id' 'id'
> & { > & {
options: Array< options: Array<
{ __typename?: 'ProductOption' } & Pick< { __typename?: 'ProductOption' } & Pick<
ProductOption, ProductOption,
'name' 'name'
> >
>
}
}
>
}
>
optionGroups: Array<
{ __typename?: 'ProductOptionGroup' } & Pick<
ProductOptionGroup,
'id' | 'code' | 'name'
> & {
options: Array<
{ __typename?: 'ProductOption' } & Pick<
ProductOption,
'id' | 'name'
> >
> }
} }
>
facetValues: Array<
{ __typename?: 'FacetValue' } & Pick<
FacetValue,
'id'
> >
> }
collections: Array< >
{ __typename?: 'Collection' } & Pick< optionGroups: Array<
Collection, { __typename?: 'ProductOptionGroup' } & Pick<
'id'|"name" ProductOptionGroup,
'id' | 'code' | 'name'
> & {
options: Array<
{ __typename?: 'ProductOption' } & Pick<
ProductOption,
'id' | 'name'
>
> >
}
>
facetValues: Array<
{ __typename?: 'FacetValue' } & Pick<
FacetValue,
'id'
> >
} >
collections: Array<
{ __typename?: 'Collection' } & Pick<
Collection,
'id' | "name"
>
>
}
> >
} }

View File

@@ -0,0 +1,24 @@
export const setCustomerForOrderMutation = /* GraphQL */ `
mutation setCustomerForOrder($input: CreateCustomerInput!) {
setCustomerForOrder(input: $input) {
__typename
... on Order {
id
createdAt
updatedAt
code
customer {
id
firstName
lastName
emailAddress
phoneNumber
}
}
... on ErrorResult {
errorCode
message
}
}
}
`

View File

@@ -2,8 +2,9 @@
"name": "nextjs-commerce", "name": "nextjs-commerce",
"version": "1.0.0", "version": "1.0.0",
"scripts": { "scripts": {
"dev": "NODE_OPTIONS='--inspect' PORT=3005 next dev", "dev": "set NODE_OPTIONS='--inspect' && set PORT=3005 && next dev",
"dev-windows": "set NODE_OPTIONS='--inspect' && set PORT=3005 && next dev", "dev-windows": "set NODE_OPTIONS='--inspect' && set PORT=3005 && next dev",
"dev-macos": "set NODE_OPTIONS='--inspect' && set PORT=3005 && next dev",
"build": "next build", "build": "next build",
"start": "PORT=3005 next start", "start": "PORT=3005 next start",
"analyze": "BUNDLE_ANALYZE=both yarn build", "analyze": "BUNDLE_ANALYZE=both yarn build",

View File

@@ -4,7 +4,8 @@ import { CheckoutPage } from 'src/components/modules/checkout';
export default function Checkout() { export default function Checkout() {
return ( return (
<> <>
<CheckoutPage/> <CheckoutPage />
</> </>
) )
} }

View File

@@ -1,7 +1,6 @@
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import { FC } from 'react' import { FC } from 'react'
import { useMessage } from 'src/components/contexts' import { useMessage } from 'src/components/contexts'
import { useModalCommon } from 'src/components/hooks'
import { FILTER_PAGE, ROUTE } from 'src/utils/constanst.utils' import { FILTER_PAGE, ROUTE } from 'src/utils/constanst.utils'
import { CartDrawer, Footer, MessageCommon, ScrollToTop } from '../..' import { CartDrawer, Footer, MessageCommon, ScrollToTop } from '../..'
import Header from '../../Header/Header' import Header from '../../Header/Header'

View File

@@ -1,3 +1,4 @@
import { MessageProvider } from 'src/components/contexts'
import s from './LayoutCheckout.module.scss' import s from './LayoutCheckout.module.scss'
interface Props { interface Props {
@@ -6,14 +7,18 @@ interface Props {
const LayoutCheckout = ({ children }: Props) => { const LayoutCheckout = ({ children }: Props) => {
return ( return (
<div className={s.layoutCheckout}> <>
<main>{children}</main> <MessageProvider>
<footer className={s.footer}> <div className={s.layoutCheckout}>
<div> <main>{children}</main>
© 2021 Online Grocery <footer className={s.footer}>
<div>
© 2021 Online Grocery
</div>
</footer>
</div> </div>
</footer> </MessageProvider>
</div> </>
) )
} }

View File

@@ -1,4 +1,4 @@
import React, { memo, useEffect } from 'react' import React, { memo } from 'react'
import s from './MessageCommon.module.scss' import s from './MessageCommon.module.scss'
import MessageItem, { MessageItemProps } from './MessageItem/MessageItem' import MessageItem, { MessageItemProps } from './MessageItem/MessageItem'

View File

@@ -6,7 +6,7 @@ export type MessageContextType = {
removeMessage: (id: number) => void removeMessage: (id: number) => void
showMessageSuccess: (content: string, timeout?: number) => void showMessageSuccess: (content: string, timeout?: number) => void
showMessageInfo: (content: string, timeout?: number) => void showMessageInfo: (content: string, timeout?: number) => void
showMessageError: (content: string, timeout?: number) => void showMessageError: (content?: string, timeout?: number) => void
showMessageWarning: (content: string, timeout?: number) => void showMessageWarning: (content: string, timeout?: number) => void
} }
export const DEFAULT_MESSAGE_CONTEXT: MessageContextType = { export const DEFAULT_MESSAGE_CONTEXT: MessageContextType = {

View File

@@ -1,5 +1,6 @@
import { ReactNode, useCallback, useState } from 'react' import { ReactNode, useState } from 'react'
import { MessageItemProps } from 'src/components/common/MessageCommon/MessageItem/MessageItem' import { MessageItemProps } from 'src/components/common/MessageCommon/MessageItem/MessageItem'
import { LANGUAGE } from 'src/utils/language.utils'
import { MessageContext } from './MessageContext' import { MessageContext } from './MessageContext'
type Props = { type Props = {
@@ -33,8 +34,8 @@ export function MessageProvider({ children }: Props) {
createNewMessage(content, timeout, 'info') createNewMessage(content, timeout, 'info')
} }
const showMessageError = (content: string, timeout?: number) => { const showMessageError = (content?: string, timeout?: number) => {
createNewMessage(content, timeout, 'error') createNewMessage(content || LANGUAGE.MESSAGE.ERROR, timeout, 'error')
} }
const showMessageWarning = (content: string, timeout?: number) => { const showMessageWarning = (content: string, timeout?: number) => {

View File

@@ -1,4 +1,3 @@
import { Cart } from '@commerce/types/cart'
import { ActiveOrderQuery } from '@framework/schema' import { ActiveOrderQuery } from '@framework/schema'
import { cartFragment } from '@framework/utils/fragments/cart-fragment' import { cartFragment } from '@framework/utils/fragments/cart-fragment'
import { normalizeCart } from '@framework/utils/normalize' import { normalizeCart } from '@framework/utils/normalize'

View File

@@ -0,0 +1,2 @@
export { default as useSetCustomerForOrder } from './useSetCustomerForOrder'

View File

@@ -0,0 +1,47 @@
import { CreateCustomerInput, SetCustomerForOrderMutation } from '@framework/schema'
import { setCustomerForOrderMutation } from '@framework/utils/mutations/set-customer-order-mutation'
import { useState } from 'react'
import { CommonError } from 'src/domains/interfaces/CommonError'
import rawFetcher from 'src/utils/rawFetcher'
import { useGetActiveOrder } from '../cart'
const useSetCustomerForOrder = () => {
const [loading, setLoading] = useState(false)
const [error, setError] = useState<CommonError | null>(null)
const { mutate } = useGetActiveOrder()
const setCustomerForOrder = (input: CreateCustomerInput,
fCallBack: (isSuccess: boolean, message?: string) => void
) => {
setError(null)
setLoading(true)
rawFetcher<SetCustomerForOrderMutation>({
query: setCustomerForOrderMutation,
variables: {input},
})
.then(({ data, headers }) => {
console.log("data here: ", data)
if (data.setCustomerForOrder.__typename === 'ActiveOrderCustomerFragment') {
console.log("success: ")
fCallBack(true)
mutate()
} else {
console.log("fail ")
fCallBack(false, data.setCustomerForOrder.message)
}
})
.catch((error) => {
setError(error)
fCallBack(false, error.message)
})
.finally(() => setLoading(false))
}
return { loading, setCustomerForOrder, error }
}
export default useSetCustomerForOrder

View File

@@ -2,6 +2,8 @@ import Link from 'next/link'
import React, { useRef } from 'react' import React, { useRef } from 'react'
import { ButtonCommon, Inputcommon } from 'src/components/common' import { ButtonCommon, Inputcommon } from 'src/components/common'
import InputCommon from 'src/components/common/InputCommon/InputCommon' import InputCommon from 'src/components/common/InputCommon/InputCommon'
import { useMessage } from 'src/components/contexts'
import { useSetCustomerForOrder } from 'src/components/hooks/order'
import { ROUTE } from 'src/utils/constanst.utils' import { ROUTE } from 'src/utils/constanst.utils'
import { CheckOutForm } from 'src/utils/types.utils' import { CheckOutForm } from 'src/utils/types.utils'
import s from './CustomerInfoForm.module.scss' import s from './CustomerInfoForm.module.scss'
@@ -13,13 +15,26 @@ interface CustomerInfoFormProps {
const CustomerInfoForm = ({ id, onConfirm }: CustomerInfoFormProps) => { const CustomerInfoForm = ({ id, onConfirm }: CustomerInfoFormProps) => {
const nameRef = useRef<React.ElementRef<typeof InputCommon>>(null) const nameRef = useRef<React.ElementRef<typeof InputCommon>>(null)
const emailRef = useRef<React.ElementRef<typeof InputCommon>>(null) const emailRef = useRef<React.ElementRef<typeof InputCommon>>(null)
const { setCustomerForOrder, loading } = useSetCustomerForOrder()
const { showMessageError } = useMessage()
const handleConfirmClick = () => { const handleConfirmClick = () => {
onConfirm && setCustomerForOrder({ firstName: 'Ly', lastName: 'Tran', emailAddress: 'test7@gmail.com' }, onSubmitCalBack)
onConfirm(id, { // onConfirm &&
name: nameRef?.current?.getValue().toString(), // onConfirm(id, {
email: emailRef.current?.getValue().toString(), // name: nameRef?.current?.getValue().toString(),
}) // email: emailRef.current?.getValue().toString(),
// })
}
const onSubmitCalBack = (isSuccess: boolean, msg?: string) => {
// TODO:
if (isSuccess) {
} else {
console.log("error here")
showMessageError(msg)
}
} }
return ( return (

View File

@@ -1,5 +1,7 @@
import classNames from 'classnames' import classNames from 'classnames'
import React, { useState } from 'react' import React, { useState } from 'react'
import { MessageCommon } from 'src/components/common'
import { useMessage } from 'src/components/contexts'
import IconHide from 'src/components/icons/IconHide' import IconHide from 'src/components/icons/IconHide'
import { CHECKOUT_BILL_DATA } from 'src/utils/demo-data' import { CHECKOUT_BILL_DATA } from 'src/utils/demo-data'
import { CheckoutBill, CheckoutInfo } from '..' import { CheckoutBill, CheckoutInfo } from '..'
@@ -8,7 +10,9 @@ interface CheckoutPageProps {
} }
const CheckoutPage = ({}: CheckoutPageProps) => { const CheckoutPage = ({}: CheckoutPageProps) => {
const { messages, removeMessage } = useMessage()
const [isShow, setIsShow] = useState(false) const [isShow, setIsShow] = useState(false)
const onClose = () => { const onClose = () => {
setIsShow(false) setIsShow(false)
} }
@@ -17,6 +21,7 @@ const CheckoutPage = ({}: CheckoutPageProps) => {
} }
return ( return (
<div className={s.warrper}> <div className={s.warrper}>
<MessageCommon messages={messages} onRemove={removeMessage} />
<div className={s.left}><CheckoutInfo onViewCart = {onViewCart}/></div> <div className={s.left}><CheckoutInfo onViewCart = {onViewCart}/></div>
<div className={s.right}><CheckoutBill data={CHECKOUT_BILL_DATA}/></div> <div className={s.right}><CheckoutBill data={CHECKOUT_BILL_DATA}/></div>
<div className={classNames({ [s.mobile] :true,[s.isShow]: isShow})}> <div className={classNames({ [s.mobile] :true,[s.isShow]: isShow})}>