Added the redirect to the invites page back in…

This commit is contained in:
Matt Aitken
2023-11-09 16:30:21 +00:00
parent e48c9b5e69
commit 9f1f59cc81
+13 -6
View File
@@ -1,19 +1,26 @@
import { LoaderFunctionArgs, redirect } from "@remix-run/server-runtime";
import { getUsersInvites } from "~/models/member.server";
import { SelectBestProjectPresenter } from "~/presenters/SelectBestProjectPresenter.server";
import { requireUserId } from "~/services/session.server";
import { newOrganizationPath, projectPath } from "~/utils/pathBuilder";
import { requireUser } from "~/services/session.server";
import { invitesPath, newOrganizationPath, 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) => {
const userId = await requireUserId(request);
const user = await requireUser(request);
//if there are invites then we should redirect to the invites page
const invites = await getUsersInvites({ email: user.email });
if (invites.length > 0) {
return redirect(invitesPath());
}
const presenter = new SelectBestProjectPresenter();
try {
const { project, organization } = await presenter.call({ userId, request });
const { project, organization } = await presenter.call({ userId: user.id, request });
//redirect them to the most appropriate project
return redirect(projectPath(organization, project));
} catch (e) {
//this should only happen if the user has no projects
//this should only happen if the user has no projects, and no invites
return redirect(newOrganizationPath());
}
};