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; } return (
{/* */}

Product

{/*
  1. CMD-App
  2. CMD-Category
*/}
{/* */}
{" "} {product.image && ( )} {/* */}
Id
{product?._id}
Name {product?.name}
image {product.image.map((i) => ( ))}
Description {product?.description}
Base Price ₹{product?.price}
Product Time{product?.time}
Location{product?.location}
Created On {new Date(`${product?.createdAt}`).toDateString()} {" "} , {`${formatAMPM(product?.createdAt)}`}
Updated At {new Date(`${product?.updatedAt}`).toDateString()} {" "} , {`${formatAMPM(product?.updatedAt)}`}
Category {product.category !== "" ? product.category : "Category not selected "}
{/* */}
{/* */}
); } export default ViewProduct;