Skip to content

Commit

Permalink
Remove more TS
Browse files Browse the repository at this point in the history
  • Loading branch information
danrowden committed Sep 20, 2023
1 parent f568848 commit e118ee9
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 123 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { getSession } from "@/lib/auth";
import type { Metadata } from 'next';
import Link from 'next/link';
import { PlansComponent } from '@/components/manage';
import { getPlans, getSubscription } from '@/lib/data';
import { redirect } from 'next/navigation';


export const metadata: Metadata = {
export const metadata = {
title: 'Billing'
}

Expand Down
9 changes: 5 additions & 4 deletions app/(app)/billing/page.tsx → app/(app)/billing/page.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getSession } from "@/lib/auth";
import type { Metadata } from 'next';
import { SubscriptionComponent } from '@/components/subscription';
// import { SubscriptionComponent } from '@/components/subscription';
import { PortalSubscriptionComponent } from '@/components/subscription-customer-portal';
import { getPlans, getSubscription } from '@/lib/data';


export const metadata: Metadata = {
export const metadata = {
title: 'Billing'
}

Expand All @@ -23,7 +23,8 @@ export default async function Page() {

<h1 className="text-xl font-bold mb-3">Billing</h1>

<SubscriptionComponent sub={sub} plans={plans} />
{/* <SubscriptionComponent sub={sub} plans={plans} /> */}
<PortalSubscriptionComponent sub={sub} />

<script src="https://app.lemonsqueezy.com/js/lemon.js" defer></script>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import prisma from "@/lib/prisma";
import LemonSqueezy from '@lemonsqueezy/lemonsqueezy.js';
import type { Variant, Product, ProductAttributes, ApiQueryParams } from '@/types/types';


const ls = new LemonSqueezy(process.env.LEMONSQUEEZY_API_KEY);
Expand All @@ -9,13 +8,13 @@ const ls = new LemonSqueezy(process.env.LEMONSQUEEZY_API_KEY);
async function getPlans() {
// Fetch data from Lemon Squeezy

const params: ApiQueryParams = { include: 'product', perPage: 50 }
const params = { include: 'product', perPage: 50 }

let hasNextPage = true;
let page = 1;

let variants: Variant[] = []
let products: Product[] = []
let variants = []
let products = []

while (hasNextPage) {
const resp = await ls.getVariants(params);
Expand All @@ -32,7 +31,7 @@ async function getPlans() {
}

// Nest products inside variants
const prods: Record<string, ProductAttributes> = {};
const prods = {};
for (let i = 0; i < products.length; i++) {
prods[products[i]['id']] = products[i]['attributes']
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { type NextRequest } from 'next/server'
import prisma from "@/lib/prisma";
import { SubscriptionCreateData, SubscriptionUpdateData } from '@/types/types';


async function processEvent(event) {
Expand Down Expand Up @@ -42,7 +40,7 @@ async function processEvent(event) {

const lemonSqueezyId = parseInt(obj['id'])

const updateData: SubscriptionUpdateData = {
const updateData = {
orderId: data['order_id'],
name: data['user_name'],
email: data['user_email'],
Expand All @@ -55,7 +53,7 @@ async function processEvent(event) {
price: event.eventName == 'subscription_created' ? plan['price'] : null
}

const createData: SubscriptionCreateData = updateData
const createData = updateData
createData.lemonSqueezyId = lemonSqueezyId
createData.price = plan.price

Expand All @@ -66,8 +64,8 @@ async function processEvent(event) {
where: {
lemonSqueezyId: lemonSqueezyId
},
update: updateData as any,
create: createData as any
update: updateData,
create: createData,
})

} catch (error) {
Expand Down Expand Up @@ -100,7 +98,7 @@ async function processEvent(event) {
}


export async function POST(request: NextRequest) {
export async function POST(request) {

const crypto = require('crypto');

Expand Down
6 changes: 3 additions & 3 deletions app/(app)/login/page.tsx → app/(app)/login/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import { signIn } from "next-auth/react"

const handleSubmit = (event) => {
event.preventDefault()
signIn("email", { email: event.target.email.value })
const handleSubmit = (e) => {
e.preventDefault()
signIn("email", { email: e.target.email.value })
}

export default function SignIn() {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion app/api/checkouts/route.ts → app/api/checkouts/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import LemonSqueezy from '@lemonsqueezy/lemonsqueezy.js';
const ls = new LemonSqueezy(process.env.LEMONSQUEEZY_API_KEY);


export async function POST(request: Request) {
export async function POST(request) {
const session = await getSession();

if (!session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ const ls = new LemonSqueezy(process.env.LEMONSQUEEZY_API_KEY);


export async function GET(request, { params }) {
// Get subscription update billing link
/**
* Used by some buttons to get subscription update billing URLs
*/
try {
const subscription = await ls.getSubscription({ id: params.id })
return NextResponse.json({ error: false, subscription: {
update_billing_url: subscription['data']['attributes']['urls']['update_payment_method']
update_billing_url: subscription['data']['attributes']['urls']['update_payment_method'],
// customer_portal_url: subscription['data']['attributes']['urls']['customer_portal']
} }, { status: 200 })
} catch(e) {
return NextResponse.json({ error: true, message: e.message }, { status: 400 })
Expand Down
99 changes: 0 additions & 99 deletions types/types.d.ts

This file was deleted.

0 comments on commit e118ee9

Please sign in to comment.