Skip to content

Commit

Permalink
working pnpm build (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
Codehagen authored Jul 23, 2024
1 parent 2a78f5d commit 894b8cd
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 155 deletions.
68 changes: 68 additions & 0 deletions apps/www/src/actions/generate-user-stripe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"use server";

import { redirect } from "next/navigation";
import { authOptions } from "@/lib/auth";
import { stripe } from "@/lib/stripe";
import { getUserSubscriptionPlan } from "@/lib/subscription";
import { absoluteUrl } from "@/lib/utils";
import { getServerSession } from "next-auth";

export interface responseAction {
status: "success" | "error";
stripeUrl?: string;
}

// const billingUrl = absoluteUrl("/dashboard/billing")
const billingUrl = absoluteUrl("/pricing");

export async function generateUserStripe(
priceId: string
): Promise<responseAction> {
let redirectUrl = "";

try {
const session = await getServerSession(authOptions);

if (!session?.user || !session.user.email) {
throw new Error("Unauthorized");
}

const subscriptionPlan = await getUserSubscriptionPlan(session.user.id);

if (subscriptionPlan.isPaid && subscriptionPlan.stripeCustomerId) {
// User on Paid Plan - Create a portal session to manage subscription.
const stripeSession = await stripe.billingPortal.sessions.create({
customer: subscriptionPlan.stripeCustomerId,
return_url: billingUrl,
});

redirectUrl = stripeSession.url;
} else {
// User on Free Plan - Create a checkout session to upgrade.
const stripeSession = await stripe.checkout.sessions.create({
success_url: billingUrl,
cancel_url: billingUrl,
payment_method_types: ["card"],
mode: "subscription",
billing_address_collection: "auto",
customer_email: session.user.email,
line_items: [
{
price: priceId,
quantity: 1,
},
],
metadata: {
userId: session.user.id,
},
});

redirectUrl = stripeSession.url!;
}
} catch (error) {
throw new Error("Failed to generate user stripe session");
}

// no revalidatePath because redirect
redirect(redirectUrl);
}
40 changes: 40 additions & 0 deletions apps/www/src/actions/update-user-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"use server"

import { revalidatePath } from "next/cache"
import { getServerSession } from "next-auth"

import { authOptions } from "@/lib/auth"
import { prisma } from "@/lib/db"
import { userNameSchema } from "@/lib/validations/user"

export interface FormData {
name: string
}

export async function updateUserName(userId: string, data: FormData) {
try {
const session = await getServerSession(authOptions)

if (!session?.user || session.user.id !== userId) {
throw new Error("Unauthorized")
}

const { name } = userNameSchema.parse(data)

// Update the user name.
await prisma.user.update({
where: {
id: userId,
},
data: {
name: name,
},
})

revalidatePath("/dashboard/settings")
return { status: "success" }
} catch (error) {
console.log(error)
return { status: "error" }
}
}
17 changes: 3 additions & 14 deletions apps/www/src/app/(dashboard)/dashboard/settings/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { redirect } from "next/navigation";
import { getMetricsForUser } from "@/actions/get-metrics-user";

import {
Card,
Expand Down Expand Up @@ -30,8 +29,6 @@ export default async function SettingsPage() {
redirect(authOptions.pages?.signIn || "/login");
}

const metrics = await getMetricsForUser();

const formatNumber = (number) => {
return new Intl.NumberFormat("en-US").format(number);
};
Expand All @@ -47,11 +44,7 @@ export default async function SettingsPage() {
<Card>
<CardHeader className="relative pb-2">
<CardDescription>Logs</CardDescription>
<CardTitle className="text-4xl">
{metrics
? `${formatNumber(metrics.logsUsed)} / ${formatNumber(metrics.logsLimit)}`
: "N/A"}
</CardTitle>

<LayersIcon className="absolute right-2 top-2 h-8 w-8" />
</CardHeader>
<CardContent className="text-xs text-muted-foreground">
Expand All @@ -61,9 +54,7 @@ export default async function SettingsPage() {
<Card>
<CardHeader className="relative pb-2">
<CardDescription>Seats</CardDescription>
<CardTitle className="text-4xl">
{metrics ? `${formatNumber(metrics.seatsUsed)} / 1` : "N/A"}
</CardTitle>

<UsersIcon className="absolute right-2 top-2 h-8 w-8" />
</CardHeader>
<CardContent className="text-xs text-muted-foreground">
Expand All @@ -73,9 +64,7 @@ export default async function SettingsPage() {
<Card>
<CardHeader className="relative pb-2">
<CardDescription>Projects</CardDescription>
<CardTitle className="text-4xl">
{metrics ? `${formatNumber(metrics.projectsUsed)} / ∞` : "N/A"}
</CardTitle>

<FolderIcon className="absolute right-2 top-2 h-8 w-8" />
</CardHeader>
<CardContent className="text-xs text-muted-foreground">
Expand Down
48 changes: 0 additions & 48 deletions apps/www/src/app/(onboarding)/onboarding/layout.tsx

This file was deleted.

93 changes: 0 additions & 93 deletions apps/www/src/app/(onboarding)/onboarding/page.tsx

This file was deleted.

0 comments on commit 894b8cd

Please sign in to comment.