Skip to content

Commit

Permalink
feat(admin): implement uncheck-in button
Browse files Browse the repository at this point in the history
Co-authored-by: Modlizard <58074763>
  • Loading branch information
Modlizard authored Mar 27, 2022
1 parent 2c0c879 commit 9b4a0c5
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/pages/admin/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -57,6 +58,23 @@ const ManageSpecificUser: NextPage = () => {
getUser();
};

const unCheckIn = async () => {
const { error, data: newTicket } = await supabase.from<Ticket>('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 <Error statusCode={errorCode} />;

return (
Expand All @@ -74,6 +92,10 @@ const ManageSpecificUser: NextPage = () => {
</>
)}

{managedUser?.checked_in && (
<Button mt={3} onClick={unCheckIn}>Un Check-in</Button>
)}

<Button mt={3} onClick={toggleAdmin}>Toggle Admin</Button>
</Flex>
</BaseLayout>
Expand Down

1 comment on commit 9b4a0c5

@vercel
Copy link

@vercel vercel bot commented on 9b4a0c5 Mar 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.