Log machine context errors in portal
This commit is contained in:
parent
545d5bea4b
commit
0fb95147f4
3 changed files with 82 additions and 5 deletions
|
|
@ -31,7 +31,7 @@ function toHtml(text: string) {
|
|||
|
||||
export function PortalTicketForm() {
|
||||
const router = useRouter()
|
||||
const { convexUserId, session, machineContext } = useAuth()
|
||||
const { convexUserId, session, machineContext, machineContextError, machineContextLoading } = useAuth()
|
||||
const createTicket = useMutation(api.tickets.create)
|
||||
const addComment = useMutation(api.tickets.addComment)
|
||||
|
||||
|
|
@ -49,13 +49,19 @@ export function PortalTicketForm() {
|
|||
return Boolean(subject.trim() && description.trim() && categoryId && subcategoryId)
|
||||
}, [subject, description, categoryId, subcategoryId])
|
||||
const isViewerReady = Boolean(viewerId)
|
||||
const viewerErrorMessage = useMemo(() => {
|
||||
if (!machineContextError) return null
|
||||
const suffix = machineContextError.status ? ` (status ${machineContextError.status})` : ""
|
||||
return `${machineContextError.message}${suffix}`
|
||||
}, [machineContextError])
|
||||
|
||||
async function handleSubmit(event: React.FormEvent) {
|
||||
event.preventDefault()
|
||||
if (isSubmitting || !isFormValid) return
|
||||
if (!viewerId) {
|
||||
const detail = viewerErrorMessage ? ` Detalhes: ${viewerErrorMessage}` : ""
|
||||
toast.error(
|
||||
"Não foi possível identificar o colaborador vinculado a esta máquina. Tente abrir novamente o portal ou contate o suporte.",
|
||||
`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}`,
|
||||
{ id: "portal-new-ticket" }
|
||||
)
|
||||
return
|
||||
|
|
@ -124,6 +130,14 @@ export function PortalTicketForm() {
|
|||
{!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.
|
||||
{machineContextLoading ? (
|
||||
<p className="mt-2 text-xs text-amber-600">Carregando informa<EFBFBD><EFBFBD>es da m<EFBFBD>quina...</p>
|
||||
) : null}
|
||||
{viewerErrorMessage ? (
|
||||
<p className="mt-2 text-xs text-amber-600">
|
||||
Detalhes do erro: {viewerErrorMessage}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
<form onSubmit={handleSubmit} className="space-y-6">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue