Skip to content

Commit 2fa5780

Browse files
committed
At the root path, if you have no projects yet but you do have an org then go to the new project page
1 parent 914a394 commit 2fa5780

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

apps/webapp/app/presenters/OrganizationsPresenter.server.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import { PrismaClient } from "@trigger.dev/database";
22
import { redirect } from "remix-typedjson";
33
import { prisma } from "~/db.server";
4+
import { redirectWithErrorMessage } from "~/models/message.server";
45
import {
5-
clearCurrentProjectId,
66
commitCurrentProjectSession,
77
getCurrentProjectId,
88
setCurrentProjectId,
99
} from "~/services/currentProject.server";
1010
import { logger } from "~/services/logger.server";
1111
import { newProjectPath } from "~/utils/pathBuilder";
1212
import { ProjectPresenter } from "./ProjectPresenter.server";
13-
import { redirectWithErrorMessage } from "~/models/message.server";
14-
import { match } from "assert";
1513

1614
export class OrganizationsPresenter {
1715
#prismaClient: PrismaClient;

apps/webapp/app/routes/_app._index/route.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { LoaderFunctionArgs, redirect } from "@remix-run/server-runtime";
2+
import { prisma } from "~/db.server";
23
import { getUsersInvites } from "~/models/member.server";
34
import { SelectBestProjectPresenter } from "~/presenters/SelectBestProjectPresenter.server";
45
import { requireUser } from "~/services/session.server";
5-
import { invitesPath, newOrganizationPath, projectPath } from "~/utils/pathBuilder";
6+
import { invitesPath, newOrganizationPath, newProjectPath, projectPath } from "~/utils/pathBuilder";
67

78
//this loader chooses the best project to redirect you to, ideally based on the cookie
89
export const loader = async ({ request }: LoaderFunctionArgs) => {
@@ -20,6 +21,24 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
2021
//redirect them to the most appropriate project
2122
return redirect(projectPath(organization, project));
2223
} catch (e) {
24+
const organization = await prisma.organization.findFirst({
25+
where: {
26+
members: {
27+
some: {
28+
userId: user.id,
29+
},
30+
},
31+
deletedAt: null,
32+
},
33+
orderBy: {
34+
createdAt: "desc",
35+
},
36+
});
37+
38+
if (organization) {
39+
return redirect(newProjectPath(organization));
40+
}
41+
2342
//this should only happen if the user has no projects, and no invites
2443
return redirect(newOrganizationPath());
2544
}

0 commit comments

Comments
 (0)