infoalloggi-monorepo/apps/infoalloggi/src/pages/area-riservata/admin/utenti.tsx

85 lines
2.3 KiB
TypeScript
Raw Normal View History

2025-08-04 17:45:44 +02:00
import { RefreshCcw } from "lucide-react";
import { useState } from "react";
import { AreaRiservataLayout } from "~/components/Layout";
import { LoadingPage } from "~/components/loading";
import { Status500 } from "~/components/status-page";
import { UsersTable } from "~/components/tables/users-table";
import { Button } from "~/components/ui/button";
import {
2025-08-28 18:27:07 +02:00
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
2025-08-04 17:45:44 +02:00
} from "~/components/ui/dialog";
2025-08-28 18:27:07 +02:00
import { FormNewUser } from "~/forms/FormNewUser";
2025-08-04 17:45:44 +02:00
import type { NextPageWithLayout } from "~/pages/_app";
import { api } from "~/utils/api";
const Admin_Utenti: NextPageWithLayout = () => {
2025-08-28 18:27:07 +02:00
const { data, isLoading, refetch } = api.users.getUsersWChatInfo.useQuery(
undefined,
{
refetchOnWindowFocus: true,
},
);
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
if (isLoading) return <LoadingPage />;
if (!data) return <Status500 />;
return (
<div className="mx-1 flex-1 overflow-auto">
<div className="mx-auto pt-4">
<div className="mx-3 items-start justify-between md:flex">
<div className="flex max-w-lg items-center gap-3">
<h3 className="text-2xl font-bold">Utenti</h3>
<button
type="button"
onClick={async () => await refetch()}
className="cursor-pointer"
>
<RefreshCcw className="size-6" />
</button>
</div>
<div className="mt-3 md:mt-0">
<NewUserModal />
</div>
</div>
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
<UsersTable data={data} />
</div>
</div>
);
2025-08-04 17:45:44 +02:00
};
export default Admin_Utenti;
Admin_Utenti.getLayout = function getLayout(page) {
2025-08-28 18:27:07 +02:00
return <AreaRiservataLayout>{page}</AreaRiservataLayout>;
2025-08-04 17:45:44 +02:00
};
const NewUserModal = () => {
2025-08-28 18:27:07 +02:00
const [open, setOpen] = useState(false);
const handleOpen = (status: boolean) => setOpen(status);
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button variant="outline">Aggiungi Utente</Button>
</DialogTrigger>
<DialogContent className="max-h-[80%] overflow-auto sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>Aggiungi Utente</DialogTitle>
<DialogDescription className="sr-only">
Aggiungi un nuovo utente al sistema.
</DialogDescription>
</DialogHeader>
<div className="py-4">
<FormNewUser setOpen={handleOpen} />
</div>
</DialogContent>
</Dialog>
);
2025-08-04 17:45:44 +02:00
};