atualizacoes modulo fechamento

This commit is contained in:
Vitex Tecnologia
2026-04-26 22:54:56 -03:00
parent 7a01c6f97b
commit 6da067c641
29 changed files with 5973 additions and 3 deletions
+125
View File
@@ -0,0 +1,125 @@
import { useState } from "react";
import { Loader2, ShieldX } from "lucide-react";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import type { AccessBlockReason } from "@/contexts/AuthAccessContext";
import { authMeService } from "@/services/fechamento/authMe";
type NoAccessScreenProps = {
reason: AccessBlockReason | null;
errorMessage?: string | null;
};
function getMessage(reason: AccessBlockReason | null): string {
if (reason === "inativo") {
return "Seu usuário está inativo neste módulo. Solicite a reativação ao administrador.";
}
if (reason === "erro") {
return "Não foi possível validar seu acesso agora. Tente novamente em instantes.";
}
if (reason === "bootstrap") {
return "Primeiro acesso detectado. Cadastre a unidade e o primeiro usuário administrador para iniciar o sistema.";
}
return "Você não tem acesso a este módulo no momento. Solicite acesso ao administrador.";
}
export function NoAccessScreen({ reason, errorMessage }: NoAccessScreenProps) {
const [unidadeNome, setUnidadeNome] = useState("");
const [adminNome, setAdminNome] = useState("");
const [adminEmail, setAdminEmail] = useState("");
const [saving, setSaving] = useState(false);
const estabelecimentoId = (errorMessage ?? "").trim();
const handleBootstrap = async () => {
if (!estabelecimentoId) {
return;
}
if (!unidadeNome.trim() || !adminNome.trim() || !adminEmail.trim()) {
alert("Preencha nome da unidade, nome do admin e e-mail.");
return;
}
try {
setSaving(true);
await authMeService.bootstrapInitialize({
estabelecimentoId,
unidadeNome: unidadeNome.trim(),
adminNome: adminNome.trim(),
adminEmail: adminEmail.trim(),
});
window.location.reload();
} catch (error) {
alert(error instanceof Error ? error.message : "Erro ao inicializar ambiente.");
} finally {
setSaving(false);
}
};
return (
<div className="flex min-h-screen items-center justify-center bg-background p-4">
<Card className="w-full max-w-xl">
<CardHeader className="text-center">
<div className="mb-3 flex justify-center">
<ShieldX className="h-10 w-10 text-destructive" />
</div>
<CardTitle>Você não tem acesso a este módulo</CardTitle>
</CardHeader>
<CardContent className="space-y-3 text-center">
<p className="text-muted-foreground">{getMessage(reason)}</p>
{reason === "bootstrap" ? (
<div className="space-y-4 rounded-md border p-4 text-left">
<div className="space-y-1">
<Label>Código do estabelecimento</Label>
<Input value={estabelecimentoId} readOnly className="font-mono bg-muted" />
</div>
<div className="space-y-1">
<Label htmlFor="bootstrap-unidade">Nome da unidade</Label>
<Input
id="bootstrap-unidade"
value={unidadeNome}
onChange={(e) => setUnidadeNome(e.target.value)}
placeholder="Ex.: Unidade Matriz"
/>
</div>
<div className="space-y-1">
<Label htmlFor="bootstrap-admin-nome">Nome do primeiro admin</Label>
<Input
id="bootstrap-admin-nome"
value={adminNome}
onChange={(e) => setAdminNome(e.target.value)}
placeholder="Ex.: João Silva"
/>
</div>
<div className="space-y-1">
<Label htmlFor="bootstrap-admin-email">E-mail do primeiro admin</Label>
<Input
id="bootstrap-admin-email"
type="email"
value={adminEmail}
onChange={(e) => setAdminEmail(e.target.value)}
placeholder="admin@empresa.com"
/>
</div>
<div className="flex justify-end">
<Button type="button" onClick={handleBootstrap} disabled={saving}>
{saving ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
Inicializando...
</>
) : (
"Inicializar ambiente"
)}
</Button>
</div>
</div>
) : null}
{reason !== "bootstrap" && errorMessage ? (
<p className="text-sm text-muted-foreground">{errorMessage}</p>
) : null}
</CardContent>
</Card>
</div>
);
}