Beratung: Inhaber/Leitung ohne eigenes Profil sehen einen Hinweis statt einer Umleitung

"Meine Termine" leitete Inhaber ohne Beraterinnen-Profil still auf "Beraterinnen" um. Jetzt erscheint
"Du hast noch kein Beraterinnen-Profil" mit "Eigenes Profil anlegen" und Links zu "Alle Termine" und
"Beraterinnen". Ein so angelegtes Profil ist beim Inhaber direkt freigegeben, bei der Leitung durchläuft
es die normale Freigabe.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Maaxxs 2026-10-21 10:02:51 +02:00
parent dcfe85627f
commit d9ffdec854
6 changed files with 60 additions and 15 deletions

View file

@ -1,5 +1,6 @@
"use server"; "use server";
import { revalidatePath } from "next/cache"; import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";
import { db } from "@/lib/db"; import { db } from "@/lib/db";
import { assertPermission, audit, can, type CurrentUser } from "@/lib/auth"; import { assertPermission, audit, can, type CurrentUser } from "@/lib/auth";
import { fail, ok, type ActionResult } from "@/lib/action-result"; import { fail, ok, type ActionResult } from "@/lib/action-result";
@ -72,6 +73,16 @@ export async function saveProfile(_prev: ActionResult, fd: FormData): Promise<Ac
return done(); return done();
} }
/** Inhaber oder Leitung legt sich selbst ein Profil an. Der Inhaber ist direkt freigegeben, die Leitung durchläuft die normale Freigabe. */
export async function createOwnProfile() {
const user = await assertPermission("consulting.own");
const advisor = await getOwnAdvisor(user);
if (user.role?.isSystem && advisor.status === "draft") await db.advisor.update({ where: { id: advisor.id }, data: { status: "approved" } });
await audit(user, "Eigenes Beraterinnen-Profil angelegt", advisor.displayName);
revalidatePath("/admin/beratung", "layout");
redirect("/admin/beratung/profil");
}
/** Beraterin schickt ihr Profil zur Freigabe. */ /** Beraterin schickt ihr Profil zur Freigabe. */
export async function submitProfile(fd: FormData) { export async function submitProfile(fd: FormData) {
const { advisor } = await targetAdvisor(fd); const { advisor } = await targetAdvisor(fd);

View file

@ -5,7 +5,7 @@ import { ConfirmButton } from "@/components/admin/AdminForm";
import { Card, Empty, PageHead, Pill } from "@/components/admin/ui"; import { Card, Empty, PageHead, Pill } from "@/components/admin/ui";
import { OfferForm } from "@/components/admin/OfferForm"; import { OfferForm } from "@/components/admin/OfferForm";
import { approveOffer, deleteOffer } from "../actions"; import { approveOffer, deleteOffer } from "../actions";
import { AdvisorStatus, AdvisorTabs, loadAdvisor } from "../shared"; import { AdvisorStatus, AdvisorTabs, loadAdvisor, NoAdvisorProfile } from "../shared";
export const metadata = { title: "Meine Angebote" }; export const metadata = { title: "Meine Angebote" };
@ -13,7 +13,9 @@ const MODE: Record<string, string> = { both: "Video oder Audio", video: "Video",
export default async function AdvisorOffers({ searchParams }: { searchParams: Promise<{ b?: string }> }) { export default async function AdvisorOffers({ searchParams }: { searchParams: Promise<{ b?: string }> }) {
const { b } = await searchParams; const { b } = await searchParams;
const { advisor, foreign, user } = await loadAdvisor(b); const ctx = await loadAdvisor(b);
if (!ctx.advisor) return <NoAdvisorProfile title="Meine Angebote" />;
const { advisor, foreign, user } = { ...ctx, advisor: ctx.advisor };
const offers = await db.advisorOffer.findMany({ where: { advisorId: advisor.id }, orderBy: { sort: "asc" } }); const offers = await db.advisorOffer.findMany({ where: { advisorId: advisor.id }, orderBy: { sort: "asc" } });
const manager = can(user, "consulting.manage"); const manager = can(user, "consulting.manage");
return ( return (

View file

@ -6,7 +6,7 @@ import { ConfirmButton } from "@/components/admin/AdminForm";
import { Card, Empty, PageHead, Pill } from "@/components/admin/ui"; import { Card, Empty, PageHead, Pill } from "@/components/admin/ui";
import { AdvisorCancelForm, NoteForm, RespondForm } from "@/components/admin/ConsultForms"; import { AdvisorCancelForm, NoteForm, RespondForm } from "@/components/admin/ConsultForms";
import { markNoShow, submitProfile } from "./actions"; import { markNoShow, submitProfile } from "./actions";
import { AdvisorStatus, AdvisorTabs, loadAdvisor } from "./shared"; import { AdvisorStatus, AdvisorTabs, loadAdvisor, NoAdvisorProfile } from "./shared";
export const metadata = { title: "Meine Termine" }; export const metadata = { title: "Meine Termine" };
@ -17,7 +17,9 @@ const left = (d: Date) => {
export default async function AdvisorDashboard({ searchParams }: { searchParams: Promise<{ b?: string }> }) { export default async function AdvisorDashboard({ searchParams }: { searchParams: Promise<{ b?: string }> }) {
const { b } = await searchParams; const { b } = await searchParams;
const { advisor, foreign } = await loadAdvisor(b); const ctx = await loadAdvisor(b);
if (!ctx.advisor) return <NoAdvisorProfile title="Meine Termine" />;
const { advisor, foreign } = { ...ctx, advisor: ctx.advisor };
const now = new Date(); const now = new Date();
const [requests, waiting, upcoming, past, plan] = await Promise.all([ const [requests, waiting, upcoming, past, plan] = await Promise.all([
db.appointment.findMany({ where: { advisorId: advisor.id, status: { in: ["requested", "proposed"] } }, orderBy: { startsAt: "asc" }, include: { customer: { select: { firstName: true } }, proposals: { orderBy: { startsAt: "asc" } }, offer: true } }), db.appointment.findMany({ where: { advisorId: advisor.id, status: { in: ["requested", "proposed"] } }, orderBy: { startsAt: "asc" }, include: { customer: { select: { firstName: true } }, proposals: { orderBy: { startsAt: "asc" } }, offer: true } }),

View file

@ -4,13 +4,15 @@ import { Card, PageHead } from "@/components/admin/ui";
import { ImageManager } from "@/components/admin/ImageManager"; import { ImageManager } from "@/components/admin/ImageManager";
import { Alert } from "@/components/shop/Blocks"; import { Alert } from "@/components/shop/Blocks";
import { saveProfile } from "../actions"; import { saveProfile } from "../actions";
import { AdvisorStatus, AdvisorTabs, loadAdvisor } from "../shared"; import { AdvisorStatus, AdvisorTabs, loadAdvisor, NoAdvisorProfile } from "../shared";
export const metadata = { title: "Mein Profil" }; export const metadata = { title: "Mein Profil" };
export default async function AdvisorProfile({ searchParams }: { searchParams: Promise<{ b?: string }> }) { export default async function AdvisorProfile({ searchParams }: { searchParams: Promise<{ b?: string }> }) {
const { b } = await searchParams; const { b } = await searchParams;
const { advisor, foreign } = await loadAdvisor(b); const ctx = await loadAdvisor(b);
if (!ctx.advisor) return <NoAdvisorProfile title="Mein Profil" />;
const { advisor, foreign } = { ...ctx, advisor: ctx.advisor };
return ( return (
<div className="ad-wrap ad-wrap--narrow"> <div className="ad-wrap ad-wrap--narrow">
<PageHead title={foreign ? `Profil von ${advisor.displayName}` : "Mein Profil"} lead="So stellst du dich im Shop vor." back={foreign ? { href: "/admin/beratung/beraterinnen", label: "Beraterinnen" } : undefined} /> <PageHead title={foreign ? `Profil von ${advisor.displayName}` : "Mein Profil"} lead="So stellst du dich im Shop vor." back={foreign ? { href: "/admin/beratung/beraterinnen", label: "Beraterinnen" } : undefined} />

View file

@ -1,20 +1,46 @@
import Link from "next/link"; import Link from "next/link";
import { notFound, redirect } from "next/navigation"; import { notFound } from "next/navigation";
import { db } from "@/lib/db"; import { db } from "@/lib/db";
import { can, requireAdmin } from "@/lib/auth"; import { can, requireAdmin } from "@/lib/auth";
import { getOwnAdvisor } from "@/lib/consulting"; import { getOwnAdvisor } from "@/lib/consulting";
import { Alert } from "@/components/shop/Blocks"; import { Alert } from "@/components/shop/Blocks";
import { Card, PageHead } from "@/components/admin/ui";
import { createOwnProfile } from "./actions";
/** Eigenes Profil, oder mit consulting.manage das über ?b= gewählte. */ /**
* Eigenes Profil, oder mit consulting.manage das über ?b= gewählte.
* Inhaber und Leitung haben nicht automatisch ein Profil: dann `advisor: null`, die Seite zeigt <NoAdvisorProfile />.
*/
export async function loadAdvisor(b?: string) { export async function loadAdvisor(b?: string) {
const user = await requireAdmin("consulting.own"); const user = await requireAdmin("consulting.own");
const manager = can(user, "consulting.manage"); const manager = can(user, "consulting.manage");
// Inhaber und Leitung ohne eigenes Profil landen in der Übersicht, statt ungewollt eins anzulegen if (b && manager) {
if (!b && manager && !(await db.advisor.findUnique({ where: { userId: user.id } }))) redirect("/admin/beratung/beraterinnen"); const advisor = await db.advisor.findUnique({ where: { id: b } });
const advisor = b && manager ? await db.advisor.findUnique({ where: { id: b } }) : await getOwnAdvisor(user);
if (!advisor) notFound(); if (!advisor) notFound();
return { user, manager, advisor, foreign: advisor.userId !== user.id }; return { user, manager, advisor, foreign: advisor.userId !== user.id };
} }
// Beraterinnen bekommen ihr Profil beim ersten Besuch; Inhaber/Leitung nur auf ausdrücklichen Wunsch
const advisor = manager ? await db.advisor.findUnique({ where: { userId: user.id } }) : await getOwnAdvisor(user);
return { user, manager, advisor, foreign: false };
}
/** Hinweis für Inhaber/Leitung ohne eigenes Beraterinnen-Profil. */
export function NoAdvisorProfile({ title }: { title: string }) {
return (
<div className="ad-wrap ad-wrap--narrow">
<PageHead title={title} />
<Card title="Du hast noch kein Beraterinnen-Profil" lead="Hier verwaltet eine Beraterin ihre eigenen Termine, ihr Profil, ihre Angebote und Zeiten. Wenn du selbst Karten legen möchtest, leg dir ein eigenes Profil an.">
<div className="sm-btn-row" style={{ flexWrap: "wrap" }}>
<form action={createOwnProfile}>
<button className="sm-btn sm-btn--primary" type="submit">Eigenes Profil anlegen</button>
</form>
<Link className="sm-btn sm-btn--secondary" href="/admin/beratung/alle">Alle Termine</Link>
<Link className="sm-btn sm-btn--ghost" href="/admin/beratung/beraterinnen">Beraterinnen</Link>
</div>
</Card>
</div>
);
}
const TABS = [ const TABS = [
{ href: "/admin/beratung", label: "Termine" }, { href: "/admin/beratung", label: "Termine" },

View file

@ -5,7 +5,7 @@ import { AdminForm, ConfirmButton } from "@/components/admin/AdminForm";
import { Card, Empty, PageHead } from "@/components/admin/ui"; import { Card, Empty, PageHead } from "@/components/admin/ui";
import { WeeklyPlan } from "@/components/admin/WeeklyPlan"; import { WeeklyPlan } from "@/components/admin/WeeklyPlan";
import { addException, deleteException } from "../actions"; import { addException, deleteException } from "../actions";
import { AdvisorStatus, AdvisorTabs, loadAdvisor } from "../shared"; import { AdvisorStatus, AdvisorTabs, loadAdvisor, NoAdvisorProfile } from "../shared";
export const metadata = { title: "Meine Zeiten" }; export const metadata = { title: "Meine Zeiten" };
@ -13,7 +13,9 @@ const dayFmt = (date: string) => new Intl.DateTimeFormat("de-DE", { weekday: "sh
export default async function AdvisorTimes({ searchParams }: { searchParams: Promise<{ b?: string }> }) { export default async function AdvisorTimes({ searchParams }: { searchParams: Promise<{ b?: string }> }) {
const { b } = await searchParams; const { b } = await searchParams;
const { advisor, foreign } = await loadAdvisor(b); const ctx = await loadAdvisor(b);
if (!ctx.advisor) return <NoAdvisorProfile title="Meine Zeiten" />;
const { advisor, foreign } = { ...ctx, advisor: ctx.advisor };
const today = berlinParts(new Date()).date; const today = berlinParts(new Date()).date;
const [rules, exceptions] = await Promise.all([ const [rules, exceptions] = await Promise.all([
db.availabilityRule.findMany({ where: { advisorId: advisor.id }, orderBy: [{ weekday: "asc" }, { start: "asc" }] }), db.availabilityRule.findMany({ where: { advisorId: advisor.id }, orderBy: [{ weekday: "asc" }, { start: "asc" }] }),