eleven-solutions-common-website-unique-web 21.0.0 → 21.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,7 @@ const Users = ({ url }) => {
|
|
15
15
|
const [users, setUsers] = useState([]);
|
16
16
|
const [searchTerm, setSearchTerm] = useState("");
|
17
17
|
const [filterModal, setFilterModal] = useState(false);
|
18
|
+
const [selectedRoleType, setSelectedRoleType] = useState("");
|
18
19
|
const fetchUsersData = () => __awaiter(void 0, void 0, void 0, function* () {
|
19
20
|
const data = yield fetchUsersApi(url);
|
20
21
|
if (data) {
|
@@ -34,15 +35,26 @@ const Users = ({ url }) => {
|
|
34
35
|
};
|
35
36
|
const [currentPage, setCurrentPage] = useState(1);
|
36
37
|
const itemsPerPage = 10;
|
38
|
+
// const filteredUsers = users.filter((user) => {
|
39
|
+
// if (searchTerm.length < 2) return true;
|
40
|
+
// const nameMatch = user.name?.toLowerCase().includes(searchTerm) ?? false;
|
41
|
+
// const emailMatch = user.email?.toLowerCase().includes(searchTerm) ?? false;
|
42
|
+
// const mobileMatch = user.mobile?.toString().includes(searchTerm) ?? false;
|
43
|
+
// return nameMatch || emailMatch || mobileMatch;
|
44
|
+
// });
|
37
45
|
const filteredUsers = users.filter((user) => {
|
38
|
-
var _a, _b, _c
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
const
|
44
|
-
return
|
46
|
+
var _a, _b, _c;
|
47
|
+
const matchesSearch = searchTerm.length < 2 ||
|
48
|
+
((_a = user.name) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(searchTerm)) ||
|
49
|
+
((_b = user.email) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes(searchTerm)) ||
|
50
|
+
((_c = user.mobile) === null || _c === void 0 ? void 0 : _c.toString().includes(searchTerm));
|
51
|
+
const matchesRoleType = selectedRoleType === "" || user.roleType === selectedRoleType;
|
52
|
+
return matchesSearch && matchesRoleType;
|
45
53
|
});
|
54
|
+
const handleRoleTypeChange = (event) => {
|
55
|
+
setSelectedRoleType(event.target.value);
|
56
|
+
setCurrentPage(1); // Reset to the first page
|
57
|
+
};
|
46
58
|
const totalPages = Math.ceil(filteredUsers.length / itemsPerPage);
|
47
59
|
const handleNextPage = () => {
|
48
60
|
if (currentPage < totalPages) {
|
@@ -91,6 +103,6 @@ const Users = ({ url }) => {
|
|
91
103
|
: "Not Provided" }), _jsx("td", { className: "px-4 py-4 text-sm text-gray-500 dark:text-gray-300 whitespace-nowrap", children: user.roleType === 1 ? "Guest" : "Admin" })] }, user.id || index))) })] }) }), _jsxs("div", { className: "flex items-center justify-between mt-6", children: [_jsxs("button", { onClick: handlePreviousPage, disabled: currentPage === 1, className: "flex items-center px-5 py-2 text-sm text-gray-700 capitalize transition-colors duration-200 bg-white border rounded-md gap-x-2 hover:bg-gray-100 dark:bg-gray-900 dark:text-gray-200 dark:border-gray-700 dark:hover:bg-gray-800", children: [_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", "stroke-width": "1.5", stroke: "currentColor", className: "w-5 h-5 rtl:-scale-x-100", children: _jsx("path", { "stroke-linecap": "round", "stroke-linejoin": "round", d: "M6.75 15.75L3 12m0 0l3.75-3.75M3 12h18" }) }), _jsx("span", { children: "previous" })] }), _jsx("div", { className: "items-center hidden lg:flex gap-x-3", children: Array.from({ length: totalPages }, (_, index) => (_jsx("button", { onClick: () => handlePageClick(index + 1), className: `px-2 py-1 text-sm ${currentPage === index + 1
|
92
104
|
? "text-blue-500 bg-blue-100"
|
93
105
|
: "text-gray-500 hover:bg-gray-100"} rounded-md`, children: index + 1 }, index + 1))) }), _jsxs("button", { onClick: handleNextPage, disabled: currentPage === totalPages, className: "flex items-center px-5 py-2 text-sm text-gray-700 capitalize transition-colors duration-200 bg-white border rounded-md gap-x-2 hover:bg-gray-100 dark:bg-gray-900 dark:text-gray-200 dark:border-gray-700 dark:hover:bg-gray-800", children: [_jsx("span", { children: "Next" }), _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", "stroke-width": "1.5", stroke: "currentColor", className: "w-5 h-5 rtl:-scale-x-100", children: _jsx("path", { "stroke-linecap": "round", "stroke-linejoin": "round", d: "M17.25 8.25L21 12m0 0l-3.75 3.75M21 12H3" }) })] })] }), _jsx("div", { className: "flex-grow ml-0 mt-4 w-0", children: _jsxs("button", { type: "button", onClick: (event) => handleNavigation(event, "/admin/users/userform"), className: "flex items-center justify-center px-6 py-2 font-medium tracking-wide text-white capitalize transition-colors duration-300 transform bg-blue-600 rounded-lg hover:bg-blue-500 focus:outline-none focus:ring focus:ring-blue-300 focus:ring-opacity-80", children: [_jsx(FaPlus, { className: "mr-2 font-medium" }), "User"] }) })] }), _jsx("div", { className: "inset-0 bg-gray-800 bg-opacity-50 z-50 transition-opacity duration-300", children: _jsxs("div", { className: `fixed top-0 right-0 h-full w-[300px] md:w-[500px] bg-white p-4 rounded-md shadow-lg transform transition-transform duration-500 ease-in-out
|
94
|
-
${filterModal ? "translate-x-0" : "translate-x-full"}`, children: [_jsx("h1", { className: "text-2xl md:text-3xl font-bold text-blue-600 mb-4 md:mb-6", children: "Filter" }), _jsx("button", { onClick: () => setFilterModal(false), className: "absolute top-1 right-3 text-gray-400 hover:text-gray-600 text-2xl", children: "\u00D7" }), _jsx("div", { className: "flex flex-col", children: _jsxs("div", { className: "mb-4 flex flex-col", children: [_jsx("label", { className: "block text-gray-700 mb-2", children: "Role Type" }), _jsx("div", { className: "w-full", children: _jsxs("select", { required: true, className: "w-full px-4 py-2 text-gray-800 bg-white border border-gray-400 rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-800 focus:border-blue-400 focus:ring-blue-300 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring", children: [_jsx("option", { value: "1", children: "Guest" }), _jsx("option", { value: "2", children: "Admin" })] }) })] }) })] }) })] }));
|
106
|
+
${filterModal ? "translate-x-0" : "translate-x-full"}`, children: [_jsx("h1", { className: "text-2xl md:text-3xl font-bold text-blue-600 mb-4 md:mb-6", children: "Filter" }), _jsx("button", { onClick: () => setFilterModal(false), className: "absolute top-1 right-3 text-gray-400 hover:text-gray-600 text-2xl", children: "\u00D7" }), _jsx("div", { className: "flex flex-col", children: _jsxs("div", { className: "mb-4 flex flex-col", children: [_jsx("label", { className: "block text-gray-700 mb-2", children: "Role Type" }), _jsx("div", { className: "w-full", children: _jsxs("select", { value: selectedRoleType, onChange: handleRoleTypeChange, required: true, className: "w-full px-4 py-2 text-gray-800 bg-white border border-gray-400 rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-800 focus:border-blue-400 focus:ring-blue-300 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring", children: [_jsx("option", { value: "", children: "Select a Role Type" }), _jsx("option", { value: "1", children: "Guest" }), _jsx("option", { value: "2", children: "Admin" })] }) })] }) })] }) })] }));
|
95
107
|
};
|
96
108
|
export default Users;
|
package/package.json
CHANGED
@@ -14,6 +14,7 @@ const Users = ({ url }: UsersProps) => {
|
|
14
14
|
const [searchTerm, setSearchTerm] = useState<string>("");
|
15
15
|
|
16
16
|
const [filterModal, setFilterModal] = useState(false);
|
17
|
+
const [selectedRoleType, setSelectedRoleType] = useState<string>("");
|
17
18
|
|
18
19
|
const fetchUsersData = async () => {
|
19
20
|
const data = await fetchUsersApi(url);
|
@@ -37,16 +38,36 @@ const Users = ({ url }: UsersProps) => {
|
|
37
38
|
const [currentPage, setCurrentPage] = useState(1);
|
38
39
|
const itemsPerPage = 10;
|
39
40
|
|
41
|
+
// const filteredUsers = users.filter((user) => {
|
42
|
+
// if (searchTerm.length < 2) return true;
|
43
|
+
|
44
|
+
// const nameMatch = user.name?.toLowerCase().includes(searchTerm) ?? false;
|
45
|
+
// const emailMatch = user.email?.toLowerCase().includes(searchTerm) ?? false;
|
46
|
+
// const mobileMatch = user.mobile?.toString().includes(searchTerm) ?? false;
|
47
|
+
|
48
|
+
// return nameMatch || emailMatch || mobileMatch;
|
49
|
+
// });
|
50
|
+
|
40
51
|
const filteredUsers = users.filter((user) => {
|
41
|
-
|
52
|
+
const matchesSearch =
|
53
|
+
searchTerm.length < 2 ||
|
54
|
+
user.name?.toLowerCase().includes(searchTerm) ||
|
55
|
+
user.email?.toLowerCase().includes(searchTerm) ||
|
56
|
+
user.mobile?.toString().includes(searchTerm);
|
42
57
|
|
43
|
-
const
|
44
|
-
|
45
|
-
const mobileMatch = user.mobile?.toString().includes(searchTerm) ?? false;
|
58
|
+
const matchesRoleType =
|
59
|
+
selectedRoleType === "" || user.roleType === selectedRoleType;
|
46
60
|
|
47
|
-
return
|
61
|
+
return matchesSearch && matchesRoleType;
|
48
62
|
});
|
49
63
|
|
64
|
+
const handleRoleTypeChange = (
|
65
|
+
event: React.ChangeEvent<HTMLSelectElement>
|
66
|
+
) => {
|
67
|
+
setSelectedRoleType(event.target.value);
|
68
|
+
setCurrentPage(1); // Reset to the first page
|
69
|
+
};
|
70
|
+
|
50
71
|
const totalPages = Math.ceil(filteredUsers.length / itemsPerPage);
|
51
72
|
|
52
73
|
const handleNextPage = () => {
|
@@ -414,31 +435,18 @@ const Users = ({ url }: UsersProps) => {
|
|
414
435
|
>
|
415
436
|
×
|
416
437
|
</button>
|
417
|
-
{/* <div className="flex flex-col">
|
418
|
-
<div className="mb-4 flex flex-col md:flex-row md:justify-between">
|
419
|
-
<label className="block text-gray-700 mt-2 mr-0 md:mr-5">
|
420
|
-
Role Type
|
421
|
-
</label>
|
422
|
-
<div className="w-full mt-2 md:mt-0">
|
423
|
-
<select
|
424
|
-
required
|
425
|
-
className="w-full px-4 py-2 mt-2 text-gray-800 bg-white border border-gray-400 rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-800 focus:border-blue-400 focus:ring-blue-300 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring"
|
426
|
-
>
|
427
|
-
<option value="1">Guest</option>
|
428
|
-
<option value="2">Admin</option>
|
429
|
-
</select>
|
430
|
-
</div>
|
431
|
-
</div>
|
432
|
-
</div> */}
|
433
438
|
|
434
439
|
<div className="flex flex-col">
|
435
440
|
<div className="mb-4 flex flex-col">
|
436
441
|
<label className="block text-gray-700 mb-2">Role Type</label>
|
437
442
|
<div className="w-full">
|
438
443
|
<select
|
444
|
+
value={selectedRoleType}
|
445
|
+
onChange={handleRoleTypeChange}
|
439
446
|
required
|
440
447
|
className="w-full px-4 py-2 text-gray-800 bg-white border border-gray-400 rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-800 focus:border-blue-400 focus:ring-blue-300 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring"
|
441
448
|
>
|
449
|
+
<option value="">Select a Role Type</option>
|
442
450
|
<option value="1">Guest</option>
|
443
451
|
<option value="2">Admin</option>
|
444
452
|
</select>
|