Skip to content

Commit

Permalink
feat: basic checkout page added and database updated
Browse files Browse the repository at this point in the history
  • Loading branch information
wreshi committed Nov 5, 2024
1 parent 2cc145d commit 748d0cb
Show file tree
Hide file tree
Showing 20 changed files with 127 additions and 20 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/qodana_code_quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
push:
branches: # Specify your branches here
- main # The 'main' branch
- 'releases/*' # The release branches
- "releases/*" # The release branches

jobs:
qodana:
Expand All @@ -17,12 +17,12 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit
fetch-depth: 0 # a full history is required for pull request analysis
- name: 'Qodana Scan'
ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit
fetch-depth: 0 # a full history is required for pull request analysis
- name: "Qodana Scan"
uses: JetBrains/qodana-action@v2024.1
with:
pr-mode: false
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN_1776540167 }}
QODANA_ENDPOINT: 'https://qodana.cloud'
QODANA_ENDPOINT: "https://qodana.cloud"
1 change: 1 addition & 0 deletions database/schema/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const userTable = table("users", {
.notNull()
.defaultNow(),
verifiedAt: timestamp("verified_at"),
checkoutAt: timestamp("checkout_at"),
onboardedAt: timestamp("onboarded_at"),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at"),
Expand Down
2 changes: 1 addition & 1 deletion qodana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ linter: jetbrains/qodana-js:2024.1
profile:
name: qodana.recommended
include:
- name: CheckDependencyLicenses
- name: CheckDependencyLicenses
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export function NewActivityForm({
{...field}
placeholder={`Enter title for ${activityType}`}
className="h-8"
autoFocus={activityType === "call"}
/>
</FormControl>
<FormMessage />
Expand Down Expand Up @@ -198,6 +199,7 @@ export function NewActivityForm({
<FormControl>
<Textarea
{...field}
autoFocus={activityType === "comment"}
placeholder={`Enter ${activityType === "comment" ? "comment" : "notes"}`}
/>
</FormControl>
Expand Down
4 changes: 3 additions & 1 deletion src/app/app/_components/sidebar/app-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ export function AppSidebar({
const [loadedPathnames, setLoadedPathnames] = React.useState<string[]>([]);
const [loadingPathname, setLoadingPathname] = React.useState<string>("");
const { user, cookieselectedworkspaceid: cookieSelectedWorkspaceId } = props;
const router = useRouter();
const router = useRouter({
fancy: true,
});

const { commandOpen, setCommandOpen } = React.useContext(CommandContext);

Expand Down
4 changes: 3 additions & 1 deletion src/app/app/deals/_components/DealViewSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ interface DealViewSwitcherProps {
export function DealViewSwitcher({ view, setView }: DealViewSwitcherProps) {
const gridActive = view === "grid";
const boardActive = view === "board";
const router = useRouter();
const router = useRouter({
fancy: true,
});
return (
<div>
<div className="flex h-8 items-center rounded-lg ring-1 ring-border">
Expand Down
6 changes: 5 additions & 1 deletion src/app/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { redirect } from "next/navigation";
import { getUserById } from "@/data-access/users";
import { fetchAuthenticatedUser } from "@/lib/session";

Check warning on line 6 in src/app/app/layout.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused import

Unused ``` import { fetchAuthenticatedUser } from "@/lib/session"; ```
import {
afterCheckoutUrl,
afterSignUpUrl,
afterVerifyUrl,
unauthenticatedUrl,
Expand Down Expand Up @@ -36,9 +37,12 @@ export default async function ApplicationLayout({
if (!dbUser.verifiedAt) {
return redirect(afterSignUpUrl);
}
if (!dbUser.onboardedAt) {
if (!dbUser.checkoutAt) {
return redirect(afterVerifyUrl);
}
if (!dbUser.onboardedAt) {
return redirect(afterCheckoutUrl);
}

const workspaces = await getAllUserWorkspaces(dbUser.id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ export const LoginForm = ({

return (
<main className="grid h-screen items-center">
<Link
{/* <Link
href="/signup"
className={cn(
buttonVariants({ variant: "outline" }),
"absolute right-4 top-4 md:right-8 md:top-8",
)}
>
Sign Up
</Link>
</Link> */}
<div>
<div className="mx-auto flex w-full flex-col justify-center space-y-6 sm:w-[350px]">
<div className="flex flex-col space-y-2 text-center">
Expand Down
4 changes: 2 additions & 2 deletions src/app/(access)/login/page.tsx → src/app/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LoginForm } from "@/app/(access)/login/_components/LoginForm";
import { LoginForm } from "@/app/login/_components/LoginForm";

Check failure on line 1 in src/app/login/page.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package
import { loginAction } from "@/server/login";
import { Metadata } from "next";
import { fetchAuthenticatedUser } from "@/lib/session";
Expand All @@ -13,7 +13,7 @@ export const metadata: Metadata = {
export default async function LoginPage() {
const user = await fetchAuthenticatedUser();
const dbUser = await getUserById(user?.id || "");
if (dbUser && dbUser.verifiedAt) {
if (dbUser && dbUser.verifiedAt && dbUser.checkoutAt) {
return redirect(authenticatedUrl);
}
return <LoginForm login={loginAction} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import { Loader } from "lucide-react";

import Image from "next/image";
import Link from "@/components/performance-link";
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { toast } from "sonner";
import { PasswordField } from "@/components/ui/password-input";
import { useRouter } from "@/hooks/use-performance-router";
import { useServerAction } from "zsa-react";
import { useSearchParams } from "next/navigation";

export const SignUpForm = ({
signUp,
Expand All @@ -33,6 +34,16 @@ export const SignUpForm = ({
const [isSubmitting, setIsSubmitting] = useState(false);
const router = useRouter();

Check warning on line 35 in src/app/signup/_components/SignUpForm.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused local symbol

Unused constant router

const searchParams = useSearchParams();

useEffect(() => {
if (searchParams.get("redirecterror") === "nouser") {
toast.error(
"You need to create an account or login before accessing the checkout page.",
);
}
}, [searchParams]);

const form = useForm<z.infer<typeof signUpSchema>>({
resolver: zodResolver(signUpSchema),
defaultValues: {
Expand Down
27 changes: 27 additions & 0 deletions src/app/signup/checkout/_components/DemoCheckoutButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use client";

Check failure on line 1 in src/app/signup/checkout/_components/DemoCheckoutButton.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package
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();

Check warning on line 12 in src/app/signup/checkout/_components/DemoCheckoutButton.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused local symbol

Unused constant data
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>
);
}
35 changes: 35 additions & 0 deletions src/app/signup/checkout/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Metadata } from "next";

Check failure on line 1 in src/app/signup/checkout/page.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package
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";

Check warning on line 6 in src/app/signup/checkout/page.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused import

Unused 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.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getUserById } from "@/data-access/users";
import { fetchAuthenticatedUser } from "@/lib/session";
import { redirect } from "next/navigation";
import { authenticatedUrl, unauthenticatedUrl } from "@/constants";
import { OnboardingForm } from "@/app/(access)/onboarding/_components/OnboardingForm";
import { OnboardingForm } from "@/app/signup/onboarding/_components/OnboardingForm";

export const metadata: Metadata = {
title: "Onboarding",
Expand All @@ -16,7 +16,10 @@ const OnboardingPage = async () => {
return redirect(unauthenticatedUrl);
}
const dbUser = await getUserById(user.id);
if (dbUser?.verifiedAt && dbUser?.onboardedAt) {
if (
(dbUser?.verifiedAt && dbUser?.onboardedAt) ||
(dbUser?.checkoutAt && dbUser?.verifiedAt && dbUser?.onboardedAt)
) {
return redirect(authenticatedUrl);
}
return <OnboardingForm />;
Expand Down
4 changes: 2 additions & 2 deletions src/app/(access)/signup/page.tsx → src/app/signup/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SignUpForm } from "@/app/(access)/signup/_components/SignUpForm";
import { SignUpForm } from "@/app/signup/_components/SignUpForm";

Check failure on line 1 in src/app/signup/page.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package
import { signUpAction } from "@/server/signup";
import { Metadata } from "next";
import { fetchAuthenticatedUser } from "@/lib/session";
Expand All @@ -13,7 +13,7 @@ export const metadata: Metadata = {
export default async function LoginPage() {
const user = await fetchAuthenticatedUser();
const dbUser = await getUserById(user?.id || "");
if (dbUser && dbUser.verifiedAt && dbUser.onboardedAt) {
if (dbUser && dbUser.verifiedAt && dbUser.onboardedAt && dbUser.checkoutAt) {
return redirect(authenticatedUrl);
}
return <SignUpForm signUp={signUpAction} />;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const afterSignUpUrl = "/verify-email";
export const afterVerifyUrl = "/onboarding";
export const afterSignUpUrl = "/signup/verify-email";

Check failure on line 1 in src/constants.ts

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package
export const afterVerifyUrl = "/signup/checkout";
export const afterCheckoutUrl = "/signup/onboarding";
export const authenticatedUrl = "/app/home";
export const unauthenticatedUrl = "/login";

Expand Down
19 changes: 19 additions & 0 deletions src/server/billing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use server";

Check failure on line 1 in src/server/billing.ts

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package
import { createServerAction } from "zsa";

Check warning on line 2 in src/server/billing.ts

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused import

Unused import { createServerAction } from "zsa";
import { getUserById, updateUser } from "@/data-access/users";

Check warning on line 3 in src/server/billing.ts

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused import

Unused import specifier getUserById
import { redirect } from "next/navigation";
import { authenticatedUrl } from "@/constants";
import { fetchAuthenticatedUser } from "@/lib/session";

Check warning on line 6 in src/server/billing.ts

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused import

Unused ``` import { fetchAuthenticatedUser } from "@/lib/session"; ```
import { authenticatedAction } from "@/lib/zsa";

export const setUserCheckoutAction = authenticatedAction
.createServerAction()
.handler(async ({ input, ctx }) => {

Check warning on line 11 in src/server/billing.ts

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused local symbol

Unused parameter input
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);
});

0 comments on commit 748d0cb

Please sign in to comment.