| 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/ManageAdminUser/ |
Upload File : |
'use client';
import {
Row,
Col,
OverlayTrigger,
Tooltip,
Dropdown,
InputGroup,
Form,
Button,
} from "react-bootstrap";
import { HiMiniChevronUpDown } from "react-icons/hi2";
import { BsThreeDotsVertical } from "react-icons/bs";
import { useEffect, useState } from "react";
import { Access, UserList } from "../interface";
import { toast } from "react-toastify";
import { FiEdit, FiSearch, FiTrash2 } from "react-icons/fi";
import Link from "next/link";
import { useRouter } from "next/navigation";
import CommonFunction from "@/Services/CommonFunction";
import HelperService from "@/Services/HelperService";
import WebService from "@/Services/WebService";
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";
const Users = (props: any) => {
const [getAccess, setAccess] = useState<Access>({});
const [getUserList, setUserList] = 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 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/users?keyword=${keyword}&offset=${offset}&order_by=${orderBy}&sort_by=${sortBy}`,
body: null,
isShowError: false,
})
.then((res: any) => {
setUserList([]);
if (res?.list?.length > 0) {
let userLists = res?.list?.map((item: any) => ({
uuid: item?.uuid,
name: item?.name,
email: item?.email,
status: item?.status,
created_at: item?.created_at,
dial_code: item?.dial_code,
mobile_number: item?.mobile_number,
added_by: item?.added_by,
role_name: item?.role?.role_name,
updated_by: item?.updated_by
}));
setUserList(userLists);
}
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/user/${deleteId}`);
setShowDeleteModal(true);
};
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=" Admin Users" backArrow={false} />
</div>
</Col>
<Col
lg={4}
className="d-flex justify-content-end gap-3 mobile-sticky-bottom"
>
<Button onClick={() => {
navigate.push("/manage-admin-user/add-user")
}}>
Add Admin User
</Button>
</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"
onClick={() => GetList(keyword)}
/>
</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>
</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>
Role{" "}
{/* <span className="sorting-icon" style={{ cursor: "pointer" }}>
<HiMiniChevronUpDown />
</span> */}
</th>
<th onClick={() => handleSort('status')}>
Status{" "}
</th>
<th onClick={() => handleSort('created_at')}>
Created At{" "}
{/* <span className="sorting-icon" style={{ cursor: "pointer" }}>
<HiMiniChevronUpDown />
</span> */}
</th>
<th className="text-center">Action</th>
</tr>
</thead>
<tbody>
{getUserList && getUserList.length > 0 ? (
getUserList &&
getUserList?.map((data: UserList, index: any) => {
return (
<tr key={index}>
<td className="col-id">
{getSrNo(index)}
</td>
<td className="col-designation">
{data?.name}
</td>
<td className="col-designation">
{data?.email}
</td>
<td className="col-designation">
{data?.dial_code + " " + data?.mobile_number}
</td>
<td className="col-designation">
{data?.role_name}
</td>
<td className="col-designation">
<span className={`${CommonFunction.addBadgesBasedOnStatus(data?.status)}`}>{HelperService.toProperCase(data?.status)}</span>
</td>
<td className="col-designation">
{HelperService.getFormattedDateOnly(data?.created_at)}
</td>
<td className="d-flex gap-3 text-center col-designation" style={{ cursor: "pointer" }}>
<FiEdit
size={25}
className="p-1 me-2 text-primary text-center"
onClick={() => navigate.push(`manage-admin-user/edit-user/${data?.uuid}`)}
/>
<FiTrash2 className="p-1 text-danger"
onClick={(e: any) => {
e.preventDefault();
openDeleteModel(data?.uuid);
}}
size={25}
/>
</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>
</>
);
}
export default Users;