Skip to content

Commit

Permalink
merged improvement-to-subscription-display and fixed conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
DonKoko committed Apr 8, 2024
2 parents 8a5dd97 + 599e2be commit cf8c7e4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
11 changes: 4 additions & 7 deletions app/modules/tier/service.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,10 @@ export async function getOrganizationTierLimit({
organizations,
}: {
organizationId?: string;
organizations: {
id: string;
type: OrganizationType;
name: string;
imageId: string | null;
userId: string;
}[];
organizations: Pick<
Organization,
"id" | "type" | "name" | "imageId" | "userId"
>[];
}) {
try {
/** Find the current organization as we need the owner */
Expand Down
4 changes: 2 additions & 2 deletions app/routes/_layout+/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ export async function loader({ context, request }: LoaderFunctionArgs) {
isAdmin: user?.roles.some((role) => role.name === Roles["ADMIN"]),
canUseBookings: canUseBookings(currentOrganization),
/** THis is used to disable team organizations when the currentOrg is Team and no subscription is present */
disabledTeamOrg: disabledTeamOrg({
disabledTeamOrg: await disabledTeamOrg({
currentOrganization,
tierId: user.tierId,
organizations,
}),
}),
{
Expand Down
23 changes: 17 additions & 6 deletions app/utils/stripe.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Stripe from "stripe";
import type { PriceWithProduct } from "~/components/subscription/prices";
import { config } from "~/config/shelf.config";
import { db } from "~/database/db.server";

import { getOrganizationTierLimit } from "~/modules/tier/service.server";
import { STRIPE_SECRET_KEY } from "./env";
import type { ErrorLabel } from "./error";
import { ShelfError } from "./error";
Expand Down Expand Up @@ -355,18 +357,27 @@ export async function getDataFromStripeEvent(event: Stripe.Event) {
}
}

export const disabledTeamOrg = ({
export const disabledTeamOrg = async ({
currentOrganization,
tierId,
organizations,
}: {
currentOrganization: Pick<Organization, "type">;
tierId: string;
}) =>
organizations: Pick<
Organization,
"id" | "type" | "name" | "imageId" | "userId"
>[];
currentOrganization: Pick<Organization, "id" | "type">;
}) => {
/**
* We need to check a few things before disabling team orgs
*
* 1. The current organization is a team
* 2. The current tier has to be tier_2. Anything else is not allowed
*/

currentOrganization.type === "TEAM" && tierId !== "tier_2";
const tierLimit = await getOrganizationTierLimit({
organizationId: currentOrganization.id,
organizations,
});

return currentOrganization.type === "TEAM" && tierLimit?.id !== "tier_2";
};

0 comments on commit cf8c7e4

Please sign in to comment.