feat: HL tenant + email domain auto-assignment
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Sidebar } from "@/components/layout/Sidebar";
|
||||
import { Header } from "@/components/layout/Header";
|
||||
import { DemoBanner } from "@/components/layout/DemoBanner";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
@@ -12,6 +13,7 @@ export default function AppLayout({
|
||||
<div className="flex h-screen overflow-hidden bg-neutral-50">
|
||||
<Sidebar />
|
||||
<div className="flex flex-1 flex-col overflow-hidden">
|
||||
<DemoBanner />
|
||||
<Header />
|
||||
<main className="flex-1 overflow-y-auto p-4 sm:p-6">{children}</main>
|
||||
</div>
|
||||
|
||||
@@ -5,12 +5,22 @@ import { api } from "@/lib/api";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
interface AutoAssignResponse {
|
||||
assigned: boolean;
|
||||
tenant_id?: string;
|
||||
name?: string;
|
||||
slug?: string;
|
||||
role?: string;
|
||||
settings?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export default function RegisterPage() {
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [firmName, setFirmName] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [showFirmName, setShowFirmName] = useState(true);
|
||||
const router = useRouter();
|
||||
const supabase = createClient();
|
||||
|
||||
@@ -34,8 +44,30 @@ export default function RegisterPage() {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Create tenant via backend (the backend adds the user as owner)
|
||||
if (data.session) {
|
||||
// 2. Check if email domain matches an existing tenant for auto-assignment
|
||||
try {
|
||||
const result = await api.post<AutoAssignResponse>("/tenants/auto-assign", { email });
|
||||
if (result.assigned && result.tenant_id) {
|
||||
// Auto-assigned — store tenant and go to dashboard
|
||||
localStorage.setItem("kanzlai_tenant_id", result.tenant_id);
|
||||
router.push("/");
|
||||
router.refresh();
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
// Auto-assign failed — fall through to manual tenant creation
|
||||
}
|
||||
|
||||
// 3. No auto-assignment — create tenant manually
|
||||
if (!firmName) {
|
||||
// Show firm name field if not yet visible
|
||||
setShowFirmName(true);
|
||||
setError("Bitte geben Sie einen Kanzleinamen ein");
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await api.post("/tenants", { name: firmName });
|
||||
} catch (err: unknown) {
|
||||
@@ -68,23 +100,27 @@ export default function RegisterPage() {
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleRegister} className="space-y-4">
|
||||
<div>
|
||||
<label
|
||||
htmlFor="firm"
|
||||
className="block text-sm font-medium text-neutral-700"
|
||||
>
|
||||
Kanzleiname
|
||||
</label>
|
||||
<input
|
||||
id="firm"
|
||||
type="text"
|
||||
value={firmName}
|
||||
onChange={(e) => setFirmName(e.target.value)}
|
||||
required
|
||||
className="mt-1 block w-full rounded-md border border-neutral-300 px-3 py-2 text-sm placeholder-neutral-400 focus:border-neutral-900 focus:outline-none focus:ring-1 focus:ring-neutral-900"
|
||||
placeholder="Muster & Partner Rechtsanwaelte"
|
||||
/>
|
||||
</div>
|
||||
{showFirmName && (
|
||||
<div>
|
||||
<label
|
||||
htmlFor="firm"
|
||||
className="block text-sm font-medium text-neutral-700"
|
||||
>
|
||||
Kanzleiname
|
||||
</label>
|
||||
<input
|
||||
id="firm"
|
||||
type="text"
|
||||
value={firmName}
|
||||
onChange={(e) => setFirmName(e.target.value)}
|
||||
className="mt-1 block w-full rounded-md border border-neutral-300 px-3 py-2 text-sm placeholder-neutral-400 focus:border-neutral-900 focus:outline-none focus:ring-1 focus:ring-neutral-900"
|
||||
placeholder="Muster & Partner Rechtsanwaelte"
|
||||
/>
|
||||
<p className="mt-1 text-xs text-neutral-400">
|
||||
Leer lassen, falls Sie zu einer bestehenden Kanzlei eingeladen wurden
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<label
|
||||
|
||||
17
frontend/src/components/layout/DemoBanner.tsx
Normal file
17
frontend/src/components/layout/DemoBanner.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
"use client";
|
||||
|
||||
import { usePermissions } from "@/lib/hooks/usePermissions";
|
||||
|
||||
export function DemoBanner() {
|
||||
const { isDemo, isLoading } = usePermissions();
|
||||
|
||||
if (isLoading || !isDemo) return null;
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-center gap-2 bg-amber-50 border-b border-amber-200 px-4 py-2 text-sm text-amber-800">
|
||||
<span className="font-medium">Demo-Modus</span>
|
||||
<span className="text-amber-600">—</span>
|
||||
<span>Keine echten Mandantendaten eingeben</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -25,5 +25,6 @@ export function usePermissions() {
|
||||
isLoading,
|
||||
userId: data?.user_id ?? null,
|
||||
tenantId: data?.tenant_id ?? null,
|
||||
isDemo: data?.is_demo ?? false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -202,6 +202,7 @@ export interface UserInfo {
|
||||
tenant_id: string;
|
||||
role: UserRole;
|
||||
permissions: string[];
|
||||
is_demo: boolean;
|
||||
}
|
||||
|
||||
export type UserRole = "owner" | "partner" | "associate" | "paralegal" | "secretary";
|
||||
|
||||
Reference in New Issue
Block a user