import React, { useState, useEffect } from 'react' import { Link } from 'react-router-dom' import Button from '@material-ui/core/Button' import { useNavigate } from 'react-router-dom' import axios from 'axios' import { isAutheticated } from 'src/auth' const Complaints = () => { const token = isAutheticated() const navigate = useNavigate() const [loading, setLoading] = useState(true) const [success, setSuccess] = useState(true) const [ComplaintsData, setComplaintsData] = useState([]) const [currentPage, setCurrentPage] = useState(1) const [itemPerPage, setItemPerPage] = useState(10) const [showData, setShowData] = useState(ComplaintsData) const handleShowEntries = (e) => { setCurrentPage(1) setItemPerPage(e.target.value) } const getComplaintsData = async () => { axios .get(`/api/complaint/getAll/`, { headers: { Authorization: `Bearer ${token}`, }, }) .then((res) => { setComplaintsData(res.data?.complaint) setLoading(false) }) .catch((err) => { setLoading(false) }) } useEffect(() => { getComplaintsData() }, [success]) useEffect(() => { const loadData = () => { const indexOfLastPost = currentPage * itemPerPage const indexOfFirstPost = indexOfLastPost - itemPerPage setShowData(ComplaintsData.slice(indexOfFirstPost, indexOfLastPost)) } loadData() }, [currentPage, itemPerPage, ComplaintsData]) const handleDelete = (id) => { swal({ title: 'Are you sure?', icon: 'error', buttons: { Yes: { text: 'Yes', value: true }, Cancel: { text: 'Cancel', value: 'cancel' } }, }).then((value) => { if (value === true) { axios .delete(`/api/product/delete/${id}`, { headers: { 'Access-Control-Allow-Origin': '*', Authorization: `Bearer ${token}`, }, }) .then((res) => { setSuccess((prev) => !prev) }) .catch((err) => { swal({ title: 'Warning', text: 'Something went wrong!', icon: 'error', button: 'Retry', dangerMode: true, }) }) } }) } return (
Mobile or EMail | Complaints | Date & Time | Action | ||
---|---|---|---|---|---|
No Data Available |
|||||
Loading... | |||||
{product.MobileOrEmail} | {product.Complaint} | {new Date(product.createdAt).toLocaleString('en-IN', { weekday: 'short', month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true, })} |