feat: integrate admin store in api services tab

This commit is contained in:
2025-05-30 21:27:59 +02:00
parent 70f860824c
commit 8abc4396ac

View File

@ -1,71 +1,102 @@
import type { FC } from "react"; import { useAdmin } from "@/store/admin";
import { useEffect, type FC } from "react";
import { Link } from "react-router"; import { Link } from "react-router";
const services = [ // const services = [
{ // {
id: "1", // id: "1",
name: "User Service", // name: "User Service",
clientId: "user-svc-001", // clientId: "user-svc-001",
isActive: true, // isActive: true,
createdAt: "2024-09-15T10:20:30Z", // createdAt: "2024-09-15T10:20:30Z",
updatedAt: "2025-01-10T12:00:00Z", // updatedAt: "2025-01-10T12:00:00Z",
}, // },
{ // {
id: "2", // id: "2",
name: "Billing Service", // name: "Billing Service",
clientId: "billing-svc-009", // clientId: "billing-svc-009",
isActive: false, // isActive: false,
createdAt: "2024-10-01T08:45:10Z", // createdAt: "2024-10-01T08:45:10Z",
updatedAt: "2025-03-22T14:30:00Z", // updatedAt: "2025-03-22T14:30:00Z",
}, // },
{ // {
id: "3", // id: "3",
name: "Analytics Service", // name: "Analytics Service",
clientId: "analytics-svc-777", // clientId: "analytics-svc-777",
isActive: true, // isActive: true,
createdAt: "2024-11-25T16:00:00Z", // createdAt: "2024-11-25T16:00:00Z",
updatedAt: "2025-02-05T10:15:45Z", // updatedAt: "2025-02-05T10:15:45Z",
}, // },
{ // {
id: "4", // id: "4",
name: "Email Service", // name: "Email Service",
clientId: "email-svc-333", // clientId: "email-svc-333",
isActive: false, // isActive: false,
createdAt: "2023-07-10T13:00:00Z", // createdAt: "2023-07-10T13:00:00Z",
updatedAt: "2024-12-31T09:25:00Z", // updatedAt: "2024-12-31T09:25:00Z",
}, // },
]; // ];
const ApiServicesPage: FC = () => { const ApiServicesPage: FC = () => {
const apiServices = useAdmin((state) => state.apiServices);
const loading = useAdmin((state) => state.loadingApiServices);
const fetchApiServices = useAdmin((state) => state.fetchApiServices);
useEffect(() => {
fetchApiServices();
}, [fetchApiServices]);
return ( return (
<div className="overflow-x-auto rounded shadow-md dark:shadow-gray-800"> <div className="relative overflow-x-auto flex flex-col w-full h-full">
<table className="min-w-full divide-y divide-gray-200 dark:divide-gray-700"> <div className="p-4">
<thead className="bg-gray-50 dark:bg-gray-800"> <p className="text-gray-800 dark:text-gray-300">Search...</p>
</div>
{loading && (
<div className="absolute inset-0 z-10 flex items-center justify-center bg-white/60 dark:bg-gray-900/60 backdrop-blur-sm">
<div className="text-gray-800 dark:text-gray-200 font-medium">
Loading...
</div>
</div>
)}
<table className="min-w-full flex-1 border-l-0 border border-gray-700 dark:border-gray-800 border-collapse divide-y divide-gray-200 dark:divide-gray-800">
<thead className="bg-black/5 dark:bg-white/5">
<tr> <tr>
<th className="px-6 py-3 text-left text-sm font-semibold text-gray-700 dark:text-gray-200"> <th className="px-6 py-3 text-left text-sm font-semibold text-gray-700 dark:text-white/70 border border-l-0 border-gray-700 dark:border-gray-800">
Name Name
</th> </th>
<th className="px-6 py-3 text-left text-sm font-semibold text-gray-700 dark:text-gray-200"> <th className="px-6 py-3 text-left text-sm font-semibold text-gray-700 dark:text-white/70 border border-l-0 border-gray-700 dark:border-gray-800">
Client ID Client ID
</th> </th>
<th className="px-6 py-3 text-left text-sm font-semibold text-gray-700 dark:text-gray-200"> <th className="px-6 py-3 text-left text-sm font-semibold text-gray-700 dark:text-white/70 border border-l-0 border-gray-700 dark:border-gray-800">
Is Active Is Active
</th> </th>
<th className="px-6 py-3 text-left text-sm font-semibold text-gray-700 dark:text-gray-200"> <th className="px-6 py-3 text-left text-sm font-semibold text-gray-700 dark:text-white/70 border border-l-0 border-gray-700 dark:border-gray-800">
Created At Created At
</th> </th>
<th className="px-6 py-3 text-left text-sm font-semibold text-gray-700 dark:text-gray-200"> <th className="px-6 py-3 text-left text-sm font-semibold text-gray-700 dark:text-white/70 border border-l-0 border-gray-700 dark:border-gray-800">
Updated At Updated At
</th> </th>
</tr> </tr>
</thead> </thead>
<tbody className="bg-white dark:bg-gray-900 divide-y divide-gray-200 dark:divide-gray-700"> <tbody className="divide-y divide-gray-200 dark:divide-gray-700">
{services.map((service) => ( {!loading && apiServices.length === 0 ? (
<tr>
<td
colSpan={5}
className="px-6 py-12 text-center text-gray-500 dark:text-gray-400"
>
No services found.
</td>
</tr>
) : (
apiServices.map((service) => (
<tr <tr
key={service.id} key={service.id}
className="hover:bg-gray-50 dark:hover:bg-gray-800" className="hover:bg-gray-50 dark:hover:bg-gray-800"
> >
<td className="px-6 py-4 text-sm font-medium text-blue-600"> <td className="px-6 py-4 text-sm font-medium text-blue-600 border border-gray-700">
<Link <Link
to={`/services/${service.id}`} to={`/services/${service.id}`}
className="hover:underline hover:text-gray-600 dark:hover:text-gray-300 transition-colors" className="hover:underline hover:text-gray-600 dark:hover:text-gray-300 transition-colors"
@ -73,28 +104,29 @@ const ApiServicesPage: FC = () => {
{service.name} {service.name}
</Link> </Link>
</td> </td>
<td className="px-6 py-4 text-sm text-gray-700 dark:text-gray-300"> <td className="px-6 py-4 text-sm text-gray-700 dark:text-gray-300 border border-gray-700">
{service.clientId} {service.client_id}
</td> </td>
<td className="px-6 py-4 text-sm"> <td className="px-6 py-4 text-sm border border-gray-700">
<span <span
className={`inline-block px-2 py-1 text-xs rounded-full font-semibold ${ className={`inline-block px-2 py-1 text-xs rounded-full font-semibold ${
service.isActive service.is_active
? "bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300" ? "bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300"
: "bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-300" : "bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-300"
}`} }`}
> >
{service.isActive ? "Yes" : "No"} {service.is_active ? "Yes" : "No"}
</span> </span>
</td> </td>
<td className="px-6 py-4 text-sm text-gray-500 dark:text-gray-400"> <td className="px-6 py-4 text-sm text-gray-500 dark:text-gray-400 border border-gray-700">
{new Date(service.createdAt).toLocaleString()} {new Date(service.created_at).toLocaleString()}
</td> </td>
<td className="px-6 py-4 text-sm text-gray-500 dark:text-gray-400"> <td className="px-6 py-4 text-sm text-gray-500 dark:text-gray-400 border border-gray-700">
{new Date(service.updatedAt).toLocaleString()} {new Date(service.updated_at).toLocaleString()}
</td> </td>
</tr> </tr>
))} ))
)}
</tbody> </tbody>
</table> </table>
</div> </div>