Skip to content

Commit

Permalink
Added ability to still enroll after hitting request enrollment (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
alasdairwilson authored Oct 16, 2024
1 parent e5541e3 commit 721991e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 5 additions & 3 deletions components/EnrolDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EventStatus, UserOnEvent } from "@prisma/client"
import { Button, Modal, Toast, TextInput } from "flowbite-react"
import { Event } from "lib/types"
import { useSession } from "next-auth/react"
import { useUserOnEvent } from "lib/hooks/useUserOnEvent"
import React from "react"
import Content from "./content/Content"
import { HiCheckCircle, HiMail, HiX } from "react-icons/hi"
Expand Down Expand Up @@ -30,8 +31,9 @@ const EnrolDialog: React.FC<Props> = ({ event, show, onEnrol }) => {
const [keySuccess, setKeySuccess] = React.useState<string | undefined>(undefined)
const [success, setSuccess] = React.useState<string | null>(null)
const session = useSession()
const { userOnEvent } = useUserOnEvent(event.id)
const { event: eventData, error: eventError, isLoading: eventIsLoading, mutate: mutateEvent } = useEvent(event.id)

const isRequested = userOnEvent ? userOnEvent.eventId == event.id && userOnEvent.status == "REQUEST" : false
const onClose = () => {
onEnrol(undefined)
}
Expand Down Expand Up @@ -142,8 +144,8 @@ const EnrolDialog: React.FC<Props> = ({ event, show, onEnrol }) => {
</Modal.Body>
<Modal.Footer>
<p>If you have not received an enrolment key, you can request enrolment:</p>
<Button data-cy={`request-enrol-${event.id}`} onClick={onClick}>
Request Enrollment
<Button data-cy={`request-enrol-${event.id}`} onClick={onClick} disabled={isRequested}>
{isRequested ? "Enrollment requested" : "Request Enrollment"}
</Button>
</Modal.Footer>
</Modal>
Expand Down
10 changes: 7 additions & 3 deletions components/EventActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ const EventActions: React.FC<EventActionsProps> = ({ event }) => {
<HiArrowNarrowRight className="ml-2 h-3 w-3" />
</Button>
) : isRequested ? (
<Button color="gray" style={{ zIndex: 1 }} disabled>
Requested
</Button>
<>
<Button color="gray" onClick={handleEnrol(event)} style={{ zIndex: 1 }}>
Requested
<HiArrowNarrowRight className="ml-2 h-3 w-3" />
</Button>
<EnrolDialog event={event} show={showEvent == event} onEnrol={onEnrol} />
</>
) : (
session && (
<>
Expand Down

0 comments on commit 721991e

Please sign in to comment.