Frontend adjustments

This commit is contained in:
2026-04-14 20:45:58 +02:00
parent f0eca1959b
commit f550b3400f
5 changed files with 41 additions and 19 deletions

View File

@@ -91,7 +91,13 @@ function UsageChart({ data }: { data: DailyUsage[] }) {
);
}
export function UsageDisplay({ teamId }: { teamId: string | null }) {
/**
* Usage display widget.
*
* - Customers: don't pass teamId — the backend resolves it from the session.
* - Admins inspecting a specific tenant: pass teamId to override.
*/
export function UsageDisplay({ teamId }: { teamId?: string | null }) {
const t = useTranslations("usage");
const [month, setMonth] = useState(getCurrentMonth);
const [data, setData] = useState<UsageData | null>(null);
@@ -101,10 +107,15 @@ export function UsageDisplay({ teamId }: { teamId: string | null }) {
const isCurrentMonth = month === getCurrentMonth();
const fetchUsage = useCallback(() => {
if (!teamId) { setLoading(false); return; }
setLoading(true);
setError(null);
fetch(`/api/usage?teamId=${encodeURIComponent(teamId)}&month=${month}`)
const params = new URLSearchParams({ month });
if (teamId) {
params.set("teamId", teamId);
}
fetch(`/api/usage?${params}`)
.then((res) => { if (!res.ok) throw new Error(`${res.status}`); return res.json(); })
.then(setData)
.catch((e) => setError(e.message))
@@ -113,8 +124,6 @@ export function UsageDisplay({ teamId }: { teamId: string | null }) {
useEffect(() => { fetchUsage(); }, [fetchUsage]);
if (!teamId) return null;
return (
<div className="space-y-4">
{/* Month selector */}
@@ -182,4 +191,4 @@ function StatCard({ label, value, accent }: { label: string; value: string; acce
<div className={`font-display text-lg font-semibold tabular-nums ${accent ? "text-accent" : "text-text-primary"}`}>{value}</div>
</div>
);
}
}

View File

@@ -90,7 +90,7 @@ export function OnboardingWizard({ orgName, onComplete }: WizardProps) {
// Fetch DB-stored defaults on mount
useEffect(() => {
fetch(`/api/workspace-defaults?orgName=${encodeURIComponent(orgName)}`)
fetch("/api/workspace-defaults")
.then((r) => (r.ok ? r.json() : null))
.then((data) => {
if (data) {
@@ -106,7 +106,8 @@ export function OnboardingWizard({ orgName, onComplete }: WizardProps) {
.catch(() => {
/* use inline fallbacks */
});
}, [orgName]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
// Re-fetch TOOLS.md preview when packages change
const packagesKey = config.packages.sort().join(",");
@@ -115,14 +116,14 @@ export function OnboardingWizard({ orgName, onComplete }: WizardProps) {
if (prevPackagesKey.current === packagesKey && defaultsLoaded) return;
prevPackagesKey.current = packagesKey;
fetch(
`/api/workspace-defaults?orgName=${encodeURIComponent(orgName)}&packages=${encodeURIComponent(packagesKey)}`
`/api/workspace-defaults?packages=${encodeURIComponent(packagesKey)}`
)
.then((r) => (r.ok ? r.json() : null))
.then((data) => {
if (data?.toolsMd) setToolsMdPreview(data.toolsMd);
})
.catch(() => {});
}, [packagesKey, orgName, defaultsLoaded]);
}, [packagesKey, defaultsLoaded]);
const stepIndex = STEPS.indexOf(step);