-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: basic checkout page added and database updated
- Loading branch information
Showing
20 changed files
with
127 additions
and
20 deletions.
There are no files selected for viewing
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
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
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
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
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
27 changes: 27 additions & 0 deletions
27
src/app/signup/checkout/_components/DemoCheckoutButton.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,27 @@ | ||
"use client"; | ||
import { Button } from "@/components/ui/button"; | ||
import { setUserCheckoutAction } from "@/server/billing"; | ||
import React from "react"; | ||
import { toast } from "sonner"; | ||
import { useServerAction } from "zsa-react"; | ||
|
||
export function DemoCheckoutButton() { | ||
const { execute } = useServerAction(setUserCheckoutAction); | ||
async function handleClick() { | ||
try { | ||
const [data, err] = await execute(); | ||
if (err) { | ||
toast.error(err.message); | ||
} else { | ||
toast.success("Checkout Completed"); | ||
} | ||
} catch (error) { | ||
toast.error("Something Went Wrong. Failed to complete checkout."); | ||
} | ||
} | ||
return ( | ||
<Button className="h-7" variant="outline" onClick={handleClick}> | ||
Complete Checkout (DEMO) | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Metadata } from "next"; | ||
import { fetchAuthenticatedUser } from "@/lib/session"; | ||
import { redirect } from "next/navigation"; | ||
import { getUserById } from "@/data-access/users"; | ||
import { authenticatedUrl } from "@/constants"; | ||
import { Link } from "next-view-transitions"; | ||
import { DemoCheckoutButton } from "./_components/DemoCheckoutButton"; | ||
|
||
export const metadata: Metadata = { | ||
title: "Sign Up", | ||
}; | ||
|
||
export default async function CheckoutPage() { | ||
const user = await fetchAuthenticatedUser(); | ||
const PADDLE_DOMAIN_APPROVED = false; | ||
if (!user) return redirect("/signup?redirecterror=nouser"); | ||
const dbUser = await getUserById(user.id || ""); | ||
if (PADDLE_DOMAIN_APPROVED) { | ||
if ( | ||
dbUser && | ||
dbUser.verifiedAt && | ||
dbUser.onboardedAt && | ||
dbUser.checkoutAt | ||
) { | ||
return redirect(authenticatedUrl); | ||
} | ||
} | ||
|
||
return ( | ||
<main className="flex h-screen flex-col items-center justify-center gap-5"> | ||
Checkout Page here.... (Embedded checkout from paddle) | ||
<DemoCheckoutButton /> | ||
</main> | ||
); | ||
} |
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,19 @@ | ||
"use server"; | ||
import { createServerAction } from "zsa"; | ||
import { getUserById, updateUser } from "@/data-access/users"; | ||
import { redirect } from "next/navigation"; | ||
import { authenticatedUrl } from "@/constants"; | ||
import { fetchAuthenticatedUser } from "@/lib/session"; | ||
import { authenticatedAction } from "@/lib/zsa"; | ||
|
||
export const setUserCheckoutAction = authenticatedAction | ||
.createServerAction() | ||
.handler(async ({ input, ctx }) => { | ||
const { user } = ctx; | ||
const updatedUser = await updateUser(user.id, { | ||
checkoutAt: new Date(), | ||
updatedAt: new Date(), | ||
}); | ||
if (!updatedUser) throw new Error("Couldn't set user as checked out"); | ||
return redirect(authenticatedUrl); | ||
}); |