-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fe): add contest register deregister button (#1545)
* feat(fe): add register and deregister button * feat(fe): register button for upgoing and ongoing * fix(fe): register for ongoing button * fix(fe): change deregister button color * fix(fe): fix toast message * fix: get rid of comments * fix(fe): change parameter name
- Loading branch information
1 parent
5fb21d1
commit a76bce0
Showing
3 changed files
with
96 additions
and
29 deletions.
There are no files selected for viewing
24 changes: 0 additions & 24 deletions
24
apps/frontend/app/(main)/contest/[contestId]/@tabs/_components/ParticipateButton.tsx
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
apps/frontend/app/(main)/contest/[contestId]/@tabs/_components/RegisterButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
'use client' | ||
|
||
import { Button } from '@/components/ui/button' | ||
import { fetcherWithAuth } from '@/lib/utils' | ||
import { useState } from 'react' | ||
import { toast } from 'sonner' | ||
|
||
const clickRegister = async (contestId: string) => { | ||
await fetcherWithAuth | ||
.post(`contest/${contestId}/participation`, { | ||
searchParams: { groupId: 1 } | ||
}) | ||
.then((res) => res.json()) | ||
.catch((err) => console.log(err)) | ||
} | ||
|
||
const clickDeregister = async (contestId: string) => { | ||
await fetcherWithAuth | ||
.delete(`contest/${contestId}/participation`, { | ||
searchParams: { groupId: 1 } | ||
}) | ||
.then((res) => res.json()) | ||
.catch((err) => console.log(err)) | ||
} | ||
|
||
export default function RegisterButton({ | ||
id, | ||
registered, | ||
state | ||
}: { | ||
id: string | ||
registered: boolean | ||
state: string | ||
}) { | ||
const [isRegistered, setIsRegistered] = useState(registered) | ||
const buttonColor = isRegistered ? 'bg-secondary' : 'bg-primary' | ||
return ( | ||
<> | ||
{state === 'Upcoming' ? ( | ||
<Button | ||
className={`px-12 py-6 text-lg font-light ${buttonColor} hover:${buttonColor}`} | ||
onClick={() => { | ||
if (isRegistered) { | ||
clickDeregister(id) | ||
setIsRegistered(false) | ||
toast.success('Deregistered Upcoming test successfully') | ||
} else { | ||
clickRegister(id) | ||
setIsRegistered(true) | ||
toast.success('Registered Upcoming test successfully') | ||
} | ||
}} | ||
> | ||
{isRegistered ? 'Deregister' : 'Register'} | ||
</Button> | ||
) : ( | ||
<> | ||
{!isRegistered && ( | ||
<Button | ||
className={`px-12 py-6 text-lg font-light ${buttonColor} hover:${buttonColor}`} | ||
onClick={() => { | ||
clickRegister(id) | ||
setIsRegistered(true) | ||
toast.success('Registered Ongoing test successfully') | ||
}} | ||
> | ||
Register | ||
</Button> | ||
)} | ||
</> | ||
)} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters