import { useEffect, useRef, useState } from "react"; import { useRequestsData } from "../../Hooks/Requests"; import { StepForwardOutlined, StepBackwardOutlined } from "@ant-design/icons"; import { Button, Input, Radio, RadioChangeEvent, Space, Typography, } from "antd"; import { TRequests } from "../../types/Requests/TRequests"; import { TSocket } from "../../types/common/TSocket"; import RequestsEdit from "./RequestsEdit"; import RequestsTable from "./RequestsTable"; // @ts-ignore import IconSearch from "../../assets/searchIcon.png"; const Requests = ({ socketData }: { socketData: TSocket | undefined }) => { const [search, setSearch] = useState(""); const [modalOpen, setModalOpen] = useState(false); const [requestData, setRequestData] = useState(); const [status, setStatus] = useState("Pending"); const [page, setPage] = useState(1); const { data, refetch, isLoading } = useRequestsData({ search: search, status: status, page: page, page_size: 10, }); const [mainData, setMainData] = useState(); const timerRef = useRef(null); const handleSearchChange = (e: React.ChangeEvent) => { if (timerRef.current) { clearTimeout(timerRef.current); } const searchText = e.target.value; timerRef.current = setTimeout(() => { setSearch(searchText); }, 1000); }; const theme = localStorage.getItem("theme") === "true" ? true : false; useEffect(() => { if (data) { setMainData(data.data); } }, [data]); // useEffect(() => { // if (socketData) { // setMainData((prev: TRequests[] | undefined) => { // if (prev && prev?.length >= 15) { // prev?.pop(); // } // if (socketData.type === "driver_request") { // } // return prev; // }); // } // }, [socketData]); const Next = () => { const a = Number(page) + 1; setPage(a); }; const Previos = () => { Number(page); if (page > 1) { const a = Number(page) - 1; setPage(a); } }; return (
{modalOpen && ( )}
Requests
setStatus(e.target.value)} size="middle" value={status} className="request-radio-group" > Pending Assigned Rejected
{/* { let num = e.target.value; if (Number(num) && num !== "0") { setPage(Number(num)); } }} /> */}
); }; export default Requests;