Skip to content

Commit

Permalink
Save applications and create enrollments when logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
TWilson023 committed Nov 15, 2024
1 parent f25e5dd commit ed0cfb8
Show file tree
Hide file tree
Showing 10 changed files with 322 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export function ProgramApplicationForm({

if (!response?.data?.ok) {
toast.error(
response?.data?.message ?? "Failed to submit application",
(response?.data as { message?: string }).message ??
"Failed to submit application",
);
setError("root.serverError", {
message: "Failed to submit application. Please try again.",
Expand All @@ -60,7 +61,12 @@ export function ProgramApplicationForm({

toast.success("Application submitted successfully");
router.push(
`/apply/${program.slug}/application/success?applicationId=${response.data.programApplicationId}`,
`/apply/${program.slug}/application/success?${new URLSearchParams({
applicationId: response.data.programApplicationId,
...("programEnrollmentId" in response.data && {
enrollmentId: response.data.programEnrollmentId,
}),
}).toString()}`,
);
})}
className="flex flex-col gap-6"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use client";

import { Button } from "@dub/ui";
import { useSession } from "next-auth/react";
import { useRouter } from "next/navigation";

export function CTAButtons() {
const router = useRouter();
const { data: session, status } = useSession();

return (
<>
<Button
type="button"
text={
status === "authenticated"
? "Continue to Dub Partners"
: "Create your Dub Partners account"
}
className="border-[var(--brand)] bg-[var(--brand)] hover:bg-[var(--brand)] hover:ring-[var(--brand-ring)]"
onClick={() =>
router.push(status === "authenticated" ? "/" : "/register")
}
/>
{status === "unauthenticated" && (
<Button
type="button"
variant="secondary"
text="Log in to Dub Partners"
onClick={() => router.push("/login")}
/>
)}
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Store } from "lucide-react";
import { notFound } from "next/navigation";
import { CSSProperties } from "react";
import { Header } from "../../header";
import { CTAButton } from "./cta-button";
import { CTAButtons } from "./cta-buttons";
import { Screenshot } from "./screenshot";

const FEATURES = [
Expand Down Expand Up @@ -42,7 +42,7 @@ export default async function SuccessPage({
searchParams,
}: {
params: { programSlug: string };
searchParams: { applicationId?: string };
searchParams: { applicationId?: string; enrollmentId?: string };
}) {
const { programSlug } = params;
const program = await prisma.program.findUnique({
Expand All @@ -64,6 +64,8 @@ export default async function SuccessPage({

if (!program) notFound();

const isEnrolled = !!searchParams.enrollmentId;

const application = searchParams.applicationId
? await prisma.programApplication.findFirst({
where: {
Expand Down Expand Up @@ -97,24 +99,32 @@ export default async function SuccessPage({
/>
<div className="p-6">
<div className="grid grid-cols-1 gap-5 sm:pt-20">
<h1 className="text-4xl font-semibold">Application submitted</h1>
<h1 className="text-4xl font-semibold">
Application {isEnrolled ? "submitted" : "saved"}
</h1>
<div className="flex flex-col gap-4 text-base text-neutral-700">
<p>
Your application has been submitted for review.
{application && (
<>
{" "}
You'll receive an update at{" "}
<strong className="font-semibold">{application.email}</strong>
.
</>
)}
</p>
<p>
While you're waiting, complete your account setup on{" "}
<strong className="font-semibold">Dub Partners</strong>, which
powers this program.
</p>
{isEnrolled && (
<p>
Your application has been submitted for review.
{application && (
<>
{" "}
You'll receive an update at{" "}
<strong className="font-semibold">
{application.email}
</strong>
.
</>
)}
</p>
)}
{!isEnrolled && (
<p>
Complete your account setup on{" "}
<strong className="font-semibold">Dub Partners</strong> to
finish submitting your application.
</p>
)}
</div>
</div>

Expand Down Expand Up @@ -149,8 +159,8 @@ export default async function SuccessPage({
))}
</div>

<div className="mt-12">
<CTAButton />
<div className="mt-12 flex flex-col gap-3">
<CTAButtons />
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit ed0cfb8

Please sign in to comment.