Skip to content

Commit

Permalink
feat: Update to new docs (#488)
Browse files Browse the repository at this point in the history
* feat: Update to new docs

* Add legal pages
  • Loading branch information
storm1729 authored Sep 20, 2024
1 parent 8b23507 commit 1adaf82
Show file tree
Hide file tree
Showing 17 changed files with 433 additions and 218 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.3",
"sharp": "^0.33.5",
"stripe": "^9.13.0"
},
"devDependencies": {
Expand Down
14 changes: 7 additions & 7 deletions scripts/license.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { addMonths } from 'date-fns';
import { writeFile } from 'fs/promises';
import { tmpdir } from 'os';
import { addMonths } from "date-fns";
import { writeFile } from "fs/promises";
import { tmpdir } from "os";

import { generateLicense } from '../src/util/license';
import { generateLicense } from "../src/util/license";

async function main(): Promise<void> {
const myArgs = process.argv.slice(2);

if (myArgs.length < 2 || myArgs.length > 3) {
console.error(
'Usage: yarn gen:license [name] [email] [address] [optional_start_date]'
"Usage: yarn gen:license [name] [email] [address] [optional_start_date]"
);
process.exit(1);
}
Expand All @@ -18,8 +18,8 @@ async function main(): Promise<void> {

// Generate with dummy data.
const pdf = await generateLicense({
backend_version: '0.3.x',
ciee_version: '0.8.x',
backend_version: "0.7.x",
ciee_version: "0.8.x | 0.9.x",
license_end_date: addMonths(startDate, 1),
number_devs: 25,
stripe_buy_date: startDate,
Expand Down
31 changes: 31 additions & 0 deletions src/app/[lang]/legal/LegalPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import axios from "axios";

import { Md } from "./Md";
import { Nav } from "@/components/Nav/Nav";
import { Page } from "@/components/Geist";
import { dictionary } from "@/dictionaries";
import { Footer } from "@/components/Footer";
import { removeFrontMatter } from "@/components/Markdown";

export async function LegalPage(
contentUrl: string,
{
params: { lang },
}: {
params: { lang: string };
}
) {
const { data } = await axios.get(contentUrl);
const content = removeFrontMatter(data);
const d = await dictionary(lang);

return (
<>
<Nav d={d} />
<Page>
<Md>{content}</Md>
</Page>
<Footer d={d} />
</>
);
}
8 changes: 8 additions & 0 deletions src/app/[lang]/legal/Md.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use client";

import Markdown from "marked-react";
import React from "react";

export function Md({ children }: { children: string }) {
return <Markdown>{children}</Markdown>;
}
8 changes: 8 additions & 0 deletions src/app/[lang]/legal/mentions/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { LegalPage } from "../LegalPage";

export default async function Mentions(p: { params: { lang: string } }) {
return LegalPage(
"https://raw.githubusercontent.com/reacherhq/policies/refs/heads/master/mentions/index.fr.md",
p
);
}
8 changes: 8 additions & 0 deletions src/app/[lang]/legal/privacy/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { LegalPage } from "../LegalPage";

export default async function Privacy(p: { params: { lang: string } }) {
return LegalPage(
"https://raw.githubusercontent.com/reacherhq/policies/refs/heads/master/privacy/index.fr.md",
p
);
}
8 changes: 8 additions & 0 deletions src/app/[lang]/legal/terms/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { LegalPage } from "../LegalPage";

export default async function Terms(p: { params: { lang: string } }) {
return LegalPage(
"https://raw.githubusercontent.com/reacherhq/policies/refs/heads/master/terms/index.fr.md",
p
);
}
166 changes: 77 additions & 89 deletions src/app/api/stripe/create-checkout-session/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,101 +10,89 @@ import { sentryException } from "@/util/sentry";
import { createClient } from "@/supabase/server";

export async function POST(req: Request) {
if (req.method === "POST") {
// 1. Destructure the price and quantity from the POST body
const {
price,
quantity = 1,
metadata = {},
...rest
} = await req.json();
const locale = rest.locale || "en";
// 1. Destructure the price and quantity from the POST body
const { price, quantity = 1, metadata = {}, ...rest } = await req.json();
const locale = rest.locale || "en";

try {
// 2. Get the user from Supabase auth
const cookieStore = cookies();
const supabase = createClient(cookieStore);
const {
data: { user },
} = await supabase.auth.getUser();
try {
// 2. Get the user from Supabase auth
const cookieStore = cookies();
const supabase = createClient(cookieStore);
const {
data: { user },
} = await supabase.auth.getUser();

// 3. Retrieve or create the customer in Stripe
const customer = await createOrRetrieveCustomer({
uuid: user?.id || "",
email: user?.email || "",
});
// 3. Retrieve or create the customer in Stripe
const customer = await createOrRetrieveCustomer({
uuid: user?.id || "",
email: user?.email || "",
});

// 4. Create a checkout session in Stripe
let session;
if (price.type === "recurring") {
session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
billing_address_collection: "required",
customer,
customer_update: {
address: "auto",
},
line_items: [
{
price: price.id,
quantity,
},
],
locale,
mode: "subscription",
allow_promotion_codes: true,
subscription_data: {
trial_from_plan: true,
metadata,
// 4. Create a checkout session in Stripe
let session;
if (price.type === "recurring") {
session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
billing_address_collection: "required",
customer,
customer_update: {
address: "auto",
},
line_items: [
{
price: price.id,
quantity,
},
success_url: `${getWebappURL()}/${locale}/dashboard`,
cancel_url: `${getWebappURL()}/${locale}/dashboard`,
});
} else if (price.type === "one_time") {
session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
billing_address_collection: "required",
customer,
customer_update: {
address: "auto",
],
locale,
mode: "subscription",
allow_promotion_codes: true,
subscription_data: {
trial_from_plan: true,
metadata,
},
success_url: `${getWebappURL()}/${locale}/dashboard`,
cancel_url: `${getWebappURL()}/${locale}/dashboard`,
});
} else if (price.type === "one_time") {
session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
billing_address_collection: "required",
customer,
customer_update: {
address: "auto",
},
line_items: [
{
price: price.id,
quantity,
},
line_items: [
{
price: price.id,
quantity,
},
],
locale,
mode: "payment",
allow_promotion_codes: true,
success_url: `${getWebappURL()}/${locale}/dashboard`,
cancel_url: `${getWebappURL()}/${locale}/dashboard`,
});
}
],
locale,
mode: "payment",
allow_promotion_codes: true,
success_url: `${getWebappURL()}/${locale}/dashboard`,
cancel_url: `${getWebappURL()}/${locale}/dashboard`,
});
}

if (session) {
return new Response(JSON.stringify({ sessionId: session.id }), {
status: 200,
});
} else {
return new Response(
JSON.stringify({
error: {
statusCode: 500,
message: "Session is not defined",
},
}),
{ status: 500 }
);
}
} catch (err) {
sentryException(err as Error);
return new Response(JSON.stringify(err), { status: 500 });
if (session) {
return new Response(JSON.stringify({ sessionId: session.id }), {
status: 200,
});
} else {
return new Response(
JSON.stringify({
error: {
statusCode: 500,
message: "Session is not defined",
},
}),
{ status: 500 }
);
}
} else {
return new Response("Method Not Allowed", {
headers: { Allow: "POST" },
status: 405,
});
} catch (err) {
sentryException(err as Error);
return new Response(JSON.stringify(err), { status: 500 });
}
}
71 changes: 32 additions & 39 deletions src/app/api/stripe/create-portal-link/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,40 @@ import { sentryException } from "@/util/sentry";
import { createClient } from "@/supabase/server";

export async function POST(req: Request) {
if (req.method === "POST") {
try {
const cookieStore = cookies();
const supabase = createClient(cookieStore);
const {
data: { user },
} = await supabase.auth.getUser();
try {
const cookieStore = cookies();
const supabase = createClient(cookieStore);
const {
data: { user },
} = await supabase.auth.getUser();

if (!user) throw Error("Could not get user");
const customer = await createOrRetrieveCustomer({
uuid: user.id || "",
email: user.email || "",
});
if (!user) throw Error("Could not get user");
const customer = await createOrRetrieveCustomer({
uuid: user.id || "",
email: user.email || "",
});

if (!customer) throw Error("Could not get customer");
// This line was added to the original code.
const body = (await req.json()) as { locale?: "fr" | "en" };
const locale = body.locale || "en";
const { url } = await stripe.billingPortal.sessions.create({
customer,
locale,
return_url: `${getWebappURL()}/${locale}/dashboard`,
});
return new Response(JSON.stringify({ url }), {
status: 200,
});
} catch (err) {
sentryException(err as Error);
return new Response(
JSON.stringify({
error: { statusCode: 500, message: (err as Error).message },
}),
{
status: 500,
}
);
}
} else {
return new Response("Method Not Allowed", {
headers: { Allow: "POST" },
status: 405,
if (!customer) throw Error("Could not get customer");
// This line was added to the original code.
const body = (await req.json()) as { locale?: "fr" | "en" };
const locale = body.locale || "en";
const { url } = await stripe.billingPortal.sessions.create({
customer,
locale,
return_url: `${getWebappURL()}/${locale}/dashboard`,
});
return new Response(JSON.stringify({ url }), {
status: 200,
});
} catch (err) {
sentryException(err as Error);
return new Response(
JSON.stringify({
error: { statusCode: 500, message: (err as Error).message },
}),
{
status: 500,
}
);
}
}
Loading

0 comments on commit 1adaf82

Please sign in to comment.