Uname:Linux machinox-server 6.17.0-1013-aws #13~24.04.1-Ubuntu SMP Fri Apr 24 21:36:58 UTC 2026 aarch64

Base Dir : /var/www/machinox.in

User : root


403WebShell
403Webshell
Server IP : 13.235.167.51  /  Your IP : 216.73.217.116
Web Server : Apache
System : Linux machinox-server 6.17.0-1013-aws #13~24.04.1-Ubuntu SMP Fri Apr 24 21:36:58 UTC 2026 aarch64
User : root ( 0)
PHP Version : 8.2.29
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/control.machinox.in/src/components/ManageMachineEnquiry/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/control.machinox.in/src/components/ManageMachineEnquiry/MachineEnquiryListing.tsx
'use client';
import {
    Row,
    Col,
    OverlayTrigger,
    Tooltip,
    Dropdown,
    InputGroup,
    Form,
    Button,
    Modal,
} from "react-bootstrap";
import { HiMiniChevronUpDown } from "react-icons/hi2";
import { useEffect, useState } from "react";
import { Access, UserList } from "../interface";
import { toast } from "react-toastify";
import { FiSearch } from "react-icons/fi";
import { useRouter } from "next/navigation";
import HelperService from "@/Services/HelperService";
import CompoLoader from "@/Common/ComponentLoader/CompoLoader";
import PageTitle from "@/Common/PageTitle";
import NoDataFound from "@/Common/NoDataFound/NoDataFound";
import RentCityPagination from "@/Common/Pagination/RentCityPagination";
import DeleteModal from "@/Common/DeleteModal/DeleteModal";
import WebService from "@/Services/WebService";
import DatePicker from "react-datepicker";
import moment from "moment";

const MachineEnquiryListing = (props: any) => {

    const [getAccess, setAccess] = useState<Access>({});
    const [getMachineList, setMachineList] = useState<UserList[]>([]);
    const [totalCount, setTotalCount] = useState<any>(0);
    const [pageLoader, setPageLoader] = useState<any>(false);
    const [offset, setOffset] = useState<any>(0);
    const [keyword, setKeyword] = useState<any>("");
    const [action, setAction] = useState<string>("");
    const [showDeleteModal, setShowDeleteModal] = useState(false);
    const [orderBy, setOrderBy] = useState("DESC");
    const [sortBy, setSortBy] = useState("id");
    const navigate = useRouter();
    const [currentPage, setCurrentPage] = useState(1);
    const [showModal, setShowModal] = useState(false);
    const [exportType, setExportType] = useState("csv");
    const [startDate, setStartDate] = useState(null);
    const [endDate, setEndDate] = useState(null);

    const getSrNo = (index: number) => {
        const itemsPerPage = 10;
        const offset = (currentPage - 1) * itemsPerPage;
        return offset + index + 1;
    };

    const handleSort = (column: string) => {
        if (sortBy == column) {
            setOrderBy(prev => (prev === 'DESC' ? 'ASC' : 'DESC'));
        } else {
            setSortBy(column);
            setOrderBy('DESC');
        }
    };

    const handleCloseModal = () => {
        setShowDeleteModal(false);
    };

    useEffect(() => {
        GetList(keyword);
    }, [offset, sortBy, orderBy]);

    const GetList = (
        keyword: any,
    ) => {
        setPageLoader(true);
        return WebService.CommonApi({
            method: "GET",
            action: `admin/machine/enquiries?keyword=${keyword}&offset=${offset}&order_by=${orderBy}&sort_by=${sortBy}`,
            body: null,
            isShowError: false,
        })
            .then((res: any) => {
                setMachineList(res?.list);
                if (res?.access) {
                    let obj: Access = {
                        can_create: res?.access?.can_create,
                        can_delete: res?.access?.can_delete,
                        can_read: res?.access?.can_read,
                        can_update: res?.access?.can_update,
                        can_has_view_access: res?.access?.can_has_view_access,
                    };
                    setAccess(obj);
                }
                setTotalCount(res?.count ?? 0);
                setPageLoader(false);
                setCurrentPage(res?.current_page);
            })
            .catch((error: any) => {
                setPageLoader(false);
                toast.error(error?.response?.data?.message);
                return error;
            });
    };

    const openDeleteModel = (deleteId: any) => {
        setAction(`admin/machine/enquiries/${deleteId}`);
        setShowDeleteModal(true);
    };

    const openExportModal = () => {
        setShowModal(true);
    };

    const closeExportModal = () => {
        setShowModal(false);
        setStartDate(null);
        setEndDate(null);
    };

    const handleExport = () => {
        const formattedStartDate = startDate ? moment(startDate).format("YYYY-MM-DD") : "";
        const formattedEndDate = endDate ? moment(endDate).format("YYYY-MM-DD") : "";

        const params = {
            start_date: formattedStartDate,
            end_date: formattedEndDate,
            export_type: exportType,
        };

        WebService.addLoader("export");

        WebService.downloadFileAPI({
            action: `admin/reports/MACHINE_ENQUIRY?start_date=${params.start_date}&end_date=${params.end_date}&export=${params.export_type}`,
            body: null,
            isShowError: true,
        })
            .then((res: any) => {
                WebService.removeLoader("export");
                closeExportModal();
                try {
                    let blob;

                    if (exportType === "csv") {
                        blob = new Blob([res], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });

                        const url = window.URL.createObjectURL(blob);
                        const link = document.createElement("a");
                        link.href = url;
                        link.download = `App_user_report_${Date.now()}.xlsx`;
                        link.click();
                        window.URL.revokeObjectURL(url);


                    } else if (exportType === "pdf") {
                        blob = new Blob([res], { type: "application/pdf" });

                        const url = window.URL.createObjectURL(blob);
                        const link = document.createElement("a");
                        link.href = url;
                        link.download = `App_user_report_${Date.now()}.pdf`;
                        link.click();
                        window.URL.revokeObjectURL(url);
                    }
                } catch (err) {
                    console.log("Download Error →", err);
                }
            })
            .catch((err: any) => {
                WebService.removeLoader("export");
                console.log("Error:", err);
            });
    };

    return (
        <>
            {pageLoader && <CompoLoader />}
            <div className="page-accounting pb-3">
                <div className="sticky-top-mo">
                    <Row className="align-items-center">
                        <Col lg={8} xs={12}>
                            <div className="d-flex gap-2 align-items-center">
                                <PageTitle title=" Machine Enquiry" backArrow={false} />
                            </div>
                        </Col>
                    </Row>
                </div>
                <div className="pt-0 pt-lg-2">
                    <Row className="">
                        <Col lg={5} xs={10} className="d-flex gap-2 align-items-sm-center">
                            <InputGroup className="search-box mb-lg-2 mb-2">
                                <InputGroup.Text id="basic-addon1">
                                    <FiSearch className="icon" />
                                </InputGroup.Text>
                                <Form.Control
                                    placeholder="Search by keyword...."
                                    onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => {
                                        if (e.key === "Enter") {
                                            setKeyword(e.currentTarget.value);
                                            GetList(
                                                e.currentTarget.value
                                            );
                                        }
                                    }}
                                />
                            </InputGroup>
                        </Col>
                        <Col>
                            <div className="float-right">
                                <Button onClick={openExportModal}>
                                    Export
                                </Button>
                            </div>
                        </Col>
                    </Row>
                    <div className="table-style-1 table-employee table-responsive position-relative">
                        <table className="table">
                            <thead className="">
                                <tr>
                                    <th>
                                        Sr.No{" "}
                                    </th>
                                    <th onClick={() => handleSort('name')}>
                                        Name{" "}
                                        {/* <span className="sorting-icon" style={{ cursor: "pointer" }}>
                                            <HiMiniChevronUpDown />
                                        </span> */}
                                    </th>
                                    <th>
                                        Email{" "}
                                    </th>
                                    <th>
                                        Mobile Number{" "}
                                    </th>
                                    <th>Equipment Name</th>
                                    <th>Capacity</th>
                                    <th>
                                        Brand {" "}
                                    </th>
                                    <th>
                                        Model{" "}
                                    </th>
                                    <th onClick={() => handleSort('created_at')}>
                                        Created At{" "}
                                        {/* <span className="sorting-icon" style={{ cursor: "pointer" }}>
                                            <HiMiniChevronUpDown />
                                        </span> */}
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                {getMachineList && getMachineList.length > 0 ? (
                                    getMachineList?.map((data: any, index: any) => {
                                        return (
                                            <tr key={index}>
                                                <td className="col-id">
                                                    {getSrNo(index)}
                                                </td>

                                                <td className="col-designation">
                                                    {data?.user?.name}
                                                </td>
                                                <td className="col-designation">
                                                    {data?.user?.email}
                                                </td>
                                                <td className="col-designation">
                                                    {data?.user?.mobile_number}
                                                </td>
                                                <td>{data?.equipment_name}</td>
                                                <td>{data?.capacity}</td>
                                                <td className="col-designation">
                                                    {data?.brand_name}
                                                </td>
                                                <td className="col-designation">
                                                    {data?.model}
                                                </td>
                                                <td className="col-designation">
                                                    {HelperService.getFormattedDateOnly(data?.created_at)}
                                                </td>
                                            </tr>
                                        );
                                    })
                                ) : !pageLoader && (
                                    <tr>
                                        <td colSpan={8}>
                                            <NoDataFound />
                                        </td>
                                    </tr>
                                )}
                            </tbody>
                        </table>
                        {totalCount > 10 && (
                            <div className="float-end me-2">
                                <RentCityPagination
                                    totalCount={totalCount}
                                    itemCountPerPage={10}
                                    changePage={(page: any) => {
                                        setOffset(page - 1);
                                    }}
                                />
                            </div>
                        )}
                    </div>
                </div>
                <DeleteModal
                    show={showDeleteModal}
                    getApiCall={() => {
                        GetList(keyword);
                    }}
                    closeModal={(flag: any) => {
                        handleCloseModal();
                    }}
                    action={action}
                />
            </div>

            <Modal show={showModal} onHide={closeExportModal}>
                <Modal.Header closeButton>
                    <Modal.Title> Export Machine Enquiry</Modal.Title>
                </Modal.Header>
                <Modal.Body>
                    <Form>
                        {/* Start Date */}
                        <Row>
                            <Col>
                                <Form.Group>
                                    <Form.Label><strong>Start Date</strong></Form.Label>
                                    <DatePicker
                                        selected={startDate}
                                        onChange={(date: any) => setStartDate(date)}
                                        dateFormat="dd-MM-yyyy"
                                        className="form-control"
                                        placeholderText="Select Date"
                                    />
                                </Form.Group>
                            </Col>
                            {/* End Date */}
                            <Col>
                                <Form.Group>
                                    <Form.Label> <strong>End Date</strong></Form.Label>
                                    <DatePicker
                                        selected={endDate}
                                        onChange={(date: any) => setEndDate(date)}
                                        dateFormat="dd-MM-yyyy"
                                        className="form-control"
                                        placeholderText="Select Date"
                                    />
                                </Form.Group>
                            </Col>
                        </Row>

                        <Row className="mt-3">
                            <Col md={3}>
                                <Form.Label>
                                    <strong>
                                        Export Type
                                    </strong>
                                </Form.Label>
                                <Form.Check
                                    type="radio"
                                    label="Excel"
                                    name="exportType"
                                    value="csv"
                                    checked={exportType === "csv"}
                                    onChange={(e) => setExportType(e.target.value)}
                                />
                                <Form.Check
                                    type="radio"
                                    label="PDF"
                                    name="exportType"
                                    value="pdf"
                                    checked={exportType === "pdf"}
                                    onChange={(e) => setExportType(e.target.value)}
                                />
                            </Col>
                        </Row>

                        <Button
                            variant="primary"
                            id="export"
                            onClick={() => {
                                handleExport();
                            }}
                        >
                            Export
                        </Button>
                    </Form>
                </Modal.Body>
            </Modal>
        </>
    );
}

export default MachineEnquiryListing;

Youez - 2016 - github.com/yon3zu
LinuXploit