From 547556e5e10334be3ff91d9f7c7b0479d122a746 Mon Sep 17 00:00:00 2001 From: sevelinCA Date: Thu, 18 Jul 2024 12:00:36 +0200 Subject: [PATCH] Merge with analytics components --- package-lock.json | 8 ++++++++ src/Components/vendor/NewProduct.tsx | 4 ++-- src/Components/vendor/UpdateProduct.tsx | 14 +++++++------- src/Redux/features/sellerSlice.tsx | 14 +++++++++++++- src/pages/vendor/VendorSingleProduct.tsx | 14 ++++++++++++-- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6a4c7d7d..ec1c8dec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6137,6 +6137,14 @@ "node": "*" } }, + "node_modules/css-color-keywords": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/css-color-keywords/-/css-color-keywords-1.0.0.tgz", + "integrity": "sha512-FyyrDHZKEjXDpNJYvVsV960FiqQyXc/LlYmsxl2BcdMb2WPx0OGRVgTg55rPSyLSNMqP52R9r8geSp7apN3Ofg==", + "engines": { + "node": ">=4" + } + }, "node_modules/css-loader": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/css-loader/-/css-loader-7.1.2.tgz", diff --git a/src/Components/vendor/NewProduct.tsx b/src/Components/vendor/NewProduct.tsx index 97bf4d31..8d527686 100644 --- a/src/Components/vendor/NewProduct.tsx +++ b/src/Components/vendor/NewProduct.tsx @@ -96,8 +96,8 @@ const NewProduct = (property: productProps) => { return ( -
-
+
+

New Products

X
diff --git a/src/Components/vendor/UpdateProduct.tsx b/src/Components/vendor/UpdateProduct.tsx index 641895b5..b625e21b 100644 --- a/src/Components/vendor/UpdateProduct.tsx +++ b/src/Components/vendor/UpdateProduct.tsx @@ -2,7 +2,7 @@ import React, { FormEvent, useEffect, useState } from 'react' import Input from '../../Constants/Input' import AuthButton from '../../Constants/AuthButton' import axios from 'axios' -import { useCreateProductMutation } from '../../Redux/features/sellerSlice' +import {useUpdateProductMutation } from '../../Redux/features/sellerSlice' import useAuthHeader from 'react-auth-kit/hooks/useAuthHeader' @@ -18,7 +18,7 @@ const UpdateProduct = (property: productProps) => { const [discount, setDiscount] = useState(property.productData.discount) const [price, setPrice] = useState(property.productData.price) const [image, setImage] = useState(property.productData.image); - const [category, setCategory] = useState("") + const [category, setCategory] = useState(property.productData.category) const [quantity, setQuantity] = useState(property.productData.quantity) const [expiringDate, setExpiringDate] = useState(property.productData.expiringDate) const [error, setError] = useState(false) @@ -28,7 +28,7 @@ const UpdateProduct = (property: productProps) => { - const [createProduct, {isLoading:uploadLoading,isError}] = useCreateProductMutation() + const [updateProduct, {isLoading:uploadLoading,isError}] = useUpdateProductMutation() const handleImages = (value: FileList): void => { const newImages = Array.from(value) @@ -79,10 +79,10 @@ const UpdateProduct = (property: productProps) => { const imageUrls = responses.map(response => response.data.secure_url); const vendor = JSON.parse(localStorage.getItem('vendorData') as string); - const data = {name,quantity,description,price,discount,expiringDate,category,image: imageUrls, id: vendor.vendorId }; + const data = {name,quantity,description,price,discount,expiringDate,category,image: imageUrls, vendorId: vendor.vendorId,id: property.productData.productId }; - const response = await createProduct({data,token}).unwrap(); - if (response.message && response.message === "Product Created") { + const response = await updateProduct({data,token}).unwrap(); + if (response.message && response.message === "Product updated successfully") { console.log(response) setLoading(false) property.setModal(false) @@ -100,7 +100,7 @@ const UpdateProduct = (property: productProps) => {
-

New Products

+

Update Product

property.setModal(false)}>X
diff --git a/src/Redux/features/sellerSlice.tsx b/src/Redux/features/sellerSlice.tsx index adfc07c7..97b8fdd8 100644 --- a/src/Redux/features/sellerSlice.tsx +++ b/src/Redux/features/sellerSlice.tsx @@ -35,6 +35,18 @@ const SellerSlice = apiSlice.injectEndpoints({ } } }), + updateProduct: builder.mutation({ + query: ({data,token}) => { + return{ + url: `/updateProduct/${data.id}`, + method: "PUT", + body: data, + headers:{ + Authorization: token + } + } + } + }), selectSingleProduct: builder.query({ query: (id)=> `/readProduct/${id}` }), @@ -53,5 +65,5 @@ const SellerSlice = apiSlice.injectEndpoints({ }) }); -export const { useSelectFeddbackQuery, useSelectProductsQuery,useSelectVendorQuery,useCreateProductMutation,useSelectSingleProductQuery,useDeleteProductMutation } = SellerSlice; +export const { useSelectFeddbackQuery, useSelectProductsQuery,useSelectVendorQuery,useCreateProductMutation,useSelectSingleProductQuery,useDeleteProductMutation,useUpdateProductMutation } = SellerSlice; export default SellerSlice; diff --git a/src/pages/vendor/VendorSingleProduct.tsx b/src/pages/vendor/VendorSingleProduct.tsx index 83ca4425..22ec0d0b 100644 --- a/src/pages/vendor/VendorSingleProduct.tsx +++ b/src/pages/vendor/VendorSingleProduct.tsx @@ -12,13 +12,20 @@ const VendorSingleProduct = () => { const { id } = useParams<{ id: string }>() const navigate:any = useNavigate() const token = useAuthHeader() - const { data: singleProduct, error, isLoading } = useSelectSingleProductQuery(id) + const { data: singleProduct, error, isLoading,refetch } = useSelectSingleProductQuery(id) const [deleteProduct, { isLoading: deleteLoading, isError: deleteError }] = useDeleteProductMutation() const vendorData: any = localStorage.getItem('vendorData') const vendor = JSON.parse(vendorData) const [openedImage, setOpenedImage] = useState(0) + useEffect(() => { + if (isComplete) { + toast.success("Product updated") + refetch().then(() => setIsComplete(false)) + } + }, [isComplete, refetch]) + if (isLoading) { return (
@@ -33,6 +40,7 @@ const VendorSingleProduct = () => {
) } + const expiringDate = new Date(singleProduct.expiringDate) const day = expiringDate.getDate() @@ -54,6 +62,8 @@ const VendorSingleProduct = () => { } } + + return ( <> @@ -93,7 +103,7 @@ const VendorSingleProduct = () => {
Quantity - {singleProduct.quantity} In Stock + {singleProduct.quantity} In Stock
Price