fix: shoud not be empty variandId
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
'use client'
|
||||
import { FC, useState, useEffect } from 'react'
|
||||
import { Swiper, SwiperSlide } from 'swiper/react';
|
||||
import { FC, useState, useEffect, useRef } from 'react'
|
||||
import { Swiper, SwiperSlide, SwiperRef } from 'swiper/react';
|
||||
import { Pagination } from 'swiper/modules';
|
||||
import { ArrowLeft2, ArrowRight2 } from 'iconsax-react';
|
||||
import Image from 'next/image';
|
||||
import Link from 'next/link';
|
||||
import { useGetLanding } from '../hooks/useHomeData';
|
||||
@@ -9,6 +10,9 @@ import { useGetLanding } from '../hooks/useHomeData';
|
||||
const Carousel: FC = () => {
|
||||
const { data } = useGetLanding()
|
||||
const [isMobile, setIsMobile] = useState(false)
|
||||
const swiperRef = useRef<SwiperRef>(null)
|
||||
const [isBeginning, setIsBeginning] = useState(true)
|
||||
const [isEnd, setIsEnd] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
const checkIsMobile = () => {
|
||||
@@ -30,7 +34,21 @@ const Carousel: FC = () => {
|
||||
|
||||
return (
|
||||
<div className='relative' style={{ zIndex: 0 }}>
|
||||
<Swiper pagination={true} modules={[Pagination]} className="mySwiper pb-5" style={{ zIndex: 0, position: 'relative' }}>
|
||||
<Swiper
|
||||
ref={swiperRef}
|
||||
pagination={true}
|
||||
modules={[Pagination]}
|
||||
className="mySwiper pb-5"
|
||||
style={{ zIndex: 0, position: 'relative' }}
|
||||
onSlideChange={(swiper) => {
|
||||
setIsBeginning(swiper.isBeginning)
|
||||
setIsEnd(swiper.isEnd)
|
||||
}}
|
||||
onSwiper={(swiper) => {
|
||||
setIsBeginning(swiper.isBeginning)
|
||||
setIsEnd(swiper.isEnd)
|
||||
}}
|
||||
>
|
||||
{sliders.map((slider) => (
|
||||
<SwiperSlide key={slider._id}>
|
||||
{slider.linkUrl ? (
|
||||
@@ -55,6 +73,28 @@ const Carousel: FC = () => {
|
||||
</SwiperSlide>
|
||||
))}
|
||||
</Swiper>
|
||||
|
||||
{/* Navigation buttons */}
|
||||
<button
|
||||
onClick={() => swiperRef.current?.swiper?.slidePrev()}
|
||||
disabled={isBeginning}
|
||||
className={`absolute left-2 top-1/2 -translate-y-1/2 z-10 rounded-full p-2 shadow-md transition-all duration-200 ${isBeginning
|
||||
? 'bg-gray-100 cursor-not-allowed opacity-50'
|
||||
: 'bg-white/80 hover:bg-white cursor-pointer'
|
||||
}`}
|
||||
>
|
||||
<ArrowLeft2 size="20" color={isBeginning ? "#9CA3AF" : "#374151"} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => swiperRef.current?.swiper?.slideNext()}
|
||||
disabled={isEnd}
|
||||
className={`absolute right-2 top-1/2 -translate-y-1/2 z-10 rounded-full p-2 shadow-md transition-all duration-200 ${isEnd
|
||||
? 'bg-gray-100 cursor-not-allowed opacity-50'
|
||||
: 'bg-white/80 hover:bg-white cursor-pointer'
|
||||
}`}
|
||||
>
|
||||
<ArrowRight2 size="20" color={isEnd ? "#9CA3AF" : "#374151"} />
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
import Layout from '@/hoc/Layout'
|
||||
import { NextPage } from 'next'
|
||||
import React, { useState, useMemo } from 'react'
|
||||
import React, { useState } from 'react'
|
||||
import Menu from '../components/Menu'
|
||||
import { useGetOrders, useGetReturnOrder } from './hooks/useOrdersData'
|
||||
import { Order, ReturnOrder } from './types/Types'
|
||||
@@ -16,25 +16,6 @@ const Orders: NextPage = () => {
|
||||
const { data: ordersData } = useGetOrders(activeTab);
|
||||
const { data: returnOrderData } = useGetReturnOrder();
|
||||
|
||||
// محاسبه تعداد سفارشات در هر تب از دادههای اصلی
|
||||
const tabCounts = useMemo(() => {
|
||||
if (!ordersData?.results?.orders) return { current: 0, delivered: 0, returned: 0, cancelled: 0 };
|
||||
|
||||
return ordersData.results.orders.reduce((acc, order: Order) => {
|
||||
const status = (order.status || 'pending').toLowerCase();
|
||||
if (['pending', 'processing', 'shipped'].includes(status)) {
|
||||
acc.current++;
|
||||
} else if (status === 'delivered') {
|
||||
acc.delivered++;
|
||||
} else if (status === 'returned') {
|
||||
acc.returned++;
|
||||
} else if (status === 'cancelled') {
|
||||
acc.cancelled++;
|
||||
}
|
||||
return acc;
|
||||
}, { current: 0, delivered: 0, returned: 0, cancelled: 0 });
|
||||
}, [ordersData]);
|
||||
|
||||
// تابع تبدیل وضعیت به فارسی
|
||||
const getStatusText = (status: string) => {
|
||||
const statusMap: { [key: string]: string } = {
|
||||
@@ -48,6 +29,9 @@ const Orders: NextPage = () => {
|
||||
return statusMap[status.toLowerCase()] || status;
|
||||
};
|
||||
|
||||
console.log('ordersData', ordersData);
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div className='p-3 sm:p-4 md:p-6'>
|
||||
@@ -57,7 +41,12 @@ const Orders: NextPage = () => {
|
||||
<OrderTabs
|
||||
activeTab={activeTab}
|
||||
setActiveTab={setActiveTab}
|
||||
tabCounts={tabCounts}
|
||||
tabCounts={{
|
||||
cancelled: ordersData?.results?.userOrderCount.cancelled || 0,
|
||||
current: ordersData?.results?.userOrderCount.processing || 0,
|
||||
delivered: ordersData?.results?.userOrderCount.delivered || 0,
|
||||
returned: ordersData?.results?.userOrderCount.returned || 0,
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Orders List */}
|
||||
|
||||
@@ -289,15 +289,20 @@ export interface OrderDetailResponse {
|
||||
};
|
||||
}
|
||||
|
||||
export interface UserOrderCount {
|
||||
processing: number;
|
||||
delivered: number;
|
||||
cancelled: number;
|
||||
returned: number;
|
||||
}
|
||||
|
||||
export interface OrdersResponse {
|
||||
status: number;
|
||||
success: boolean;
|
||||
results: {
|
||||
mappedOrders: MappedOrder[];
|
||||
orders: Order[];
|
||||
shipmentAddress: ShipmentAddress;
|
||||
orderStatus: string;
|
||||
createdAt: string;
|
||||
userOrderCount: UserOrderCount;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,16 +2,24 @@
|
||||
|
||||
import { useProductStore } from "@/app/product/store/Store";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useEffect } from "react";
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
const ManageData = () => {
|
||||
|
||||
const { setVariantId } = useProductStore()
|
||||
const pathname = usePathname()
|
||||
const prevPathnameRef = useRef(pathname)
|
||||
|
||||
useEffect(() => {
|
||||
setVariantId('')
|
||||
}, [pathname]);
|
||||
const prevPath = prevPathnameRef.current
|
||||
const isLeavingProduct = prevPath?.startsWith('/product/') && !pathname.startsWith('/product/')
|
||||
|
||||
if (isLeavingProduct) {
|
||||
setVariantId('')
|
||||
}
|
||||
|
||||
prevPathnameRef.current = pathname
|
||||
}, [pathname, setVariantId]);
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
export const TOKEN_NAME = "sh_token";
|
||||
export const REFRESH_TOKEN_NAME = "sh_refresh_token";
|
||||
export const BASE_URL = "https://shop-api.dev.danakcorp.com";
|
||||
export const BASE_URL = "https://api.fajrtabloshop.com";
|
||||
// export const BASE_URL = "http://192.168.1.111:4000";
|
||||
|
||||
export const PRIMARY_COLOR = "#DA2129";
|
||||
|
||||
Reference in New Issue
Block a user