diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml index cd9f71e..26e536b 100644 --- a/k8s/deployment.yaml +++ b/k8s/deployment.yaml @@ -13,9 +13,11 @@ spec: labels: app: website spec: + imagePullSecrets: + - name: harbor-secret containers: - name: website - image: 192.168.49.2:30004/vaishnavi-ecommerce/website:latest + image: 192.168.108.200:80/vaishnavi-ecommerce/website:latest imagePullPolicy: Always ports: - containerPort: 5173 diff --git a/k8s/ingress.yaml b/k8s/ingress.yaml index 7d8563c..3f5d5c2 100644 --- a/k8s/ingress.yaml +++ b/k8s/ingress.yaml @@ -8,7 +8,7 @@ metadata: spec: ingressClassName: nginx rules: - - host: website.local + - host: vaishnavi-test.myriadcara.in http: paths: - path: / diff --git a/k8s/service.yaml b/k8s/service.yaml index 4db9ec5..9fcbe19 100644 --- a/k8s/service.yaml +++ b/k8s/service.yaml @@ -4,10 +4,9 @@ metadata: name: website namespace: ecommerce spec: - type: NodePort + type: LoadBalancer selector: app: website ports: - port: 5173 targetPort: 5173 - nodePort: 30081 diff --git a/src/components/navbar/CartIcon.jsx b/src/components/navbar/CartIcon.jsx index b593253..3ce2004 100644 --- a/src/components/navbar/CartIcon.jsx +++ b/src/components/navbar/CartIcon.jsx @@ -21,10 +21,12 @@ import { ShoppingCart } from "lucide-react"; import { Link } from "react-router-dom"; +import { useSelector } from "react-redux"; import { useGetCartItemsQuery } from "../../features/cart/cartAPI"; const CartIcon = ({ className = "" }) => { - const { data } = useGetCartItemsQuery(); + const token = useSelector((state) => state.auth.token); + const { data } = useGetCartItemsQuery(undefined, { skip: !token }); const cartCount = data?.data?.items?.length || 0; diff --git a/src/components/navbar/Wishlist.jsx b/src/components/navbar/Wishlist.jsx index 6c7cd75..44d6218 100644 --- a/src/components/navbar/Wishlist.jsx +++ b/src/components/navbar/Wishlist.jsx @@ -195,11 +195,13 @@ import { import { useAddToCartMutation } from "../../features/cart/cartAPI"; import WishlistEmpty from "./WishlistEmpty"; import { useNavigate } from "react-router-dom"; +import { useSelector } from "react-redux"; const Wishlist = () => { const navigate = useNavigate(); + const token = useSelector((state) => state.auth.token); - const { data, isLoading, isError } = useGetWishlistQuery(); + const { data, isLoading, isError } = useGetWishlistQuery(undefined, { skip: !token }); const [addToCart] = useAddToCartMutation(); const [removeFromWishlist] = useRemoveFromWishlistMutation(); diff --git a/src/components/order/MyOrders.jsx b/src/components/order/MyOrders.jsx index 13bf522..1090b54 100644 --- a/src/components/order/MyOrders.jsx +++ b/src/components/order/MyOrders.jsx @@ -207,6 +207,7 @@ import React, { useState } from "react"; import { useGetOrdersQuery } from "../../features/orders/ordersApi"; import { useNavigate } from "react-router-dom"; +import { useSelector } from "react-redux"; import { statusColor } from "../../constants/statusColor"; // const statusColor = { @@ -347,10 +348,11 @@ const OrderCard = ({ order }) => { // MAIN COMPONENT const MyOrders = () => { - const { data, isLoading, isError } = useGetOrdersQuery({ - page: 1, - limit: 50, - }); + const token = useSelector((state) => state.auth.token); + const { data, isLoading, isError } = useGetOrdersQuery( + { page: 1, limit: 50 }, + { skip: !token } + ); const [filters, setFilters] = useState({ status: [], diff --git a/src/components/product/ProductCategoryPage.jsx b/src/components/product/ProductCategoryPage.jsx index 6fd4f94..265f678 100644 --- a/src/components/product/ProductCategoryPage.jsx +++ b/src/components/product/ProductCategoryPage.jsx @@ -1,5 +1,6 @@ import React, { useState } from "react"; import { useParams, Link } from "react-router-dom"; +import { useSelector } from "react-redux"; import Pagination from "../ui/Pagination"; import Breadcrumb from "../ui/Breadcrumb"; import CategoryGrid from "../home/Category/CategoryGrid"; @@ -16,8 +17,9 @@ import { Heart, Eye } from "lucide-react"; const ProductCategoryPage = () => { const { parent, category, subCategory } = useParams(); const categorySlug = subCategory || category; + const token = useSelector((state) => state.auth.token); - const { data: wishlistData } = useGetWishlistQuery(); + const { data: wishlistData } = useGetWishlistQuery(undefined, { skip: !token }); const [addToWishlist] = useAddToWishlistMutation(); const [removeFromWishlist] = useRemoveFromWishlistMutation(); diff --git a/src/components/product/ProductDetails.jsx b/src/components/product/ProductDetails.jsx index 55fb5ca..8f07589 100644 --- a/src/components/product/ProductDetails.jsx +++ b/src/components/product/ProductDetails.jsx @@ -1,6 +1,6 @@ import { useParams } from "react-router-dom"; import { useEffect } from "react"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import Breadcrumb from "../../components/ui/Breadcrumb"; import ProductImages from "./ProductImages"; import ProductInfo from "./ProductInfo"; @@ -19,9 +19,10 @@ import RecommendedForYou from "../home/RecommendedForYou/RecommendedForYou"; const ProductDetails = () => { const { slug } = useParams(); const dispatch = useDispatch(); + const token = useSelector((state) => state.auth.token); const { data, isLoading, isError } = useGetProductBySlugQuery(slug); - const { data: wishlistData } = useGetWishlistQuery(); + const { data: wishlistData } = useGetWishlistQuery(undefined, { skip: !token }); const [addToWishlist] = useAddToWishlistMutation(); const [removeFromWishlist] = useRemoveFromWishlistMutation(); diff --git a/src/components/profile/ProfilePage.jsx b/src/components/profile/ProfilePage.jsx index 2a647d0..5242b35 100644 --- a/src/components/profile/ProfilePage.jsx +++ b/src/components/profile/ProfilePage.jsx @@ -1,5 +1,5 @@ import { useState } from "react"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { useNavigate } from "react-router-dom"; import { useGetProfileQuery } from "../../features/auth/authApi"; // import { useDispatch } from "react-redux"; @@ -10,7 +10,8 @@ import ProfileContent from "./ProfileContent"; const ProfilePage = () => { const dispatch = useDispatch(); const navigate = useNavigate(); - const { data, isLoading, isError } = useGetProfileQuery(); + const token = useSelector((state) => state.auth.token); + const { data, isLoading, isError } = useGetProfileQuery(undefined, { skip: !token }); const [activeTab, setActiveTab] = useState("profile"); // <--- state lifted if (isLoading) return
Loading profile...
; diff --git a/src/components/profile/addresses/Addresses.jsx b/src/components/profile/addresses/Addresses.jsx index 67087d0..8e217fc 100644 --- a/src/components/profile/addresses/Addresses.jsx +++ b/src/components/profile/addresses/Addresses.jsx @@ -1,10 +1,12 @@ import { useState } from "react"; +import { useSelector } from "react-redux"; import { useGetAddressesQuery } from "../../../features/auth/authApi"; import AddressCard from "./AddressCard"; import UpdateAddressModal from "./UpdateAddressModal"; const Addresses = () => { - const { data, isLoading, isError } = useGetAddressesQuery(); + const token = useSelector((state) => state.auth.token); + const { data, isLoading, isError } = useGetAddressesQuery(undefined, { skip: !token }); const addresses = data?.data?.addresses || []; const [selectedAddress, setSelectedAddress] = useState(null); diff --git a/src/components/recentlyViewed/RecentlyViewed.jsx b/src/components/recentlyViewed/RecentlyViewed.jsx index c4122d9..d48f192 100644 --- a/src/components/recentlyViewed/RecentlyViewed.jsx +++ b/src/components/recentlyViewed/RecentlyViewed.jsx @@ -204,8 +204,9 @@ const RecentlyViewedCard = ({ product, wishlistIds, handleWishlist }) => { const RecentlyViewed = ({ limit = 6 }) => { const allProducts = useSelector(selectRecentProducts); const recentProducts = allProducts.slice(0, limit); + const token = useSelector((state) => state.auth.token); - const { data: wishlistData } = useGetWishlistQuery(); + const { data: wishlistData } = useGetWishlistQuery(undefined, { skip: !token }); const [addToWishlist] = useAddToWishlistMutation(); const [removeFromWishlist] = useRemoveFromWishlistMutation(); diff --git a/src/pages/Cart/CartPage.jsx b/src/pages/Cart/CartPage.jsx index 17558ed..8c9ed69 100644 --- a/src/pages/Cart/CartPage.jsx +++ b/src/pages/Cart/CartPage.jsx @@ -9,11 +9,13 @@ import EmptyCart from "./EmptyCart"; import ProgressStepper from "./ProgressStepper"; import { useNavigate } from "react-router-dom"; import CartFeatures from "./CartFeatures"; +import { useSelector } from "react-redux"; const CartPage = () => { const navigate = useNavigate(); + const token = useSelector((state) => state.auth.token); - const { data, isLoading, error } = useGetCartItemsQuery(); + const { data, isLoading, error } = useGetCartItemsQuery(undefined, { skip: !token }); const cartItems = data?.data || []; const [quantities, setQuantities] = useState({}); diff --git a/vite.config.js b/vite.config.js index 8b0f57b..ef5844f 100644 --- a/vite.config.js +++ b/vite.config.js @@ -4,4 +4,7 @@ import react from '@vitejs/plugin-react' // https://vite.dev/config/ export default defineConfig({ plugins: [react()], + preview: { + allowedHosts: ['vaishnavi-test.myriadcara.in'], + }, })