Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fontanierh committed Nov 6, 2023
1 parent c68b807 commit 2fb80f9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 101 deletions.
2 changes: 1 addition & 1 deletion front/lib/plans/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const internalInviteWorkspaceToEnterprisePlan = async ({
const model = await front_sequelize.transaction(async (t) => {
if (invitation) {
await PlanInvitation.destroy({
where: { id: workspace.id, consumedAt: null },
where: { workspaceId: workspace.id, consumedAt: null },
transaction: t,
});
}
Expand Down
57 changes: 0 additions & 57 deletions front/pages/api/upgrade-enterprise/[secret].ts

This file was deleted.

63 changes: 21 additions & 42 deletions front/pages/upgrade-enterprise/[secret].tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { GetServerSideProps, InferGetServerSidePropsType } from "next";
import { useEffect } from "react";

import OnboardingLayout from "@app/components/sparkle/OnboardingLayout";
import { Workspace } from "@app/lib/models";
import { PlanInvitation } from "@app/lib/models/plan";
import { internalUpgradeWorkspace } from "@app/lib/plans/subscription";

const { GA_TRACKING_ID = "" } = process.env;

export const getServerSideProps: GetServerSideProps<{
secret: string;
gaTrackingId: string;
}> = async (context) => {
export const getServerSideProps: GetServerSideProps<object> = async (
context
) => {
const token = context.params?.secret as string;
if (!token) {
return {
Expand Down Expand Up @@ -42,43 +38,26 @@ export const getServerSideProps: GetServerSideProps<{
};
}

const checkoutUrl = await internalUpgradeWorkspace({
workspaceSId: workspace.sId,
});
if (!checkoutUrl) {
return {
notFound: true,
};
}

return {
props: {
secret: token,
gaTrackingId: GA_TRACKING_ID,
redirect: {
destination: checkoutUrl,
permanent: false,
},
};
};

export default function Welcome({
secret,
gaTrackingId,
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
useEffect(() => {
async function redirect() {
const res = await fetch(`/api/upgrade-enterprise/${secret}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
});
if (!res.ok) {
window.location.href = "/";
return;
}

const data = await res.json();
if (data.checkoutUrl) {
window.location.href = data.checkoutUrl;
}
}

void redirect();
}, [secret]);

return (
<OnboardingLayout gaTrackingId={gaTrackingId}>
<div />
</OnboardingLayout>
);
export default function Welcome(
_props: InferGetServerSidePropsType<typeof getServerSideProps>
) {
void _props;
return null;
}
2 changes: 1 addition & 1 deletion front/pages/w/[wId]/subscription/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const getServerSideProps: GetServerSideProps<{
};
}

const planInvitation = await getPlanInvitation({ workspaceId: owner.sId });
const planInvitation = await getPlanInvitation({ workspaceSId: owner.sId });

return {
props: {
Expand Down

0 comments on commit 2fb80f9

Please sign in to comment.