Impede acesso ao portal para máquinas desativadas
This commit is contained in:
parent
0e97e4c0d6
commit
e5085962e9
5 changed files with 195 additions and 18 deletions
|
|
@ -44,10 +44,15 @@ export function PortalTicketForm() {
|
|||
const [categoryId, setCategoryId] = useState<string | null>(null)
|
||||
const [subcategoryId, setSubcategoryId] = useState<string | null>(null)
|
||||
const [attachments, setAttachments] = useState<Array<{ storageId: string; name: string; size?: number; type?: string }>>([])
|
||||
const attachmentsTotalBytes = useMemo(
|
||||
() => attachments.reduce((acc, item) => acc + (item.size ?? 0), 0),
|
||||
[attachments]
|
||||
)
|
||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||
const machineInactive = machineContext?.isActive === false
|
||||
const isFormValid = useMemo(() => {
|
||||
return Boolean(subject.trim() && description.trim() && categoryId && subcategoryId)
|
||||
}, [subject, description, categoryId, subcategoryId])
|
||||
return Boolean(subject.trim() && description.trim() && categoryId && subcategoryId && !machineInactive)
|
||||
}, [subject, description, categoryId, subcategoryId, machineInactive])
|
||||
const isViewerReady = Boolean(viewerId)
|
||||
const viewerErrorMessage = useMemo(() => {
|
||||
if (!machineContextError) return null
|
||||
|
|
@ -58,10 +63,14 @@ export function PortalTicketForm() {
|
|||
async function handleSubmit(event: React.FormEvent) {
|
||||
event.preventDefault()
|
||||
if (isSubmitting || !isFormValid) return
|
||||
if (machineInactive) {
|
||||
toast.error("Esta máquina está desativada no momento. Reative-a para abrir novos chamados.", { id: "portal-new-ticket" })
|
||||
return
|
||||
}
|
||||
if (!viewerId) {
|
||||
const detail = viewerErrorMessage ? ` Detalhes: ${viewerErrorMessage}` : ""
|
||||
toast.error(
|
||||
`N<EFBFBD>o foi poss<73>vel identificar o colaborador vinculado a esta m<>quina. Tente abrir novamente o portal ou contate o suporte.${detail}`,
|
||||
`Não foi possível identificar o colaborador vinculado a esta máquina. Tente abrir novamente o portal ou contate o suporte.${detail}`,
|
||||
{ id: "portal-new-ticket" }
|
||||
)
|
||||
return
|
||||
|
|
@ -127,6 +136,11 @@ export function PortalTicketForm() {
|
|||
<CardTitle className="text-xl font-semibold text-neutral-900">Abrir novo chamado</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6 px-5 pb-6">
|
||||
{machineInactive ? (
|
||||
<div className="rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-700">
|
||||
Esta máquina foi desativada pelos administradores e não pode abrir novos chamados até ser reativada.
|
||||
</div>
|
||||
) : null}
|
||||
{!isViewerReady ? (
|
||||
<div className="rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-700">
|
||||
Vincule esta máquina a um colaborador na aplicação desktop para enviar chamados em nome dele.
|
||||
|
|
@ -151,6 +165,7 @@ export function PortalTicketForm() {
|
|||
value={subject}
|
||||
onChange={(event) => setSubject(event.target.value)}
|
||||
placeholder="Ex.: Problema de acesso ao sistema"
|
||||
disabled={machineInactive || isSubmitting}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
|
@ -163,6 +178,7 @@ export function PortalTicketForm() {
|
|||
value={summary}
|
||||
onChange={(event) => setSummary(event.target.value)}
|
||||
placeholder="Descreva rapidamente o que está acontecendo"
|
||||
disabled={machineInactive || isSubmitting}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
|
|
@ -174,6 +190,7 @@ export function PortalTicketForm() {
|
|||
onChange={(html) => setDescription(html)}
|
||||
placeholder="Compartilhe passos para reproduzir, mensagens de erro ou informações adicionais."
|
||||
className="rounded-2xl border border-slate-200 shadow-sm focus-within:border-neutral-900 focus-within:ring-neutral-900/20"
|
||||
disabled={machineInactive || isSubmitting}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -195,6 +212,9 @@ export function PortalTicketForm() {
|
|||
<Dropzone
|
||||
onUploaded={(files) => setAttachments((prev) => [...prev, ...files])}
|
||||
className="rounded-xl border border-dashed border-slate-300 bg-slate-50 px-3 py-4 text-sm text-neutral-600 shadow-inner"
|
||||
currentFileCount={attachments.length}
|
||||
currentTotalBytes={attachmentsTotalBytes}
|
||||
disabled={!isViewerReady || machineInactive || isSubmitting}
|
||||
/>
|
||||
<p className="text-xs text-neutral-500">
|
||||
Formatos comuns de imagens e documentos são aceitos.
|
||||
|
|
@ -208,12 +228,13 @@ export function PortalTicketForm() {
|
|||
variant="outline"
|
||||
onClick={() => router.push("/portal/tickets")}
|
||||
className="rounded-full border-slate-300 px-6 text-sm font-semibold text-neutral-700 hover:bg-neutral-100"
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
Cancelar
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={!isFormValid || isSubmitting}
|
||||
disabled={!isFormValid || isSubmitting || machineInactive}
|
||||
className="rounded-full bg-neutral-900 px-6 text-sm font-semibold text-white hover:bg-neutral-900/90"
|
||||
>
|
||||
Registrar chamado
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue