Jelajahi Sumber

删除购物车产品时弹窗确认弹窗;删除注释代码;

fogwind 6 hari lalu
induk
melakukan
2b05581df8

+ 6 - 0
src/app/(checkout)/checkout/_components/CheckoutProducts/CheckoutProducts.tsx

@@ -9,6 +9,7 @@ import { useCustomToast } from "@/utils/hooks/useToast";
 import {useConfig} from "@/utils/hooks/useConfig";
 import { formatCartDetail } from "@/utils/cartDetailTools";
 import { overlayLoading } from "@/components/theme/ui/kernel/loading/api";
+import { confirmDialog } from "@/components/theme/ui/kernel/confirm/api";
 import CommonModal from "@/components/theme/ui/CommonModal";
 
 
@@ -50,6 +51,11 @@ export default function CheckoutProducts({
         // 删除商品;购物车是否还有商品,没有的话:
         // 登录用户 跳转到空购物车页面或首页
         // 游客  清除cookie 跳转到首页或空购物车页面
+        const confirmres = await confirmDialog({
+            title: "Warning",
+            content: "Are you sure you want to delete this product.",
+        });
+        if(!confirmres) return; // 取消删除
         overlayLoading.start();
         const res = await deleteProductFromCart(Number(cartItemId));
         if(!res.error) {

+ 1 - 1
src/app/(checkout)/checkout/_components/RewardPointsRedeemMoney/RewardPointsRedeemMoney.tsx

@@ -65,7 +65,7 @@ export default function RewardPointsRedeemMoney({
                 if(res.mergeCartSuccess) { // 购物车合并成功
                     if(res.cartAfterMerge) {
                         const newCartDetail = formatCartDetail(res.cartAfterMerge);
-                        onPointsChange(newCartDetail, false);
+                        onPointsChange(newCartDetail);
                     }
                     
                 } else { // 购物车合并失败

+ 6 - 0
src/app/(checkout)/checkout/cart/_components/CartWrapper.tsx

@@ -122,6 +122,12 @@ export function CartWrapper({
         // 删除商品;购物车是否还有商品,没有的话:
         // 登录用户 跳转到空购物车页面或首页
         // 游客  清除cookie 跳转到首页或空购物车页面
+        const confirmres = await confirmDialog({
+            title: "Warning",
+            content: "Are you sure you want to delete this product.",
+        });
+        if(!confirmres) return; // 取消删除
+
         overlayLoading.start();
         const res = await deleteProductFromCart(Number(cartItemId));
         if(!res.error) {

+ 2 - 2
src/app/(checkout)/checkout/cart/page.tsx

@@ -33,10 +33,10 @@ export default async function CheckoutPage() {
     if(cartDetails) {
         cartDatahash = createHash('sha256').update(JSON.stringify(cartDetails)).digest('hex');
     }
-    
+    const title = "My Cart" + (cartDetails?.itemsQty ? ' ('+cartDetails?.itemsQty+')' : '');
     return (
         <>
-            <TitleHeader title="My Cart" />
+            <TitleHeader title={title} />
             <PromiseInCart />
             {!cartDetails && 
                 <EmptyCart 

+ 3 - 14
src/app/(public)/page.tsx

@@ -1,9 +1,3 @@
-// import { GET_THEME_CUSTOMIZATION } from "@/graphql";
-// import RenderThemeCustomization from "@components/home/RenderThemeCustomization";
-// import HomeImageBanner from "@components/home/HomeImageBanner";
-// import { ThemeCustomizationResponse } from "@/types/theme/theme-customization";
-// import { cachedGraphQLRequest } from "@/utils/hooks/useCache";
-import { DatePicker } from "@heroui/date-picker";
 import HomeContent from "./_components/HomeContent";
 import { restApiFetch } from "@utils/bagisto/index";
 import {HomeApiData} from "@/types/home/type"
@@ -11,12 +5,7 @@ export const revalidate = 3600;
 
 
 export default async function Home() {
-  // const
-  // const {data} = await cachedGraphQLRequest<ThemeCustomizationResponse>(
-  //   "home",
-  //   GET_THEME_CUSTOMIZATION,
-  //   { first: 20 }
-  // );
+
 // 2. 服务端 fetch 请求我们自己的 Next.js API
 const res = await restApiFetch({
   api: `/home`,
@@ -31,8 +20,8 @@ const homeData: HomeApiData = res.body.data;
   return (
     <>
       {/* <HomeImageBanner /> */}
-      <DatePicker label={"Birth date"} labelPlacement={"outside"} />
-      {/* <RenderThemeCustomization themeCustomizations={data?.themeCustomizations ?? {edges: []}} /> */}
+
+
       <HomeContent homeData={homeData} />
     </>
   );

+ 6 - 29
src/app/(public)/product/[...urlProduct]/page.tsx

@@ -1,9 +1,5 @@
 import { notFound } from "next/navigation";
 import { Suspense } from "react";
-// import clsx from "clsx";
-// import type { ProductReviewList } from "@/types/products/productDetail";
-// import { getProductReviews } from "@utils/hooks/getProductReviews";
-// import { restApiFetch } from "@utils/bagisto/index";
 import {
   ProductDetailSkeleton,
   RelatedProductSkeleton,
@@ -20,7 +16,6 @@ import { RelatedProductsSection } from "@components/catalog/product/RelatedProdu
 import { HeroCarouselShimmer } from "@components/common/slider";
 import { ProductMedia } from "@/app/(public)/product/_components/ProductMedia";
 import { ProductInformation } from "@/app/(public)/product/_components/ProductInformation";
-// import { ProductShortDescription } from "@/app/(public)/product/_components/ProductShortDescription";
 import { ProductDetail } from "@/app/(public)/product/_components/ProductDetail";
 import ProductDescription from "../_components/ProductDescription";
 import SwitchButton from "../_components/SwitchButton";
@@ -49,6 +44,7 @@ export default async function ProductPage({
         urlKey: fullPath 
       },
       takeAuthorization: false,
+      cache: 'no-cache'
       
   });
   console.log("productCustomerFeatures----------------------",resProductData);
@@ -56,18 +52,10 @@ export default async function ProductPage({
   const fetchProductError = resProductData.error;
   if (fetchProductError && fetchProductError.extensions.status === 404) return notFound();
   if(!product) throw new Error(fetchProductError?.message ?? 'Get product data failed');
-  // const allReviews: ProductReviewList = await getProductReviews(
-  //   String(product._id),
-  // );
-  // 3792
-  // const res = await restApiFetch({
-  // api: `/shop/products/${3792}/reviews?page=1&per_page=10&has_images=0&sort=all`,
-  // method: "GET",
-// });
-// const allReviews = res?.body?.data;
+ 
 
   const questionTotal = 73;
-  // const imageUrl = getImageUrl(product?.baseImageUrl, baseUrl, NOT_IMAGE);
+  
 
   // JSON-LD数据格式,便于搜索引擎识别页面信息,利于seo
   const productJsonLd = {
@@ -89,15 +77,7 @@ export default async function ProductPage({
 
   const flexibleVariants = formatFlexibleVariants(product?.flexibleVariants);
 
-  // const reviews = Array.isArray(product?.reviews?.edges)
-  // ? product?.reviews.edges.map((e) => e.node)
-  // : [];
 
-  // const VariantImages = isArray(product?.variants?.edges)
-  //   ? product?.variants.edges.map(
-  //       (edge: { node: ProductVariantNode }) => edge.node,
-  //     )
-  //   : [];
 
   return (
     <>
@@ -125,19 +105,16 @@ export default async function ProductPage({
             shortDescription={product.shortDescription || ""}
           />
           <ShopServicePanel />
-          {/* <ProductShortDescription
-            shortDescription={product.shortDescription || ""}
-          /> */}
+
          <ProductDescription   htmlString={product?.feature || ""} />
           <SwitchButton
             productId={"3792"} //|| String(product._id)
-            // reviewList={allReviews}
-            // reviewTotal={allReviews.length}
+
             questionTotal={questionTotal}
             questionList={["aaa"]}
           />
           <ProductDetail detail={product.description || ""} />
-          {/* <ProductReviewSection reviews={allReviews} productId={String(product._id)} /> */}
+          
         </Suspense>
         <Recommend/>
       </div>

+ 4 - 93
src/app/(public)/search/page.tsx

@@ -4,22 +4,15 @@ import Grid from "@/components/theme/ui/grid/Grid";
 import { isArray } from "@/utils/type-guards";
 import { serverGraphqlFetch } from "@utils/bagisto/index";
 import {
-  GET_PRODUCTS,
-  // GET_PRODUCTS_PAGINATION,
-  // GET_FILTER_PRODUCTS,
   SEARCH_PRODUCTS,
 } from "@/graphql";
-import {
-  cachedGraphQLRequest,
-  // getFilterAttributes,
-} from "@/utils/hooks/useCache";
+
 import { generateMetadataForPage, buildProductFilters } from "@/utils/helper";
 import SortOrder from "@/components/theme/filters/SortOrder";
 import { SortByFields } from "@/utils/constants";
 // import MobileFilter from "@/components/theme/filters/MobileFilter";
 // import FilterList from "@/components/theme/filters/FilterList";
 import {
-  ProductsResponse,
   SearchProductsResponse,
   SearchProductsVariables,
 } from "@/components/catalog/type";
@@ -33,61 +26,7 @@ const ProductGridItems = dynamicImport(
 );
 
 export const dynamicParams = true;
-// 获取全站商品
-export async function generateStaticParams() {
-  try {
-    const itemsPerPage = 8;
-    const commonSearches = [""];
-    const params = [];
-    for (const query of commonSearches) {
-      // 获取默认产品回头换成 you may like 的产品
-      const { data } = await cachedGraphQLRequest<ProductsResponse>(
-        "search",
-        GET_PRODUCTS,
-        {
-          query: query,
-          first: 1,
-          sortKey: "CREATED_AT",
-          reverse: true,
-        },
-      );
-
-      const totalCount = data?.products?.totalCount || 0;
-      const totalPages = Math.ceil(totalCount / itemsPerPage);
-      let cursor: string | undefined;
-
-      for (let i = 0; i < totalPages; i++) {
-        const pageParams: { page: string; cursor?: string } = {
-          page: String(i + 1),
-        };
-        if (i > 0 && cursor) {
-          pageParams.cursor = cursor;
-        }
-        params.push(pageParams);
-        if (i < totalPages - 1) {
-          const { data: pageData } =
-            await cachedGraphQLRequest<ProductsResponse>(
-              "search",
-              GET_PRODUCTS,
-              {
-                query: query,
-                first: itemsPerPage,
-                sortKey: "CREATED_AT",
-                reverse: true,
-                ...(cursor && { after: cursor }),
-              },
-            );
-          cursor = pageData?.products?.pageInfo?.endCursor;
-        }
-      }
-    }
 
-    return params;
-  } catch (error) {
-    console.error("Error generating static params:", error);
-    return [];
-  }
-}
 // SEO+分享
 export async function generateMetadata({
   searchParams,
@@ -149,19 +88,7 @@ export default async function SearchPage({
         reverse: selectedSort.reverse,
       },
     });
-    //  dataPromise = cachedGraphQLRequest<ProductsResponse>(
-    //     "search",
-    //     GET_FILTER_PRODUCTS,
-    //     {
-    //       query: searchValue,
-    //       filter: filterInput,
-    //       ...(beforeCursor
-    //         ? { last: itemsPerPage, before: beforeCursor }
-    //         : { first: itemsPerPage, after: afterCursor }),
-    //       sortKey: selectedSort.sortKey,
-    //       reverse: selectedSort.reverse,
-    //     },
-    //   );
+
   } else {
     dataPromise = (async () => {
       let currentAfterCursor: string | undefined = afterCursor;
@@ -182,16 +109,7 @@ export default async function SearchPage({
             reverse: selectedSort.reverse,
           },
         });
-        // await cachedGraphQLRequest<ProductsResponse>(
-        //   "search",
-        //   GET_PRODUCTS_PAGINATION,
-        //   {
-        //     query: searchValue,
-        //     first: currentPage * itemsPerPage,
-        //     sortKey: selectedSort.sortKey,
-        //     reverse: selectedSort.reverse,
-        //   },
-        // );
+
         currentAfterCursor = cursorData?.search?.pageInfo?.endCursor;
         // console.log("currentAfterCursoraaaaa:",currentAfterCursor);
       }
@@ -210,14 +128,7 @@ export default async function SearchPage({
           reverse: selectedSort.reverse,
         },
       });
-      //    cachedGraphQLRequest<ProductsResponse>("search", GET_PRODUCTS, {
-      //   query: searchValue,
-      //   ...(beforeCursor
-      //     ? { last: itemsPerPage, before: beforeCursor }
-      //     : { first: itemsPerPage, after: currentAfterCursor }),
-      //   sortKey: selectedSort.sortKey,
-      //   reverse: selectedSort.reverse,
-      // });
+
     })();
   }