import axios from "axios"; import React, { useEffect, useState, useCallback, useMemo } from "react"; import { Link } from "react-router-dom"; import swal from 'sweetalert'; // import { API } from "../../data"; import { isAutheticated } from "../../auth"; function Offer() { const [offer, setOffer] = useState([]) const token = isAutheticated(); const getOffer = useCallback(async () => { let res = await axios.get( `/api/offer/getAll`, { headers: { Authorization: `Bearer ${token}`, }, } ); // console.log(res.data) setOffer(res.data.offer) }, [token]); useEffect(() => { getOffer(); }, [getOffer]); const handleDelete = async (id) => { let status = window.confirm("Do you want to delete"); if (!status) return; let res = await axios.delete(`/api/offer/delete/${id}`, { headers: { Authorization: `Bearer ${token}`, }, }); console.log(res) if (res.data.success == true) { swal("success!", "Offer Deleted Successfully!", "success"); window.location.reload(); } }; //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 (
{/* */}

CMP-Offers

{/* */}
{offer && offer.map((item, index) => )}
Title Image Business Name Location Added On Action
{item?.title} {item?.bisunessName} {item?.location} {/* {item?.addedOn} */} {new Date(`${item?.addedOn}`).toDateString()} , {`${formatAMPM(item?.addedOn)}`}
{/* */}
{/* */}
); } export default Offer;