Skip to content

Commit

Permalink
fix: automatic redirect if only a single tenant exists
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanCassiere committed Jun 30, 2024
1 parent 2612d0d commit 65625e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/routers/app/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const app = new Hono<ServerContext>();

app.get("/", checkUserAuthed, async (c) => {
const user = c.var.user!;
const view_all = c.req.query("view_all") || "false";

const relationships = await db.query.usersToTenants.findMany({
where: (fields, { eq }) => eq(fields.userId, user.id),
Expand All @@ -25,6 +26,11 @@ app.get("/", checkUserAuthed, async (c) => {

const tenants = relationships.map((r) => r.tenant);

if (tenants.length === 1 && view_all !== "true") {
const tenant = tenants[0];
return c.redirect(`/app/${tenant.workspace}`);
}

return c.html(<DashboardLandingPage user={user} tenants={tenants} />);
});

Expand Down
14 changes: 3 additions & 11 deletions src/routers/app/ui/pages/workspace-landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export const WorkspaceLandingPage: FC<{
<a class={getButtonStyles("secondary", "xs")} href="/app/logout">
Logout 👋🏼
</a>
<a class={getButtonStyles("secondary", "xs")} href={`/app?view_all=true`}>
Organizations ⬅️
</a>
<a class={getButtonStyles("secondary", "xs")} href={`/app/${tenant.workspace}/edit`}>
Edit ✏️
</a>
Expand All @@ -43,9 +46,6 @@ export const WorkspaceLandingPage: FC<{
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
Created at
</th>
<th scope="col" class="relative py-3.5 pl-3 pr-4 sm:pr-6 lg:pr-8">
<span class="sr-only">Edit</span>
</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200 bg-white">
Expand All @@ -62,14 +62,6 @@ export const WorkspaceLandingPage: FC<{
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
{dateFormatter.humanReadable(new Date(service.createdAt))}
</td>
<td class="relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6 lg:pr-8">
<a
href={`/app/${tenant.workspace}/${service.id}/edit`}
class="text-indigo-600 hover:text-indigo-900"
>
Edit<span class="sr-only">, {service.name}</span>
</a>
</td>
</tr>
))}
</tbody>
Expand Down

0 comments on commit 65625e1

Please sign in to comment.