Firmenkunden-CRM mit B2B-Patenschaften und Firmenportal

Admin: Firmen mit Vertriebsstufe und Wiedervorlage, Ansprechpartner mit
Einladung ins Portal, B2B-Patenschaften mit Lieferungen und Neuigkeiten,
private Dokumente, Notizen und Anfragen.
Portal unter /konto/firma: Patenschaften, Lieferungen, Neuigkeiten,
Dokument-Download und Anfrageformular.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
torbinus
2026-11-05 12:11:03 +01:00
parent 22d3e25fe2
commit 9b368f9b7a
37 changed files with 4727 additions and 0 deletions
+111
View File
@@ -0,0 +1,111 @@
import { medusaConfig, medusaFetch } from "./medusa";
/** Firmenportal: Daten des angemeldeten Firmenkunden. */
export interface B2bDelivery {
title: string;
quantity: string | null;
planned_at: string | null;
shipped_at: string | null;
tracking_number: string | null;
status: "planned" | "shipped" | "delivered";
}
export interface B2bReport {
id: string;
title: string;
body: string | null;
images: string[];
published_at: string;
}
export interface B2bSponsorship {
id: string;
title: string;
colonies: number;
location: string | null;
start_date: string | null;
end_date: string | null;
price: number | null;
status: "offer" | "active" | "renewal" | "ended";
deliveries: B2bDelivery[];
reports: B2bReport[];
}
export interface B2bDocument {
id: string;
title: string;
kind: "contract" | "certificate" | "invoice" | "offer" | "other";
file_name: string;
sponsorship_id: string | null;
created_at: string;
}
export interface B2bPortal {
company: { name: string; street: string | null; postal_code: string | null; city: string | null; vat_id: string | null };
contacts: { name: string; email: string; role: string | null; has_login: boolean }[];
sponsorships: B2bSponsorship[];
documents: B2bDocument[];
inquiries: { kind: string; colonies: number | null; message: string | null; status: "open" | "done"; created_at: string }[];
}
export const PATEN_STATUS: Record<string, string> = {
offer: "Angebot",
active: "Aktiv",
renewal: "Verlängerung steht an",
ended: "Beendet",
};
export const LIEFER_STATUS: Record<string, string> = {
planned: "Geplant",
shipped: "Versendet",
delivered: "Zugestellt",
};
export const DOKUMENT_ARTEN: Record<string, string> = {
contract: "Vertrag",
certificate: "Urkunde",
invoice: "Rechnung",
offer: "Angebot",
other: "Dokument",
};
export const ANFRAGE_ARTEN: Record<string, string> = {
new: "Neue Patenschaft",
more: "Mehr Völker",
other: "Sonstiges",
};
/** Portal-Daten, oder `null`, wenn das Konto zu keiner Firma gehört. */
export async function getMyCompany(token: string): Promise<B2bPortal | null> {
const { url, key } = medusaConfig();
const res = await fetch(`${url}/store/customers/me/b2b`, {
headers: { Authorization: `Bearer ${token}`, "x-publishable-api-key": key },
});
if (res.status === 404) return null;
if (!res.ok) throw new Error(`Firmenportal nicht ladbar (${res.status})`);
return res.json();
}
export async function getInvite(token: string): Promise<{ email: string; first_name: string | null; company: string } | null> {
try {
return await medusaFetch(`/store/b2b/invite?token=${encodeURIComponent(token)}`);
} catch {
return null;
}
}
export async function acceptInvite(token: string, password: string): Promise<{ email: string }> {
return medusaFetch("/store/b2b/invite", { method: "POST", body: JSON.stringify({ token, password }) });
}
export async function createInquiry(
token: string,
payload: { kind: string; colonies?: number | null; message?: string }
): Promise<void> {
await medusaFetch("/store/customers/me/b2b/inquiries", {
method: "POST",
headers: { Authorization: `Bearer ${token}` },
body: JSON.stringify(payload),
});
}