diff --git a/lib/api/controllers/users/getUsers.ts b/lib/api/controllers/users/getUsers.ts index dd2b168..496efcf 100644 --- a/lib/api/controllers/users/getUsers.ts +++ b/lib/api/controllers/users/getUsers.ts @@ -14,7 +14,6 @@ export default async function getUsers() { }, }, createdAt: true, - updatedAt: true, }, }); diff --git a/pages/admin.tsx b/pages/admin.tsx index 6624fe3..be634f8 100644 --- a/pages/admin.tsx +++ b/pages/admin.tsx @@ -11,6 +11,9 @@ interface User extends U { export default function Admin() { const [users, setUsers] = useState(); + const [searchQuery, setSearchQuery] = useState(""); + const [filteredUsers, setFilteredUsers] = useState(); + useEffect(() => { // fetch users fetch("/api/v1/users") @@ -19,59 +22,109 @@ export default function Admin() { }, []); return ( -
-
- - - -

- User Administration -

+
+
+
+ + + +

+ User Administration +

+
+ +
+
+ + + { + setSearchQuery(e.target.value); + + if (users) { + setFilteredUsers( + users.filter((user) => + JSON.stringify(user) + .toLowerCase() + .includes(e.target.value.toLowerCase()) + ) + ); + } + }} + className="border border-neutral-content bg-base-200 focus:border-primary py-1 rounded-md pl-9 pr-2 w-full max-w-[15rem] md:w-[15rem] md:max-w-full duration-200 outline-none" + /> +
+ +
+ +
+
- {users && users.length > 0 ? ( -
- - - - - - {process.env.NEXT_PUBLIC_EMAIL_PROVIDER === "true" && ( - - )} - {process.env.NEXT_PUBLIC_STRIPE === "true" && ( - - )} - - - - - - {users.map((user, index) => ( - - - - {process.env.NEXT_PUBLIC_EMAIL_PROVIDER === "true" && ( - - )} - {process.env.NEXT_PUBLIC_STRIPE === "true" && ( - - )} - - - - ))} - -
UsernameEmailSubscribedCreated AtUpdated At
{index + 1}{user.username}{user.email}{user.subscriptions.active ? "Yes" : "No"}{new Date(user.createdAt).toLocaleString()}{new Date(user.updatedAt).toLocaleString()}
-
+ {filteredUsers && filteredUsers.length > 0 && searchQuery !== "" ? ( + UserLising(filteredUsers) + ) : searchQuery !== "" ? ( +

No users found with the given search query.

+ ) : users && users.length > 0 ? ( + UserLising(users) ) : (

No users found.

)}
); } + +const UserLising = (users: User[]) => { + return ( +
+ + + + + + {process.env.NEXT_PUBLIC_EMAIL_PROVIDER === "true" && ( + + )} + {process.env.NEXT_PUBLIC_STRIPE === "true" && } + + + + + + {users.map((user, index) => ( + + + + {process.env.NEXT_PUBLIC_EMAIL_PROVIDER === "true" && ( + + )} + {process.env.NEXT_PUBLIC_STRIPE === "true" && ( + + )} + + + + ))} + +
UsernameEmailSubscribedCreated At
{index + 1}{user.username}{user.email}{JSON.stringify(user.subscriptions.active)}{new Date(user.createdAt).toLocaleString()} + +
+
+ ); +};