Compare commits
3
Commits
804b7637e7
...
864a1cef6a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
864a1cef6a | ||
|
|
d72aa9fbf3 | ||
|
|
8933169ba9 |
No files matched your search
@@ -6,6 +6,10 @@ import { userRouter } from './user.js';
|
||||
import { dashboardRouter } from './dashboard.js';
|
||||
import { projectRouter } from './project.js';
|
||||
import { dealRouter, gtmRouter } from './deal.js';
|
||||
import { leadRouter } from './lead.js';
|
||||
import { riskRouter } from './risk.js';
|
||||
import { stakeholderRouter } from './stakeholder.js';
|
||||
import { changeRouter } from './change.js';
|
||||
import { campaignRouter } from './campaign.js';
|
||||
import { areaRouter } from './area.js';
|
||||
import { blockerRouter } from './blocker.js';
|
||||
@@ -21,6 +25,10 @@ export const appRouter = router({
|
||||
project: projectRouter,
|
||||
deal: dealRouter,
|
||||
gtm: gtmRouter,
|
||||
lead: leadRouter,
|
||||
risk: riskRouter,
|
||||
stakeholder: stakeholderRouter,
|
||||
change: changeRouter,
|
||||
campaign: campaignRouter,
|
||||
blocker: blockerRouter,
|
||||
dayEntry: dayEntryRouter,
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { TRPCError } from '@trpc/server';
|
||||
import { desc, eq } from 'drizzle-orm';
|
||||
import { changeEntry, user } from '@cockpit/db';
|
||||
import { ChangeSchemas } from '@cockpit/shared';
|
||||
import { router, protectedProcedure } from '../trpc.js';
|
||||
|
||||
export const changeRouter = router({
|
||||
forProject: protectedProcedure
|
||||
.input(ChangeSchemas.changeForProjectInput)
|
||||
.query(async ({ ctx, input }) => {
|
||||
const rows = await ctx.db
|
||||
.select({ change: changeEntry, authorName: user.name })
|
||||
.from(changeEntry)
|
||||
.leftJoin(user, eq(user.id, changeEntry.createdBy))
|
||||
.where(eq(changeEntry.projectId, input.projectId))
|
||||
.orderBy(desc(changeEntry.createdAt));
|
||||
return rows.map((r) => ({ ...r.change, authorName: r.authorName }));
|
||||
}),
|
||||
|
||||
create: protectedProcedure
|
||||
.input(ChangeSchemas.createChangeInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const [created] = await ctx.db
|
||||
.insert(changeEntry)
|
||||
.values({
|
||||
projectId: input.projectId,
|
||||
titel: input.titel,
|
||||
auswirkung: input.auswirkung ?? null,
|
||||
entscheidung: input.entscheidung,
|
||||
createdBy: ctx.user.id,
|
||||
})
|
||||
.returning();
|
||||
return created;
|
||||
}),
|
||||
|
||||
update: protectedProcedure
|
||||
.input(ChangeSchemas.updateChangeInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const { id, ...patch } = input;
|
||||
if (Object.keys(patch).length === 0) {
|
||||
const existing = (
|
||||
await ctx.db.select().from(changeEntry).where(eq(changeEntry.id, id)).limit(1)
|
||||
)[0];
|
||||
if (!existing) throw new TRPCError({ code: 'NOT_FOUND', message: 'Eintrag nicht gefunden.' });
|
||||
return existing;
|
||||
}
|
||||
const [updated] = await ctx.db
|
||||
.update(changeEntry)
|
||||
.set(patch)
|
||||
.where(eq(changeEntry.id, id))
|
||||
.returning();
|
||||
if (!updated) throw new TRPCError({ code: 'NOT_FOUND', message: 'Eintrag nicht gefunden.' });
|
||||
return updated;
|
||||
}),
|
||||
|
||||
remove: protectedProcedure
|
||||
.input(ChangeSchemas.removeChangeInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
await ctx.db.delete(changeEntry).where(eq(changeEntry.id, input.id));
|
||||
return { ok: true as const };
|
||||
}),
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import { and, eq, isNotNull, isNull, count } from 'drizzle-orm';
|
||||
import { area, project, blocker, dayEntry, user, type Area, type Project } from '@cockpit/db';
|
||||
import { and, eq, ne, isNotNull, isNull, count } from 'drizzle-orm';
|
||||
import { area, project, blocker, dayEntry, user, risk, type Area, type Project } from '@cockpit/db';
|
||||
import { router, protectedProcedure } from '../trpc.js';
|
||||
import { todayIso, previousWerktag } from '../lib/werktag.js';
|
||||
import { aggregateAreaAmpel } from '../lib/ampel.js';
|
||||
@@ -7,7 +7,7 @@ import { aggregateAreaAmpel } from '../lib/ampel.js';
|
||||
export const dashboardRouter = router({
|
||||
overview: protectedProcedure.query(async ({ ctx }) => {
|
||||
const todayDate = todayIso();
|
||||
const [areas, allProjects, openBlockers, todayPresence, totalActiveUsers, feedRows] =
|
||||
const [areas, allProjects, openBlockers, todayPresence, totalActiveUsers, feedRows, showstopperRows] =
|
||||
await Promise.all([
|
||||
ctx.db.select().from(area).orderBy(area.order),
|
||||
ctx.db.select().from(project).where(eq(project.archiviert, false)),
|
||||
@@ -33,6 +33,23 @@ export const dashboardRouter = router({
|
||||
.where(and(isNotNull(dayEntry.publishedAt), eq(dayEntry.status, 'full')))
|
||||
.orderBy(dayEntry.publishedAt)
|
||||
.limit(50),
|
||||
ctx.db
|
||||
.select({
|
||||
id: risk.id,
|
||||
title: risk.title,
|
||||
projectId: risk.projectId,
|
||||
projectName: project.name,
|
||||
})
|
||||
.from(risk)
|
||||
.innerJoin(project, eq(project.id, risk.projectId))
|
||||
.where(
|
||||
and(
|
||||
eq(risk.showstopper, true),
|
||||
eq(risk.kind, 'risiko'),
|
||||
ne(risk.status, 'geschlossen'),
|
||||
eq(project.archiviert, false),
|
||||
),
|
||||
),
|
||||
]);
|
||||
|
||||
const projectsByArea = new Map<string, Project[]>();
|
||||
@@ -78,6 +95,10 @@ export const dashboardRouter = router({
|
||||
fehlende,
|
||||
},
|
||||
jourfixe: { nextDate: nextJourfixe(todayDate), label: 'Di 11:00' },
|
||||
showstoppers: showstopperRows,
|
||||
kritischeModi: allProjects
|
||||
.filter((p) => p.modus === 'eskalation' || p.modus === 'taskforce')
|
||||
.map((p) => ({ id: p.id, name: p.name, areaId: p.areaId, modus: p.modus })),
|
||||
pflichtMinimumOffen: allProjects
|
||||
.filter((p) => Object.values(p.pflichtMinimumState).some((v) => v === false))
|
||||
.map((p) => ({ id: p.id, name: p.name, areaId: p.areaId })),
|
||||
|
||||
@@ -209,6 +209,37 @@ export const dayEntryRouter = router({
|
||||
return result;
|
||||
}),
|
||||
|
||||
/**
|
||||
* Einzelnen ToDo-Titel korrigieren (z. B. Tippfehler) — auch noch in der
|
||||
* Reflexion. Erlaubt, solange das ToDo der eigenen Person gehört und vom
|
||||
* heutigen Berlin-Tag ist (gleiche Editierbarkeits-Regel wie die Reflexion).
|
||||
*/
|
||||
editTodoTitle: protectedProcedure
|
||||
.input(DayEntrySchemas.editTodoTitleInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const rows = await ctx.db
|
||||
.select()
|
||||
.from(todo)
|
||||
.where(and(eq(todo.id, input.todoId), eq(todo.userId, ctx.user.id)))
|
||||
.limit(1);
|
||||
const existing = rows[0];
|
||||
if (!existing) {
|
||||
throw new TRPCError({ code: 'NOT_FOUND', message: 'ToDo nicht gefunden.' });
|
||||
}
|
||||
if (existing.date !== todayIso(new Date())) {
|
||||
throw new TRPCError({
|
||||
code: 'BAD_REQUEST',
|
||||
message: 'ToDos eines Vortags können nicht mehr bearbeitet werden.',
|
||||
});
|
||||
}
|
||||
const [updated] = await ctx.db
|
||||
.update(todo)
|
||||
.set({ title: input.title })
|
||||
.where(eq(todo.id, input.todoId))
|
||||
.returning();
|
||||
return updated;
|
||||
}),
|
||||
|
||||
/**
|
||||
* Abend-Reflexion. Setzt Ampel + Trend, optional Blocker.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
import { TRPCError } from '@trpc/server';
|
||||
import { asc, desc, eq, sql } from 'drizzle-orm';
|
||||
import { lead, leadContact, leadTouchpoint, deal, area, user } from '@cockpit/db';
|
||||
import type { Db } from '@cockpit/db';
|
||||
import { LeadSchemas } from '@cockpit/shared';
|
||||
import { router, protectedProcedure } from '../trpc.js';
|
||||
|
||||
const SALES_AREA_SLUG = 'vertrieb';
|
||||
|
||||
async function getSalesAreaId(db: Db): Promise<string> {
|
||||
const a = (await db.select().from(area).where(eq(area.slug, SALES_AREA_SLUG)).limit(1))[0];
|
||||
if (!a) throw new Error('Vertriebs-Bereich fehlt — bitte seed laufen lassen.');
|
||||
return a.id;
|
||||
}
|
||||
|
||||
export const leadRouter = router({
|
||||
// Liste aller Leads, mit Owner-Namen. Sortiert: zuletzt aktualisiert zuerst.
|
||||
list: protectedProcedure.query(async ({ ctx }) => {
|
||||
const rows = await ctx.db
|
||||
.select({
|
||||
lead: lead,
|
||||
ownerName: user.name,
|
||||
})
|
||||
.from(lead)
|
||||
.leftJoin(user, eq(user.id, lead.ownerUserId))
|
||||
.orderBy(desc(lead.updatedAt));
|
||||
return rows.map((r) => ({ ...r.lead, ownerName: r.ownerName }));
|
||||
}),
|
||||
|
||||
byId: protectedProcedure.input(LeadSchemas.leadIdInput).query(async ({ ctx, input }) => {
|
||||
const l = (await ctx.db.select().from(lead).where(eq(lead.id, input.id)).limit(1))[0];
|
||||
if (!l) throw new TRPCError({ code: 'NOT_FOUND', message: 'Lead nicht gefunden.' });
|
||||
const contacts = await ctx.db
|
||||
.select()
|
||||
.from(leadContact)
|
||||
.where(eq(leadContact.leadId, l.id))
|
||||
.orderBy(desc(leadContact.isPrimary), asc(leadContact.order));
|
||||
const touchpoints = await ctx.db
|
||||
.select({
|
||||
touchpoint: leadTouchpoint,
|
||||
bearbeiterName: user.name,
|
||||
})
|
||||
.from(leadTouchpoint)
|
||||
.leftJoin(user, eq(user.id, leadTouchpoint.bearbeiterUserId))
|
||||
.where(eq(leadTouchpoint.leadId, l.id))
|
||||
.orderBy(desc(leadTouchpoint.datum), desc(leadTouchpoint.createdAt));
|
||||
return {
|
||||
lead: l,
|
||||
contacts,
|
||||
touchpoints: touchpoints.map((t) => ({ ...t.touchpoint, bearbeiterName: t.bearbeiterName })),
|
||||
};
|
||||
}),
|
||||
|
||||
create: protectedProcedure
|
||||
.input(LeadSchemas.createLeadInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const areaId = await getSalesAreaId(ctx.db);
|
||||
const [created] = await ctx.db
|
||||
.insert(lead)
|
||||
.values({
|
||||
areaId,
|
||||
firma: input.firma,
|
||||
status: input.status,
|
||||
score: input.score,
|
||||
ownerUserId: input.ownerUserId ?? null,
|
||||
branche: input.branche ?? null,
|
||||
subSegment: input.subSegment ?? null,
|
||||
website: input.website ?? null,
|
||||
quelle: input.quelle ?? null,
|
||||
createdBy: ctx.user.id,
|
||||
})
|
||||
.returning();
|
||||
if (!created) throw new Error('Lead konnte nicht angelegt werden.');
|
||||
return created;
|
||||
}),
|
||||
|
||||
update: protectedProcedure
|
||||
.input(LeadSchemas.updateLeadInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const { id, ...patch } = input;
|
||||
if (Object.keys(patch).length === 0) {
|
||||
const existing = (await ctx.db.select().from(lead).where(eq(lead.id, id)).limit(1))[0];
|
||||
if (!existing) throw new TRPCError({ code: 'NOT_FOUND', message: 'Lead nicht gefunden.' });
|
||||
return existing;
|
||||
}
|
||||
const [updated] = await ctx.db
|
||||
.update(lead)
|
||||
.set({ ...patch, updatedAt: new Date() })
|
||||
.where(eq(lead.id, id))
|
||||
.returning();
|
||||
if (!updated) throw new TRPCError({ code: 'NOT_FOUND', message: 'Lead nicht gefunden.' });
|
||||
return updated;
|
||||
}),
|
||||
|
||||
// Kontaktpersonen -----------------------------------------------------------
|
||||
addContact: protectedProcedure
|
||||
.input(LeadSchemas.addContactInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const count = (
|
||||
await ctx.db
|
||||
.select({ c: sql<number>`count(*)::int` })
|
||||
.from(leadContact)
|
||||
.where(eq(leadContact.leadId, input.leadId))
|
||||
)[0]?.c ?? 0;
|
||||
const [created] = await ctx.db
|
||||
.insert(leadContact)
|
||||
.values({
|
||||
leadId: input.leadId,
|
||||
name: input.name,
|
||||
rolle: input.rolle ?? null,
|
||||
funktion: input.funktion ?? null,
|
||||
email: input.email ?? null,
|
||||
telefon: input.telefon ?? null,
|
||||
linkedin: input.linkedin ?? null,
|
||||
imBuyingCenterSeit: input.imBuyingCenterSeit ?? null,
|
||||
sprache: input.sprache ?? null,
|
||||
isPrimary: input.isPrimary,
|
||||
order: count,
|
||||
})
|
||||
.returning();
|
||||
return created;
|
||||
}),
|
||||
|
||||
removeContact: protectedProcedure
|
||||
.input(LeadSchemas.removeContactInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
await ctx.db.delete(leadContact).where(eq(leadContact.id, input.contactId));
|
||||
return { ok: true as const };
|
||||
}),
|
||||
|
||||
// Austausch-Log -------------------------------------------------------------
|
||||
addTouchpoint: protectedProcedure
|
||||
.input(LeadSchemas.addTouchpointInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const [created] = await ctx.db
|
||||
.insert(leadTouchpoint)
|
||||
.values({
|
||||
leadId: input.leadId,
|
||||
datum: input.datum,
|
||||
kanal: input.kanal,
|
||||
bearbeiterUserId: ctx.user.id,
|
||||
inhalt: input.inhalt,
|
||||
outcome: input.outcome ?? null,
|
||||
followUpBis: input.followUpBis ?? null,
|
||||
})
|
||||
.returning();
|
||||
// Touchpoint zählt als Aktivität → Lead als aktualisiert markieren.
|
||||
await ctx.db.update(lead).set({ updatedAt: new Date() }).where(eq(lead.id, input.leadId));
|
||||
return created;
|
||||
}),
|
||||
|
||||
removeTouchpoint: protectedProcedure
|
||||
.input(LeadSchemas.removeTouchpointInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
await ctx.db.delete(leadTouchpoint).where(eq(leadTouchpoint.id, input.touchpointId));
|
||||
return { ok: true as const };
|
||||
}),
|
||||
|
||||
// Lead → Pipeline-Deal promoten --------------------------------------------
|
||||
promoteToDeal: protectedProcedure
|
||||
.input(LeadSchemas.promoteToDealInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const l = (await ctx.db.select().from(lead).where(eq(lead.id, input.leadId)).limit(1))[0];
|
||||
if (!l) throw new TRPCError({ code: 'NOT_FOUND', message: 'Lead nicht gefunden.' });
|
||||
if (l.promotedDealId) {
|
||||
throw new TRPCError({
|
||||
code: 'BAD_REQUEST',
|
||||
message: 'Dieser Lead wurde bereits zu einem Deal gemacht.',
|
||||
});
|
||||
}
|
||||
const result = await ctx.db.transaction(async (tx) => {
|
||||
const [createdDeal] = await tx
|
||||
.insert(deal)
|
||||
.values({
|
||||
areaId: l.areaId,
|
||||
name: l.firma,
|
||||
ownerUserId: l.ownerUserId,
|
||||
valueEur: input.valueEur,
|
||||
probability: input.probability,
|
||||
stage: 'lead',
|
||||
})
|
||||
.returning();
|
||||
if (!createdDeal) throw new Error('Deal konnte nicht angelegt werden.');
|
||||
await tx
|
||||
.update(lead)
|
||||
.set({ promotedDealId: createdDeal.id, updatedAt: new Date() })
|
||||
.where(eq(lead.id, l.id));
|
||||
return createdDeal;
|
||||
});
|
||||
return result;
|
||||
}),
|
||||
});
|
||||
@@ -1,10 +1,16 @@
|
||||
import { TRPCError } from '@trpc/server';
|
||||
import { z } from 'zod';
|
||||
import { and, eq, desc } from 'drizzle-orm';
|
||||
import { project, milestone, area, user, type Project } from '@cockpit/db';
|
||||
import { project, milestone, area, user, projectStatus, phaseGate, type Project } from '@cockpit/db';
|
||||
import { ProjectSchemas } from '@cockpit/shared';
|
||||
import { router, protectedProcedure } from '../trpc.js';
|
||||
|
||||
const PHASE_ORDER = ['definition', 'planung', 'umsetzung', 'abschluss'] as const;
|
||||
function nextPhase(p: (typeof PHASE_ORDER)[number]): (typeof PHASE_ORDER)[number] {
|
||||
const i = PHASE_ORDER.indexOf(p);
|
||||
return PHASE_ORDER[Math.min(i + 1, PHASE_ORDER.length - 1)]!;
|
||||
}
|
||||
|
||||
const byAreaInput = z.object({
|
||||
slug: z.string().min(1),
|
||||
includeArchived: z.boolean().optional(),
|
||||
@@ -120,7 +126,9 @@ export const projectRouter = router({
|
||||
.set({
|
||||
archiviert: true,
|
||||
archiviertAm: new Date(),
|
||||
phase: 'abschluss',
|
||||
lessonsLearnedUrl: input.lessonsLearnedUrl,
|
||||
abschlussvermerk: input.abschlussvermerk ?? p.abschlussvermerk,
|
||||
pflichtMinimumState: { ...p.pflichtMinimumState, retrospektive: true },
|
||||
})
|
||||
.where(eq(project.id, input.projectId))
|
||||
@@ -128,6 +136,95 @@ export const projectRouter = router({
|
||||
return updated as Project;
|
||||
}),
|
||||
|
||||
// Phase direkt setzen (Leitfaden Kap. 2).
|
||||
setPhase: protectedProcedure
|
||||
.input(ProjectSchemas.setPhaseInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const [updated] = await ctx.db
|
||||
.update(project)
|
||||
.set({ phase: input.phase, updatedAt: new Date() })
|
||||
.where(eq(project.id, input.projectId))
|
||||
.returning();
|
||||
if (!updated) throw new TRPCError({ code: 'NOT_FOUND', message: 'Projekt nicht gefunden.' });
|
||||
return updated;
|
||||
}),
|
||||
|
||||
// Gate-Review am Phasenende (Leitfaden Kap. 5), optional Folgephase freigeben.
|
||||
addPhaseGate: protectedProcedure
|
||||
.input(ProjectSchemas.addPhaseGateInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const [gate] = await ctx.db
|
||||
.insert(phaseGate)
|
||||
.values({
|
||||
projectId: input.projectId,
|
||||
phase: input.phase,
|
||||
ergebnisErreicht: input.ergebnisErreicht,
|
||||
notiz: input.notiz ?? null,
|
||||
reviewedBy: ctx.user.id,
|
||||
})
|
||||
.returning();
|
||||
if (input.advance) {
|
||||
await ctx.db
|
||||
.update(project)
|
||||
.set({ phase: nextPhase(input.phase), updatedAt: new Date() })
|
||||
.where(eq(project.id, input.projectId));
|
||||
}
|
||||
return gate;
|
||||
}),
|
||||
|
||||
phaseGates: protectedProcedure
|
||||
.input(ProjectSchemas.phaseGatesInput)
|
||||
.query(async ({ ctx, input }) => {
|
||||
return ctx.db
|
||||
.select()
|
||||
.from(phaseGate)
|
||||
.where(eq(phaseGate.projectId, input.projectId))
|
||||
.orderBy(desc(phaseGate.reviewedAt));
|
||||
}),
|
||||
|
||||
// Statusbericht erfassen (Leitfaden Kap. 5) — speist statusCache + Pflicht-Minimum.
|
||||
addStatus: protectedProcedure
|
||||
.input(ProjectSchemas.addProjectStatusInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const p = (
|
||||
await ctx.db.select().from(project).where(eq(project.id, input.projectId)).limit(1)
|
||||
)[0];
|
||||
if (!p) throw new TRPCError({ code: 'NOT_FOUND', message: 'Projekt nicht gefunden.' });
|
||||
const [created] = await ctx.db
|
||||
.insert(projectStatus)
|
||||
.values({
|
||||
projectId: input.projectId,
|
||||
ampel: input.ampel,
|
||||
trend: input.trend ?? null,
|
||||
text: input.text ?? null,
|
||||
externSichtbar: input.externSichtbar,
|
||||
createdBy: ctx.user.id,
|
||||
})
|
||||
.returning();
|
||||
await ctx.db
|
||||
.update(project)
|
||||
.set({
|
||||
statusCache: input.ampel,
|
||||
trendCache: input.trend ?? null,
|
||||
pflichtMinimumState: { ...p.pflichtMinimumState, status_aktuell: true },
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(eq(project.id, input.projectId));
|
||||
return created;
|
||||
}),
|
||||
|
||||
statusHistory: protectedProcedure
|
||||
.input(ProjectSchemas.projectStatusHistoryInput)
|
||||
.query(async ({ ctx, input }) => {
|
||||
const rows = await ctx.db
|
||||
.select({ status: projectStatus, authorName: user.name })
|
||||
.from(projectStatus)
|
||||
.leftJoin(user, eq(user.id, projectStatus.createdBy))
|
||||
.where(eq(projectStatus.projectId, input.projectId))
|
||||
.orderBy(desc(projectStatus.createdAt));
|
||||
return rows.map((r) => ({ ...r.status, authorName: r.authorName }));
|
||||
}),
|
||||
|
||||
setMilestoneStatus: protectedProcedure
|
||||
.input(ProjectSchemas.setMilestoneStatusInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
@@ -139,6 +236,121 @@ export const projectRouter = router({
|
||||
return updated;
|
||||
}),
|
||||
|
||||
// Projekt-Modus setzen (Buch Kap. 4): muss jederzeit ans Team kommuniziert sein.
|
||||
setModus: protectedProcedure
|
||||
.input(ProjectSchemas.setModusInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const [updated] = await ctx.db
|
||||
.update(project)
|
||||
.set({ modus: input.modus, updatedAt: new Date() })
|
||||
.where(eq(project.id, input.projectId))
|
||||
.returning();
|
||||
if (!updated) throw new TRPCError({ code: 'NOT_FOUND', message: 'Projekt nicht gefunden.' });
|
||||
return updated;
|
||||
}),
|
||||
|
||||
// Maxime / Beschreibung / DoD bearbeiten (Ziel-Disziplin).
|
||||
update: protectedProcedure
|
||||
.input(ProjectSchemas.updateProjectInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const { projectId, ...patch } = input;
|
||||
if (Object.keys(patch).length === 0) {
|
||||
const existing = (
|
||||
await ctx.db.select().from(project).where(eq(project.id, projectId)).limit(1)
|
||||
)[0];
|
||||
if (!existing) throw new TRPCError({ code: 'NOT_FOUND', message: 'Projekt nicht gefunden.' });
|
||||
return existing;
|
||||
}
|
||||
const [updated] = await ctx.db
|
||||
.update(project)
|
||||
.set({ ...patch, updatedAt: new Date() })
|
||||
.where(eq(project.id, projectId))
|
||||
.returning();
|
||||
if (!updated) throw new TRPCError({ code: 'NOT_FOUND', message: 'Projekt nicht gefunden.' });
|
||||
return updated;
|
||||
}),
|
||||
|
||||
addMilestone: protectedProcedure
|
||||
.input(ProjectSchemas.addMilestoneInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const existing = await ctx.db
|
||||
.select({ id: milestone.id })
|
||||
.from(milestone)
|
||||
.where(eq(milestone.projectId, input.projectId));
|
||||
const [created] = await ctx.db
|
||||
.insert(milestone)
|
||||
.values({
|
||||
projectId: input.projectId,
|
||||
title: input.title,
|
||||
due: input.due ?? null,
|
||||
order: existing.length,
|
||||
})
|
||||
.returning();
|
||||
// Pflicht-Minimum-Punkt „Meilensteine" nachziehen (Buch: mind. 2).
|
||||
const p = (
|
||||
await ctx.db.select().from(project).where(eq(project.id, input.projectId)).limit(1)
|
||||
)[0];
|
||||
if (p) {
|
||||
await ctx.db
|
||||
.update(project)
|
||||
.set({
|
||||
pflichtMinimumState: {
|
||||
...p.pflichtMinimumState,
|
||||
meilensteine: existing.length + 1 >= 2,
|
||||
},
|
||||
})
|
||||
.where(eq(project.id, input.projectId));
|
||||
}
|
||||
return created;
|
||||
}),
|
||||
|
||||
updateMilestone: protectedProcedure
|
||||
.input(ProjectSchemas.updateMilestoneInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const { milestoneId, ...patch } = input;
|
||||
if (Object.keys(patch).length === 0) {
|
||||
const existing = (
|
||||
await ctx.db.select().from(milestone).where(eq(milestone.id, milestoneId)).limit(1)
|
||||
)[0];
|
||||
if (!existing) throw new TRPCError({ code: 'NOT_FOUND', message: 'Meilenstein nicht gefunden.' });
|
||||
return existing;
|
||||
}
|
||||
const [updated] = await ctx.db
|
||||
.update(milestone)
|
||||
.set(patch)
|
||||
.where(eq(milestone.id, milestoneId))
|
||||
.returning();
|
||||
if (!updated) throw new TRPCError({ code: 'NOT_FOUND', message: 'Meilenstein nicht gefunden.' });
|
||||
return updated;
|
||||
}),
|
||||
|
||||
removeMilestone: protectedProcedure
|
||||
.input(ProjectSchemas.removeMilestoneInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const [removed] = await ctx.db
|
||||
.delete(milestone)
|
||||
.where(eq(milestone.id, input.milestoneId))
|
||||
.returning({ projectId: milestone.projectId });
|
||||
if (removed) {
|
||||
const rest = await ctx.db
|
||||
.select({ id: milestone.id })
|
||||
.from(milestone)
|
||||
.where(eq(milestone.projectId, removed.projectId));
|
||||
const p = (
|
||||
await ctx.db.select().from(project).where(eq(project.id, removed.projectId)).limit(1)
|
||||
)[0];
|
||||
if (p) {
|
||||
await ctx.db
|
||||
.update(project)
|
||||
.set({
|
||||
pflichtMinimumState: { ...p.pflichtMinimumState, meilensteine: rest.length >= 2 },
|
||||
})
|
||||
.where(eq(project.id, removed.projectId));
|
||||
}
|
||||
}
|
||||
return { ok: true as const };
|
||||
}),
|
||||
|
||||
listArchived: protectedProcedure.query(async ({ ctx }) => {
|
||||
return await ctx.db
|
||||
.select()
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import { TRPCError } from '@trpc/server';
|
||||
import { desc, eq } from 'drizzle-orm';
|
||||
import { risk } from '@cockpit/db';
|
||||
import { RiskSchemas } from '@cockpit/shared';
|
||||
import { router, protectedProcedure } from '../trpc.js';
|
||||
|
||||
export const riskRouter = router({
|
||||
forProject: protectedProcedure
|
||||
.input(RiskSchemas.riskForProjectInput)
|
||||
.query(async ({ ctx, input }) => {
|
||||
return ctx.db
|
||||
.select()
|
||||
.from(risk)
|
||||
.where(eq(risk.projectId, input.projectId))
|
||||
.orderBy(desc(risk.showstopper), desc(risk.createdAt));
|
||||
}),
|
||||
|
||||
create: protectedProcedure
|
||||
.input(RiskSchemas.createRiskInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const [created] = await ctx.db
|
||||
.insert(risk)
|
||||
.values({
|
||||
projectId: input.projectId,
|
||||
kind: input.kind,
|
||||
title: input.title,
|
||||
wahrscheinlichkeit: input.wahrscheinlichkeit,
|
||||
auswirkung: input.auswirkung,
|
||||
herkunft: input.herkunft ?? null,
|
||||
showstopper: input.showstopper,
|
||||
massnahme: input.massnahme ?? null,
|
||||
strategie: input.strategie ?? null,
|
||||
ownerUserId: input.ownerUserId ?? null,
|
||||
status: input.status,
|
||||
createdBy: ctx.user.id,
|
||||
})
|
||||
.returning();
|
||||
return created;
|
||||
}),
|
||||
|
||||
update: protectedProcedure
|
||||
.input(RiskSchemas.updateRiskInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const { id, ...patch } = input;
|
||||
if (Object.keys(patch).length === 0) {
|
||||
const existing = (await ctx.db.select().from(risk).where(eq(risk.id, id)).limit(1))[0];
|
||||
if (!existing) throw new TRPCError({ code: 'NOT_FOUND', message: 'Eintrag nicht gefunden.' });
|
||||
return existing;
|
||||
}
|
||||
const [updated] = await ctx.db
|
||||
.update(risk)
|
||||
.set({ ...patch, updatedAt: new Date() })
|
||||
.where(eq(risk.id, id))
|
||||
.returning();
|
||||
if (!updated) throw new TRPCError({ code: 'NOT_FOUND', message: 'Eintrag nicht gefunden.' });
|
||||
return updated;
|
||||
}),
|
||||
|
||||
remove: protectedProcedure
|
||||
.input(RiskSchemas.removeRiskInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
await ctx.db.delete(risk).where(eq(risk.id, input.id));
|
||||
return { ok: true as const };
|
||||
}),
|
||||
});
|
||||
@@ -0,0 +1,71 @@
|
||||
import { TRPCError } from '@trpc/server';
|
||||
import { asc, eq, sql } from 'drizzle-orm';
|
||||
import { stakeholder } from '@cockpit/db';
|
||||
import { StakeholderSchemas } from '@cockpit/shared';
|
||||
import { router, protectedProcedure } from '../trpc.js';
|
||||
|
||||
export const stakeholderRouter = router({
|
||||
forProject: protectedProcedure
|
||||
.input(StakeholderSchemas.stakeholderForProjectInput)
|
||||
.query(async ({ ctx, input }) => {
|
||||
return ctx.db
|
||||
.select()
|
||||
.from(stakeholder)
|
||||
.where(eq(stakeholder.projectId, input.projectId))
|
||||
.orderBy(asc(stakeholder.order), asc(stakeholder.createdAt));
|
||||
}),
|
||||
|
||||
create: protectedProcedure
|
||||
.input(StakeholderSchemas.createStakeholderInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const count =
|
||||
(
|
||||
await ctx.db
|
||||
.select({ c: sql<number>`count(*)::int` })
|
||||
.from(stakeholder)
|
||||
.where(eq(stakeholder.projectId, input.projectId))
|
||||
)[0]?.c ?? 0;
|
||||
const [created] = await ctx.db
|
||||
.insert(stakeholder)
|
||||
.values({
|
||||
projectId: input.projectId,
|
||||
name: input.name,
|
||||
rolle: input.rolle ?? null,
|
||||
interesse: input.interesse,
|
||||
einfluss: input.einfluss,
|
||||
haltung: input.haltung,
|
||||
beduerfnis: input.beduerfnis ?? null,
|
||||
notiz: input.notiz ?? null,
|
||||
order: count,
|
||||
})
|
||||
.returning();
|
||||
return created;
|
||||
}),
|
||||
|
||||
update: protectedProcedure
|
||||
.input(StakeholderSchemas.updateStakeholderInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const { id, ...patch } = input;
|
||||
if (Object.keys(patch).length === 0) {
|
||||
const existing = (
|
||||
await ctx.db.select().from(stakeholder).where(eq(stakeholder.id, id)).limit(1)
|
||||
)[0];
|
||||
if (!existing) throw new TRPCError({ code: 'NOT_FOUND', message: 'Stakeholder nicht gefunden.' });
|
||||
return existing;
|
||||
}
|
||||
const [updated] = await ctx.db
|
||||
.update(stakeholder)
|
||||
.set(patch)
|
||||
.where(eq(stakeholder.id, id))
|
||||
.returning();
|
||||
if (!updated) throw new TRPCError({ code: 'NOT_FOUND', message: 'Stakeholder nicht gefunden.' });
|
||||
return updated;
|
||||
}),
|
||||
|
||||
remove: protectedProcedure
|
||||
.input(StakeholderSchemas.removeStakeholderInput)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
await ctx.db.delete(stakeholder).where(eq(stakeholder.id, input.id));
|
||||
return { ok: true as const };
|
||||
}),
|
||||
});
|
||||
@@ -0,0 +1,54 @@
|
||||
// Anzeige-Metadaten für Leads — zentral, von /leads und /lead/:id genutzt.
|
||||
|
||||
export type LeadStatus = 'cold' | 'warm' | 'hot' | 'won' | 'lost';
|
||||
|
||||
export const LEAD_STATUS_META: Record<
|
||||
LeadStatus,
|
||||
{ label: string; badge: string; dot: string }
|
||||
> = {
|
||||
cold: {
|
||||
label: 'Cold',
|
||||
badge: 'bg-black/5 text-[var(--color-ink-muted)]',
|
||||
dot: 'bg-[var(--color-border-strong)]',
|
||||
},
|
||||
warm: {
|
||||
label: 'Warm',
|
||||
badge: 'bg-[var(--color-ampel-amber-bg)] text-[var(--color-ampel-amber-fg)]',
|
||||
dot: 'bg-[var(--color-ampel-amber-fg)]',
|
||||
},
|
||||
hot: {
|
||||
label: 'Hot',
|
||||
badge: 'bg-[var(--color-ampel-red-bg)] text-[var(--color-ampel-red-fg)]',
|
||||
dot: 'bg-[var(--color-ampel-red-fg)]',
|
||||
},
|
||||
won: {
|
||||
label: 'Won',
|
||||
badge: 'bg-[var(--color-ampel-green-bg)] text-[var(--color-ampel-green-fg)]',
|
||||
dot: 'bg-[var(--color-ampel-green-fg)]',
|
||||
},
|
||||
lost: {
|
||||
label: 'Lost',
|
||||
badge: 'bg-black/5 text-[var(--color-ink-faint)]',
|
||||
dot: 'bg-[var(--color-ink-faint)]',
|
||||
},
|
||||
};
|
||||
|
||||
// Reihenfolge für Gruppierung/Sortierung in der Liste.
|
||||
export const LEAD_STATUS_ORDER: LeadStatus[] = ['hot', 'warm', 'cold', 'won', 'lost'];
|
||||
|
||||
export const CONTACT_FUNKTION_LABEL: Record<string, string> = {
|
||||
entscheider: 'Entscheider',
|
||||
influencer: 'Influencer',
|
||||
gatekeeper: 'Gatekeeper',
|
||||
end_user: 'End-User',
|
||||
champion: 'Champion',
|
||||
};
|
||||
|
||||
export const TOUCHPOINT_KANAL_LABEL: Record<string, string> = {
|
||||
call: 'Call',
|
||||
mail: 'Mail',
|
||||
linkedin: 'LinkedIn',
|
||||
termin: 'Termin',
|
||||
event: 'Event',
|
||||
sonstiges: 'Sonstiges',
|
||||
};
|
||||
@@ -0,0 +1,114 @@
|
||||
// Anzeige-Metadaten für die PM-Insights-Features (Modus, Risiken, Stakeholder).
|
||||
|
||||
export type ProjectModus = 'relax' | 'standard' | 'eskalation' | 'taskforce';
|
||||
|
||||
export const MODUS_META: Record<ProjectModus, { label: string; badge: string; hint: string }> = {
|
||||
relax: {
|
||||
label: 'Relax',
|
||||
badge: 'bg-[var(--color-ampel-green-bg)] text-[var(--color-ampel-green-fg)]',
|
||||
hint: 'Ruhige Phase, kein Druck.',
|
||||
},
|
||||
standard: {
|
||||
label: 'Standard',
|
||||
badge: 'bg-black/5 text-[var(--color-ink-muted)]',
|
||||
hint: 'Normaler Projektbetrieb.',
|
||||
},
|
||||
eskalation: {
|
||||
label: 'Eskalation',
|
||||
badge: 'bg-[var(--color-ampel-amber-bg)] text-[var(--color-ampel-amber-fg)]',
|
||||
hint: 'Erhöhte Aufmerksamkeit nötig.',
|
||||
},
|
||||
taskforce: {
|
||||
label: 'Taskforce',
|
||||
badge: 'bg-[var(--color-ampel-red-bg)] text-[var(--color-ampel-red-fg)]',
|
||||
hint: 'Alle Kräfte gebündelt, höchste Priorität.',
|
||||
},
|
||||
};
|
||||
export const MODI: ProjectModus[] = ['relax', 'standard', 'eskalation', 'taskforce'];
|
||||
|
||||
export type Level = 'niedrig' | 'mittel' | 'hoch';
|
||||
|
||||
export const LEVEL_META: Record<Level, { label: string; badge: string }> = {
|
||||
niedrig: { label: 'Niedrig', badge: 'bg-[var(--color-ampel-green-bg)] text-[var(--color-ampel-green-fg)]' },
|
||||
mittel: { label: 'Mittel', badge: 'bg-[var(--color-ampel-amber-bg)] text-[var(--color-ampel-amber-fg)]' },
|
||||
hoch: { label: 'Hoch', badge: 'bg-[var(--color-ampel-red-bg)] text-[var(--color-ampel-red-fg)]' },
|
||||
};
|
||||
export const LEVELS: Level[] = ['niedrig', 'mittel', 'hoch'];
|
||||
|
||||
export type RiskStatus = 'offen' | 'beobachtet' | 'eingetreten' | 'geschlossen';
|
||||
export const RISK_STATUS_LABEL: Record<RiskStatus, string> = {
|
||||
offen: 'Offen',
|
||||
beobachtet: 'Beobachtet',
|
||||
eingetreten: 'Eingetreten',
|
||||
geschlossen: 'Geschlossen',
|
||||
};
|
||||
export const RISK_STATUSES: RiskStatus[] = ['offen', 'beobachtet', 'eingetreten', 'geschlossen'];
|
||||
|
||||
export type Haltung = 'pro' | 'neutral' | 'contra';
|
||||
export const HALTUNG_META: Record<Haltung, { label: string; dot: string }> = {
|
||||
pro: { label: 'Pro', dot: 'bg-[var(--color-ampel-green-fg)]' },
|
||||
neutral: { label: 'Neutral', dot: 'bg-[var(--color-ink-faint)]' },
|
||||
contra: { label: 'Contra', dot: 'bg-[var(--color-ampel-red-fg)]' },
|
||||
};
|
||||
export const HALTUNGEN: Haltung[] = ['pro', 'neutral', 'contra'];
|
||||
|
||||
// Empfehlung je Quadrant der Macht/Interesse-Matrix (Einfluss × Interesse).
|
||||
export function stakeholderStrategie(einfluss: Level, interesse: Level): string {
|
||||
const hochEinfluss = einfluss === 'hoch';
|
||||
const hochInteresse = interesse === 'hoch';
|
||||
if (hochEinfluss && hochInteresse) return 'Eng managen';
|
||||
if (hochEinfluss && !hochInteresse) return 'Zufrieden halten';
|
||||
if (!hochEinfluss && hochInteresse) return 'Informiert halten';
|
||||
return 'Beobachten';
|
||||
}
|
||||
|
||||
export type ProjectPhase = 'definition' | 'planung' | 'umsetzung' | 'abschluss';
|
||||
export const PHASES: ProjectPhase[] = ['definition', 'planung', 'umsetzung', 'abschluss'];
|
||||
export const PHASE_META: Record<ProjectPhase, { label: string; gateZiel: string }> = {
|
||||
definition: { label: 'Definition', gateZiel: 'Steckbrief abgestimmt und freigegeben' },
|
||||
planung: { label: 'Planung', gateZiel: 'Plan steht — Backlog zerlegt, Meilensteine & Risiken erfasst' },
|
||||
umsetzung: { label: 'Umsetzung', gateZiel: 'Liefergegenstände abgenommen' },
|
||||
abschluss: { label: 'Abschluss', gateZiel: 'Projekt beendet, Erkenntnisse gesichert' },
|
||||
};
|
||||
|
||||
export type ZieldreieckFlex = 'leistung' | 'zeit' | 'aufwand';
|
||||
export const ZIELDREIECK_LABEL: Record<ZieldreieckFlex, string> = {
|
||||
leistung: 'Leistung / Umfang',
|
||||
zeit: 'Zeit',
|
||||
aufwand: 'Aufwand',
|
||||
};
|
||||
export const ZIELDREIECK_FLEX: ZieldreieckFlex[] = ['leistung', 'zeit', 'aufwand'];
|
||||
|
||||
export type RiskStrategie = 'vermeiden' | 'verlagern' | 'mindern' | 'akzeptieren';
|
||||
export const RISK_STRATEGIE_LABEL: Record<RiskStrategie, string> = {
|
||||
vermeiden: 'Vermeiden',
|
||||
verlagern: 'Verlagern',
|
||||
mindern: 'Mindern',
|
||||
akzeptieren: 'Akzeptieren',
|
||||
};
|
||||
export const RISK_STRATEGIEN: RiskStrategie[] = ['vermeiden', 'verlagern', 'mindern', 'akzeptieren'];
|
||||
|
||||
export type ChangeEntscheidung = 'offen' | 'genehmigt' | 'abgelehnt';
|
||||
export const CHANGE_ENTSCHEIDUNG_META: Record<ChangeEntscheidung, { label: string; badge: string }> = {
|
||||
offen: { label: 'Offen', badge: 'bg-[var(--color-ampel-amber-bg)] text-[var(--color-ampel-amber-fg)]' },
|
||||
genehmigt: { label: 'Genehmigt', badge: 'bg-[var(--color-ampel-green-bg)] text-[var(--color-ampel-green-fg)]' },
|
||||
abgelehnt: { label: 'Abgelehnt', badge: 'bg-black/5 text-[var(--color-ink-faint)]' },
|
||||
};
|
||||
export const CHANGE_ENTSCHEIDUNGEN: ChangeEntscheidung[] = ['offen', 'genehmigt', 'abgelehnt'];
|
||||
|
||||
// Datums-Warnungen nach Buch-Regeln (keine Meilensteine Freitag / vor Feiertagen).
|
||||
export function dateWarnings(iso: string | null | undefined): string[] {
|
||||
if (!iso) return [];
|
||||
const d = new Date(`${iso}T00:00:00`);
|
||||
if (Number.isNaN(d.getTime())) return [];
|
||||
const out: string[] = [];
|
||||
const wd = d.getDay(); // 0=So .. 6=Sa
|
||||
if (wd === 5) out.push('Fällt auf einen Freitag — Buch-Regel: keine Meilensteine/Abgaben freitags.');
|
||||
if (wd === 0 || wd === 6) out.push('Fällt aufs Wochenende.');
|
||||
const month = d.getMonth();
|
||||
const day = d.getDate();
|
||||
if ((month === 11 && day >= 20) || (month === 0 && day <= 6)) {
|
||||
out.push('Liegt in der Weihnachts-/Neujahrszeit — besser einige Wochen davor oder danach.');
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -12,6 +12,8 @@ const Reflexion = lazy(() =>
|
||||
);
|
||||
const Bereich = lazy(() => import('../routes/bereich').then((m) => ({ default: m.BereichRoute })));
|
||||
const Projekt = lazy(() => import('../routes/projekt').then((m) => ({ default: m.ProjektRoute })));
|
||||
const Leads = lazy(() => import('../routes/leads').then((m) => ({ default: m.LeadsRoute })));
|
||||
const Lead = lazy(() => import('../routes/lead').then((m) => ({ default: m.LeadRoute })));
|
||||
const Archiv = lazy(() => import('../routes/archiv').then((m) => ({ default: m.ArchivRoute })));
|
||||
const NotFound = lazy(() =>
|
||||
import('../routes/not-found').then((m) => ({ default: m.NotFoundRoute })),
|
||||
@@ -40,6 +42,8 @@ const router = createBrowserRouter([
|
||||
{ path: 'bereich', element: withSuspense(<Bereich />) },
|
||||
{ path: 'bereich/:slug', element: withSuspense(<Bereich />) },
|
||||
{ path: 'projekt/:id', element: withSuspense(<Projekt />) },
|
||||
{ path: 'leads', element: withSuspense(<Leads />) },
|
||||
{ path: 'lead/:id', element: withSuspense(<Lead />) },
|
||||
{ path: 'archiv', element: withSuspense(<Archiv />) },
|
||||
{ path: '*', element: withSuspense(<NotFound />) },
|
||||
],
|
||||
|
||||
@@ -11,6 +11,8 @@ export const voice = {
|
||||
blockerResolved: 'Blocker erledigt.',
|
||||
projectCreated: 'Projekt angelegt.',
|
||||
projectArchived: 'Projekt archiviert.',
|
||||
leadCreated: 'Lead angelegt.',
|
||||
leadPromoted: 'Lead ist jetzt ein Deal.',
|
||||
saved: 'Gespeichert.',
|
||||
strong: 'Stark.',
|
||||
},
|
||||
@@ -19,6 +21,7 @@ export const voice = {
|
||||
reflect: 'Reflektieren',
|
||||
newBlocker: 'Neuer Blocker',
|
||||
newProject: 'Neues Projekt',
|
||||
newLead: 'Neuer Lead',
|
||||
},
|
||||
hint: {
|
||||
notCheckedInToday: 'Du hast heute noch nicht gepingt.',
|
||||
|
||||
@@ -7,6 +7,8 @@ import { Button } from '../components/ui/Button';
|
||||
import { SkeletonCard } from '../components/ui/SkeletonCard';
|
||||
import { toast } from 'sonner';
|
||||
import { clsx } from 'clsx';
|
||||
import { LEAD_STATUS_META, type LeadStatus } from '../lib/lead-meta';
|
||||
import { MODUS_META, type ProjectModus } from '../lib/project-meta';
|
||||
|
||||
const BEREICHE: Array<{ slug: 'entwicklung' | 'vertrieb' | 'marketing'; label: string }> = [
|
||||
{ slug: 'entwicklung', label: 'Entwicklung' },
|
||||
@@ -85,6 +87,7 @@ function Section({
|
||||
name: string;
|
||||
statusCache: 'green' | 'amber' | 'red' | null;
|
||||
deadline: string | null;
|
||||
modus: ProjectModus;
|
||||
pflichtMinimumState: Record<string, boolean>;
|
||||
}>;
|
||||
}) {
|
||||
@@ -104,7 +107,19 @@ function Section({
|
||||
<Card.Root className="cursor-pointer hover:shadow-[var(--shadow-md)]">
|
||||
<Card.Body className="flex items-center justify-between">
|
||||
<div>
|
||||
<p className="font-medium">{p.name}</p>
|
||||
<p className="flex items-center gap-2 font-medium">
|
||||
{p.name}
|
||||
{p.modus !== 'standard' && (
|
||||
<span
|
||||
className={clsx(
|
||||
'rounded-full px-2 py-0.5 text-[10px] font-medium',
|
||||
MODUS_META[p.modus].badge,
|
||||
)}
|
||||
>
|
||||
{MODUS_META[p.modus].label}
|
||||
</span>
|
||||
)}
|
||||
</p>
|
||||
<p className="text-xs text-[var(--color-ink-muted)]">
|
||||
{p.deadline ? `bis ${p.deadline}` : 'kein Deadline'}
|
||||
</p>
|
||||
@@ -297,7 +312,70 @@ function Field({ label, children }: { label: string; children: React.ReactNode }
|
||||
}
|
||||
|
||||
function VertriebDetail() {
|
||||
return <ProjektListeFuerBereich slug="vertrieb" />;
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<LeadsTeaser />
|
||||
<ProjektListeFuerBereich slug="vertrieb" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function LeadsTeaser() {
|
||||
const q = trpc.lead.list.useQuery();
|
||||
const leads = q.data ?? [];
|
||||
const offen = leads.filter((l) => l.status !== 'won' && l.status !== 'lost');
|
||||
const top = [...offen]
|
||||
.sort((a, b) => b.score - a.score)
|
||||
.slice(0, 3);
|
||||
return (
|
||||
<section>
|
||||
<div className="mb-2 flex items-center justify-between">
|
||||
<h2 className="text-lg font-semibold">Leads</h2>
|
||||
<Link to="/leads" className="text-sm text-[var(--color-ink-muted)] hover:text-[var(--color-ink)] hover:underline">
|
||||
Alle Leads ({leads.length}) →
|
||||
</Link>
|
||||
</div>
|
||||
<Card.Root>
|
||||
<Card.Body>
|
||||
{q.isPending ? (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">Lädt…</p>
|
||||
) : offen.length === 0 ? (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
Keine offenen Leads.{' '}
|
||||
<Link to="/leads" className="hover:underline">
|
||||
Lege einen an.
|
||||
</Link>
|
||||
</p>
|
||||
) : (
|
||||
<ul className="divide-y divide-[var(--color-border)]">
|
||||
{top.map((l) => {
|
||||
const meta = LEAD_STATUS_META[l.status as LeadStatus];
|
||||
return (
|
||||
<li key={l.id}>
|
||||
<Link
|
||||
to={`/lead/${l.id}`}
|
||||
className="flex items-center justify-between gap-2 py-2 hover:opacity-80"
|
||||
>
|
||||
<span className="flex items-center gap-2 text-sm">
|
||||
<span className={clsx('h-2 w-2 rounded-full', meta.dot)} />
|
||||
<span className="font-medium">{l.firma}</span>
|
||||
{l.subSegment && (
|
||||
<span className="text-xs text-[var(--color-ink-muted)]">{l.subSegment}</span>
|
||||
)}
|
||||
</span>
|
||||
<span className="font-mono text-xs tabular-nums text-[var(--color-ink-muted)]">
|
||||
{l.score}/10
|
||||
</span>
|
||||
</Link>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</Card.Body>
|
||||
</Card.Root>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function MarketingDetail() {
|
||||
|
||||
@@ -5,6 +5,8 @@ import { Card } from '../components/ui/Card';
|
||||
import { Button } from '../components/ui/Button';
|
||||
import { SkeletonCard } from '../components/ui/SkeletonCard';
|
||||
import { TeamTimeSection } from '../components/time/TeamTimeSection';
|
||||
import { MODUS_META, type ProjectModus } from '../lib/project-meta';
|
||||
import { AlertTriangle } from 'lucide-react';
|
||||
import { clsx } from 'clsx';
|
||||
|
||||
type Ampel = 'green' | 'amber' | 'red' | 'grey';
|
||||
@@ -72,6 +74,61 @@ export function DashboardRoute() {
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{q.data.showstoppers.length > 0 && (
|
||||
<section>
|
||||
<Card.Root className="border-[var(--color-ampel-red-fg)]">
|
||||
<Card.Header>
|
||||
<h2 className="flex items-center gap-2 text-lg font-semibold text-[var(--color-ampel-red-fg)]">
|
||||
<AlertTriangle size={18} /> Showstopper
|
||||
</h2>
|
||||
</Card.Header>
|
||||
<Card.Body>
|
||||
<ul className="space-y-2">
|
||||
{q.data.showstoppers.map((s) => (
|
||||
<li
|
||||
key={s.id}
|
||||
className="flex items-start justify-between gap-3 rounded-[var(--radius-md)] border border-[var(--color-border)] p-3"
|
||||
>
|
||||
<span className="text-sm">{s.title}</span>
|
||||
<Link
|
||||
to={`/projekt/${s.projectId}`}
|
||||
className="shrink-0 text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)] hover:underline"
|
||||
>
|
||||
{s.projectName} →
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</Card.Body>
|
||||
</Card.Root>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{q.data.kritischeModi.length > 0 && (
|
||||
<section>
|
||||
<h2 className="mb-2 text-lg font-semibold">Projekte in Eskalation / Taskforce</h2>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{q.data.kritischeModi.map((p) => (
|
||||
<Link
|
||||
key={p.id}
|
||||
to={`/projekt/${p.id}`}
|
||||
className="inline-flex items-center gap-2 rounded-[var(--radius-md)] border border-[var(--color-border)] px-3 py-1.5 text-sm hover:border-[var(--color-ink)]"
|
||||
>
|
||||
<span
|
||||
className={clsx(
|
||||
'rounded-full px-2 py-0.5 text-[10px] font-medium',
|
||||
MODUS_META[p.modus as ProjectModus].badge,
|
||||
)}
|
||||
>
|
||||
{MODUS_META[p.modus as ProjectModus].label}
|
||||
</span>
|
||||
{p.name}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
|
||||
<section className="grid grid-cols-1 gap-6 md:grid-cols-3">
|
||||
<Card.Root>
|
||||
<Card.Header>
|
||||
|
||||
@@ -0,0 +1,990 @@
|
||||
import { useState } from 'react';
|
||||
import { useParams, Link, useNavigate } from 'react-router';
|
||||
import { ArrowLeft, Pencil, Plus, Trash2, Star } from 'lucide-react';
|
||||
import { clsx } from 'clsx';
|
||||
import { toast } from 'sonner';
|
||||
import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
|
||||
import type { AppRouter } from '@cockpit/api/router';
|
||||
import { trpc } from '../lib/trpc';
|
||||
import { voice } from '../lib/voice';
|
||||
import { Card } from '../components/ui/Card';
|
||||
import { Button } from '../components/ui/Button';
|
||||
import { SkeletonCard } from '../components/ui/SkeletonCard';
|
||||
import {
|
||||
LEAD_STATUS_META,
|
||||
LEAD_STATUS_ORDER,
|
||||
CONTACT_FUNKTION_LABEL,
|
||||
TOUCHPOINT_KANAL_LABEL,
|
||||
type LeadStatus,
|
||||
} from '../lib/lead-meta';
|
||||
|
||||
type LeadByIdOutput = inferRouterOutputs<AppRouter>['lead']['byId'];
|
||||
type LeadDossier = LeadByIdOutput['lead'];
|
||||
type Contact = LeadByIdOutput['contacts'][number];
|
||||
type Touchpoint = LeadByIdOutput['touchpoints'][number];
|
||||
type LeadUpdateInput = inferRouterInputs<AppRouter>['lead']['update'];
|
||||
|
||||
// Nur nullable Text-/Datums-Felder — werden über die generische EditableSection bearbeitet.
|
||||
type LeadTextKey =
|
||||
| 'branche'
|
||||
| 'subSegment'
|
||||
| 'standorte'
|
||||
| 'mitarbeiterzahl'
|
||||
| 'umsatz'
|
||||
| 'website'
|
||||
| 'quelle'
|
||||
| 'painPoint'
|
||||
| 'statusQuoKosten'
|
||||
| 'bestehendeLoesung'
|
||||
| 'wechselgrund'
|
||||
| 'persoenlicherErfolg'
|
||||
| 'budgetIndikation'
|
||||
| 'entscheidungshorizont'
|
||||
| 'compellingEvent'
|
||||
| 'mitbewerber'
|
||||
| 'buyingCenter'
|
||||
| 'beschaffungsweg'
|
||||
| 'kommunikationsstil'
|
||||
| 'vorlieben'
|
||||
| 'hotButtons'
|
||||
| 'noGos'
|
||||
| 'druckpunkte'
|
||||
| 'anker'
|
||||
| 'nutzenHypothese'
|
||||
| 'differenzierer'
|
||||
| 'naechsterSchritt'
|
||||
| 'naechsterSchrittDatum'
|
||||
| 'risiken'
|
||||
| 'planB';
|
||||
|
||||
const inputCls =
|
||||
'w-full rounded-[var(--radius-md)] border border-[var(--color-border)] bg-white px-3 py-2 text-sm';
|
||||
|
||||
function today(): string {
|
||||
return new Date().toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
export function LeadRoute() {
|
||||
const { id = '' } = useParams<{ id: string }>();
|
||||
const navigate = useNavigate();
|
||||
const q = trpc.lead.byId.useQuery({ id });
|
||||
|
||||
if (q.isPending) return <SkeletonCard lines={8} />;
|
||||
if (!q.data) return null;
|
||||
const { lead, contacts, touchpoints } = q.data;
|
||||
|
||||
function goBack() {
|
||||
if (window.history.length > 1) navigate(-1);
|
||||
else navigate('/leads');
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<Header lead={lead} onBack={goBack} />
|
||||
|
||||
<EditableSection
|
||||
leadId={lead.id}
|
||||
lead={lead}
|
||||
title="Stammdaten"
|
||||
fields={[
|
||||
{ key: 'branche', label: 'Branche' },
|
||||
{ key: 'subSegment', label: 'Nische / Sub-Segment' },
|
||||
{ key: 'standorte', label: 'Standort(e)' },
|
||||
{ key: 'mitarbeiterzahl', label: 'Mitarbeiterzahl' },
|
||||
{ key: 'umsatz', label: 'Umsatz (geschätzt)' },
|
||||
{ key: 'website', label: 'Website' },
|
||||
{ key: 'quelle', label: 'Quelle (wie gefunden)' },
|
||||
]}
|
||||
/>
|
||||
|
||||
<ContactsSection leadId={lead.id} contacts={contacts} />
|
||||
|
||||
<EditableSection
|
||||
leadId={lead.id}
|
||||
lead={lead}
|
||||
title="Pain & Bedarf"
|
||||
fields={[
|
||||
{ key: 'painPoint', label: 'Akuter Pain-Point (in seinen Worten)', multiline: true },
|
||||
{ key: 'statusQuoKosten', label: 'Was kostet der Status quo?', multiline: true },
|
||||
{ key: 'bestehendeLoesung', label: 'Bestehende Lösung im Einsatz' },
|
||||
{ key: 'wechselgrund', label: 'Warum unzufrieden / wechselbereit?', multiline: true },
|
||||
{
|
||||
key: 'persoenlicherErfolg',
|
||||
label: 'Was wäre für die Person persönlich ein Erfolg?',
|
||||
multiline: true,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
<EditableSection
|
||||
leadId={lead.id}
|
||||
lead={lead}
|
||||
title="Geschäftliches"
|
||||
fields={[
|
||||
{ key: 'budgetIndikation', label: 'Budget-Indikation' },
|
||||
{ key: 'entscheidungshorizont', label: 'Entscheidungshorizont' },
|
||||
{ key: 'compellingEvent', label: 'Auslöser / Compelling Event', multiline: true },
|
||||
{ key: 'mitbewerber', label: 'Mitbewerber im Rennen' },
|
||||
{ key: 'buyingCenter', label: 'Buying-Center (alle Beteiligten)', multiline: true },
|
||||
{ key: 'beschaffungsweg', label: 'Beschaffungsweg' },
|
||||
]}
|
||||
/>
|
||||
|
||||
<EditableSection
|
||||
leadId={lead.id}
|
||||
lead={lead}
|
||||
title="Soft Factors"
|
||||
note="🔒 Intern. Beobachtungen, keine Bewertungen — nicht an den Lead weitergeben."
|
||||
extra={<VertrauenslevelControl leadId={lead.id} value={lead.vertrauenslevel} />}
|
||||
fields={[
|
||||
{ key: 'kommunikationsstil', label: 'Kommunikationsstil' },
|
||||
{ key: 'vorlieben', label: 'Vorlieben & Interessen', multiline: true },
|
||||
{ key: 'hotButtons', label: 'Hot Buttons (positiv)', multiline: true },
|
||||
{ key: 'noGos', label: 'No-Gos / heikle Themen', multiline: true },
|
||||
{ key: 'druckpunkte', label: 'Schwächen / Druckpunkte', multiline: true },
|
||||
{ key: 'anker', label: 'Persönliche Anker / Anekdoten', multiline: true },
|
||||
]}
|
||||
/>
|
||||
|
||||
<EditableSection
|
||||
leadId={lead.id}
|
||||
lead={lead}
|
||||
title="Strategie"
|
||||
fields={[
|
||||
{ key: 'nutzenHypothese', label: 'Nutzen-Hypothese für DIESEN Lead', multiline: true },
|
||||
{ key: 'differenzierer', label: 'Unser Differenzierer hier', multiline: true },
|
||||
{ key: 'naechsterSchritt', label: 'Nächster konkreter Schritt' },
|
||||
{ key: 'naechsterSchrittDatum', label: 'Nächster Schritt bis', date: true },
|
||||
{ key: 'risiken', label: 'Risiken / Blocker', multiline: true },
|
||||
{ key: 'planB', label: 'Plan B falls Hauptkontakt wegfällt', multiline: true },
|
||||
]}
|
||||
/>
|
||||
|
||||
<TouchpointsSection leadId={lead.id} touchpoints={touchpoints} />
|
||||
|
||||
<OffeneFragenSection leadId={lead.id} fragen={lead.offeneFragen} />
|
||||
|
||||
<AnhaengeSection leadId={lead.id} anhaenge={lead.anhaenge} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// --- Header mit Inline-Schnellbearbeitung -----------------------------------
|
||||
function Header({ lead, onBack }: { lead: LeadDossier; onBack: () => void }) {
|
||||
const utils = trpc.useUtils();
|
||||
const [editFirma, setEditFirma] = useState(false);
|
||||
const [firmaDraft, setFirmaDraft] = useState(lead.firma);
|
||||
const [promoteOpen, setPromoteOpen] = useState(false);
|
||||
|
||||
const update = trpc.lead.update.useMutation({
|
||||
onSuccess: async () => {
|
||||
await utils.lead.byId.invalidate({ id: lead.id });
|
||||
await utils.lead.list.invalidate();
|
||||
},
|
||||
});
|
||||
|
||||
const users = trpc.user.list.useQuery();
|
||||
const meta = LEAD_STATUS_META[lead.status as LeadStatus];
|
||||
|
||||
return (
|
||||
<header>
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onBack}
|
||||
aria-label="Zurück"
|
||||
className="inline-flex h-8 w-8 items-center justify-center rounded-[var(--radius-md)] border border-[var(--color-border)] text-[var(--color-ink-muted)] hover:border-[var(--color-ink)] hover:text-[var(--color-ink)]"
|
||||
>
|
||||
<ArrowLeft size={16} />
|
||||
</button>
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
<Link to="/bereich/vertrieb" className="hover:underline">
|
||||
Vertrieb
|
||||
</Link>
|
||||
{' › '}
|
||||
<Link to="/leads" className="hover:underline">
|
||||
Leads
|
||||
</Link>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="mt-2 flex flex-wrap items-start justify-between gap-4">
|
||||
{editFirma ? (
|
||||
<form
|
||||
className="flex items-center gap-2"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
const v = firmaDraft.trim();
|
||||
if (v) update.mutate({ id: lead.id, firma: v });
|
||||
setEditFirma(false);
|
||||
}}
|
||||
>
|
||||
<input
|
||||
value={firmaDraft}
|
||||
onChange={(e) => setFirmaDraft(e.target.value)}
|
||||
className="rounded-[var(--radius-md)] border border-[var(--color-border)] bg-white px-3 py-1 text-2xl font-bold"
|
||||
/>
|
||||
<Button type="submit" size="sm">
|
||||
OK
|
||||
</Button>
|
||||
</form>
|
||||
) : (
|
||||
<h1 className="flex items-center gap-2 text-3xl font-bold">
|
||||
{lead.firma}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setFirmaDraft(lead.firma);
|
||||
setEditFirma(true);
|
||||
}}
|
||||
aria-label="Firmenname bearbeiten"
|
||||
className="text-[var(--color-ink-faint)] hover:text-[var(--color-ink)]"
|
||||
>
|
||||
<Pencil size={16} />
|
||||
</button>
|
||||
</h1>
|
||||
)}
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{lead.promotedDealId ? (
|
||||
<span className="rounded-full bg-[var(--color-ampel-green-bg)] px-2.5 py-1 text-xs text-[var(--color-ampel-green-fg)]">
|
||||
In Pipeline als Deal
|
||||
</span>
|
||||
) : (
|
||||
<Button variant="secondary" size="sm" onClick={() => setPromoteOpen(true)}>
|
||||
Zu Deal machen
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-3 flex flex-wrap items-center gap-4">
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
<span className="text-[var(--color-ink-muted)]">Status</span>
|
||||
<span className={clsx('rounded-full px-2 py-0.5 text-xs', meta.badge)}>{meta.label}</span>
|
||||
<select
|
||||
value={lead.status}
|
||||
onChange={(e) => update.mutate({ id: lead.id, status: e.target.value as LeadStatus })}
|
||||
className="rounded-[var(--radius-md)] border border-[var(--color-border)] bg-white px-2 py-1 text-sm"
|
||||
>
|
||||
{LEAD_STATUS_ORDER.map((s) => (
|
||||
<option key={s} value={s}>
|
||||
{LEAD_STATUS_META[s].label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
<span className="text-[var(--color-ink-muted)]">Score</span>
|
||||
<select
|
||||
value={lead.score}
|
||||
onChange={(e) => update.mutate({ id: lead.id, score: Number(e.target.value) })}
|
||||
className="rounded-[var(--radius-md)] border border-[var(--color-border)] bg-white px-2 py-1 text-sm"
|
||||
>
|
||||
{Array.from({ length: 11 }, (_, i) => i).map((n) => (
|
||||
<option key={n} value={n}>
|
||||
{n}/10
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
<span className="text-[var(--color-ink-muted)]">Owner</span>
|
||||
<select
|
||||
value={lead.ownerUserId ?? ''}
|
||||
onChange={(e) =>
|
||||
update.mutate({ id: lead.id, ownerUserId: e.target.value || null })
|
||||
}
|
||||
className="rounded-[var(--radius-md)] border border-[var(--color-border)] bg-white px-2 py-1 text-sm"
|
||||
>
|
||||
<option value="">— niemand —</option>
|
||||
{(users.data ?? []).map((u) => (
|
||||
<option key={u.id} value={u.id}>
|
||||
{u.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{promoteOpen && <PromoteDialog leadId={lead.id} onClose={() => setPromoteOpen(false)} />}
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
function PromoteDialog({ leadId, onClose }: { leadId: string; onClose: () => void }) {
|
||||
const [euro, setEuro] = useState(0);
|
||||
const [probability, setProbability] = useState(50);
|
||||
const utils = trpc.useUtils();
|
||||
const promote = trpc.lead.promoteToDeal.useMutation({
|
||||
onSuccess: async () => {
|
||||
toast(voice.toast.leadPromoted);
|
||||
await utils.lead.byId.invalidate({ id: leadId });
|
||||
await utils.lead.list.invalidate();
|
||||
onClose();
|
||||
},
|
||||
});
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/30" onClick={onClose}>
|
||||
<div
|
||||
className="w-full max-w-sm rounded-[var(--radius-xl)] bg-[var(--color-bg)] p-6 shadow-[var(--shadow-lg)]"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<h2 className="text-xl font-semibold">Zu Deal machen</h2>
|
||||
<p className="mt-1 text-sm text-[var(--color-ink-muted)]">
|
||||
Legt einen Pipeline-Deal in Stufe „Lead“ an und verknüpft ihn.
|
||||
</p>
|
||||
<form
|
||||
className="mt-4 space-y-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
promote.mutate({ leadId, valueEur: Math.round(euro * 100), probability });
|
||||
}}
|
||||
>
|
||||
<label className="block">
|
||||
<span className="text-sm font-medium">Wert (EUR)</span>
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
value={euro}
|
||||
onChange={(e) => setEuro(Number(e.target.value))}
|
||||
className={clsx(inputCls, 'mt-1')}
|
||||
/>
|
||||
</label>
|
||||
<label className="block">
|
||||
<span className="text-sm font-medium">Wahrscheinlichkeit: {probability}%</span>
|
||||
<input
|
||||
type="range"
|
||||
min={0}
|
||||
max={100}
|
||||
value={probability}
|
||||
onChange={(e) => setProbability(Number(e.target.value))}
|
||||
className="mt-1 w-full"
|
||||
/>
|
||||
</label>
|
||||
<div className="flex justify-end gap-2 pt-2">
|
||||
<Button type="button" variant="ghost" onClick={onClose}>
|
||||
Abbrechen
|
||||
</Button>
|
||||
<Button type="submit" disabled={promote.isPending}>
|
||||
Anlegen
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// --- Generische editierbare Text-Sektion ------------------------------------
|
||||
function EditableSection({
|
||||
leadId,
|
||||
lead,
|
||||
title,
|
||||
note,
|
||||
extra,
|
||||
fields,
|
||||
}: {
|
||||
leadId: string;
|
||||
lead: LeadDossier;
|
||||
title: string;
|
||||
note?: string;
|
||||
extra?: React.ReactNode;
|
||||
fields: Array<{ key: LeadTextKey; label: string; multiline?: boolean; date?: boolean }>;
|
||||
}) {
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [draft, setDraft] = useState<Record<string, string>>({});
|
||||
const utils = trpc.useUtils();
|
||||
const update = trpc.lead.update.useMutation({
|
||||
onSuccess: async () => {
|
||||
toast(voice.toast.saved);
|
||||
await utils.lead.byId.invalidate({ id: leadId });
|
||||
await utils.lead.list.invalidate();
|
||||
setEditing(false);
|
||||
},
|
||||
});
|
||||
|
||||
function startEdit() {
|
||||
const d: Record<string, string> = {};
|
||||
for (const f of fields) d[f.key] = lead[f.key] ?? '';
|
||||
setDraft(d);
|
||||
setEditing(true);
|
||||
}
|
||||
|
||||
function save() {
|
||||
const patch: Partial<LeadUpdateInput> = { id: leadId };
|
||||
for (const f of fields) {
|
||||
const v = (draft[f.key] ?? '').trim();
|
||||
patch[f.key] = v === '' ? null : v;
|
||||
}
|
||||
update.mutate(patch as LeadUpdateInput);
|
||||
}
|
||||
|
||||
return (
|
||||
<Card.Root>
|
||||
<Card.Header className="flex items-center justify-between">
|
||||
<h2 className="text-lg font-semibold">{title}</h2>
|
||||
{!editing && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={startEdit}
|
||||
className="inline-flex items-center gap-1 text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]"
|
||||
>
|
||||
<Pencil size={13} /> Bearbeiten
|
||||
</button>
|
||||
)}
|
||||
</Card.Header>
|
||||
<Card.Body className="space-y-3">
|
||||
{note && <p className="text-xs text-[var(--color-ink-muted)]">{note}</p>}
|
||||
{extra}
|
||||
{editing ? (
|
||||
<div className="space-y-3">
|
||||
{fields.map((f) => (
|
||||
<label key={f.key} className="block">
|
||||
<span className="text-sm font-medium">{f.label}</span>
|
||||
{f.multiline ? (
|
||||
<textarea
|
||||
rows={3}
|
||||
value={draft[f.key] ?? ''}
|
||||
onChange={(e) => setDraft((d) => ({ ...d, [f.key]: e.target.value }))}
|
||||
className={clsx(inputCls, 'mt-1')}
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
type={f.date ? 'date' : 'text'}
|
||||
value={draft[f.key] ?? ''}
|
||||
onChange={(e) => setDraft((d) => ({ ...d, [f.key]: e.target.value }))}
|
||||
className={clsx(inputCls, 'mt-1')}
|
||||
/>
|
||||
)}
|
||||
</label>
|
||||
))}
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button type="button" variant="ghost" size="sm" onClick={() => setEditing(false)}>
|
||||
Abbrechen
|
||||
</Button>
|
||||
<Button type="button" size="sm" onClick={save} disabled={update.isPending}>
|
||||
Speichern
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<dl className="space-y-2 text-sm">
|
||||
{fields.map((f) => (
|
||||
<div key={f.key} className="grid grid-cols-3 gap-3">
|
||||
<dt className="text-[var(--color-ink-muted)]">{f.label}</dt>
|
||||
<dd className="col-span-2 whitespace-pre-wrap">
|
||||
{lead[f.key] ? (
|
||||
f.key === 'website' ? (
|
||||
<ExternalLink url={lead[f.key] as string} />
|
||||
) : (
|
||||
lead[f.key]
|
||||
)
|
||||
) : (
|
||||
<span className="text-[var(--color-ink-faint)]">—</span>
|
||||
)}
|
||||
</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
)}
|
||||
</Card.Body>
|
||||
</Card.Root>
|
||||
);
|
||||
}
|
||||
|
||||
function VertrauenslevelControl({
|
||||
leadId,
|
||||
value,
|
||||
}: {
|
||||
leadId: string;
|
||||
value: number | null;
|
||||
}) {
|
||||
const utils = trpc.useUtils();
|
||||
const update = trpc.lead.update.useMutation({
|
||||
onSuccess: async () => {
|
||||
await utils.lead.byId.invalidate({ id: leadId });
|
||||
},
|
||||
});
|
||||
return (
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
<span className="text-[var(--color-ink-muted)]">Vertrauenslevel zu uns</span>
|
||||
<select
|
||||
value={value ?? ''}
|
||||
onChange={(e) =>
|
||||
update.mutate({ id: leadId, vertrauenslevel: e.target.value ? Number(e.target.value) : null })
|
||||
}
|
||||
className="rounded-[var(--radius-md)] border border-[var(--color-border)] bg-white px-2 py-1 text-sm"
|
||||
>
|
||||
<option value="">—</option>
|
||||
{[1, 2, 3, 4, 5].map((n) => (
|
||||
<option key={n} value={n}>
|
||||
{n}/5
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
// --- Kontaktpersonen ---------------------------------------------------------
|
||||
function ContactsSection({ leadId, contacts }: { leadId: string; contacts: Contact[] }) {
|
||||
const [adding, setAdding] = useState(false);
|
||||
return (
|
||||
<Card.Root>
|
||||
<Card.Header className="flex items-center justify-between">
|
||||
<h2 className="text-lg font-semibold">Kontaktpersonen</h2>
|
||||
{!adding && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setAdding(true)}
|
||||
className="inline-flex items-center gap-1 text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]"
|
||||
>
|
||||
<Plus size={13} /> Kontakt
|
||||
</button>
|
||||
)}
|
||||
</Card.Header>
|
||||
<Card.Body className="space-y-3">
|
||||
{contacts.length === 0 && !adding && (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">Noch keine Kontakte.</p>
|
||||
)}
|
||||
{contacts.map((c) => (
|
||||
<ContactRow key={c.id} leadId={leadId} contact={c} />
|
||||
))}
|
||||
{adding && <AddContactForm leadId={leadId} onDone={() => setAdding(false)} />}
|
||||
</Card.Body>
|
||||
</Card.Root>
|
||||
);
|
||||
}
|
||||
|
||||
function ContactRow({ leadId, contact }: { leadId: string; contact: Contact }) {
|
||||
const utils = trpc.useUtils();
|
||||
const remove = trpc.lead.removeContact.useMutation({
|
||||
onSuccess: async () => {
|
||||
await utils.lead.byId.invalidate({ id: leadId });
|
||||
},
|
||||
});
|
||||
const details = [
|
||||
contact.email,
|
||||
contact.telefon,
|
||||
contact.sprache,
|
||||
contact.imBuyingCenterSeit ? `seit ${contact.imBuyingCenterSeit}` : null,
|
||||
].filter(Boolean);
|
||||
return (
|
||||
<div className="rounded-[var(--radius-md)] border border-[var(--color-border)] p-3">
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<div>
|
||||
<p className="flex items-center gap-2 font-medium">
|
||||
{contact.isPrimary && (
|
||||
<Star size={13} className="text-[var(--color-ampel-amber-fg)]" fill="currentColor" />
|
||||
)}
|
||||
{contact.name}
|
||||
{contact.rolle && (
|
||||
<span className="text-sm font-normal text-[var(--color-ink-muted)]">
|
||||
· {contact.rolle}
|
||||
</span>
|
||||
)}
|
||||
</p>
|
||||
{contact.funktion && (
|
||||
<span className="mt-1 inline-block rounded-full bg-black/5 px-2 py-0.5 text-xs text-[var(--color-ink-muted)]">
|
||||
{CONTACT_FUNKTION_LABEL[contact.funktion] ?? contact.funktion}
|
||||
</span>
|
||||
)}
|
||||
{details.length > 0 && (
|
||||
<p className="mt-1 text-xs text-[var(--color-ink-muted)]">{details.join(' · ')}</p>
|
||||
)}
|
||||
{contact.linkedin && (
|
||||
<p className="mt-1 text-xs">
|
||||
<ExternalLink url={contact.linkedin} label="LinkedIn" />
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => remove.mutate({ contactId: contact.id })}
|
||||
aria-label="Kontakt entfernen"
|
||||
className="text-[var(--color-ink-faint)] hover:text-[var(--color-ampel-red-fg)]"
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function AddContactForm({ leadId, onDone }: { leadId: string; onDone: () => void }) {
|
||||
const utils = trpc.useUtils();
|
||||
const [name, setName] = useState('');
|
||||
const [rolle, setRolle] = useState('');
|
||||
const [funktion, setFunktion] = useState('');
|
||||
const [email, setEmail] = useState('');
|
||||
const [telefon, setTelefon] = useState('');
|
||||
const [linkedin, setLinkedin] = useState('');
|
||||
const [sprache, setSprache] = useState('');
|
||||
const [seit, setSeit] = useState('');
|
||||
const [isPrimary, setIsPrimary] = useState(false);
|
||||
|
||||
const add = trpc.lead.addContact.useMutation({
|
||||
onSuccess: async () => {
|
||||
await utils.lead.byId.invalidate({ id: leadId });
|
||||
onDone();
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<form
|
||||
className="space-y-2 rounded-[var(--radius-md)] border border-dashed border-[var(--color-border)] p-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
if (!name.trim()) return;
|
||||
add.mutate({
|
||||
leadId,
|
||||
name: name.trim(),
|
||||
rolle: rolle.trim() || undefined,
|
||||
funktion: (funktion || undefined) as
|
||||
| 'entscheider'
|
||||
| 'influencer'
|
||||
| 'gatekeeper'
|
||||
| 'end_user'
|
||||
| 'champion'
|
||||
| undefined,
|
||||
email: email.trim() || undefined,
|
||||
telefon: telefon.trim() || undefined,
|
||||
linkedin: linkedin.trim() || undefined,
|
||||
sprache: sprache.trim() || undefined,
|
||||
imBuyingCenterSeit: seit.trim() || undefined,
|
||||
isPrimary,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<input placeholder="Name *" value={name} onChange={(e) => setName(e.target.value)} className={inputCls} />
|
||||
<input placeholder="Rolle / Titel" value={rolle} onChange={(e) => setRolle(e.target.value)} className={inputCls} />
|
||||
<select value={funktion} onChange={(e) => setFunktion(e.target.value)} className={inputCls}>
|
||||
<option value="">Funktion im Kaufprozess</option>
|
||||
{Object.entries(CONTACT_FUNKTION_LABEL).map(([v, l]) => (
|
||||
<option key={v} value={v}>
|
||||
{l}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<input placeholder="E-Mail" value={email} onChange={(e) => setEmail(e.target.value)} className={inputCls} />
|
||||
<input placeholder="Telefon" value={telefon} onChange={(e) => setTelefon(e.target.value)} className={inputCls} />
|
||||
<input placeholder="LinkedIn-URL" value={linkedin} onChange={(e) => setLinkedin(e.target.value)} className={inputCls} />
|
||||
<input placeholder="Sprache / Anrede" value={sprache} onChange={(e) => setSprache(e.target.value)} className={inputCls} />
|
||||
<input placeholder="Im Buying-Center seit" value={seit} onChange={(e) => setSeit(e.target.value)} className={inputCls} />
|
||||
</div>
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
<input type="checkbox" checked={isPrimary} onChange={(e) => setIsPrimary(e.target.checked)} />
|
||||
Hauptkontakt
|
||||
</label>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button type="button" variant="ghost" size="sm" onClick={onDone}>
|
||||
Abbrechen
|
||||
</Button>
|
||||
<Button type="submit" size="sm" disabled={add.isPending}>
|
||||
Hinzufügen
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
// --- Austausch-Log -----------------------------------------------------------
|
||||
function TouchpointsSection({
|
||||
leadId,
|
||||
touchpoints,
|
||||
}: {
|
||||
leadId: string;
|
||||
touchpoints: Touchpoint[];
|
||||
}) {
|
||||
const [adding, setAdding] = useState(false);
|
||||
return (
|
||||
<Card.Root>
|
||||
<Card.Header className="flex items-center justify-between">
|
||||
<h2 className="text-lg font-semibold">Austausch-Log</h2>
|
||||
{!adding && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setAdding(true)}
|
||||
className="inline-flex items-center gap-1 text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]"
|
||||
>
|
||||
<Plus size={13} /> Touchpoint
|
||||
</button>
|
||||
)}
|
||||
</Card.Header>
|
||||
<Card.Body className="space-y-3">
|
||||
{adding && <AddTouchpointForm leadId={leadId} onDone={() => setAdding(false)} />}
|
||||
{touchpoints.length === 0 && !adding ? (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
Noch kein Kontakt protokolliert. Faustregel: kein Touchpoint ohne Eintrag.
|
||||
</p>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
{touchpoints.map((t) => (
|
||||
<TouchpointRow key={t.id} leadId={leadId} touchpoint={t} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</Card.Body>
|
||||
</Card.Root>
|
||||
);
|
||||
}
|
||||
|
||||
function TouchpointRow({ leadId, touchpoint }: { leadId: string; touchpoint: Touchpoint }) {
|
||||
const utils = trpc.useUtils();
|
||||
const remove = trpc.lead.removeTouchpoint.useMutation({
|
||||
onSuccess: async () => {
|
||||
await utils.lead.byId.invalidate({ id: leadId });
|
||||
},
|
||||
});
|
||||
return (
|
||||
<div className="rounded-[var(--radius-md)] border border-[var(--color-border)] p-3 text-sm">
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<div className="flex flex-wrap items-center gap-2 text-xs text-[var(--color-ink-muted)]">
|
||||
<span className="font-mono tabular-nums">{touchpoint.datum}</span>
|
||||
<span className="rounded-full bg-black/5 px-2 py-0.5">
|
||||
{TOUCHPOINT_KANAL_LABEL[touchpoint.kanal] ?? touchpoint.kanal}
|
||||
</span>
|
||||
{touchpoint.bearbeiterName && <span>{touchpoint.bearbeiterName}</span>}
|
||||
{touchpoint.followUpBis && (
|
||||
<span className="rounded-full bg-[var(--color-ampel-amber-bg)] px-2 py-0.5 text-[var(--color-ampel-amber-fg)]">
|
||||
Follow-up bis {touchpoint.followUpBis}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => remove.mutate({ touchpointId: touchpoint.id })}
|
||||
aria-label="Eintrag entfernen"
|
||||
className="text-[var(--color-ink-faint)] hover:text-[var(--color-ampel-red-fg)]"
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</button>
|
||||
</div>
|
||||
<p className="mt-1 whitespace-pre-wrap">{touchpoint.inhalt}</p>
|
||||
{touchpoint.outcome && (
|
||||
<p className="mt-1 text-xs text-[var(--color-ink-muted)]">Outcome: {touchpoint.outcome}</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function AddTouchpointForm({ leadId, onDone }: { leadId: string; onDone: () => void }) {
|
||||
const utils = trpc.useUtils();
|
||||
const [datum, setDatum] = useState(today());
|
||||
const [kanal, setKanal] = useState('call');
|
||||
const [inhalt, setInhalt] = useState('');
|
||||
const [outcome, setOutcome] = useState('');
|
||||
const [followUp, setFollowUp] = useState('');
|
||||
|
||||
const add = trpc.lead.addTouchpoint.useMutation({
|
||||
onSuccess: async () => {
|
||||
await utils.lead.byId.invalidate({ id: leadId });
|
||||
await utils.lead.list.invalidate();
|
||||
onDone();
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<form
|
||||
className="space-y-2 rounded-[var(--radius-md)] border border-dashed border-[var(--color-border)] p-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
if (!inhalt.trim()) return;
|
||||
add.mutate({
|
||||
leadId,
|
||||
datum,
|
||||
kanal: kanal as 'call' | 'mail' | 'linkedin' | 'termin' | 'event' | 'sonstiges',
|
||||
inhalt: inhalt.trim(),
|
||||
outcome: outcome.trim() || undefined,
|
||||
followUpBis: followUp || undefined,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<input type="date" value={datum} onChange={(e) => setDatum(e.target.value)} className={inputCls} />
|
||||
<select value={kanal} onChange={(e) => setKanal(e.target.value)} className={inputCls}>
|
||||
{Object.entries(TOUCHPOINT_KANAL_LABEL).map(([v, l]) => (
|
||||
<option key={v} value={v}>
|
||||
{l}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<textarea
|
||||
placeholder="Worum ging es? 1–2 Sätze."
|
||||
rows={2}
|
||||
value={inhalt}
|
||||
onChange={(e) => setInhalt(e.target.value)}
|
||||
className={inputCls}
|
||||
/>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<input placeholder="Outcome" value={outcome} onChange={(e) => setOutcome(e.target.value)} className={inputCls} />
|
||||
<label className="flex flex-col text-xs text-[var(--color-ink-muted)]">
|
||||
Follow-up bis
|
||||
<input type="date" value={followUp} onChange={(e) => setFollowUp(e.target.value)} className={inputCls} />
|
||||
</label>
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button type="button" variant="ghost" size="sm" onClick={onDone}>
|
||||
Abbrechen
|
||||
</Button>
|
||||
<Button type="submit" size="sm" disabled={add.isPending}>
|
||||
Erfassen
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
// --- Offene Fragen (JSONB) ---------------------------------------------------
|
||||
function OffeneFragenSection({
|
||||
leadId,
|
||||
fragen,
|
||||
}: {
|
||||
leadId: string;
|
||||
fragen: Array<{ text: string; done: boolean }>;
|
||||
}) {
|
||||
const utils = trpc.useUtils();
|
||||
const [neu, setNeu] = useState('');
|
||||
const update = trpc.lead.update.useMutation({
|
||||
onSuccess: async () => {
|
||||
await utils.lead.byId.invalidate({ id: leadId });
|
||||
},
|
||||
});
|
||||
function persist(next: Array<{ text: string; done: boolean }>) {
|
||||
update.mutate({ id: leadId, offeneFragen: next });
|
||||
}
|
||||
return (
|
||||
<Card.Root>
|
||||
<Card.Header>
|
||||
<h2 className="text-lg font-semibold">Offene Fragen / Hypothesen</h2>
|
||||
</Card.Header>
|
||||
<Card.Body className="space-y-2">
|
||||
{fragen.length === 0 && (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">Keine offenen Fragen.</p>
|
||||
)}
|
||||
<ul className="space-y-1.5 text-sm">
|
||||
{fragen.map((f, i) => (
|
||||
<li key={i} className="flex items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={f.done}
|
||||
onChange={() =>
|
||||
persist(fragen.map((x, j) => (j === i ? { ...x, done: !x.done } : x)))
|
||||
}
|
||||
/>
|
||||
<span className={clsx('flex-1', f.done && 'text-[var(--color-ink-muted)] line-through')}>
|
||||
{f.text}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => persist(fragen.filter((_, j) => j !== i))}
|
||||
aria-label="Frage entfernen"
|
||||
className="text-[var(--color-ink-faint)] hover:text-[var(--color-ampel-red-fg)]"
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<form
|
||||
className="flex gap-2"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
const v = neu.trim();
|
||||
if (!v) return;
|
||||
persist([...fragen, { text: v, done: false }]);
|
||||
setNeu('');
|
||||
}}
|
||||
>
|
||||
<input
|
||||
placeholder="Neue offene Frage…"
|
||||
value={neu}
|
||||
onChange={(e) => setNeu(e.target.value)}
|
||||
className={inputCls}
|
||||
/>
|
||||
<Button type="submit" size="sm" variant="secondary">
|
||||
<Plus size={14} />
|
||||
</Button>
|
||||
</form>
|
||||
</Card.Body>
|
||||
</Card.Root>
|
||||
);
|
||||
}
|
||||
|
||||
// --- Anhänge (JSONB) ---------------------------------------------------------
|
||||
function AnhaengeSection({
|
||||
leadId,
|
||||
anhaenge,
|
||||
}: {
|
||||
leadId: string;
|
||||
anhaenge: Array<{ label: string; url: string }>;
|
||||
}) {
|
||||
const utils = trpc.useUtils();
|
||||
const [label, setLabel] = useState('');
|
||||
const [url, setUrl] = useState('');
|
||||
const update = trpc.lead.update.useMutation({
|
||||
onSuccess: async () => {
|
||||
await utils.lead.byId.invalidate({ id: leadId });
|
||||
},
|
||||
});
|
||||
function persist(next: Array<{ label: string; url: string }>) {
|
||||
update.mutate({ id: leadId, anhaenge: next });
|
||||
}
|
||||
return (
|
||||
<Card.Root>
|
||||
<Card.Header>
|
||||
<h2 className="text-lg font-semibold">Anhänge / verlinkte Dokumente</h2>
|
||||
</Card.Header>
|
||||
<Card.Body className="space-y-2">
|
||||
{anhaenge.length === 0 && (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">Noch keine Anhänge.</p>
|
||||
)}
|
||||
<ul className="space-y-1.5 text-sm">
|
||||
{anhaenge.map((a, i) => (
|
||||
<li key={i} className="flex items-center justify-between gap-2">
|
||||
<ExternalLink url={a.url} label={a.label} />
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => persist(anhaenge.filter((_, j) => j !== i))}
|
||||
aria-label="Anhang entfernen"
|
||||
className="text-[var(--color-ink-faint)] hover:text-[var(--color-ampel-red-fg)]"
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<form
|
||||
className="grid grid-cols-[1fr_1fr_auto] gap-2"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
if (!label.trim() || !url.trim()) return;
|
||||
persist([...anhaenge, { label: label.trim(), url: url.trim() }]);
|
||||
setLabel('');
|
||||
setUrl('');
|
||||
}}
|
||||
>
|
||||
<input placeholder="Bezeichnung" value={label} onChange={(e) => setLabel(e.target.value)} className={inputCls} />
|
||||
<input placeholder="URL" value={url} onChange={(e) => setUrl(e.target.value)} className={inputCls} />
|
||||
<Button type="submit" size="sm" variant="secondary">
|
||||
<Plus size={14} />
|
||||
</Button>
|
||||
</form>
|
||||
</Card.Body>
|
||||
</Card.Root>
|
||||
);
|
||||
}
|
||||
|
||||
function ExternalLink({ url, label }: { url: string; label?: string }) {
|
||||
const href = url.startsWith('http') ? url : `https://${url}`;
|
||||
return (
|
||||
<a href={href} target="_blank" rel="noreferrer" className="truncate text-[var(--color-ink)] hover:underline">
|
||||
{label ?? url}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
import { useState } from 'react';
|
||||
import { Link } from 'react-router';
|
||||
import { clsx } from 'clsx';
|
||||
import { toast } from 'sonner';
|
||||
import { trpc } from '../lib/trpc';
|
||||
import { voice } from '../lib/voice';
|
||||
import { Card } from '../components/ui/Card';
|
||||
import { Button } from '../components/ui/Button';
|
||||
import { SkeletonCard } from '../components/ui/SkeletonCard';
|
||||
import {
|
||||
LEAD_STATUS_META,
|
||||
LEAD_STATUS_ORDER,
|
||||
type LeadStatus,
|
||||
} from '../lib/lead-meta';
|
||||
|
||||
export function LeadsRoute() {
|
||||
const q = trpc.lead.list.useQuery();
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
if (q.isPending) return <SkeletonCard lines={6} />;
|
||||
const leads = q.data ?? [];
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<header className="flex items-end justify-between gap-4">
|
||||
<div>
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
<Link to="/bereich/vertrieb" className="hover:underline">
|
||||
Vertrieb
|
||||
</Link>
|
||||
{' › Leads'}
|
||||
</p>
|
||||
<h1 className="text-3xl font-bold">Leads</h1>
|
||||
<p className="text-[var(--color-ink-muted)]">
|
||||
Qualitative Lead-Dossiers — Stammdaten, Pain, Strategie, Austausch-Log.
|
||||
</p>
|
||||
</div>
|
||||
<Button onClick={() => setOpen(true)}>{voice.cta.newLead}</Button>
|
||||
</header>
|
||||
|
||||
{leads.length === 0 ? (
|
||||
<Card.Root>
|
||||
<Card.Body>
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
Noch keine Leads. Leg einen an.
|
||||
</p>
|
||||
</Card.Body>
|
||||
</Card.Root>
|
||||
) : (
|
||||
LEAD_STATUS_ORDER.map((status) => {
|
||||
const group = leads.filter((l) => l.status === status);
|
||||
if (group.length === 0) return null;
|
||||
return (
|
||||
<section key={status}>
|
||||
<h2 className="mb-2 text-lg font-semibold">
|
||||
{LEAD_STATUS_META[status].label}{' '}
|
||||
<span className="text-sm font-normal text-[var(--color-ink-muted)]">
|
||||
({group.length})
|
||||
</span>
|
||||
</h2>
|
||||
<div className="grid grid-cols-1 gap-3 md:grid-cols-2 lg:grid-cols-3">
|
||||
{group.map((l) => (
|
||||
<LeadCard key={l.id} lead={l} />
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
})
|
||||
)}
|
||||
|
||||
{open && <LeadCreateDialog onClose={() => setOpen(false)} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function LeadCard({
|
||||
lead,
|
||||
}: {
|
||||
lead: {
|
||||
id: string;
|
||||
firma: string;
|
||||
status: LeadStatus;
|
||||
score: number;
|
||||
ownerName: string | null;
|
||||
branche: string | null;
|
||||
subSegment: string | null;
|
||||
naechsterSchrittDatum: string | null;
|
||||
};
|
||||
}) {
|
||||
const meta = LEAD_STATUS_META[lead.status];
|
||||
const sub = [lead.branche, lead.subSegment].filter(Boolean).join(' · ');
|
||||
return (
|
||||
<Link to={`/lead/${lead.id}`} className="contents">
|
||||
<Card.Root className="cursor-pointer hover:shadow-[var(--shadow-md)]">
|
||||
<Card.Body className="space-y-2">
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<p className="font-semibold">{lead.firma}</p>
|
||||
<span className={clsx('shrink-0 rounded-full px-2 py-0.5 text-xs', meta.badge)}>
|
||||
{meta.label}
|
||||
</span>
|
||||
</div>
|
||||
{sub && <p className="text-xs text-[var(--color-ink-muted)]">{sub}</p>}
|
||||
<div className="flex items-center justify-between text-xs text-[var(--color-ink-muted)]">
|
||||
<span>{lead.ownerName ?? 'ohne Owner'}</span>
|
||||
<span className="font-mono tabular-nums">Score {lead.score}/10</span>
|
||||
</div>
|
||||
{lead.naechsterSchrittDatum && (
|
||||
<p className="text-xs text-[var(--color-ink-muted)]">
|
||||
Nächster Schritt: {lead.naechsterSchrittDatum}
|
||||
</p>
|
||||
)}
|
||||
</Card.Body>
|
||||
</Card.Root>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
function LeadCreateDialog({ onClose }: { onClose: () => void }) {
|
||||
const users = trpc.user.list.useQuery();
|
||||
const [firma, setFirma] = useState('');
|
||||
const [branche, setBranche] = useState('');
|
||||
const [subSegment, setSubSegment] = useState('');
|
||||
const [website, setWebsite] = useState('');
|
||||
const [quelle, setQuelle] = useState('');
|
||||
const [ownerUserId, setOwnerUserId] = useState('');
|
||||
const [status, setStatus] = useState<LeadStatus>('cold');
|
||||
const [score, setScore] = useState(0);
|
||||
|
||||
const utils = trpc.useUtils();
|
||||
const create = trpc.lead.create.useMutation({
|
||||
onSuccess: async () => {
|
||||
toast(voice.toast.leadCreated);
|
||||
await utils.lead.list.invalidate();
|
||||
onClose();
|
||||
},
|
||||
});
|
||||
|
||||
function submit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!firma.trim()) return;
|
||||
create.mutate({
|
||||
firma: firma.trim(),
|
||||
branche: branche.trim() || undefined,
|
||||
subSegment: subSegment.trim() || undefined,
|
||||
website: website.trim() || undefined,
|
||||
quelle: quelle.trim() || undefined,
|
||||
ownerUserId: ownerUserId || undefined,
|
||||
status,
|
||||
score,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/30" onClick={onClose}>
|
||||
<div
|
||||
className="max-h-[90vh] w-full max-w-md overflow-y-auto rounded-[var(--radius-xl)] bg-[var(--color-bg)] p-6 shadow-[var(--shadow-lg)]"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<h2 className="text-xl font-semibold">Neuer Lead</h2>
|
||||
<p className="mt-1 text-sm text-[var(--color-ink-muted)]">
|
||||
Nur die Firma ist Pflicht — alles Weitere füllst du im Dossier.
|
||||
</p>
|
||||
<form onSubmit={submit} className="mt-4 space-y-3">
|
||||
<Field label="Firma">
|
||||
<input
|
||||
required
|
||||
value={firma}
|
||||
onChange={(e) => setFirma(e.target.value)}
|
||||
className={inputCls}
|
||||
/>
|
||||
</Field>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Field label="Branche">
|
||||
<input value={branche} onChange={(e) => setBranche(e.target.value)} className={inputCls} />
|
||||
</Field>
|
||||
<Field label="Nische / Sub-Segment">
|
||||
<input
|
||||
value={subSegment}
|
||||
onChange={(e) => setSubSegment(e.target.value)}
|
||||
className={inputCls}
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
<Field label="Website">
|
||||
<input value={website} onChange={(e) => setWebsite(e.target.value)} className={inputCls} />
|
||||
</Field>
|
||||
<Field label="Quelle (wie gefunden)">
|
||||
<input value={quelle} onChange={(e) => setQuelle(e.target.value)} className={inputCls} />
|
||||
</Field>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Field label="Owner">
|
||||
<select
|
||||
value={ownerUserId}
|
||||
onChange={(e) => setOwnerUserId(e.target.value)}
|
||||
className={inputCls}
|
||||
>
|
||||
<option value="">— niemand —</option>
|
||||
{(users.data ?? []).map((u) => (
|
||||
<option key={u.id} value={u.id}>
|
||||
{u.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
<Field label="Status">
|
||||
<select
|
||||
value={status}
|
||||
onChange={(e) => setStatus(e.target.value as LeadStatus)}
|
||||
className={inputCls}
|
||||
>
|
||||
{LEAD_STATUS_ORDER.map((s) => (
|
||||
<option key={s} value={s}>
|
||||
{LEAD_STATUS_META[s].label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
</div>
|
||||
<Field label={`Score: ${score}/10`}>
|
||||
<input
|
||||
type="range"
|
||||
min={0}
|
||||
max={10}
|
||||
value={score}
|
||||
onChange={(e) => setScore(Number(e.target.value))}
|
||||
className="w-full"
|
||||
/>
|
||||
</Field>
|
||||
<div className="flex justify-end gap-2 pt-2">
|
||||
<Button type="button" variant="ghost" onClick={onClose}>
|
||||
Abbrechen
|
||||
</Button>
|
||||
<Button type="submit" disabled={create.isPending}>
|
||||
Anlegen
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const inputCls =
|
||||
'w-full rounded-[var(--radius-md)] border border-[var(--color-border)] bg-white px-3 py-2 text-sm';
|
||||
|
||||
function Field({ label, children }: { label: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<label className="block">
|
||||
<span className="text-sm font-medium">{label}</span>
|
||||
<div className="mt-1">{children}</div>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
+1580
-52
File diff suppressed because it is too large.
Load diff
@@ -7,7 +7,7 @@ import { Button } from '../components/ui/Button';
|
||||
import { SkeletonCard } from '../components/ui/SkeletonCard';
|
||||
import { toast } from 'sonner';
|
||||
import { clsx } from 'clsx';
|
||||
import { Check, X, Minus, TrendingUp, TrendingDown, ArrowRight } from 'lucide-react';
|
||||
import { Check, X, Minus, TrendingUp, TrendingDown, ArrowRight, Pencil } from 'lucide-react';
|
||||
|
||||
type Ampel = 'green' | 'amber' | 'red';
|
||||
type Trend = 'besser' | 'gleich' | 'schlechter';
|
||||
@@ -128,7 +128,7 @@ function ReflectForm({
|
||||
const status = todoStates[t.id]?.status ?? 'open';
|
||||
return (
|
||||
<li key={t.id} className="flex items-center gap-2">
|
||||
<span className="flex-1 text-sm">{t.title}</span>
|
||||
<EditableTodoTitle id={t.id} title={t.title} />
|
||||
<div className="flex gap-1">
|
||||
<StatusBtn
|
||||
active={status === 'done'}
|
||||
@@ -269,6 +269,91 @@ function ReflectForm({
|
||||
);
|
||||
}
|
||||
|
||||
function EditableTodoTitle({ id, title }: { id: string; title: string }) {
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [draft, setDraft] = useState(title);
|
||||
const utils = trpc.useUtils();
|
||||
const edit = trpc.dayEntry.editTodoTitle.useMutation({
|
||||
onSuccess: async () => {
|
||||
await utils.dayEntry.today.invalidate();
|
||||
setEditing(false);
|
||||
},
|
||||
});
|
||||
|
||||
function save() {
|
||||
const v = draft.trim();
|
||||
if (!v || v === title) {
|
||||
setEditing(false);
|
||||
return;
|
||||
}
|
||||
edit.mutate({ todoId: id, title: v });
|
||||
}
|
||||
|
||||
if (editing) {
|
||||
return (
|
||||
<div className="flex flex-1 items-center gap-1">
|
||||
<input
|
||||
ref={(el) => el?.focus()}
|
||||
value={draft}
|
||||
onChange={(e) => setDraft(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
save();
|
||||
} else if (e.key === 'Escape') {
|
||||
setDraft(title);
|
||||
setEditing(false);
|
||||
}
|
||||
}}
|
||||
maxLength={200}
|
||||
aria-label="ToDo-Titel bearbeiten"
|
||||
className="flex-1 rounded-[var(--radius-md)] border border-[var(--color-border)] bg-white px-2 py-1 text-sm focus:border-[var(--color-ink)] focus:outline-none"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={save}
|
||||
disabled={edit.isPending}
|
||||
aria-label="Titel speichern"
|
||||
title="Speichern"
|
||||
className="inline-flex h-7 w-7 items-center justify-center rounded-[var(--radius-md)] border border-[var(--color-ink)] bg-[var(--color-ink)] text-[var(--color-brand-fg)]"
|
||||
>
|
||||
<Check size={14} />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setDraft(title);
|
||||
setEditing(false);
|
||||
}}
|
||||
aria-label="Bearbeiten abbrechen"
|
||||
title="Abbrechen"
|
||||
className="inline-flex h-7 w-7 items-center justify-center rounded-[var(--radius-md)] border border-[var(--color-border)] text-[var(--color-ink-muted)] hover:border-[var(--color-border-strong)]"
|
||||
>
|
||||
<X size={14} />
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setDraft(title);
|
||||
setEditing(true);
|
||||
}}
|
||||
title="Zum Bearbeiten klicken"
|
||||
className="group flex flex-1 items-center gap-1.5 text-left text-sm"
|
||||
>
|
||||
<span>{title}</span>
|
||||
<Pencil
|
||||
size={12}
|
||||
className="text-[var(--color-ink-faint)] opacity-0 transition-opacity group-hover:opacity-100"
|
||||
/>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
function StatusBtn({
|
||||
active,
|
||||
onClick,
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
CREATE TABLE "lead" (
|
||||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||
"area_id" uuid NOT NULL,
|
||||
"firma" text NOT NULL,
|
||||
"status" text DEFAULT 'cold' NOT NULL,
|
||||
"score" integer DEFAULT 0 NOT NULL,
|
||||
"owner_user_id" uuid,
|
||||
"branche" text,
|
||||
"sub_segment" text,
|
||||
"standorte" text,
|
||||
"mitarbeiterzahl" text,
|
||||
"umsatz" text,
|
||||
"website" text,
|
||||
"quelle" text,
|
||||
"pain_point" text,
|
||||
"status_quo_kosten" text,
|
||||
"bestehende_loesung" text,
|
||||
"wechselgrund" text,
|
||||
"persoenlicher_erfolg" text,
|
||||
"budget_indikation" text,
|
||||
"entscheidungshorizont" text,
|
||||
"compelling_event" text,
|
||||
"mitbewerber" text,
|
||||
"buying_center" text,
|
||||
"beschaffungsweg" text,
|
||||
"kommunikationsstil" text,
|
||||
"vorlieben" text,
|
||||
"hot_buttons" text,
|
||||
"no_gos" text,
|
||||
"druckpunkte" text,
|
||||
"anker" text,
|
||||
"vertrauenslevel" integer,
|
||||
"nutzen_hypothese" text,
|
||||
"differenzierer" text,
|
||||
"naechster_schritt" text,
|
||||
"naechster_schritt_datum" date,
|
||||
"risiken" text,
|
||||
"plan_b" text,
|
||||
"offene_fragen" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
||||
"anhaenge" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
||||
"promoted_deal_id" uuid,
|
||||
"created_by" uuid,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "lead_contact" (
|
||||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||
"lead_id" uuid NOT NULL,
|
||||
"name" text NOT NULL,
|
||||
"rolle" text,
|
||||
"funktion" text,
|
||||
"email" text,
|
||||
"telefon" text,
|
||||
"linkedin" text,
|
||||
"im_buying_center_seit" text,
|
||||
"sprache" text,
|
||||
"is_primary" boolean DEFAULT false NOT NULL,
|
||||
"order" integer DEFAULT 0 NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "lead_touchpoint" (
|
||||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||
"lead_id" uuid NOT NULL,
|
||||
"datum" date NOT NULL,
|
||||
"kanal" text NOT NULL,
|
||||
"bearbeiter_user_id" uuid,
|
||||
"inhalt" text NOT NULL,
|
||||
"outcome" text,
|
||||
"follow_up_bis" date,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "lead" ADD CONSTRAINT "lead_area_id_area_id_fk" FOREIGN KEY ("area_id") REFERENCES "public"."area"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "lead" ADD CONSTRAINT "lead_owner_user_id_user_id_fk" FOREIGN KEY ("owner_user_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "lead" ADD CONSTRAINT "lead_promoted_deal_id_deal_id_fk" FOREIGN KEY ("promoted_deal_id") REFERENCES "public"."deal"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "lead" ADD CONSTRAINT "lead_created_by_user_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "lead_contact" ADD CONSTRAINT "lead_contact_lead_id_lead_id_fk" FOREIGN KEY ("lead_id") REFERENCES "public"."lead"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "lead_touchpoint" ADD CONSTRAINT "lead_touchpoint_lead_id_lead_id_fk" FOREIGN KEY ("lead_id") REFERENCES "public"."lead"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "lead_touchpoint" ADD CONSTRAINT "lead_touchpoint_bearbeiter_user_id_user_id_fk" FOREIGN KEY ("bearbeiter_user_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX "idx_lead_status" ON "lead" USING btree ("status");--> statement-breakpoint
|
||||
CREATE INDEX "idx_lead_owner" ON "lead" USING btree ("owner_user_id");--> statement-breakpoint
|
||||
CREATE INDEX "idx_lead_contact_lead" ON "lead_contact" USING btree ("lead_id");--> statement-breakpoint
|
||||
CREATE INDEX "idx_lead_touchpoint_lead" ON "lead_touchpoint" USING btree ("lead_id");--> statement-breakpoint
|
||||
CREATE INDEX "idx_lead_touchpoint_followup" ON "lead_touchpoint" USING btree ("follow_up_bis");
|
||||
@@ -0,0 +1,40 @@
|
||||
CREATE TABLE "risk" (
|
||||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||
"project_id" uuid NOT NULL,
|
||||
"kind" text DEFAULT 'risiko' NOT NULL,
|
||||
"title" text NOT NULL,
|
||||
"wahrscheinlichkeit" text DEFAULT 'mittel' NOT NULL,
|
||||
"auswirkung" text DEFAULT 'mittel' NOT NULL,
|
||||
"herkunft" text,
|
||||
"showstopper" boolean DEFAULT false NOT NULL,
|
||||
"massnahme" text,
|
||||
"status" text DEFAULT 'offen' NOT NULL,
|
||||
"created_by" uuid,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "stakeholder" (
|
||||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||
"project_id" uuid NOT NULL,
|
||||
"name" text NOT NULL,
|
||||
"rolle" text,
|
||||
"interesse" text DEFAULT 'mittel' NOT NULL,
|
||||
"einfluss" text DEFAULT 'mittel' NOT NULL,
|
||||
"haltung" text DEFAULT 'neutral' NOT NULL,
|
||||
"beduerfnis" text,
|
||||
"notiz" text,
|
||||
"order" integer DEFAULT 0 NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "milestone" ADD COLUMN "ergebnis" text;--> statement-breakpoint
|
||||
ALTER TABLE "milestone" ADD COLUMN "kundennutzen" text;--> statement-breakpoint
|
||||
ALTER TABLE "project" ADD COLUMN "maxime" text;--> statement-breakpoint
|
||||
ALTER TABLE "project" ADD COLUMN "modus" text DEFAULT 'standard' NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "risk" ADD CONSTRAINT "risk_project_id_project_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."project"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "risk" ADD CONSTRAINT "risk_created_by_user_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "stakeholder" ADD CONSTRAINT "stakeholder_project_id_project_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."project"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX "idx_risk_project" ON "risk" USING btree ("project_id");--> statement-breakpoint
|
||||
CREATE INDEX "idx_risk_showstopper" ON "risk" USING btree ("showstopper");--> statement-breakpoint
|
||||
CREATE INDEX "idx_stakeholder_project" ON "stakeholder" USING btree ("project_id");
|
||||
@@ -0,0 +1,49 @@
|
||||
CREATE TABLE "change_entry" (
|
||||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||
"project_id" uuid NOT NULL,
|
||||
"titel" text NOT NULL,
|
||||
"auswirkung" text,
|
||||
"entscheidung" text DEFAULT 'offen' NOT NULL,
|
||||
"created_by" uuid,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "phase_gate" (
|
||||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||
"project_id" uuid NOT NULL,
|
||||
"phase" text NOT NULL,
|
||||
"ergebnis_erreicht" boolean NOT NULL,
|
||||
"notiz" text,
|
||||
"reviewed_by" uuid,
|
||||
"reviewed_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "project_status" (
|
||||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||
"project_id" uuid NOT NULL,
|
||||
"ampel" text NOT NULL,
|
||||
"trend" text,
|
||||
"text" text,
|
||||
"extern_sichtbar" boolean DEFAULT false NOT NULL,
|
||||
"created_by" uuid,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "project" ADD COLUMN "ziel" text;--> statement-breakpoint
|
||||
ALTER TABLE "project" ADD COLUMN "nicht_ziele" text;--> statement-breakpoint
|
||||
ALTER TABLE "project" ADD COLUMN "liefergegenstaende" text;--> statement-breakpoint
|
||||
ALTER TABLE "project" ADD COLUMN "zieldreieck_flex" text;--> statement-breakpoint
|
||||
ALTER TABLE "project" ADD COLUMN "phase" text DEFAULT 'definition' NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "project" ADD COLUMN "abschlussvermerk" text;--> statement-breakpoint
|
||||
ALTER TABLE "risk" ADD COLUMN "strategie" text;--> statement-breakpoint
|
||||
ALTER TABLE "risk" ADD COLUMN "owner_user_id" uuid;--> statement-breakpoint
|
||||
ALTER TABLE "change_entry" ADD CONSTRAINT "change_entry_project_id_project_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."project"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "change_entry" ADD CONSTRAINT "change_entry_created_by_user_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "phase_gate" ADD CONSTRAINT "phase_gate_project_id_project_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."project"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "phase_gate" ADD CONSTRAINT "phase_gate_reviewed_by_user_id_fk" FOREIGN KEY ("reviewed_by") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "project_status" ADD CONSTRAINT "project_status_project_id_project_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."project"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "project_status" ADD CONSTRAINT "project_status_created_by_user_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX "idx_change_entry_project" ON "change_entry" USING btree ("project_id");--> statement-breakpoint
|
||||
CREATE INDEX "idx_phase_gate_project" ON "phase_gate" USING btree ("project_id");--> statement-breakpoint
|
||||
CREATE INDEX "idx_project_status_project" ON "project_status" USING btree ("project_id");--> statement-breakpoint
|
||||
ALTER TABLE "risk" ADD CONSTRAINT "risk_owner_user_id_user_id_fk" FOREIGN KEY ("owner_user_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -57,6 +57,27 @@
|
||||
"when": 1780415208906,
|
||||
"tag": "0007_project_description",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 8,
|
||||
"version": "7",
|
||||
"when": 1780577284868,
|
||||
"tag": "0008_lead_crm",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 9,
|
||||
"version": "7",
|
||||
"when": 1780669990802,
|
||||
"tag": "0009_pm_insights",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 10,
|
||||
"version": "7",
|
||||
"when": 1780672129310,
|
||||
"tag": "0010_leitfaden_phases",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -125,11 +125,27 @@ export const project = pgTable(
|
||||
.references(() => area.id, { onDelete: 'restrict' }),
|
||||
name: text('name').notNull(),
|
||||
description: text('description'),
|
||||
// Maxime / roter Faden (ein Satz) — Leitsatz fürs ganze Team (Buch Kap. 4 Strategie).
|
||||
maxime: text('maxime'),
|
||||
// Definition (Leitfaden Phase 1) — Kurzfassung; Volltext-Steckbrief lebt in Outline.
|
||||
ziel: text('ziel'), // SMART formuliert
|
||||
nichtZiele: text('nicht_ziele'), // Scope-Schutz
|
||||
liefergegenstaende: text('liefergegenstaende'),
|
||||
// Zieldreieck (Leitfaden Kap. 1): welche Ecke gibt zuerst nach, wenn es eng wird.
|
||||
zieldreieckFlex: text('zieldreieck_flex', { enum: ['leistung', 'zeit', 'aufwand'] }),
|
||||
kind: text('kind', { enum: ['kundenprojekt', 'internes_projekt'] }).notNull(),
|
||||
verantwortlicheUserId: uuid('verantwortliche_user_id').references(() => user.id, {
|
||||
onDelete: 'set null',
|
||||
}),
|
||||
arbeitsmodus: text('arbeitsmodus', { enum: ['cycle', 'kanban'] }),
|
||||
// Projekt-Modus / Intensität — muss laut Buch jederzeit ans Team kommuniziert sein.
|
||||
modus: text('modus', { enum: ['relax', 'standard', 'eskalation', 'taskforce'] })
|
||||
.notNull()
|
||||
.default('standard'),
|
||||
// Projektlebenszyklus (Leitfaden Kap. 2): aktuelle Phase.
|
||||
phase: text('phase', { enum: ['definition', 'planung', 'umsetzung', 'abschluss'] })
|
||||
.notNull()
|
||||
.default('definition'),
|
||||
outlineSteckbriefUrl: text('outline_steckbrief_url'),
|
||||
steckbriefFreigegeben: boolean('steckbrief_freigegeben').notNull().default(false),
|
||||
planeProjectUrl: text('plane_project_url'),
|
||||
@@ -146,6 +162,8 @@ export const project = pgTable(
|
||||
archiviert: boolean('archiviert').notNull().default(false),
|
||||
archiviertAm: timestamp('archiviert_am', { withTimezone: true }),
|
||||
lessonsLearnedUrl: text('lessons_learned_url'),
|
||||
// Abschluss (Leitfaden Phase 4): kurzer Abschlussvermerk — Ziel erreicht? Aufwand vs. Plan?
|
||||
abschlussvermerk: text('abschlussvermerk'),
|
||||
createdBy: uuid('created_by').references(() => user.id, { onDelete: 'set null' }),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
@@ -174,6 +192,9 @@ export const milestone = pgTable(
|
||||
.notNull()
|
||||
.default('open'),
|
||||
description: text('description'),
|
||||
// Ergebnis-Übersicht („Patchnotes") + konkreter Kundennutzen je Meilenstein (Buch Kap. 4).
|
||||
ergebnis: text('ergebnis'),
|
||||
kundennutzen: text('kundennutzen'),
|
||||
order: integer('order').notNull().default(0),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
@@ -429,6 +450,294 @@ export const blocker = pgTable(
|
||||
}),
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// lead — qualitatives Vertriebs-Dossier (CRM). Reicher als `deal`: Stammdaten,
|
||||
// Pain, Geschäftliches, Soft Factors, Strategie. Ein Lead kann optional zu einem
|
||||
// Pipeline-`deal` promoted werden (promoted_deal_id). Spiegelt die interne
|
||||
// Lead-Schablone (9 Abschnitte).
|
||||
// ----------------------------------------------------------------------------
|
||||
export const lead = pgTable(
|
||||
'lead',
|
||||
{
|
||||
id: uuid('id')
|
||||
.default(sql`gen_random_uuid()`)
|
||||
.primaryKey(),
|
||||
areaId: uuid('area_id')
|
||||
.notNull()
|
||||
.references(() => area.id, { onDelete: 'restrict' }),
|
||||
// 1. Stammdaten
|
||||
firma: text('firma').notNull(),
|
||||
status: text('status', { enum: ['cold', 'warm', 'hot', 'won', 'lost'] })
|
||||
.notNull()
|
||||
.default('cold'),
|
||||
score: integer('score').notNull().default(0), // 0-10
|
||||
ownerUserId: uuid('owner_user_id').references(() => user.id, { onDelete: 'set null' }),
|
||||
branche: text('branche'),
|
||||
subSegment: text('sub_segment'), // Nische
|
||||
standorte: text('standorte'),
|
||||
mitarbeiterzahl: text('mitarbeiterzahl'),
|
||||
umsatz: text('umsatz'),
|
||||
website: text('website'),
|
||||
quelle: text('quelle'), // wie auf uns aufmerksam / wie gefunden
|
||||
// 3. Pain & Bedarf
|
||||
painPoint: text('pain_point'),
|
||||
statusQuoKosten: text('status_quo_kosten'),
|
||||
bestehendeLoesung: text('bestehende_loesung'),
|
||||
wechselgrund: text('wechselgrund'),
|
||||
persoenlicherErfolg: text('persoenlicher_erfolg'),
|
||||
// 4. Geschäftliches
|
||||
budgetIndikation: text('budget_indikation'),
|
||||
entscheidungshorizont: text('entscheidungshorizont'),
|
||||
compellingEvent: text('compelling_event'),
|
||||
mitbewerber: text('mitbewerber'),
|
||||
buyingCenter: text('buying_center'),
|
||||
beschaffungsweg: text('beschaffungsweg'),
|
||||
// 5. Soft Factors
|
||||
kommunikationsstil: text('kommunikationsstil'),
|
||||
vorlieben: text('vorlieben'),
|
||||
hotButtons: text('hot_buttons'),
|
||||
noGos: text('no_gos'),
|
||||
druckpunkte: text('druckpunkte'),
|
||||
anker: text('anker'),
|
||||
vertrauenslevel: integer('vertrauenslevel'), // 1-5, nullable
|
||||
// 6. Strategie
|
||||
nutzenHypothese: text('nutzen_hypothese'),
|
||||
differenzierer: text('differenzierer'),
|
||||
naechsterSchritt: text('naechster_schritt'),
|
||||
naechsterSchrittDatum: date('naechster_schritt_datum'),
|
||||
risiken: text('risiken'),
|
||||
planB: text('plan_b'),
|
||||
// 8. Offene Fragen / 9. Anhänge (leichtgewichtige Listen als JSONB)
|
||||
offeneFragen: jsonb('offene_fragen')
|
||||
.$type<Array<{ text: string; done: boolean }>>()
|
||||
.notNull()
|
||||
.default([]),
|
||||
anhaenge: jsonb('anhaenge')
|
||||
.$type<Array<{ label: string; url: string }>>()
|
||||
.notNull()
|
||||
.default([]),
|
||||
// Promotion → Pipeline-Deal
|
||||
promotedDealId: uuid('promoted_deal_id').references(() => deal.id, { onDelete: 'set null' }),
|
||||
createdBy: uuid('created_by').references(() => user.id, { onDelete: 'set null' }),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(t) => ({
|
||||
idxStatus: index('idx_lead_status').on(t.status),
|
||||
idxOwner: index('idx_lead_owner').on(t.ownerUserId),
|
||||
}),
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// lead_contact — Kontaktperson(en) eines Leads (Schablone Abschnitt 2).
|
||||
// ----------------------------------------------------------------------------
|
||||
export const leadContact = pgTable(
|
||||
'lead_contact',
|
||||
{
|
||||
id: uuid('id')
|
||||
.default(sql`gen_random_uuid()`)
|
||||
.primaryKey(),
|
||||
leadId: uuid('lead_id')
|
||||
.notNull()
|
||||
.references(() => lead.id, { onDelete: 'cascade' }),
|
||||
name: text('name').notNull(),
|
||||
rolle: text('rolle'), // Rolle / Titel
|
||||
funktion: text('funktion', {
|
||||
enum: ['entscheider', 'influencer', 'gatekeeper', 'end_user', 'champion'],
|
||||
}),
|
||||
email: text('email'),
|
||||
telefon: text('telefon'),
|
||||
linkedin: text('linkedin'),
|
||||
imBuyingCenterSeit: text('im_buying_center_seit'),
|
||||
sprache: text('sprache'), // Sprache / bevorzugte Anrede
|
||||
isPrimary: boolean('is_primary').notNull().default(false),
|
||||
order: integer('order').notNull().default(0),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(t) => ({
|
||||
idxLead: index('idx_lead_contact_lead').on(t.leadId),
|
||||
}),
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// lead_touchpoint — Austausch-Log (Schablone Abschnitt 7). Jeder Kontakt eine Zeile.
|
||||
// ----------------------------------------------------------------------------
|
||||
export const leadTouchpoint = pgTable(
|
||||
'lead_touchpoint',
|
||||
{
|
||||
id: uuid('id')
|
||||
.default(sql`gen_random_uuid()`)
|
||||
.primaryKey(),
|
||||
leadId: uuid('lead_id')
|
||||
.notNull()
|
||||
.references(() => lead.id, { onDelete: 'cascade' }),
|
||||
datum: date('datum').notNull(),
|
||||
kanal: text('kanal', {
|
||||
enum: ['call', 'mail', 'linkedin', 'termin', 'event', 'sonstiges'],
|
||||
}).notNull(),
|
||||
bearbeiterUserId: uuid('bearbeiter_user_id').references(() => user.id, { onDelete: 'set null' }),
|
||||
inhalt: text('inhalt').notNull(),
|
||||
outcome: text('outcome'),
|
||||
followUpBis: date('follow_up_bis'),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(t) => ({
|
||||
idxLead: index('idx_lead_touchpoint_lead').on(t.leadId),
|
||||
idxFollowUp: index('idx_lead_touchpoint_followup').on(t.followUpBis),
|
||||
}),
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// stakeholder — Stakeholder-Analyse pro Projekt (Buch Kap. 4). Interesse ×
|
||||
// Einfluss ergibt die Macht/Interesse-Matrix; Haltung = Grundeinstellung.
|
||||
// ----------------------------------------------------------------------------
|
||||
export const stakeholder = pgTable(
|
||||
'stakeholder',
|
||||
{
|
||||
id: uuid('id')
|
||||
.default(sql`gen_random_uuid()`)
|
||||
.primaryKey(),
|
||||
projectId: uuid('project_id')
|
||||
.notNull()
|
||||
.references(() => project.id, { onDelete: 'cascade' }),
|
||||
name: text('name').notNull(),
|
||||
rolle: text('rolle'),
|
||||
interesse: text('interesse', { enum: ['niedrig', 'mittel', 'hoch'] })
|
||||
.notNull()
|
||||
.default('mittel'),
|
||||
einfluss: text('einfluss', { enum: ['niedrig', 'mittel', 'hoch'] })
|
||||
.notNull()
|
||||
.default('mittel'),
|
||||
haltung: text('haltung', { enum: ['pro', 'neutral', 'contra'] })
|
||||
.notNull()
|
||||
.default('neutral'),
|
||||
beduerfnis: text('beduerfnis'), // Was braucht die Person, in welcher Priorität?
|
||||
notiz: text('notiz'),
|
||||
order: integer('order').notNull().default(0),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(t) => ({
|
||||
idxProject: index('idx_stakeholder_project').on(t.projectId),
|
||||
}),
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// risk — Risiko- & Chancen-Register pro Projekt (Buch Kap. 4). `kind`
|
||||
// unterscheidet Gefahr vs. Chance. Showstopper = bringt das Projekt zum Stillstand.
|
||||
// ----------------------------------------------------------------------------
|
||||
export const risk = pgTable(
|
||||
'risk',
|
||||
{
|
||||
id: uuid('id')
|
||||
.default(sql`gen_random_uuid()`)
|
||||
.primaryKey(),
|
||||
projectId: uuid('project_id')
|
||||
.notNull()
|
||||
.references(() => project.id, { onDelete: 'cascade' }),
|
||||
kind: text('kind', { enum: ['risiko', 'chance'] })
|
||||
.notNull()
|
||||
.default('risiko'),
|
||||
title: text('title').notNull(), // ausformulierter Satz
|
||||
wahrscheinlichkeit: text('wahrscheinlichkeit', { enum: ['niedrig', 'mittel', 'hoch'] })
|
||||
.notNull()
|
||||
.default('mittel'),
|
||||
auswirkung: text('auswirkung', { enum: ['niedrig', 'mittel', 'hoch'] })
|
||||
.notNull()
|
||||
.default('mittel'),
|
||||
herkunft: text('herkunft', { enum: ['intern', 'extern'] }),
|
||||
showstopper: boolean('showstopper').notNull().default(false),
|
||||
massnahme: text('massnahme'), // Gegenmaßnahme bzw. Nutzungsidee bei Chancen
|
||||
// Strategie (Leitfaden Kap. 4): vermeiden / verlagern / mindern / akzeptieren.
|
||||
strategie: text('strategie', { enum: ['vermeiden', 'verlagern', 'mindern', 'akzeptieren'] }),
|
||||
ownerUserId: uuid('owner_user_id').references(() => user.id, { onDelete: 'set null' }),
|
||||
status: text('status', { enum: ['offen', 'beobachtet', 'eingetreten', 'geschlossen'] })
|
||||
.notNull()
|
||||
.default('offen'),
|
||||
createdBy: uuid('created_by').references(() => user.id, { onDelete: 'set null' }),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(t) => ({
|
||||
idxProject: index('idx_risk_project').on(t.projectId),
|
||||
idxShowstopper: index('idx_risk_showstopper').on(t.showstopper),
|
||||
}),
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// project_status — Statusbericht pro Projekt (Leitfaden Kap. 5 „Status sichtbar
|
||||
// machen"): Ampel + Trend + 2-3 Sätze. Jüngster Eintrag speist statusCache.
|
||||
// ----------------------------------------------------------------------------
|
||||
export const projectStatus = pgTable(
|
||||
'project_status',
|
||||
{
|
||||
id: uuid('id')
|
||||
.default(sql`gen_random_uuid()`)
|
||||
.primaryKey(),
|
||||
projectId: uuid('project_id')
|
||||
.notNull()
|
||||
.references(() => project.id, { onDelete: 'cascade' }),
|
||||
ampel: text('ampel', { enum: ['green', 'amber', 'red'] }).notNull(),
|
||||
trend: text('trend', { enum: ['besser', 'gleich', 'schlechter'] }),
|
||||
text: text('text'), // 2-3 Sätze Erläuterung
|
||||
externSichtbar: boolean('extern_sichtbar').notNull().default(false),
|
||||
createdBy: uuid('created_by').references(() => user.id, { onDelete: 'set null' }),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(t) => ({
|
||||
idxProject: index('idx_project_status_project').on(t.projectId),
|
||||
}),
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// phase_gate — Gate-Review am Phasenende (Leitfaden Kap. 5 „Reviews an
|
||||
// Meilensteinen"): Ergebnis erreicht? Folgephase freigegeben?
|
||||
// ----------------------------------------------------------------------------
|
||||
export const phaseGate = pgTable(
|
||||
'phase_gate',
|
||||
{
|
||||
id: uuid('id')
|
||||
.default(sql`gen_random_uuid()`)
|
||||
.primaryKey(),
|
||||
projectId: uuid('project_id')
|
||||
.notNull()
|
||||
.references(() => project.id, { onDelete: 'cascade' }),
|
||||
phase: text('phase', { enum: ['definition', 'planung', 'umsetzung', 'abschluss'] }).notNull(),
|
||||
ergebnisErreicht: boolean('ergebnis_erreicht').notNull(),
|
||||
notiz: text('notiz'),
|
||||
reviewedBy: uuid('reviewed_by').references(() => user.id, { onDelete: 'set null' }),
|
||||
reviewedAt: timestamp('reviewed_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(t) => ({
|
||||
idxProject: index('idx_phase_gate_project').on(t.projectId),
|
||||
}),
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// change_entry — Änderungs-Log (Leitfaden Kap. 5 „Mit Änderungen umgehen"):
|
||||
// bewusste Entscheidung über Änderungen, die das Zieldreieck bewegen.
|
||||
// ----------------------------------------------------------------------------
|
||||
export const changeEntry = pgTable(
|
||||
'change_entry',
|
||||
{
|
||||
id: uuid('id')
|
||||
.default(sql`gen_random_uuid()`)
|
||||
.primaryKey(),
|
||||
projectId: uuid('project_id')
|
||||
.notNull()
|
||||
.references(() => project.id, { onDelete: 'cascade' }),
|
||||
titel: text('titel').notNull(),
|
||||
auswirkung: text('auswirkung'), // Auswirkung aufs Zieldreieck
|
||||
entscheidung: text('entscheidung', { enum: ['offen', 'genehmigt', 'abgelehnt'] })
|
||||
.notNull()
|
||||
.default('offen'),
|
||||
createdBy: uuid('created_by').references(() => user.id, { onDelete: 'set null' }),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(t) => ({
|
||||
idxProject: index('idx_change_entry_project').on(t.projectId),
|
||||
}),
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Type-Helper für Code, der mit den Entitäten arbeitet.
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -476,3 +785,27 @@ export type NewCampaign = typeof campaign.$inferInsert;
|
||||
|
||||
export type LeadHandover = typeof leadHandover.$inferSelect;
|
||||
export type NewLeadHandover = typeof leadHandover.$inferInsert;
|
||||
|
||||
export type Lead = typeof lead.$inferSelect;
|
||||
export type NewLead = typeof lead.$inferInsert;
|
||||
|
||||
export type LeadContact = typeof leadContact.$inferSelect;
|
||||
export type NewLeadContact = typeof leadContact.$inferInsert;
|
||||
|
||||
export type LeadTouchpoint = typeof leadTouchpoint.$inferSelect;
|
||||
export type NewLeadTouchpoint = typeof leadTouchpoint.$inferInsert;
|
||||
|
||||
export type Stakeholder = typeof stakeholder.$inferSelect;
|
||||
export type NewStakeholder = typeof stakeholder.$inferInsert;
|
||||
|
||||
export type Risk = typeof risk.$inferSelect;
|
||||
export type NewRisk = typeof risk.$inferInsert;
|
||||
|
||||
export type ProjectStatus = typeof projectStatus.$inferSelect;
|
||||
export type NewProjectStatus = typeof projectStatus.$inferInsert;
|
||||
|
||||
export type PhaseGate = typeof phaseGate.$inferSelect;
|
||||
export type NewPhaseGate = typeof phaseGate.$inferInsert;
|
||||
|
||||
export type ChangeEntry = typeof changeEntry.$inferSelect;
|
||||
export type NewChangeEntry = typeof changeEntry.$inferInsert;
|
||||
+218
-1
@@ -1,7 +1,7 @@
|
||||
// Seed-Skript: idempotent. Legt Areas, Test-Mitarbeiter (inkl. Admin Dejan) und
|
||||
// Dummy-Daten (Projekte, Deals, Kampagnen, Tageseinträge, Blocker) an.
|
||||
|
||||
import { sql } from 'drizzle-orm';
|
||||
import { sql, eq } from 'drizzle-orm';
|
||||
import { createDbClient } from './client.js';
|
||||
import {
|
||||
area,
|
||||
@@ -15,6 +15,13 @@ import {
|
||||
dayEntry,
|
||||
todo,
|
||||
blocker,
|
||||
lead,
|
||||
leadContact,
|
||||
leadTouchpoint,
|
||||
risk,
|
||||
stakeholder,
|
||||
projectStatus,
|
||||
changeEntry,
|
||||
} from './schema.js';
|
||||
|
||||
const AREAS = [
|
||||
@@ -366,6 +373,216 @@ export async function seed(connectionString: string): Promise<void> {
|
||||
]);
|
||||
}
|
||||
|
||||
// ----- Leads (CRM-Dossiers) -----
|
||||
const existingLeads = await db.select().from(lead);
|
||||
if (existingLeads.length === 0) {
|
||||
const sales = areaBySlug.vertrieb!;
|
||||
const [l1] = await db
|
||||
.insert(lead)
|
||||
.values({
|
||||
areaId: sales.id,
|
||||
firma: 'Alpenhof Hotels GmbH',
|
||||
status: 'hot',
|
||||
score: 8,
|
||||
ownerUserId: anna.id,
|
||||
branche: 'Hotellerie',
|
||||
subSegment: 'Internationale/deutsche Hotelketten',
|
||||
standorte: 'München, Wien, Zürich',
|
||||
mitarbeiterzahl: '350+',
|
||||
umsatz: '~ 80 Mio € (2025)',
|
||||
website: 'https://alpenhof-hotels.example',
|
||||
quelle: 'LinkedIn-Profil im MitApp-Verzeichnis',
|
||||
painPoint:
|
||||
'Projektmanagement-Workflows laufen über zig Excel-Listen, nichts ist zentral. Onboarding neuer Häuser dauert ewig.',
|
||||
statusQuoKosten: 'Mehrere Personentage pro Woche an manueller Koordination.',
|
||||
bestehendeLoesung: 'Excel + E-Mail, vereinzelt Trello',
|
||||
wechselgrund: 'Skaliert nicht mit dem Wachstum, zu fehleranfällig.',
|
||||
persoenlicherErfolg: 'Will als Onboarding-Manager sichtbar Zeit einsparen und entlasten.',
|
||||
budgetIndikation: 'noch offen, vermutlich 5-stellig p.a.',
|
||||
entscheidungshorizont: 'Q3',
|
||||
compellingEvent: 'Zwei neue Häuser kommen im Herbst dazu.',
|
||||
mitbewerber: 'keine konkret bekannt',
|
||||
buyingCenter: 'Onboarding-Manager (Champion), COO (Entscheider)',
|
||||
beschaffungsweg: 'direkt',
|
||||
kommunikationsstil: 'freundlich, pragmatisch, mag konkrete Beispiele',
|
||||
hotButtons: 'Zeitersparnis, weniger manuelle Pflege, KI-Unterstützung',
|
||||
nutzenHypothese:
|
||||
'KI-gestützte PM-Workflows sparen dem Onboarding-Team messbar Zeit bei jedem neuen Haus.',
|
||||
differenzierer: 'Eigene Erfahrung in genau dieser Nische + KI-/Prozessautomatisierung.',
|
||||
naechsterSchritt: 'Discovery-Call vereinbaren',
|
||||
naechsterSchrittDatum: isoDateOffset(4),
|
||||
vertrauenslevel: 3,
|
||||
offeneFragen: [
|
||||
{ text: 'Wer hält das Budget?', done: false },
|
||||
{ text: 'Welche Tools sind heute schon im Einsatz?', done: true },
|
||||
],
|
||||
anhaenge: [],
|
||||
createdBy: anna.id,
|
||||
})
|
||||
.returning();
|
||||
|
||||
if (l1) {
|
||||
await db.insert(leadContact).values({
|
||||
leadId: l1.id,
|
||||
name: 'Sascha Haiss',
|
||||
rolle: 'Onboarding Manager',
|
||||
funktion: 'champion',
|
||||
linkedin: 'https://www.linkedin.com/in/example',
|
||||
sprache: 'Deutsch, per Du',
|
||||
isPrimary: true,
|
||||
order: 0,
|
||||
});
|
||||
await db.insert(leadTouchpoint).values([
|
||||
{
|
||||
leadId: l1.id,
|
||||
datum: pickWerktag(2),
|
||||
kanal: 'linkedin',
|
||||
bearbeiterUserId: anna.id,
|
||||
inhalt: 'Erste Nachricht über das MitApp-Profil geschickt, Bezug auf KI-Optimierung für PM.',
|
||||
outcome: 'positiv geantwortet, Interesse an kurzem Austausch',
|
||||
followUpBis: isoDateOffset(4),
|
||||
},
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// ----- Risiken / Chancen / Stakeholder / Modus (PM-Insights) -----
|
||||
const existingRisks = await db.select().from(risk);
|
||||
if (existingRisks.length === 0) {
|
||||
const someProject = (await db.select().from(project).orderBy(project.createdAt).limit(1))[0];
|
||||
if (someProject) {
|
||||
await db
|
||||
.update(project)
|
||||
.set({
|
||||
modus: 'eskalation',
|
||||
maxime: someProject.maxime ?? 'Pilot ohne Scope-Creep bis zum Stichtag liefern.',
|
||||
})
|
||||
.where(eq(project.id, someProject.id));
|
||||
|
||||
await db.insert(risk).values([
|
||||
{
|
||||
projectId: someProject.id,
|
||||
kind: 'risiko',
|
||||
title: 'Kunde liefert die Stripe-Account-Daten nicht rechtzeitig.',
|
||||
wahrscheinlichkeit: 'hoch',
|
||||
auswirkung: 'hoch',
|
||||
herkunft: 'extern',
|
||||
showstopper: true,
|
||||
massnahme: 'Eskalation an Kundenkontakt, Deadline schriftlich fixieren.',
|
||||
status: 'offen',
|
||||
createdBy: dejan.id,
|
||||
},
|
||||
{
|
||||
projectId: someProject.id,
|
||||
kind: 'risiko',
|
||||
title: 'Interne Ressourcen werden für ein anderes Projekt abgezogen.',
|
||||
wahrscheinlichkeit: 'mittel',
|
||||
auswirkung: 'hoch',
|
||||
herkunft: 'intern',
|
||||
massnahme: 'Kapazität mit der Geschäftsführung absichern.',
|
||||
status: 'beobachtet',
|
||||
createdBy: dejan.id,
|
||||
},
|
||||
{
|
||||
projectId: someProject.id,
|
||||
kind: 'chance',
|
||||
title: 'Kunde will bei Erfolg weitere Standorte anbinden.',
|
||||
wahrscheinlichkeit: 'mittel',
|
||||
auswirkung: 'hoch',
|
||||
massnahme: 'Pilot als Referenz sauber dokumentieren.',
|
||||
status: 'offen',
|
||||
createdBy: dejan.id,
|
||||
},
|
||||
]);
|
||||
|
||||
await db.insert(stakeholder).values([
|
||||
{
|
||||
projectId: someProject.id,
|
||||
name: 'GF Schmidt',
|
||||
rolle: 'Auftraggeber',
|
||||
interesse: 'hoch',
|
||||
einfluss: 'hoch',
|
||||
haltung: 'pro',
|
||||
beduerfnis: 'Pünktlicher Go-Live, klare Status-Reports',
|
||||
order: 0,
|
||||
},
|
||||
{
|
||||
projectId: someProject.id,
|
||||
name: 'IT-Abteilung Kunde',
|
||||
rolle: 'Technik',
|
||||
interesse: 'mittel',
|
||||
einfluss: 'hoch',
|
||||
haltung: 'neutral',
|
||||
beduerfnis: 'Saubere Schnittstellen, wenig Mehraufwand',
|
||||
order: 1,
|
||||
},
|
||||
{
|
||||
projectId: someProject.id,
|
||||
name: 'Sachbearbeitung',
|
||||
rolle: 'End-User',
|
||||
interesse: 'hoch',
|
||||
einfluss: 'niedrig',
|
||||
haltung: 'pro',
|
||||
beduerfnis: 'Einfaches, schnelles Auftragsformular',
|
||||
order: 2,
|
||||
},
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// ----- Statusbericht / Phase / Definition / Änderung (Leitfaden) -----
|
||||
const existingStatus = await db.select().from(projectStatus);
|
||||
if (existingStatus.length === 0) {
|
||||
const someProject = (await db.select().from(project).orderBy(project.createdAt).limit(1))[0];
|
||||
if (someProject) {
|
||||
await db
|
||||
.update(project)
|
||||
.set({
|
||||
phase: 'umsetzung',
|
||||
ziel:
|
||||
someProject.ziel ??
|
||||
'Auftragsportal live bis 30.09., mind. 3 Auftragstypen, vom Kunden abgenommen.',
|
||||
nichtZiele:
|
||||
someProject.nichtZiele ??
|
||||
'Keine Migration der Altbestellungen. Keine mobile App in dieser Phase.',
|
||||
liefergegenstaende:
|
||||
someProject.liefergegenstaende ??
|
||||
'Portal-Frontend, Stripe-Anbindung, Admin-Übersicht, Schulungsunterlagen.',
|
||||
zieldreieckFlex: someProject.zieldreieckFlex ?? 'aufwand',
|
||||
statusCache: 'amber',
|
||||
trendCache: 'gleich',
|
||||
})
|
||||
.where(eq(project.id, someProject.id));
|
||||
|
||||
await db.insert(projectStatus).values([
|
||||
{
|
||||
projectId: someProject.id,
|
||||
ampel: 'green',
|
||||
trend: 'besser',
|
||||
text: 'Setup steht, erste Auftragstypen umgesetzt. Im Plan.',
|
||||
externSichtbar: true,
|
||||
createdBy: dejan.id,
|
||||
},
|
||||
{
|
||||
projectId: someProject.id,
|
||||
ampel: 'amber',
|
||||
trend: 'gleich',
|
||||
text: 'Stripe-Zugang vom Kunden noch offen — gefährdet den Pilottermin. Maßnahme läuft.',
|
||||
externSichtbar: true,
|
||||
createdBy: dejan.id,
|
||||
},
|
||||
]);
|
||||
|
||||
await db.insert(changeEntry).values({
|
||||
projectId: someProject.id,
|
||||
titel: 'Kunde wünscht zusätzlichen Auftragstyp „Express".',
|
||||
auswirkung: 'Mehr Umfang → Aufwand steigt, Termin gefährdet.',
|
||||
entscheidung: 'offen',
|
||||
createdBy: dejan.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await db.update(user).set({ updatedAt: new Date() }).where(sql`true`);
|
||||
} finally {
|
||||
await pool.end();
|
||||
|
||||
@@ -4,5 +4,9 @@ export * as ProjectSchemas from './schemas/project.js';
|
||||
export * as DealSchemas from './schemas/deal.js';
|
||||
export * as CampaignSchemas from './schemas/campaign.js';
|
||||
export * as TimeEntrySchemas from './schemas/time-entry.js';
|
||||
export * as LeadSchemas from './schemas/lead.js';
|
||||
export * as RiskSchemas from './schemas/risk.js';
|
||||
export * as StakeholderSchemas from './schemas/stakeholder.js';
|
||||
export * as ChangeSchemas from './schemas/change.js';
|
||||
|
||||
export const SHARED_VERSION = '0.0.3';
|
||||
export const SHARED_VERSION = '0.0.6';
|
||||
@@ -0,0 +1,24 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const changeEntscheidungSchema = z.enum(['offen', 'genehmigt', 'abgelehnt']);
|
||||
export const CHANGE_ENTSCHEIDUNGEN = changeEntscheidungSchema.options;
|
||||
|
||||
export const changeForProjectInput = z.object({ projectId: z.string().uuid() });
|
||||
|
||||
export const createChangeInput = z.object({
|
||||
projectId: z.string().uuid(),
|
||||
titel: z.string().min(1).max(300),
|
||||
auswirkung: z.string().max(1000).optional(),
|
||||
entscheidung: changeEntscheidungSchema.default('offen'),
|
||||
});
|
||||
export type CreateChangeInput = z.infer<typeof createChangeInput>;
|
||||
|
||||
export const updateChangeInput = z.object({
|
||||
id: z.string().uuid(),
|
||||
titel: z.string().min(1).max(300).optional(),
|
||||
auswirkung: z.string().max(1000).nullable().optional(),
|
||||
entscheidung: changeEntscheidungSchema.optional(),
|
||||
});
|
||||
export type UpdateChangeInput = z.infer<typeof updateChangeInput>;
|
||||
|
||||
export const removeChangeInput = z.object({ id: z.string().uuid() });
|
||||
@@ -51,6 +51,12 @@ export const todoMutationInput = z.object({
|
||||
});
|
||||
export type TodoMutationInput = z.infer<typeof todoMutationInput>;
|
||||
|
||||
export const editTodoTitleInput = z.object({
|
||||
todoId: z.string().uuid(),
|
||||
title: z.string().min(1).max(200),
|
||||
});
|
||||
export type EditTodoTitleInput = z.infer<typeof editTodoTitleInput>;
|
||||
|
||||
export const markAbsentInput = z.object({
|
||||
from: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
||||
to: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
// Status & Enums --------------------------------------------------------------
|
||||
export const leadStatusSchema = z.enum(['cold', 'warm', 'hot', 'won', 'lost']);
|
||||
export const LEAD_STATUSES = leadStatusSchema.options;
|
||||
|
||||
export const contactFunktionSchema = z.enum([
|
||||
'entscheider',
|
||||
'influencer',
|
||||
'gatekeeper',
|
||||
'end_user',
|
||||
'champion',
|
||||
]);
|
||||
export const CONTACT_FUNKTIONEN = contactFunktionSchema.options;
|
||||
|
||||
export const touchpointKanalSchema = z.enum([
|
||||
'call',
|
||||
'mail',
|
||||
'linkedin',
|
||||
'termin',
|
||||
'event',
|
||||
'sonstiges',
|
||||
]);
|
||||
export const TOUCHPOINT_KANAELE = touchpointKanalSchema.options;
|
||||
|
||||
// JSONB-Substrukturen ---------------------------------------------------------
|
||||
export const offeneFrageSchema = z.object({
|
||||
text: z.string().min(1).max(500),
|
||||
done: z.boolean(),
|
||||
});
|
||||
export const anhangSchema = z.object({
|
||||
label: z.string().min(1).max(200),
|
||||
url: z.string().min(1).max(2000),
|
||||
});
|
||||
|
||||
// Lead-Kernfelder (alle optional außer firma). Wird für create + update genutzt.
|
||||
const leadCoreFields = {
|
||||
firma: z.string().min(1).max(200),
|
||||
status: leadStatusSchema,
|
||||
score: z.number().int().min(0).max(10),
|
||||
ownerUserId: z.string().uuid().nullable(),
|
||||
branche: z.string().max(200).nullable(),
|
||||
subSegment: z.string().max(200).nullable(),
|
||||
standorte: z.string().max(500).nullable(),
|
||||
mitarbeiterzahl: z.string().max(100).nullable(),
|
||||
umsatz: z.string().max(100).nullable(),
|
||||
website: z.string().max(500).nullable(),
|
||||
quelle: z.string().max(500).nullable(),
|
||||
painPoint: z.string().max(2000).nullable(),
|
||||
statusQuoKosten: z.string().max(2000).nullable(),
|
||||
bestehendeLoesung: z.string().max(1000).nullable(),
|
||||
wechselgrund: z.string().max(2000).nullable(),
|
||||
persoenlicherErfolg: z.string().max(2000).nullable(),
|
||||
budgetIndikation: z.string().max(500).nullable(),
|
||||
entscheidungshorizont: z.string().max(500).nullable(),
|
||||
compellingEvent: z.string().max(1000).nullable(),
|
||||
mitbewerber: z.string().max(1000).nullable(),
|
||||
buyingCenter: z.string().max(1000).nullable(),
|
||||
beschaffungsweg: z.string().max(500).nullable(),
|
||||
kommunikationsstil: z.string().max(1000).nullable(),
|
||||
vorlieben: z.string().max(1000).nullable(),
|
||||
hotButtons: z.string().max(1000).nullable(),
|
||||
noGos: z.string().max(1000).nullable(),
|
||||
druckpunkte: z.string().max(1000).nullable(),
|
||||
anker: z.string().max(1000).nullable(),
|
||||
vertrauenslevel: z.number().int().min(1).max(5).nullable(),
|
||||
nutzenHypothese: z.string().max(1000).nullable(),
|
||||
differenzierer: z.string().max(1000).nullable(),
|
||||
naechsterSchritt: z.string().max(1000).nullable(),
|
||||
naechsterSchrittDatum: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).nullable(),
|
||||
risiken: z.string().max(1000).nullable(),
|
||||
planB: z.string().max(1000).nullable(),
|
||||
offeneFragen: z.array(offeneFrageSchema).max(100),
|
||||
anhaenge: z.array(anhangSchema).max(50),
|
||||
};
|
||||
|
||||
// Create: nur firma ist Pflicht, Rest optional mit sinnvollen Defaults.
|
||||
export const createLeadInput = z.object({
|
||||
firma: leadCoreFields.firma,
|
||||
status: leadStatusSchema.default('cold'),
|
||||
score: z.number().int().min(0).max(10).default(0),
|
||||
ownerUserId: z.string().uuid().optional(),
|
||||
branche: z.string().max(200).optional(),
|
||||
subSegment: z.string().max(200).optional(),
|
||||
website: z.string().max(500).optional(),
|
||||
quelle: z.string().max(500).optional(),
|
||||
});
|
||||
export type CreateLeadInput = z.infer<typeof createLeadInput>;
|
||||
|
||||
// Update: id + beliebige Teilmenge der Kernfelder (partial patch).
|
||||
export const updateLeadInput = z
|
||||
.object({ id: z.string().uuid() })
|
||||
.merge(z.object(leadCoreFields).partial());
|
||||
export type UpdateLeadInput = z.infer<typeof updateLeadInput>;
|
||||
|
||||
export const leadIdInput = z.object({ id: z.string().uuid() });
|
||||
|
||||
// Kontakte --------------------------------------------------------------------
|
||||
export const addContactInput = z.object({
|
||||
leadId: z.string().uuid(),
|
||||
name: z.string().min(1).max(200),
|
||||
rolle: z.string().max(200).optional(),
|
||||
funktion: contactFunktionSchema.optional(),
|
||||
email: z.string().max(320).optional(),
|
||||
telefon: z.string().max(100).optional(),
|
||||
linkedin: z.string().max(500).optional(),
|
||||
imBuyingCenterSeit: z.string().max(100).optional(),
|
||||
sprache: z.string().max(100).optional(),
|
||||
isPrimary: z.boolean().default(false),
|
||||
});
|
||||
export type AddContactInput = z.infer<typeof addContactInput>;
|
||||
|
||||
export const removeContactInput = z.object({ contactId: z.string().uuid() });
|
||||
|
||||
// Touchpoints (Austausch-Log) -------------------------------------------------
|
||||
export const addTouchpointInput = z.object({
|
||||
leadId: z.string().uuid(),
|
||||
datum: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
||||
kanal: touchpointKanalSchema,
|
||||
inhalt: z.string().min(1).max(2000),
|
||||
outcome: z.string().max(1000).optional(),
|
||||
followUpBis: z
|
||||
.string()
|
||||
.regex(/^\d{4}-\d{2}-\d{2}$/)
|
||||
.optional(),
|
||||
});
|
||||
export type AddTouchpointInput = z.infer<typeof addTouchpointInput>;
|
||||
|
||||
export const removeTouchpointInput = z.object({ touchpointId: z.string().uuid() });
|
||||
|
||||
// Promotion → Pipeline-Deal ---------------------------------------------------
|
||||
export const promoteToDealInput = z.object({
|
||||
leadId: z.string().uuid(),
|
||||
valueEur: z.number().int().min(0).default(0),
|
||||
probability: z.number().int().min(0).max(100).default(50),
|
||||
});
|
||||
export type PromoteToDealInput = z.infer<typeof promoteToDealInput>;
|
||||
@@ -1,5 +1,8 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const ampelSchema = z.enum(['green', 'amber', 'red']);
|
||||
const trendSchema = z.enum(['besser', 'gleich', 'schlechter']);
|
||||
|
||||
export const createProjectInput = z.object({
|
||||
areaId: z.string().uuid(),
|
||||
name: z.string().min(1).max(200),
|
||||
@@ -36,11 +39,98 @@ export type CreateProjectInput = z.infer<typeof createProjectInput>;
|
||||
export const archiveProjectInput = z.object({
|
||||
projectId: z.string().uuid(),
|
||||
lessonsLearnedUrl: z.string().url(),
|
||||
abschlussvermerk: z.string().max(2000).optional(),
|
||||
});
|
||||
export type ArchiveProjectInput = z.infer<typeof archiveProjectInput>;
|
||||
|
||||
// --- Zieldreieck (Leitfaden Kap. 1) ----------------------------------------
|
||||
export const zieldreieckFlexSchema = z.enum(['leistung', 'zeit', 'aufwand']);
|
||||
|
||||
// --- Projektphasen + Gate-Review (Leitfaden Kap. 2 + 5) --------------------
|
||||
export const projectPhaseSchema = z.enum(['definition', 'planung', 'umsetzung', 'abschluss']);
|
||||
export const PROJECT_PHASES = projectPhaseSchema.options;
|
||||
|
||||
export const setPhaseInput = z.object({
|
||||
projectId: z.string().uuid(),
|
||||
phase: projectPhaseSchema,
|
||||
});
|
||||
export type SetPhaseInput = z.infer<typeof setPhaseInput>;
|
||||
|
||||
export const addPhaseGateInput = z.object({
|
||||
projectId: z.string().uuid(),
|
||||
phase: projectPhaseSchema,
|
||||
ergebnisErreicht: z.boolean(),
|
||||
notiz: z.string().max(1000).optional(),
|
||||
advance: z.boolean().default(false), // Folgephase direkt freigeben
|
||||
});
|
||||
export type AddPhaseGateInput = z.infer<typeof addPhaseGateInput>;
|
||||
|
||||
export const phaseGatesInput = z.object({ projectId: z.string().uuid() });
|
||||
|
||||
// --- Projekt-Statusbericht (Leitfaden Kap. 5) ------------------------------
|
||||
export const addProjectStatusInput = z.object({
|
||||
projectId: z.string().uuid(),
|
||||
ampel: ampelSchema,
|
||||
trend: trendSchema.optional(),
|
||||
text: z.string().max(1000).optional(),
|
||||
externSichtbar: z.boolean().default(false),
|
||||
});
|
||||
export type AddProjectStatusInput = z.infer<typeof addProjectStatusInput>;
|
||||
|
||||
export const projectStatusHistoryInput = z.object({ projectId: z.string().uuid() });
|
||||
|
||||
export const setMilestoneStatusInput = z.object({
|
||||
milestoneId: z.string().uuid(),
|
||||
status: z.enum(['open', 'done', 'overdue']),
|
||||
});
|
||||
export type SetMilestoneStatusInput = z.infer<typeof setMilestoneStatusInput>;
|
||||
|
||||
// --- Projekt-Modus (Buch Kap. 4 Strategie) ---------------------------------
|
||||
export const projectModusSchema = z.enum(['relax', 'standard', 'eskalation', 'taskforce']);
|
||||
export const PROJECT_MODI = projectModusSchema.options;
|
||||
export const setModusInput = z.object({
|
||||
projectId: z.string().uuid(),
|
||||
modus: projectModusSchema,
|
||||
});
|
||||
export type SetModusInput = z.infer<typeof setModusInput>;
|
||||
|
||||
// --- Ziel-Disziplin: Maxime / Beschreibung / DoD editierbar ----------------
|
||||
export const updateProjectInput = z.object({
|
||||
projectId: z.string().uuid(),
|
||||
maxime: z.string().max(280).nullable().optional(),
|
||||
description: z.string().max(2000).nullable().optional(),
|
||||
dodText: z.string().max(2000).nullable().optional(),
|
||||
ziel: z.string().max(1000).nullable().optional(),
|
||||
nichtZiele: z.string().max(2000).nullable().optional(),
|
||||
liefergegenstaende: z.string().max(2000).nullable().optional(),
|
||||
zieldreieckFlex: zieldreieckFlexSchema.nullable().optional(),
|
||||
});
|
||||
export type UpdateProjectInput = z.infer<typeof updateProjectInput>;
|
||||
|
||||
// --- Meilenstein-Disziplin: anlegen, editieren, entfernen ------------------
|
||||
export const addMilestoneInput = z.object({
|
||||
projectId: z.string().uuid(),
|
||||
title: z.string().min(1).max(200),
|
||||
due: z
|
||||
.string()
|
||||
.regex(/^\d{4}-\d{2}-\d{2}$/)
|
||||
.optional(),
|
||||
});
|
||||
export type AddMilestoneInput = z.infer<typeof addMilestoneInput>;
|
||||
|
||||
export const updateMilestoneInput = z.object({
|
||||
milestoneId: z.string().uuid(),
|
||||
title: z.string().min(1).max(200).optional(),
|
||||
due: z
|
||||
.string()
|
||||
.regex(/^\d{4}-\d{2}-\d{2}$/)
|
||||
.nullable()
|
||||
.optional(),
|
||||
ergebnis: z.string().max(2000).nullable().optional(),
|
||||
kundennutzen: z.string().max(1000).nullable().optional(),
|
||||
status: z.enum(['open', 'done', 'overdue']).optional(),
|
||||
});
|
||||
export type UpdateMilestoneInput = z.infer<typeof updateMilestoneInput>;
|
||||
|
||||
export const removeMilestoneInput = z.object({ milestoneId: z.string().uuid() });
|
||||
export type RemoveMilestoneInput = z.infer<typeof removeMilestoneInput>;
|
||||
@@ -0,0 +1,43 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const riskKindSchema = z.enum(['risiko', 'chance']);
|
||||
export const riskLevelSchema = z.enum(['niedrig', 'mittel', 'hoch']);
|
||||
export const riskHerkunftSchema = z.enum(['intern', 'extern']);
|
||||
export const riskStatusSchema = z.enum(['offen', 'beobachtet', 'eingetreten', 'geschlossen']);
|
||||
export const RISK_STATUSES = riskStatusSchema.options;
|
||||
export const riskStrategieSchema = z.enum(['vermeiden', 'verlagern', 'mindern', 'akzeptieren']);
|
||||
export const RISK_STRATEGIEN = riskStrategieSchema.options;
|
||||
|
||||
export const riskForProjectInput = z.object({ projectId: z.string().uuid() });
|
||||
|
||||
export const createRiskInput = z.object({
|
||||
projectId: z.string().uuid(),
|
||||
kind: riskKindSchema.default('risiko'),
|
||||
title: z.string().min(1).max(500),
|
||||
wahrscheinlichkeit: riskLevelSchema.default('mittel'),
|
||||
auswirkung: riskLevelSchema.default('mittel'),
|
||||
herkunft: riskHerkunftSchema.optional(),
|
||||
showstopper: z.boolean().default(false),
|
||||
massnahme: z.string().max(1000).optional(),
|
||||
strategie: riskStrategieSchema.optional(),
|
||||
ownerUserId: z.string().uuid().optional(),
|
||||
status: riskStatusSchema.default('offen'),
|
||||
});
|
||||
export type CreateRiskInput = z.infer<typeof createRiskInput>;
|
||||
|
||||
export const updateRiskInput = z.object({
|
||||
id: z.string().uuid(),
|
||||
kind: riskKindSchema.optional(),
|
||||
title: z.string().min(1).max(500).optional(),
|
||||
wahrscheinlichkeit: riskLevelSchema.optional(),
|
||||
auswirkung: riskLevelSchema.optional(),
|
||||
herkunft: riskHerkunftSchema.nullable().optional(),
|
||||
showstopper: z.boolean().optional(),
|
||||
massnahme: z.string().max(1000).nullable().optional(),
|
||||
strategie: riskStrategieSchema.nullable().optional(),
|
||||
ownerUserId: z.string().uuid().nullable().optional(),
|
||||
status: riskStatusSchema.optional(),
|
||||
});
|
||||
export type UpdateRiskInput = z.infer<typeof updateRiskInput>;
|
||||
|
||||
export const removeRiskInput = z.object({ id: z.string().uuid() });
|
||||
@@ -0,0 +1,32 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const stakeholderLevelSchema = z.enum(['niedrig', 'mittel', 'hoch']);
|
||||
export const stakeholderHaltungSchema = z.enum(['pro', 'neutral', 'contra']);
|
||||
|
||||
export const stakeholderForProjectInput = z.object({ projectId: z.string().uuid() });
|
||||
|
||||
export const createStakeholderInput = z.object({
|
||||
projectId: z.string().uuid(),
|
||||
name: z.string().min(1).max(200),
|
||||
rolle: z.string().max(200).optional(),
|
||||
interesse: stakeholderLevelSchema.default('mittel'),
|
||||
einfluss: stakeholderLevelSchema.default('mittel'),
|
||||
haltung: stakeholderHaltungSchema.default('neutral'),
|
||||
beduerfnis: z.string().max(1000).optional(),
|
||||
notiz: z.string().max(1000).optional(),
|
||||
});
|
||||
export type CreateStakeholderInput = z.infer<typeof createStakeholderInput>;
|
||||
|
||||
export const updateStakeholderInput = z.object({
|
||||
id: z.string().uuid(),
|
||||
name: z.string().min(1).max(200).optional(),
|
||||
rolle: z.string().max(200).nullable().optional(),
|
||||
interesse: stakeholderLevelSchema.optional(),
|
||||
einfluss: stakeholderLevelSchema.optional(),
|
||||
haltung: stakeholderHaltungSchema.optional(),
|
||||
beduerfnis: z.string().max(1000).nullable().optional(),
|
||||
notiz: z.string().max(1000).nullable().optional(),
|
||||
});
|
||||
export type UpdateStakeholderInput = z.infer<typeof updateStakeholderInput>;
|
||||
|
||||
export const removeStakeholderInput = z.object({ id: z.string().uuid() });
|
||||
Reference in new issue
Block a user