From 8619753a9d2a64b912ca73376740b33dbfa40fee Mon Sep 17 00:00:00 2001 From: Leonardo da Silva Date: Sat, 26 Oct 2024 13:09:00 -0300 Subject: [PATCH] style: ticket UI colors --- src/app/admin/ticket/check-in/[id]/page.tsx | 2 +- src/components/ticket/Ticket.tsx | 37 ++++++++++++++++++--- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/app/admin/ticket/check-in/[id]/page.tsx b/src/app/admin/ticket/check-in/[id]/page.tsx index 7c870ba..f4981d8 100644 --- a/src/app/admin/ticket/check-in/[id]/page.tsx +++ b/src/app/admin/ticket/check-in/[id]/page.tsx @@ -9,7 +9,7 @@ export const metadata: Metadata = { export default function Page({ params }: { params: { id: string } }) { return ( -
+
}> diff --git a/src/components/ticket/Ticket.tsx b/src/components/ticket/Ticket.tsx index 1912e3d..9a6eda9 100644 --- a/src/components/ticket/Ticket.tsx +++ b/src/components/ticket/Ticket.tsx @@ -1,6 +1,6 @@ "use client"; -import {Ticket} from "@/models"; +import {Event, Ticket} from "@/models"; import "./style.css"; import {consumeTicket, getTicket} from "@/server-actions/ticket.action"; import {getUser} from "@/server-actions/user.action"; @@ -9,11 +9,15 @@ import {useRouter} from "next/navigation"; import {useEffect, useState} from "react"; import {toast} from "react-toastify"; import {toastConfig} from "@/constants"; +import {getEvent} from "@/server-actions/event.action"; +import Loading from "@/app/auth/email/confirmation/[token]/loading"; export default function TicketUI({id}: { id: string }) { const [ticket, setTicket] = useState(); + const [event, setEvent] = useState(); const [user, setUser] = useState(); const [loading, setLoading] = useState(false); + const [isFetching, setIsFetching] = useState(true); const router = useRouter(); const handleValidate = async () => { setLoading(true); @@ -22,20 +26,33 @@ export default function TicketUI({id}: { id: string }) { else toast.success("Ticket validado com sucesso!", toastConfig); setLoading(false); }; + useEffect(() => { const fetchTicket = async (id: string) => { const resp = await getTicket(id); if ("error" in resp) { + router.push("/"); toast.error(resp.error, toastConfig); return; } setTicket(resp); + + const response = await getEvent(resp.event_id); + if ("error" in response) { + router.push("/"); + toast.error(response.error, toastConfig); + return + } + setEvent(response); + const respUser = await getUser(resp.user_id); if ("error" in respUser) { + router.push("/"); toast.error(respUser.error, toastConfig); return; } setUser(respUser); + setIsFetching(false); }; fetchTicket(id); }, [router]); @@ -54,14 +71,19 @@ export default function TicketUI({id}: { id: string }) { return age + " anos"; }; - return ( + if (isFetching) { + return ; + } else return ( <> {/* desktop */}
- TICKET - IFETÃO (Finais) (28/09) + TICKET - {event?.name} ({event?.init_date.toLocaleString("pt-BR", { + day: "2-digit", + month: "2-digit" + })})

INSTITUTO FEDERAL DE SÃO PAULO - CUBATÃO @@ -71,6 +93,7 @@ export default function TicketUI({id}: { id: string }) {

Nome cadastrado: {user?.name || "Carregando..."}

Idade: {getAge(user?.birth_date)}

+

Documento: {user?.document_initials}

{ticket?.status}

@@ -91,7 +114,10 @@ export default function TicketUI({id}: { id: string }) {
- TICKET - IFETÃO (Finais) (28/09) + TICKET - {event?.name} ({event?.init_date.toLocaleString("pt-BR", { + day: "2-digit", + month: "2-digit" + })})

INSTITUTO FEDERAL DE SÃO PAULO - CUBATÃO @@ -100,7 +126,8 @@ export default function TicketUI({id}: { id: string }) {

{user?.name || "Carregando..."}

-

Idade: {getAge(user?.birth_date)}

+

{getAge(user?.birth_date)}

+

{user?.document_initials}

{ticket?.status}