Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remove unnecessary env vars #61

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const config = {
"plugin:prettier/recommended"
],
"rules": {
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/array-type": "off",
"@typescript-eslint/consistent-type-definitions": "off",
Expand Down
21 changes: 16 additions & 5 deletions src/app/actions/createMembership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { MembershipStatus } from "@prisma/client"

import { type ServerActionState, ServerActionStatus } from "@/app/actions/types"
import { db } from "@/services/db"
import { stripe } from "@/services/stripe"
import { canUseStripe, stripe } from "@/services/stripe"

const MEMBERSHIP_PRICE_ID = "price_1P3HNlCXdJySzBrwlcoAQqS2"
const MEMBERSHIP_PRICE_ID = "price_1P3HNlCXdJySzBrwlcoAQqS2" // TODO: Remove the hardcoded price ID

export interface FormProps {
email: string
Expand All @@ -20,6 +20,16 @@ export async function createMembership(
prevState: ServerActionState,
data: FormProps,
): Promise<ServerActionState> {
if (!canUseStripe()) {
return {
errors: [
{
message: "Stripe is not configured",
},
],
status: ServerActionStatus.Error,
}
}
// Avoid double membership creation
if (prevState.nextStep === "providePayment") return prevState

Expand Down Expand Up @@ -52,7 +62,7 @@ export async function createMembership(
// User is not linked to Stripe, creates it
if (!user.stripeCustomerId) {
// Create customer to Stripe and link it to user
const stripeCustomer = await stripe.customers.create({
const stripeCustomer = await stripe().customers.create({
email: data.email,
name: `${data.firstName} ${data.lastName}`.trim(),
})
Expand Down Expand Up @@ -97,7 +107,7 @@ export async function createMembership(
})

// Create Stripe subscription
const stripeSubscription = await stripe.subscriptions.create({
const stripeSubscription = await stripe().subscriptions.create({
customer: user.stripeCustomerId,
expand: ["latest_invoice.payment_intent"],
items: [
Expand All @@ -123,7 +133,8 @@ export async function createMembership(
nextStep: "providePayment",
payload: {
// eslint-disable-next-line
clientSecret: (stripeSubscription?.latest_invoice as any)?.payment_intent?.client_secret,
clientSecret: (stripeSubscription?.latest_invoice as any)?.payment_intent
?.client_secret,
membershipId: membership.id,
},
status: ServerActionStatus.Success,
Expand Down
27 changes: 12 additions & 15 deletions src/app/actions/createMembershipTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
"use server";
"use server"

import {
type ServerActionState,
ServerActionStatus,
} from "@/app/actions/types";
import { db } from "@/services/db";
import { PricePeriod, type PriceUnit } from "@prisma/client";
import { type ServerActionState, ServerActionStatus } from "@/app/actions/types"
import { db } from "@/services/db"
import { PricePeriod, type PriceUnit } from "@prisma/client"

export interface FormProps {
title: string;
description?: string;
features?: string;
priceAmount: number;
priceUnit: PriceUnit;
stripePriceId: string;
title: string
description?: string
features?: string
priceAmount: number
priceUnit: PriceUnit
stripePriceId: string
}

export async function createMembershipTemplate(
Expand All @@ -35,10 +32,10 @@ export async function createMembershipTemplate(
createdAt: new Date(),
updatedAt: new Date(),
},
});
})

return {
status: ServerActionStatus.Success,
payload: membershipTemplate,
};
}
}
29 changes: 13 additions & 16 deletions src/app/actions/editMembershipTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
"use server";
"use server"

import {
type ServerActionState,
ServerActionStatus,
} from "@/app/actions/types";
import { db } from "@/services/db";
import { PricePeriod, type PriceUnit } from "@prisma/client";
import { type ServerActionState, ServerActionStatus } from "@/app/actions/types"
import { db } from "@/services/db"
import { PricePeriod, type PriceUnit } from "@prisma/client"

export interface FormProps {
id: string;
title: string;
description?: string;
features?: string;
priceAmount: number;
priceUnit: PriceUnit;
stripePriceId: string;
id: string
title: string
description?: string
features?: string
priceAmount: number
priceUnit: PriceUnit
stripePriceId: string
}

export async function editMembershipTemplate(
Expand All @@ -38,10 +35,10 @@ export async function editMembershipTemplate(
stripePriceId: data.stripePriceId,
updatedAt: new Date(),
},
});
})

return {
status: ServerActionStatus.Success,
payload: membershipTemplate,
};
}
}
24 changes: 12 additions & 12 deletions src/app/actions/validateUserEmail.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"use server";
"use server"

import { MembershipStatus } from "@prisma/client";
import { MembershipStatus } from "@prisma/client"

import { db } from "@/services/db";
import { db } from "@/services/db"

export interface ServerActionState {
checked: boolean;
valid: boolean;
email?: string;
checked: boolean
valid: boolean
email?: string
}
interface FormProps {
email: string;
email: string
}
export async function validateUserEmail(
prevState: ServerActionState,
Expand All @@ -20,14 +20,14 @@ export async function validateUserEmail(
where: {
email: data.email,
},
});
})

// No user means that is not valid
if (!user)
return {
checked: true,
valid: false,
};
}

// User without membership means that is not valid
const membership = await db.membership.findFirst({
Expand All @@ -37,16 +37,16 @@ export async function validateUserEmail(
},
userId: user.id,
},
});
})
if (!membership)
return {
checked: true,
valid: false,
};
}

return {
checked: true,
email: data.email,
valid: true,
};
}
}
12 changes: 6 additions & 6 deletions src/app/admin/@authenticated/membership/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { find } from "lodash";
import { find } from "lodash"

import { adminMenuTreeConfig } from "@/app/admin/const";
import { LinkWithActive } from "@/components/molecules/linkWithActive";
import { adminMenuTreeConfig } from "@/app/admin/const"
import { LinkWithActive } from "@/components/molecules/linkWithActive"

interface AdminAuthenticatedLayoutInterface {
children: React.ReactNode;
children: React.ReactNode
}

export default async function AdminAuthenticatedLayout({
children,
}: AdminAuthenticatedLayoutInterface) {
const settingsChildren = find(adminMenuTreeConfig, { id: "membership" })!;
const settingsChildren = find(adminMenuTreeConfig, { id: "membership" })!

return (
<>
Expand All @@ -28,5 +28,5 @@ export default async function AdminAuthenticatedLayout({
<div className="grid gap-6">{children}</div>
</div>
</>
);
)
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
"use client";
"use client"

import { AdminMembershipCRUDForm } from "@/app/admin/@authenticated/membership/manage/form";
import { CRUDFormIntent } from "@/modules/crudForm/types";
import { useToast } from "@/components/ui/use-toast";
import { useRouter } from "next/navigation";
import { AdminMembershipCRUDForm } from "@/app/admin/@authenticated/membership/manage/form"
import { CRUDFormIntent } from "@/modules/crudForm/types"
import { useToast } from "@/components/ui/use-toast"
import { useRouter } from "next/navigation"

export function AdminMembershipCreateModalClient() {
const { toast } = useToast();
const router = useRouter();
const { toast } = useToast()
const router = useRouter()

const onSubmit = () => {
toast({
title: "Success",
description: "Membership Template created",
variant: "success",
});
router.back();
router.refresh();
};
})
router.back()
router.refresh()
}

return (
<AdminMembershipCRUDForm
intent={CRUDFormIntent.Create}
onSuccess={onSubmit}
/>
);
)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Modal } from "@/components/molecules/modal";
import { AdminMembershipCRUDForm } from "@/app/admin/@authenticated/membership/manage/form";
import { CRUDFormIntent } from "@/modules/crudForm/types";
import { Modal } from "@/components/molecules/modal"
import { AdminMembershipCRUDForm } from "@/app/admin/@authenticated/membership/manage/form"
import { CRUDFormIntent } from "@/modules/crudForm/types"

export default function AdminMembershipModalCreatePage() {
return (
<Modal>
<AdminMembershipCRUDForm intent={CRUDFormIntent.Create} />
</Modal>
);
)
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
"use client";
"use client"

import { AdminMembershipCRUDForm } from "@/app/admin/@authenticated/membership/manage/form";
import { CRUDFormIntent } from "@/modules/crudForm/types";
import { type MembershipTemplate } from "@prisma/client";
import { useToast } from "@/components/ui/use-toast";
import { useRouter } from "next/navigation";
import { AdminMembershipCRUDForm } from "@/app/admin/@authenticated/membership/manage/form"
import { CRUDFormIntent } from "@/modules/crudForm/types"
import { type MembershipTemplate } from "@prisma/client"
import { useToast } from "@/components/ui/use-toast"
import { useRouter } from "next/navigation"

interface AdminMembershipEditPageClient {
previousValues: MembershipTemplate;
previousValues: MembershipTemplate
}

export function AdminMembershipEditModalClient({
previousValues,
}: AdminMembershipEditPageClient) {
const { toast } = useToast();
const router = useRouter();
const { toast } = useToast()
const router = useRouter()

const onSubmit = () => {
toast({
title: "Success",
description: "Membership Template updated",
variant: "success",
});
router.back();
router.refresh();
};
})
router.back()
router.refresh()
}

return (
<AdminMembershipCRUDForm
intent={CRUDFormIntent.Edit}
previousValues={previousValues}
onSuccess={onSubmit}
/>
);
)
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { Modal } from "@/components/molecules/modal";
import { db } from "@/services/db";
import { AdminMembershipEditModalClient } from "@/app/admin/@authenticated/membership/manage/@modal/(.)edit/[id]/client";
import { Modal } from "@/components/molecules/modal"
import { db } from "@/services/db"
import { AdminMembershipEditModalClient } from "@/app/admin/@authenticated/membership/manage/@modal/(.)edit/[id]/client"

const getData = (id: string) => {
return db.membershipTemplate.findUnique({
where: {
id,
},
});
};
})
}

interface AdminMembershipEditPageProps {
params: {
id: string;
};
id: string
}
}

export default async function AdminMembershipModalEditPage({
params,
}: AdminMembershipEditPageProps) {
const membershipTemplate = await getData(params.id);
const membershipTemplate = await getData(params.id)

return (
<Modal>
<AdminMembershipEditModalClient previousValues={membershipTemplate!} />
</Modal>
);
)
}
Loading
Loading