From 2fa578007654e2d18df4e896f145c2f669657926 Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Fri, 24 May 2024 12:35:33 +0100 Subject: [PATCH] At the root path, if you have no projects yet but you do have an org then go to the new project page --- .../OrganizationsPresenter.server.ts | 4 +--- apps/webapp/app/routes/_app._index/route.tsx | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/apps/webapp/app/presenters/OrganizationsPresenter.server.ts b/apps/webapp/app/presenters/OrganizationsPresenter.server.ts index d4888ea3f..894b1774f 100644 --- a/apps/webapp/app/presenters/OrganizationsPresenter.server.ts +++ b/apps/webapp/app/presenters/OrganizationsPresenter.server.ts @@ -1,8 +1,8 @@ import { PrismaClient } from "@trigger.dev/database"; import { redirect } from "remix-typedjson"; import { prisma } from "~/db.server"; +import { redirectWithErrorMessage } from "~/models/message.server"; import { - clearCurrentProjectId, commitCurrentProjectSession, getCurrentProjectId, setCurrentProjectId, @@ -10,8 +10,6 @@ import { import { logger } from "~/services/logger.server"; import { newProjectPath } from "~/utils/pathBuilder"; import { ProjectPresenter } from "./ProjectPresenter.server"; -import { redirectWithErrorMessage } from "~/models/message.server"; -import { match } from "assert"; export class OrganizationsPresenter { #prismaClient: PrismaClient; diff --git a/apps/webapp/app/routes/_app._index/route.tsx b/apps/webapp/app/routes/_app._index/route.tsx index a3889f840..dc9a9a9dc 100644 --- a/apps/webapp/app/routes/_app._index/route.tsx +++ b/apps/webapp/app/routes/_app._index/route.tsx @@ -1,8 +1,9 @@ import { LoaderFunctionArgs, redirect } from "@remix-run/server-runtime"; +import { prisma } from "~/db.server"; import { getUsersInvites } from "~/models/member.server"; import { SelectBestProjectPresenter } from "~/presenters/SelectBestProjectPresenter.server"; import { requireUser } from "~/services/session.server"; -import { invitesPath, newOrganizationPath, projectPath } from "~/utils/pathBuilder"; +import { invitesPath, newOrganizationPath, newProjectPath, projectPath } from "~/utils/pathBuilder"; //this loader chooses the best project to redirect you to, ideally based on the cookie export const loader = async ({ request }: LoaderFunctionArgs) => { @@ -20,6 +21,24 @@ export const loader = async ({ request }: LoaderFunctionArgs) => { //redirect them to the most appropriate project return redirect(projectPath(organization, project)); } catch (e) { + const organization = await prisma.organization.findFirst({ + where: { + members: { + some: { + userId: user.id, + }, + }, + deletedAt: null, + }, + orderBy: { + createdAt: "desc", + }, + }); + + if (organization) { + return redirect(newProjectPath(organization)); + } + //this should only happen if the user has no projects, and no invites return redirect(newOrganizationPath()); }