From 9b4a0c562a693f74afaa01c6cc1f50f2f374ae54 Mon Sep 17 00:00:00 2001 From: Modlizard <58074763+Modlizard@users.noreply.github.com> Date: Sun, 27 Mar 2022 20:06:06 +0100 Subject: [PATCH] feat(admin): implement uncheck-in button Co-authored-by: Modlizard <58074763> --- src/pages/admin/[id]/index.tsx | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/pages/admin/[id]/index.tsx b/src/pages/admin/[id]/index.tsx index 5c7c915..6454931 100644 --- a/src/pages/admin/[id]/index.tsx +++ b/src/pages/admin/[id]/index.tsx @@ -11,8 +11,9 @@ import { useRouter } from 'next/router'; import { useCallback, useEffect, useState } from 'react'; import { useUser } from '@supabase/supabase-auth-helpers/react'; import Error from 'next/error'; -import type { UserWithTicket } from 'types/user'; +import type { UserWithTicket, Ticket } from 'types/user'; import QR from 'components/UserPanel/QR'; +import { supabaseClient as supabase } from '@supabase/supabase-auth-helpers/nextjs'; const ManageSpecificUser: NextPage = () => { const router = useRouter(); @@ -57,6 +58,23 @@ const ManageSpecificUser: NextPage = () => { getUser(); }; + const unCheckIn = async () => { + const { error, data: newTicket } = await supabase.from('tickets').update({ checked_in: false }).match({ id: managedUser.ticketId }).single(); + if (error) { + toast({ + title: 'Failed to uncheck in', + status: 'error', + }); + return; + } + toast({ + title: 'Unchecked in', + description: `New check in status: ${newTicket.checked_in}`, + status: 'success', + }); + getUser(); + }; + if (errorCode) return ; return ( @@ -74,6 +92,10 @@ const ManageSpecificUser: NextPage = () => { )} + {managedUser?.checked_in && ( + + )} +