-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
685cb62
commit 4cca9b7
Showing
7 changed files
with
254 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,64 @@ | ||
'use client'; | ||
|
||
import { ChevronLeft } from 'lucide-react'; | ||
import Link from 'next/link'; | ||
import { ReactNode, useMemo } from 'react'; | ||
import Confetti from 'react-confetti'; | ||
import { useIsClient } from 'usehooks-ts'; | ||
|
||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; | ||
import { ROUTES } from '@/utils/routes'; | ||
|
||
export default function Page({ | ||
searchParams, | ||
}: { | ||
searchParams: { variant: string }; | ||
}) { | ||
const isClient = useIsClient(); | ||
|
||
const content = useMemo((): { | ||
title: string; | ||
description?: string; | ||
button?: ReactNode; | ||
} => { | ||
switch (searchParams.variant) { | ||
case 'waitlist': | ||
return { | ||
title: "You're On the List!", | ||
description: | ||
"You're one step closer to experiencing MiBanco. We'll notify you as soon as we're ready for you.", | ||
button: ( | ||
<Link | ||
href={ROUTES.home} | ||
className="mb-2 flex text-muted-foreground hover:text-foreground" | ||
> | ||
<ChevronLeft className="size-4" /> | ||
<p className="text-xs">Home</p> | ||
</Link> | ||
), | ||
}; | ||
|
||
default: | ||
return { title: 'Success!' }; | ||
} | ||
}, [searchParams]); | ||
|
||
return ( | ||
<main className="flex h-screen w-full flex-col items-center justify-center"> | ||
{isClient ? <Confetti /> : null} | ||
<div className="z-50 mx-4 md:mx-0"> | ||
{content.button || null} | ||
<Card className="max-w-96 text-center"> | ||
<CardHeader> | ||
<CardTitle className="text-xl">{content.title}</CardTitle> | ||
</CardHeader> | ||
{content.description ? ( | ||
<CardContent> | ||
<p className="text-muted-foreground">{content.description}</p> | ||
</CardContent> | ||
) : null} | ||
</Card> | ||
</div> | ||
</main> | ||
); | ||
} |
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
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,158 @@ | ||
'use client'; | ||
|
||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { Loader2 } from 'lucide-react'; | ||
import { useRouter, useSearchParams } from 'next/navigation'; | ||
import { Dispatch, FC, SetStateAction, useState } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
import { z } from 'zod'; | ||
|
||
import { ROUTES } from '@/utils/routes'; | ||
|
||
import { Button } from '../ui/button'; | ||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardFooter, | ||
CardHeader, | ||
CardTitle, | ||
} from '../ui/card'; | ||
import { | ||
Form, | ||
FormControl, | ||
FormDescription, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
FormMessage, | ||
} from '../ui/form'; | ||
import { Input } from '../ui/input'; | ||
import { useToast } from '../ui/use-toast'; | ||
|
||
const FormSchema = z.object({ | ||
email: z.string().email().min(5, { | ||
message: 'Invalid email.', | ||
}), | ||
}); | ||
|
||
export const WaitlistForm: FC<{ | ||
setView: Dispatch<SetStateAction<'waitlist' | 'sign-up'>>; | ||
}> = ({ setView }) => { | ||
const searchParams = useSearchParams(); | ||
const emailParam = searchParams.get('email'); | ||
|
||
const { push } = useRouter(); | ||
const { toast } = useToast(); | ||
|
||
const [loading, setLoading] = useState(false); | ||
|
||
const form = useForm<z.infer<typeof FormSchema>>({ | ||
reValidateMode: 'onChange', | ||
resolver: zodResolver(FormSchema), | ||
defaultValues: { | ||
email: emailParam || '', | ||
}, | ||
}); | ||
|
||
const onSubmit = async (values: z.infer<typeof FormSchema>) => { | ||
setLoading(true); | ||
|
||
try { | ||
const result = await fetch('https://reflex.amboss.space/graphql', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
variables: { input: { email: values.email, interest: 'BANCO' } }, | ||
query: `mutation Add_interest($input: WaitlistInput!) { | ||
public { | ||
waitlist { | ||
add_interest(input: $input) { | ||
} | ||
} | ||
} | ||
}`, | ||
}), | ||
}); | ||
|
||
const response = await result.json(); | ||
|
||
if (response.data) { | ||
push(ROUTES.success.waitlist); | ||
} else { | ||
toast({ | ||
variant: 'destructive', | ||
title: 'Error joining waitlist.', | ||
description: response.errors | ||
.map((e: { message: string }) => e.message) | ||
.join(', '), | ||
}); | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
|
||
toast({ | ||
variant: 'destructive', | ||
title: 'Error joining waitlist.', | ||
description: 'Please try again.', | ||
}); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<Card> | ||
<CardHeader> | ||
<CardTitle>The MiBanco Waitlist</CardTitle> | ||
<CardDescription>Join us . No bank required.</CardDescription> | ||
</CardHeader> | ||
<Form {...form}> | ||
<form onSubmit={form.handleSubmit(onSubmit)}> | ||
<CardContent className="flex flex-col gap-4"> | ||
<FormField | ||
control={form.control} | ||
name="email" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Email</FormLabel> | ||
<FormControl> | ||
<Input placeholder="[email protected]" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
<FormDescription> | ||
{"We'll notify you as soon as we're ready for you."} | ||
</FormDescription> | ||
</FormItem> | ||
)} | ||
/> | ||
</CardContent> | ||
|
||
<CardFooter> | ||
<div className="w-full"> | ||
<Button type="submit" disabled={loading} className="w-full"> | ||
{loading ? ( | ||
<Loader2 className="mr-2 h-4 w-4 animate-spin" /> | ||
) : null} | ||
Join Waitlist | ||
</Button> | ||
|
||
<Button | ||
type="button" | ||
onClick={() => setView('sign-up')} | ||
disabled={loading} | ||
variant={'ghost'} | ||
className="mt-4 w-full" | ||
> | ||
I have a Referral Code | ||
</Button> | ||
</div> | ||
</CardFooter> | ||
</form> | ||
</Form> | ||
</Card> | ||
); | ||
}; |
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
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