mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 12:24:18 +00:00
bug: fix bug conflict
This commit is contained in:
6
framework/vendure/schema.d.ts
vendored
6
framework/vendure/schema.d.ts
vendored
@@ -3247,9 +3247,9 @@ export type ActiveCustomerQuery = { __typename?: 'Query' } & {
|
||||
activeCustomer?: Maybe<
|
||||
{ __typename?: 'Customer' } & Pick<
|
||||
Customer,
|
||||
FavoriteList,
|
||||
'id' | 'firstName' | 'lastName' | 'emailAddress' | 'favorites'
|
||||
>,
|
||||
Favorite,
|
||||
'id' | 'firstName' | 'lastName' | 'emailAddress' | 'addresses' | 'phoneNumber'| 'orders'
|
||||
>
|
||||
>
|
||||
}
|
||||
|
||||
|
@@ -1,17 +1,24 @@
|
||||
export const activeCustomerQuery = /* GraphQL */ `
|
||||
query activeCustomer {
|
||||
activeCustomer {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
emailAddress
|
||||
favorites{
|
||||
items{
|
||||
product{
|
||||
id
|
||||
}
|
||||
query activeCustomer {
|
||||
activeCustomer {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
emailAddress
|
||||
favorites{
|
||||
items{
|
||||
product{
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
phoneNumber
|
||||
addresses{
|
||||
streetLine1
|
||||
city
|
||||
province
|
||||
postalCode
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
19
framework/vendure/utils/queries/get-user-order-query.ts
Normal file
19
framework/vendure/utils/queries/get-user-order-query.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export const getUserOrderQuery = /* GraphQL */ `
|
||||
query activeCustomer {
|
||||
activeCustomer {
|
||||
orders{
|
||||
items{
|
||||
lines{
|
||||
productVariant{
|
||||
name
|
||||
}
|
||||
quantity
|
||||
}
|
||||
total
|
||||
state
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
@@ -1 +1,4 @@
|
||||
export { default as useGetFavoriteProduct } from './useGetFavoriteProduct'
|
||||
export { default as useGetFavoriteProduct } from './useGetFavoriteProduct'
|
||||
export { default as useGetUserOrder } from './useGetUserOrder';
|
||||
export { default as useEditUserInfo } from './useEditUserInfo'
|
||||
export { default as useEditCustomerAddress } from './useEditCustomerAddress'
|
||||
|
@@ -4,9 +4,8 @@ import { getFavoriteProductQuery } from '@framework/utils/queries/get-favorite-p
|
||||
import gglFetcher from 'src/utils/gglFetcher'
|
||||
import useSWR from 'swr'
|
||||
|
||||
const useGetFavoriteProduct = (options:QueryFavorite) => {
|
||||
const useGetFavoriteProduct = (options?:QueryFavorite) => {
|
||||
const { data, ...rest } = useSWR<ActiveCustomerQuery>([getFavoriteProductQuery, options], gglFetcher)
|
||||
// console.log( data?.activeCustomer?.favorites?.items);
|
||||
return {
|
||||
itemWishlist: data?.activeCustomer?.favorites?.items?.map((item:Favorite) => normalizeFavoriteProductResult(item)),
|
||||
totalItems: data?.activeCustomer?.favorites?.totalItems,
|
||||
|
20
src/components/hooks/account/useGetUserOrder.tsx
Normal file
20
src/components/hooks/account/useGetUserOrder.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import { ActiveCustomerQuery, Order } from '@framework/schema'
|
||||
import { getUserOrderQuery } from '@framework/utils/queries/get-user-order-query'
|
||||
import gglFetcher from 'src/utils/gglFetcher'
|
||||
import useSWR from 'swr'
|
||||
|
||||
const useGetUserOrder = () => {
|
||||
const { data, ...rest } = useSWR<ActiveCustomerQuery>([getUserOrderQuery], gglFetcher)
|
||||
|
||||
const addingItem = data?.activeCustomer?.orders.items.filter((val:Order) =>val.state == 'AddingItems');
|
||||
const arrangingPayment = data?.activeCustomer?.orders.items.filter((val:Order) =>val.state == 'ArrangingPayment');
|
||||
const cancelled = data?.activeCustomer?.orders.items.filter((val:Order) =>val.state == "Cancelled");
|
||||
return {
|
||||
addingItem: addingItem,
|
||||
arrangingPayment: arrangingPayment,
|
||||
cancelled: cancelled,
|
||||
...rest
|
||||
}
|
||||
}
|
||||
|
||||
export default useGetUserOrder
|
@@ -5,7 +5,6 @@ import useSWR from 'swr'
|
||||
|
||||
const useActiveCustomer = () => {
|
||||
const { data, ...rest } = useSWR<ActiveCustomerQuery>([activeCustomerQuery], gglFetcher)
|
||||
|
||||
return {
|
||||
customer: data?.activeCustomer,
|
||||
userInfo:{
|
||||
@@ -15,7 +14,6 @@ const useActiveCustomer = () => {
|
||||
phoneNumber: data?.activeCustomer?.phoneNumber,
|
||||
address: data?.activeCustomer?.addresses?.[0]
|
||||
},
|
||||
itemWishlist:data?.activeCustomer?.favorites?.items,
|
||||
wishlistId: data?.activeCustomer?.favorites?.items.map((val:Favorite)=>val.product.id),
|
||||
...rest
|
||||
}
|
||||
|
@@ -1,4 +1,2 @@
|
||||
export { default as useModalCommon } from './useModalCommon'
|
||||
export { default as useEditUserInfo } from './account/useEditUserInfo'
|
||||
export { default as useEditCustomerAddress } from './account/useEditCustomerAddress'
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { useState } from 'react'
|
||||
import useActiveCustomer from '../auth/useActiveCustomer'
|
||||
import useGetFavoriteProduct from '../account/useGetFavoriteProduct'
|
||||
import { FavoriteList } from '@framework/schema'
|
||||
import fetcher from 'src/utils/fetcher'
|
||||
import { CommonError } from 'src/domains/interfaces/CommonError'
|
||||
@@ -12,7 +12,7 @@ interface Props {
|
||||
const useToggleProductWishlist = () => {
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState<Error | null>(null)
|
||||
const { mutate } = useActiveCustomer()
|
||||
const { mutate } = useGetFavoriteProduct();
|
||||
|
||||
const onToggleProductWishlist = (
|
||||
{ productId }:Props ,
|
||||
@@ -29,7 +29,7 @@ const useToggleProductWishlist = () => {
|
||||
.then((data) => {
|
||||
mutate()
|
||||
fCallBack(true)
|
||||
return data
|
||||
return data
|
||||
})
|
||||
.catch((error) => {
|
||||
setError(error)
|
||||
|
@@ -1,13 +1,11 @@
|
||||
import { QueryFavorite } from "@framework/schema"
|
||||
import commerce from '@lib/api/commerce'
|
||||
import { GetStaticPropsContext } from 'next'
|
||||
import { useRouter } from "next/router"
|
||||
import React, { useEffect, useState } from "react"
|
||||
import { HeadingCommon, TabPane } from "src/components/common"
|
||||
import { useGetFavoriteProduct } from 'src/components/hooks/account'
|
||||
import { useGetFavoriteProduct, useGetUserOrder } from 'src/components/hooks/account'
|
||||
import { useActiveCustomer } from 'src/components/hooks/auth'
|
||||
import { ACCOUNT_TAB, DEFAULT_PAGE_SIZE, QUERY_KEY } from "src/utils/constanst.utils"
|
||||
import { getPageFromQuery } from 'src/utils/funtion.utils'
|
||||
import { PromiseWithKey } from 'src/utils/types.utils'
|
||||
import AccountNavigation from '../AccountNavigation/AccountNavigation'
|
||||
import s from './AccountPage.module.scss'
|
||||
import AccountInfomation from "./components/AccountInfomation/AccountInfomation"
|
||||
@@ -28,6 +26,8 @@ const waiting = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
|
||||
const delivering = [
|
||||
{
|
||||
id: "NO 123456",
|
||||
@@ -81,7 +81,9 @@ const AccountPage = ({ defaultActiveContent="orders" } : AccountPageProps) => {
|
||||
const router = useRouter()
|
||||
|
||||
const {userInfo} = useActiveCustomer();
|
||||
|
||||
|
||||
const {addingItem,arrangingPayment,cancelled} = useGetUserOrder();
|
||||
|
||||
|
||||
const [activeTab, setActiveTab] = useState(defaultActiveContent==="info" ? 0 : defaultActiveContent==="orders" ? 1 : 2)
|
||||
const [modalVisible, setModalVisible] = useState(false);
|
||||
@@ -125,7 +127,7 @@ const AccountPage = ({ defaultActiveContent="orders" } : AccountPageProps) => {
|
||||
<AccountInfomation account={userInfo} onClick={showModal} />
|
||||
</TabPane>
|
||||
<TabPane tabName="Your Orders">
|
||||
<OrderInfomation waiting={waiting} delivering={delivering} delivered={delivered} />
|
||||
<OrderInfomation addingItem={addingItem} arrangingPayment={arrangingPayment} cancelled={cancelled} />
|
||||
</TabPane>
|
||||
<TabPane tabName="Favourite">
|
||||
<FavouriteProducts products={itemWishlist} totalItems={totalItems} />
|
||||
|
@@ -8,7 +8,7 @@ import {
|
||||
} from 'src/components/common'
|
||||
import * as Yup from 'yup'
|
||||
import { Form, Formik } from 'formik'
|
||||
import { useEditCustomerAddress, useEditUserInfo } from "src/components/hooks";
|
||||
import { useEditCustomerAddress, useEditUserInfo } from "src/components/hooks/account";
|
||||
import { LANGUAGE } from 'src/utils/language.utils'
|
||||
import { useMessage } from 'src/components/contexts'
|
||||
interface EditInfoModalProps {
|
||||
|
@@ -4,50 +4,50 @@ import s from './OrderInformation.module.scss'
|
||||
import { TabCommon } from '../../../../../common'
|
||||
import TabPane from 'src/components/common/TabCommon/components/TabPane/TabPane'
|
||||
import DeliveryItem from '../../../DeliveryItem/DeliveryItem'
|
||||
import { Order } from "@framework/schema"
|
||||
|
||||
|
||||
interface OrderInformationProps {
|
||||
waiting: {id: string, products: string[], totalPrice: number}[],
|
||||
delivering: {id: string, products: string[], totalPrice: number}[],
|
||||
delivered: {id: string, products: string[], totalPrice: number}[],
|
||||
addingItem?: Order[],
|
||||
arrangingPayment?: Order[],
|
||||
cancelled?: Order[],
|
||||
}
|
||||
|
||||
const OrderInformation = ({ waiting, delivering, delivered} : OrderInformationProps) => {
|
||||
|
||||
const OrderInformation = ({ addingItem, arrangingPayment, cancelled} : OrderInformationProps) => {
|
||||
return (
|
||||
<section className={s.orderInformation}>
|
||||
<div className={s.title}>Order Information</div>
|
||||
|
||||
<div className={s.tabs}>
|
||||
<TabCommon>
|
||||
<TabPane tabName={"Wait for Comfirmation"} >
|
||||
<TabPane tabName={"Adding Item"} >
|
||||
<div className={s.blank}></div>
|
||||
{
|
||||
waiting.map((order, i) => {
|
||||
addingItem?.map((order, i) => {
|
||||
return (
|
||||
<DeliveryItem key={order.id} id={order.id} status="waiting" products={order.products} totalPrice={order.totalPrice} />
|
||||
<DeliveryItem key={order.code} id={order.code} status="waiting" products={order.lines} totalPrice={order.total} />
|
||||
)
|
||||
})
|
||||
}
|
||||
</TabPane>
|
||||
|
||||
<TabPane tabName={"Delivering"}>
|
||||
<TabPane tabName={"Arranging Payment"}>
|
||||
<div className={s.blank}></div>
|
||||
{
|
||||
delivering.map((order, i) => {
|
||||
arrangingPayment?.map((order, i) => {
|
||||
return (
|
||||
<DeliveryItem key={order.id} id={order.id} status="delivering" products={order.products} totalPrice={order.totalPrice} />
|
||||
<DeliveryItem key={order.id} id={order.id} status="delivering" products={order.lines} totalPrice={order.total} />
|
||||
)
|
||||
})
|
||||
}
|
||||
</TabPane>
|
||||
|
||||
<TabPane tabName={"Delivered"}>
|
||||
<TabPane tabName={"Cancelled"}>
|
||||
<div className={s.blank}></div>
|
||||
{
|
||||
delivered.map((order, i) => {
|
||||
cancelled?.map((order, i) => {
|
||||
return (
|
||||
<DeliveryItem key={order.id} id={order.id} status="delivered" products={order.products} totalPrice={order.totalPrice} />
|
||||
<DeliveryItem key={order.id} id={order.id} status="delivered" products={order.lines} totalPrice={order.total} />
|
||||
)
|
||||
})
|
||||
}
|
||||
|
@@ -5,12 +5,13 @@ import IdAndStatus from './components/IdAndStatus/IdAndStatus'
|
||||
import Products from './components/Products/Products'
|
||||
import TotalPrice from './components/TotalPrice/TotalPrice'
|
||||
import ReOrder from './components/ReOrder/ReOrder'
|
||||
import { OrderLine } from "@framework/schema"
|
||||
|
||||
|
||||
interface DeliveryItemProps {
|
||||
id: string;
|
||||
status: "waiting" | "delivering" | "delivered";
|
||||
products: string[];
|
||||
products?: OrderLine[];
|
||||
totalPrice: number;
|
||||
}
|
||||
|
||||
|
@@ -1,19 +1,19 @@
|
||||
import { OrderLine } from "@framework/schema";
|
||||
import React from "react"
|
||||
import s from './Products.module.scss'
|
||||
|
||||
interface ProductsProps {
|
||||
products: string[];
|
||||
products?: OrderLine[];
|
||||
}
|
||||
|
||||
const Products = ({ products } : ProductsProps) => {
|
||||
|
||||
function toString(products:string[]): string {
|
||||
function toString(products?:OrderLine[]): string {
|
||||
let strProducts = "";
|
||||
products.map((prod, i) => {
|
||||
products?.map((prod, i) => {
|
||||
if (i === 0) {
|
||||
strProducts += prod;
|
||||
strProducts += prod.productVariant?.name;
|
||||
} else {
|
||||
strProducts += `, ${prod}`
|
||||
strProducts += `, ${prod.productVariant?.name}`
|
||||
}
|
||||
});
|
||||
return strProducts;
|
||||
|
Reference in New Issue
Block a user