trails/apps/journal/app/routes/settings.connections.tsx
Ullrich Schäfer c0c1a53322 Split /settings into 4 sub-pages with a sidebar layout
Stream E from docs/information-architecture.md. The settings page was
a single scrollable list of five concerns; split it into four
deep-linkable sections behind a shared sidebar layout, so each
concern has a stable URL, a focused loader (only fetches what that
section needs), and a meta title that reflects the section.

Sections:
- /settings/profile — display name, bio, profile visibility
- /settings/account — email change + danger-zone account deletion
- /settings/security — passkeys
- /settings/connections — sync providers (Wahoo today)

URL pattern: nested routes under a layout. /settings itself
redirects to /settings/profile so the bare URL still lands somewhere
useful without rendering an empty container.

- apps/journal/app/routes/settings.tsx — converted from a single
  scrollable page to a layout that renders the sidebar nav + Outlet.
- apps/journal/app/routes/settings.{profile,account,security,
  connections,_index}.tsx — new files, each with its own loader and
  meta. _index redirects to /settings/profile.
- apps/journal/app/routes.ts — registers the four children + index
  under the settings layout route.
- packages/i18n/src/locales/{en,de}.ts — new settings.nav.{profile,
  account,security,connections} keys for the sidebar labels.

Specs (profile-settings, account-management, connected-services)
are unchanged — they describe behavior, not URL structure. The
journal-landing spec is also unchanged; the navbar still has a
single "Settings" link.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 09:48:00 +02:00

86 lines
2.9 KiB
TypeScript

import { data, redirect } from "react-router";
import { useTranslation } from "react-i18next";
import { eq } from "drizzle-orm";
import type { Route } from "./+types/settings.connections";
import { getSessionUser } from "~/lib/auth.server";
import { getDb } from "~/lib/db";
import { syncConnections } from "@trails-cool/db/schema/journal";
import { getAllProviders } from "~/lib/sync/registry";
export function meta() {
return [{ title: "Connected services — Settings — trails.cool" }];
}
export async function loader({ request }: Route.LoaderArgs) {
const user = await getSessionUser(request);
if (!user) throw redirect("/auth/login");
const db = getDb();
const connections = await db
.select({
provider: syncConnections.provider,
providerUserId: syncConnections.providerUserId,
})
.from(syncConnections)
.where(eq(syncConnections.userId, user.id));
const providers = getAllProviders().map((p) => {
const conn = connections.find((c) => c.provider === p.id);
return { id: p.id, name: p.name, connected: !!conn, providerUserId: conn?.providerUserId };
});
return data({ providers });
}
export default function ConnectionsSettings({ loaderData }: Route.ComponentProps) {
const { providers } = loaderData;
const { t } = useTranslation(["journal"]);
return (
<section>
<h2 className="text-lg font-semibold text-gray-900">{t("settings.services.title")}</h2>
<div className="mt-4 space-y-3">
{providers.map((p) => (
<div
key={p.id}
className="flex items-center justify-between rounded-md border border-gray-200 px-4 py-3"
>
<div>
<p className="font-medium text-gray-900">{p.name}</p>
{p.connected && p.providerUserId && (
<p className="text-xs text-gray-500">
{t("settings.services.connectedAs", { id: p.providerUserId })}
</p>
)}
</div>
{p.connected ? (
<div className="flex items-center gap-3">
<a
href={`/sync/import/${p.id}`}
className="text-sm text-blue-600 hover:underline"
>
{t("sync.import")}
</a>
<form method="post" action={`/api/sync/disconnect/${p.id}`}>
<button
type="submit"
className="text-sm text-red-600 hover:underline"
>
{t("settings.services.disconnect")}
</button>
</form>
</div>
) : (
<a
href={`/api/sync/connect/${p.id}`}
className="rounded-md bg-blue-600 px-3 py-1.5 text-sm text-white hover:bg-blue-700"
>
{t("settings.services.connect")}
</a>
)}
</div>
))}
</div>
</section>
);
}