novas atualizacoes do sistema de fechamento
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import { useState } from "react";
|
||||
import { useMemo, 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 { BorderBeam } from "@/components/ui/border-beam";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { InteractiveHoverButton } from "@/components/ui/interactive-hover-button";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import type { AccessBlockReason } from "@/contexts/AuthAccessContext";
|
||||
import { authMeService } from "@/services/fechamento/authMe";
|
||||
import { GlobalFunctions, TransferAreaProperties } from "@/GlobalFunctions";
|
||||
|
||||
type NoAccessScreenProps = {
|
||||
reason: AccessBlockReason | null;
|
||||
@@ -19,9 +21,6 @@ function getMessage(reason: AccessBlockReason | null): string {
|
||||
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.";
|
||||
}
|
||||
|
||||
@@ -30,7 +29,15 @@ export function NoAccessScreen({ reason, errorMessage }: NoAccessScreenProps) {
|
||||
const [adminNome, setAdminNome] = useState("");
|
||||
const [adminEmail, setAdminEmail] = useState("");
|
||||
const [saving, setSaving] = useState(false);
|
||||
const estabelecimentoId = (errorMessage ?? "").trim();
|
||||
|
||||
/** Código do estabelecimento: prioriza área de transferência (Codex), depois o valor repassado pelo AuthGate. */
|
||||
const estabelecimentoId = useMemo(() => {
|
||||
const fromTransfer = String(
|
||||
GlobalFunctions.getTransferProperty(TransferAreaProperties.EstabelecimentoCodigo) ?? "",
|
||||
).trim();
|
||||
const fromGate = (errorMessage ?? "").trim();
|
||||
return fromTransfer || fromGate;
|
||||
}, [errorMessage]);
|
||||
|
||||
const handleBootstrap = async () => {
|
||||
if (!estabelecimentoId) {
|
||||
@@ -58,20 +65,40 @@ export function NoAccessScreen({ reason, errorMessage }: NoAccessScreenProps) {
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-background p-4">
|
||||
<Card className="w-full max-w-xl">
|
||||
<Card className="relative w-full max-w-xl overflow-hidden">
|
||||
<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>
|
||||
{reason === "bootstrap" ? (
|
||||
<>
|
||||
<CardTitle>Bem-vindo! Configuração inicial</CardTitle>
|
||||
<CardDescription className="text-base leading-relaxed text-muted-foreground">
|
||||
Este é o <strong className="font-medium text-foreground">primeiro acesso</strong> ao Fechamento HGTX
|
||||
para este estabelecimento. Em poucos passos você cadastra a unidade e o primeiro usuário administrador
|
||||
para começar a usar o sistema.
|
||||
</CardDescription>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<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" ? <p className="text-muted-foreground">{getMessage(reason)}</p> : null}
|
||||
{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" />
|
||||
<Input value={estabelecimentoId} disabled className="font-mono bg-muted" />
|
||||
<p className="text-xs text-muted-foreground">Preenchimento automático.</p>
|
||||
{!estabelecimentoId ? (
|
||||
<p className="text-xs text-amber-700 dark:text-amber-200">
|
||||
Não foi possível obter o código do estabelecimento. Abra o Fechamento HGTX a partir do Codex com o
|
||||
estabelecimento carregado no transfer.
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="bootstrap-unidade">Nome da unidade</Label>
|
||||
@@ -102,16 +129,21 @@ export function NoAccessScreen({ reason, errorMessage }: NoAccessScreenProps) {
|
||||
/>
|
||||
</div>
|
||||
<div className="flex justify-end">
|
||||
<Button type="button" onClick={handleBootstrap} disabled={saving}>
|
||||
<InteractiveHoverButton
|
||||
type="button"
|
||||
onClick={handleBootstrap}
|
||||
disabled={saving || !estabelecimentoId}
|
||||
className="disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
{saving ? (
|
||||
<>
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
<span className="inline-flex items-center gap-2">
|
||||
<Loader2 className="h-4 w-4 shrink-0 animate-spin" aria-hidden />
|
||||
Inicializando...
|
||||
</>
|
||||
</span>
|
||||
) : (
|
||||
"Inicializar ambiente"
|
||||
"Iniciar ambiente"
|
||||
)}
|
||||
</Button>
|
||||
</InteractiveHoverButton>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
@@ -119,6 +151,7 @@ export function NoAccessScreen({ reason, errorMessage }: NoAccessScreenProps) {
|
||||
<p className="text-sm text-muted-foreground">{errorMessage}</p>
|
||||
) : null}
|
||||
</CardContent>
|
||||
<BorderBeam duration={8} size={100} />
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user