Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make ory ID optional for registration #83

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/app/(summit-pages)/register/hubspot-registration-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const executeAsSoonAsPossible = (condition: () => boolean, fn: () => void) => {
}
}

const createForm = (afterSubmitted: () => void, session: Session) => {
const createForm = (afterSubmitted: () => void, session?: Session) => {
executeAsSoonAsPossible(
() => Boolean((window as any)?.hbspt?.forms?.create),
() => {
Expand All @@ -29,6 +29,10 @@ const createForm = (afterSubmitted: () => void, session: Session) => {
target: `#${registrationFormId}`,
onFormSubmitted: afterSubmitted,
onFormReady: (form: HTMLFormElement) => {
if (!session) {
return
}

const { email, name }: { email: string; name: string } =
session.identity.traits
const names = name.split(" ")
Expand Down Expand Up @@ -77,7 +81,7 @@ export const HubspotRegistrationForm = ({
className,
}: HubspotRegistrationFormProps) => {
const router = useRouter()
const { data: session } = useSession()
const { data: session, isLoading: sessionIsLoading } = useSession()
const { mutate: mutateRegistration } = useRegistration()

const mutateRegistrationRef = useRef(mutateRegistration)
Expand All @@ -90,7 +94,7 @@ export const HubspotRegistrationForm = ({
router.push("see-you-soon")
}

if (!formHasRendered && session) {
if (!formHasRendered && !sessionIsLoading) {
createForm(afterSubmitted, session)
setFormHasRendered(true)
}
Expand Down
8 changes: 0 additions & 8 deletions src/app/(summit-pages)/register/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"use client"

import { useLoginUrl } from "@/hooks/useLoginUrl"
import { useIsRegistered } from "@/hooks/useRegistration"
import { useSession } from "@/hooks/useSession"
import { cn } from "@/utils/cn"
import { redirect } from "next/navigation"
import { Container } from "../../components/container"
Expand All @@ -11,13 +9,7 @@ import { Wrapper } from "../../components/wrapper"
import { HubspotRegistrationForm } from "./hubspot-registration-form"

export default function RegistrationPage() {
const { data: session, isLoading: sessionIsLoading } = useSession()
const { data: isRegistered } = useIsRegistered()
const loginUrl = useLoginUrl()

if (!sessionIsLoading && !session?.active) {
redirect(loginUrl)
}

if (isRegistered) {
redirect("/see-you-soon")
Expand Down
18 changes: 2 additions & 16 deletions src/app/components/get-ticket-button.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"use client"

import { useLoginUrl } from "@/hooks/useLoginUrl"
import { useIsRegistered } from "@/hooks/useRegistration"
import { useSession } from "@/hooks/useSession"
import Link from "next/link"
import { Button } from "./button"
import { RightArrow } from "./right-arrow"
Expand All @@ -13,31 +11,19 @@ type GetTicketButtonProps = {
}

export const GetTicketButton = ({ className, id }: GetTicketButtonProps) => {
const { data: session } = useSession()
const { data: isRegistered } = useIsRegistered()
const loginUrl = useLoginUrl()

if (isRegistered) {
return null
}

const getTicketButtonContent = (
<>
return (
<Button as={Link} id={id} href="/register" className={className}>
<RightArrow className="md:hidden" />
<span className="hidden text-sm leading-none md:inline-block">
Get your ticket
</span>
<span className="text-sm leading-none md:hidden">Ticket</span>
</>
)

return session ? (
<Button as={Link} id={id} href="/register" className={className}>
{getTicketButtonContent}
</Button>
) : (
<Button as={"a"} id={id} className={className} href={loginUrl}>
{getTicketButtonContent}
</Button>
)
}