diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..64e0118 --- /dev/null +++ b/.env.production @@ -0,0 +1,7 @@ +NODE_ENV="production" + +NEXT_PUBLIC_SERVER_URL=https://api.vesmook.com +NEXT_PUBLIC_PUBLIC_URL=https://api.vesmook.com +NEXT_PUBLIC_API_URL=https://api.vesmook.com/api +NEXT_PUBLIC_STORAGE_URL=http://storage.vesmook.com +NEXT_PUBLIC_PACKAGE_VERSION=0.1.4 \ No newline at end of file diff --git a/Contexts/AppContext.js b/Contexts/AppContext.js new file mode 100644 index 0000000..fbb8c92 --- /dev/null +++ b/Contexts/AppContext.js @@ -0,0 +1,7 @@ +"use client"; +import { createContext } from "react"; + +const AppContext = createContext({ + state: {}, +}); +export default AppContext; diff --git a/components/AppsComponent/CartData/page.jsx b/components/AppsComponent/CartData/page.jsx new file mode 100644 index 0000000..41299ba --- /dev/null +++ b/components/AppsComponent/CartData/page.jsx @@ -0,0 +1,148 @@ +"use client"; +import CardCart from "@comp/Cards/CardCart/page"; +import NavBarDownCart from "@comp/Carts/component/NavBarDownCart/page"; +import Navbar from "@comp/Navbar/page"; +import AppContext from "@ctx/AppContext"; +import { useRouter } from "next/navigation"; +import Chapar from "plugins/Chapar"; +import PersianNumber from "plugins/PersianNumber"; +import { useContext, useEffect } from "react"; +import { toast } from "react-toastify"; + +const CartData = () => { + const CTX = useContext(AppContext); + const router = useRouter(); + const cart = CTX.state.cart; + + const calculateTotalCost = cart.reduce( + (total, item) => total + parseInt(item.cost) * item.count, + 0 + ); + + const calculateTotalCostWithDiscount = cart.reduce( + (total, item) => total + parseInt(item.costWithDiscount) * item.count, + 0 + ); + + const handleGoCheckOut = async () => { + CTX.GoCheckOut(); + }; + + useEffect(() => { + CTX.setBottomSheetCartOpen(false); + }, []); + return ( + <> +
+ + +
+
+

+ محصولات انتخاب شده +

+ +
+

+ + محصول +

+
+
+ +
+ {cart?.map((e, index) => ( + + ))} + +
+
+

حساب نهایی

+ + {/*
+

+ + محصول +

+
*/} +
+ +
+
+

قیمت

+ +
+

+ +

+ + {" "} + تومان + +
+
+ +
+

تخفیف محصول

+ +
+

+ +

+ + {" "} + تومان + +
+
+ +
+

+ قابل پرداخت +

+ +
+

+ +

+ + {" "} + تومان + +
+
+
+
+
+
+ + handleGoCheckOut()} + permissionGoPay={!!cart.length > 0} + /> +
+ + ); +}; + +export default CartData; diff --git a/components/AppsComponent/CategoriesData/page.jsx b/components/AppsComponent/CategoriesData/page.jsx new file mode 100644 index 0000000..2525827 --- /dev/null +++ b/components/AppsComponent/CategoriesData/page.jsx @@ -0,0 +1,255 @@ +"use client"; + +import FilterCategory from "@comp/Category/FilterCategory/page"; +import ListProdocts from "@comp/Category/ListProdocts/page"; +import FilterCategoryMobile from "@comp/Category/Mobile/FilterCategoryMobile/page"; +import ListProductsMobile from "@comp/Category/Mobile/ListProductsMobile/page"; +import PaginationCategoory from "@comp/Category/PaginationCategoory/page"; +import Footer from "@comp/Footer/page"; +import Navbar from "@comp/Navbar/page"; +import AppContext from "@ctx/AppContext"; +import { usePathname, useRouter, useSearchParams } from "next/navigation"; +import { useContext, useEffect, useMemo, useState } from "react"; +import InfiniteScroll from "react-infinite-scroll-component"; + +export default function CategoriesData({ params, products }) { + const CTX = useContext(AppContext); + const searchParams = useSearchParams(); + + useEffect(() => { + if ( + Number(searchParams.get("page")) === 0 || + !Number(searchParams.get("page")) || + CTX.state.stopProducts + ) { + CTX.setProducts(products.products); + } else { + CTX.setProducts([...CTX.state.products, ...products.products]); + } + CTX.setStopProducts( + CTX.state.stopProducts || products?.products?.length < 20 + ); + CTX.setPager(products.pager); + CTX.setFilter(products.filters); + }, [products]); + + const pageGetProducts = useMemo( + () => (searchParams.get("page") ? Number(searchParams.get("page")) : 0), + [searchParams] + ); + const stopProducts = CTX.state.stopProducts; + const pager = products.pager; + const productsLength = CTX.state?.products?.length || 0; + const filter = CTX.state.filter; + + const isChecked = useMemo( + () => Boolean(Number(searchParams.get("isActive"))), + [searchParams] + ); + + const specialOffer = useMemo( + () => Boolean(Number(searchParams.get("specialOffer"))), + [searchParams] + ); + const selectedBrands = useMemo( + () => + searchParams.get("brandIds") + ? searchParams.get("brandIds").split(",") + : [], + [searchParams] + ); + const rangePrice = useMemo( + () => [ + searchParams.get("maxPrice") + ? Number(searchParams.get("maxPrice")) + : filter?.price?.maximumValue, + searchParams.get("minPrice") + ? Number(searchParams.get("minPrice")) + : filter?.price?.minimumValue, + ], + [searchParams] + ); + const isRangePrice = CTX.state.isRangePrice; + const sortBy = useMemo( + () => Number(searchParams.get("sortBy")), + [searchParams] + ); + + // + // "filters", + // filter, + // isChecked, + // selectedBrands, + // rangePrice, + // isRangePrice, + // sortBy + // ); + + const fetchBarnds = async () => { + const res = await fetch( + `${process.env.NEXT_PUBLIC_API_URL}/brand${ + params.id[0] != 0 ? `?categoryId=${params.id[0]}` : "" + }` + ); + const brands = await res.json(); + CTX.setBrands(brands); + }; + + const decodedName = decodeURIComponent(params.id[1]); + const pathname = usePathname(); + const router = useRouter(); + const handleInfiniteNextFetchProducts = () => { + // Increment the page number + const nextPage = pageGetProducts + 1; + + const params = new URLSearchParams(searchParams.toString()); + params.set("page", nextPage); + router.push(`${pathname}?${params}`, { scroll: false }); + + // Fetch products for the next page + + // CTX.fetchProducts( + // nextPage, + // params.id[0] != 0 ? params.id[0] : "", + // selectedBrands, + // isChecked, + // rangePrice, + // rangePrice, + // sortBy != -1 ? sortBy : "", + // isRangePrice + // ); + + // Update the pageGetProducts state for the next fetch + // CTX.setPageGetProducts(nextPage); + }; + + const [loading, setLoading] = useState(true); + const getData = async () => { + setLoading(true); + // await CTX.fetchProducts(0, params.id[0] != 0 ? params.id[0] : ""); + await fetchBarnds(); + setLoading(false); + }; + useEffect(() => { + setLoading(false); + getData(); + }, []); + + return ( + <> +
+ + {!CTX.state.isMobile && ( +
+
+

{decodedName.replace(/-/g, " ")}

+
+
+ + +
+ {loading && <>در حال بارگیری} + {true ? ( + <> + {!loading && ( + + + + )} + + ) : ( +
+
+ چیزی یافت نشد +
+
+ )} +
+
+
+ )} + + {CTX.state.isMobile && ( +
+ +
+

+ {decodedName.replace(/-/g, " ")} +

+
+
+ {loading && <>در حال بارگیری} + {true ? ( + <> + {!loading && ( + + + + )} + + ) : ( +
+
+ چیزی یافت نشد +
+
+ )} +
+
+ )} +
+ {pager?.totalPage > 1 && ( + + )} + +