Setup step 3 asks where you live and shows that country's bank feed (#6)
Saved as BROKE_COUNTRY. US and Canada get Plaid, NZ Akahu, UK and Europe Enable Banking, Australia Basiq, Brazil Belvo. Countries with no feed are told to import a statement after sign-in. Onboarding uses the saved country instead of asking again. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1e246336a2
commit
b532bb8dd8
8 files changed
+136
-60
No files matched your search
@@ -78,7 +78,7 @@ export function Settings({ signedIn, local, folder, repo, update, email, profile
|
||||
}, [group, local, load]);
|
||||
|
||||
const nav = local ? NAV : NAV.filter((n) => !SERVER.includes(n.id) || n.id === "banks" || n.id === "database");
|
||||
const sections = (data?.sections ?? []).filter((s) => groupOf(s) === group);
|
||||
const sections = (data?.sections ?? []).filter((s) => s.id !== "country" && groupOf(s) === group); // "country": setup's step 3 with no feed; the country itself is under Profile
|
||||
const flagged = (g: Group) => (data?.sections ?? []).some((s) => groupOf(s) === g && attention(s));
|
||||
const here = NAV.find((n) => n.id === group)!;
|
||||
const pick = (g: Group) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { countryOf, wantsAkahu } from "@/lib/countries";
|
||||
import { fromLocalhost, setupAccess, setupStatus } from "@/lib/setup";
|
||||
import { currentEnv, fromLocalhost, setupAccess, setupStatus } from "@/lib/setup";
|
||||
import { createClient } from "@/utils/supabase/server";
|
||||
|
||||
// Server setup details are for the owner on this machine only: setup writes already need localhost (writeGate).
|
||||
@@ -12,12 +12,14 @@ export async function GET() {
|
||||
// The NZ bank keys only matter to someone with NZ banks. Keys already saved stay visible, so they can be changed or removed.
|
||||
// Before Supabase is set up there's nobody signed in, and no client to ask.
|
||||
const user = access.signedIn ? (await (await createClient()).auth.getUser()).data.user : null;
|
||||
const profile = user?.user_metadata?.profile;
|
||||
// Before anyone signs in, where they live is what setup step 3 asked (BROKE_COUNTRY).
|
||||
const profile = user?.user_metadata?.profile ?? { country: currentEnv().BROKE_COUNTRY };
|
||||
const here = countryOf(profile?.country).providers as string[];
|
||||
const nz = wantsAkahu(profile);
|
||||
// Bank connections for other countries stay out of the way, unless keys are already saved.
|
||||
return NextResponse.json({ ...status, sections: status.sections.filter((s) => {
|
||||
if (s.kind === "required") return true;
|
||||
if (s.id === "akahu") return nz || s.status === "done";
|
||||
return !["enablebanking", "basiq", "belvo"].includes(s.id) || here.includes(s.id) || s.status === "done";
|
||||
return !["plaid", "enablebanking", "basiq", "belvo"].includes(s.id) || here.includes(s.id) || s.status === "done";
|
||||
}) });
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
import { Check, Copy, Eye, EyeOff } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Dropdown } from "@/components/Dropdown";
|
||||
import { COUNTRIES, countryOf, guessCountry, OTHER } from "@/lib/countries";
|
||||
import type { Field } from "@/lib/setup";
|
||||
|
||||
export function CopyCommand({ command }: { command: string }) {
|
||||
@@ -208,3 +210,50 @@ export function ConnectSupabaseButton({ onDone, onFail }: { onDone: () => void;
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
const COUNTRY_OPTIONS = [...COUNTRIES, OTHER].map((c) => ({ value: c.code, label: c.name }));
|
||||
|
||||
// Step 3 asks where they live first, so it can show that country's bank feed. Saved as BROKE_COUNTRY; onboarding uses it
|
||||
// instead of asking again. Nothing saved yet: the guess from this computer, with a Continue button.
|
||||
export function CountryPick({ saved, canWrite, writeNote, onSaved }: { saved: string; canWrite: boolean; writeNote?: string; onSaved: () => void }) {
|
||||
const [guess, setGuess] = useState("");
|
||||
const [value, setValue] = useState(saved);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [err, setErr] = useState("");
|
||||
useEffect(() => {
|
||||
if (saved) return; // the checklist remounts this (key) when the saved country changes
|
||||
const g = guessCountry(navigator.languages ?? [navigator.language], Intl.DateTimeFormat().resolvedOptions().timeZone);
|
||||
setGuess(g);
|
||||
setValue((v) => v || g);
|
||||
}, [saved]);
|
||||
|
||||
async function save(code: string) {
|
||||
setBusy(true);
|
||||
setErr("");
|
||||
try {
|
||||
const res = await fetch("/api/setup/env", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ values: { BROKE_COUNTRY: code } }) });
|
||||
const body = (await res.json().catch(() => ({}))) as { error?: string; errors?: Record<string, string> };
|
||||
if (res.ok) onSaved();
|
||||
else setErr(body.errors?.BROKE_COUNTRY ?? body.error ?? "Couldn't save.");
|
||||
} catch {
|
||||
setErr("Couldn't reach broke. Is it still running?");
|
||||
}
|
||||
setBusy(false);
|
||||
}
|
||||
|
||||
if (!canWrite) return <p className="text-sm text-muted">Where you live: {saved ? countryOf(saved).name : "not set"}. {writeNote} Set BROKE_COUNTRY there.</p>;
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<span className="block text-sm font-medium">Where do you live?</span>
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<div className="w-64 max-w-full">
|
||||
<Dropdown label="Country" value={value} options={COUNTRY_OPTIONS} onChange={(c) => { setValue(c); if (saved) save(c); }} placeholder="Choose a country" searchable />
|
||||
</div>
|
||||
{!saved && <button className="btn-primary" disabled={busy || !value} onClick={() => save(value)}>{busy ? "Saving..." : "Continue"}</button>}
|
||||
{saved && busy && <span className="text-sm text-muted">Saving...</span>}
|
||||
</div>
|
||||
{!saved && value && value === guess && <p className="text-xs text-muted">Guessed from this computer's time zone and language. Change it if that's wrong.</p>}
|
||||
{err && <p className="text-sm text-bad">{err}</p>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import Link from "next/link";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { Logo } from "@/components/Logo";
|
||||
import type { AiRow, Part, Section, SetupStatus } from "@/lib/setup";
|
||||
import { CopyCommand, KeyForm, ConnectSupabaseButton, MigrateButton } from "./SetupActions";
|
||||
import { CopyCommand, CountryPick, KeyForm, ConnectSupabaseButton, MigrateButton } from "./SetupActions";
|
||||
|
||||
export function ExtLink({ href, children }: { href: string; children: React.ReactNode }) {
|
||||
return (
|
||||
@@ -83,9 +83,8 @@ export function SetupChecklist({ signedIn }: { signedIn: boolean }) {
|
||||
const main = sections.filter((s) => s.kind !== "more");
|
||||
const more = sections.filter((s) => s.kind === "more");
|
||||
const required = main.filter((s) => s.kind === "required");
|
||||
const done = required.filter((s) => s.status === "done").length;
|
||||
const next = required.find((s) => s.status !== "done");
|
||||
const canSkipBank = next?.id === "plaid"; // the database works, so broke can open: statements can be imported without a bank feed
|
||||
const canSkipBank = next?.country !== undefined; // the database works, so broke can open: statements can be imported without a bank feed
|
||||
|
||||
return (
|
||||
<main className="min-h-screen bg-canvas px-4 py-8 md:py-12">
|
||||
@@ -97,7 +96,7 @@ export function SetupChecklist({ signedIn }: { signedIn: boolean }) {
|
||||
|
||||
<section className="card p-7 space-y-5">
|
||||
<div className="space-y-1">
|
||||
<h1 className="text-2xl font-semibold">{!data ? "Set up broke" : !next ? "You're all set" : `Step ${done + 1} of ${required.length}: ${next.title}`}</h1>
|
||||
<h1 className="text-2xl font-semibold">{!data ? "Set up broke" : !next ? "You're all set" : `Step ${required.indexOf(next) + 1} of ${required.length}: ${next.title}`}</h1>
|
||||
<p className="text-sm text-muted">
|
||||
{!data ? "Checking what's connected… " : !next ? "Open broke and sign in with your email. " : "It's free. Follow the steps below and paste each key in. "}
|
||||
Your keys stay on this computer.
|
||||
@@ -186,6 +185,7 @@ function SectionCard({ s, n, open, onToggle, data, signedIn, reload }: { s: Sect
|
||||
</button>
|
||||
<Collapse open={open}>
|
||||
<div className="px-6 pb-6 pt-1 @md:pl-[4.25rem] space-y-4">
|
||||
{s.country !== undefined && <CountryPick key={s.country} saved={s.country} canWrite={data.canWrite} writeNote={data.writeNote} onSaved={reload} />}
|
||||
<Body s={s} data={data} signedIn={signedIn} reload={reload} />
|
||||
</div>
|
||||
</Collapse>
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { redirect } from "next/navigation";
|
||||
import { MoneyProvider } from "@/components/Money";
|
||||
import { Onboarding, type Step } from "@/components/Onboarding";
|
||||
import { countryOf } from "@/lib/countries";
|
||||
import { COUNTRIES, countryOf } from "@/lib/countries";
|
||||
import { getUser, userTz } from "@/lib/data";
|
||||
import { fmtFor } from "@/lib/format";
|
||||
import { addChoices } from "@/lib/providers";
|
||||
import { currentEnv } from "@/lib/setup";
|
||||
|
||||
// First run: the app layout sends new users here until onboarding is done (profile.onboarding, Onboarding.tsx).
|
||||
// No country yet starts at the country picker; otherwise it resumes at the saved step.
|
||||
@@ -14,10 +15,12 @@ export default async function WelcomePage() {
|
||||
const profile = user.user_metadata?.profile ?? {};
|
||||
if (profile.country && (!profile.onboarding || profile.onboarding === "done")) redirect("/");
|
||||
const step = (profile.country ? profile.onboarding : "country") as Step;
|
||||
// Setup step 3 already asked where they live. Onboarding uses that instead of asking again. "Somewhere else" still asks, for the currency.
|
||||
const setupCountry = COUNTRIES.some((c) => c.code === currentEnv().BROKE_COUNTRY) ? currentEnv().BROKE_COUNTRY : undefined;
|
||||
return (
|
||||
<MoneyProvider fmt={{ ...fmtFor(profile), tz }}>
|
||||
<main className="min-h-screen bg-canvas px-4 py-10 md:py-16 flex justify-center">
|
||||
<Onboarding profile={profile} start={step} choices={addChoices(countryOf(profile.country).code)} />
|
||||
<Onboarding profile={profile} start={step} setupCountry={setupCountry} choices={addChoices(countryOf(profile.country ?? setupCountry).code)} />
|
||||
</main>
|
||||
</MoneyProvider>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user