import axios from "axios"; import React, { useEffect, useState, useCallback, useMemo } from "react"; import swal from "sweetalert"; import { Link, useParams } from "react-router-dom"; import { isAutheticated } from "src/auth"; function ViewProduct() { const [product, setProduct] = useState([]); const { id } = useParams(); const token = isAutheticated(); const getProduct = useCallback(async () => { let res = await axios.get(`/api/product/getOne/${id}`, { headers: { Authorization: `Bearer ${token}`, }, }); setProduct(res.data.product); }, [token]); useEffect(() => { getProduct(); }, [getProduct]); //change time formate function formatAMPM(date) { var hours = new Date(date).getHours(); var minutes = new Date(date).getMinutes(); var ampm = hours >= 12 ? "PM" : "AM"; hours = hours % 12; hours = hours ? hours : 12; // the hour '0' should be '12' minutes = minutes < 10 ? "0" + minutes : minutes; var strTime = hours + ":" + minutes + " " + ampm; return strTime; } // console.log(product); return (
Id | {" "}
{product.uniqueId} |
---|---|
Name | {product?.name} |
image |
{product.image.map((i) => (
|
Category | {product.category?.categoryName !== "" ? product.category?.categoryName : "Category not selected "} |
Description | {product?.description} |
Price | ₹{product?.price} |
Gst | {product?.gst?.tax}% {product?.gst?.name} |
Gst Amount | ₹{product?.gst_amount} |
Total Amount(with Gst) | ₹{product?.total_amount} |
Product Time | {product?.time} |
Location | {product?.location} |
Product Status | {product?.product_Status} |
Created On | {new Date(`${product?.createdAt}`).toDateString()} {" "} , {`${formatAMPM(product?.createdAt)}`} |
Updated At | {new Date(`${product?.updatedAt}`).toDateString()} {" "} , {`${formatAMPM(product?.updatedAt)}`} |