Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/routes/[_]dev.customer-portal-preview.settings.tsx
T

210 lines
6.3 KiB
TypeScript

import {
buildPortalDashboardVM,
buildPortalLifecycleVM,
buildPortalProjectDetailVM,
buildPortalProjectInteractionsVM,
buildPortalProjectListVM,
type PortalProjectInput,
} from "@hivegrid/view-models";
import { useSearchParams, type LoaderFunctionArgs } from "react-router";
import {
CustomerPortalDashboardPage,
CustomerPortalProjectDetailPage,
CustomerPortalProjectsPage,
CustomerPortalSettingsPage,
type PortalLifecyclePageActions,
} from "~/components/screens/customer-portal/CustomerPortalInterimPages";
const portalName = "Demo Pro CRM Kundenportal";
const viewerLabel = "Karla Kundin";
const previewProject: PortalProjectInput = {
id: "preview-project",
projectNumber: "P-2026-1042",
name: "Modernisierung Heizungsanlage",
updatedAt: "2026-07-22T08:30:00.000Z",
currentStageOrder: 20,
hasActiveAccess: true,
stages: [
{ id: "preview-stage-planning", label: "Planung", order: 10, visible: true },
{ id: "preview-stage-installation", label: "Montage", order: 20, visible: true },
{ id: "preview-stage-acceptance", label: "Abnahme", order: 30, visible: true },
],
documents: [
{
id: "preview-document",
name: "Montagefreigabe.pdf",
mimeType: "application/pdf",
releasedAt: "2026-07-22T07:45:00.000Z",
revokedAt: null,
downloadHref: "#preview-document",
},
],
};
const dashboardVm = buildPortalDashboardVM({
portalName,
viewerLabel,
frozen: false,
projects: [previewProject],
projectsHref: "?view=projects",
logoutAction: "#preview-logout",
buildProjectHref: () => "?view=project",
locale: "de-DE",
});
const projectsVm = buildPortalProjectListVM({
frozen: false,
projects: [previewProject],
dashboardHref: "?view=dashboard",
buildProjectHref: () => "?view=project",
locale: "de-DE",
});
const projectDetailVm = buildPortalProjectDetailVM({
frozen: false,
project: previewProject,
projectsHref: "?view=projects",
locale: "de-DE",
});
const interactionsVm = buildPortalProjectInteractionsVM({
hasActiveProjectAccess: true,
projectId: previewProject.id,
projectLabel: `${previewProject.projectNumber} · ${previewProject.name}`,
frozen: false,
viewerKind: "customer",
uploadAllowed: true,
uploadAction: "#preview-upload",
acceptedMimeTypes: ["image/jpeg", "application/pdf", "audio/mpeg"],
uploads: [
{
id: "preview-upload",
filename: "baustelle.jpg",
category: "photo",
status: "clean",
sizeBytes: 1_572_864,
createdAt: "2026-07-22T08:20:00.000Z",
errorMessageKey: null,
},
],
complaintForm: {
formId: "preview-complaint-form",
formSlug: "reklamation",
formName: "Reklamation melden",
submitAction: "#preview-complaint",
submitLabel: "Reklamation senden",
gdprConsentLabel: "Ich stimme der Verarbeitung zur Bearbeitung zu.",
fields: [
{ key: "subject", type: "text", label: "customerPortal.complaint.fields.subject", required: true, options: [] },
{ key: "description", type: "textarea", label: "customerPortal.complaint.fields.description", required: true, options: [] },
],
},
});
const lifecycleVm = buildPortalLifecycleVM({
frozen: false,
profile: {
name: "Karla Kundin",
email: "karla.kundin@example.de",
phone: "+49 69 123 45 67",
locale: "de-DE",
},
notificationPreferences: [
{ eventType: "status_mail", emailEnabled: true, mutedUntil: null },
{ eventType: "lifecycle", emailEnabled: false, mutedUntil: null },
],
exportJobs: [
{
id: "preview-export-ready",
status: "ready",
progressPercent: 100,
requestedAt: "2026-07-22T08:15:00.000Z",
expiresAt: "2026-07-23T08:15:00.000Z",
downloadHref: "/_dev/customer-portal-preview/export-ready.json",
},
{
id: "preview-export-expired",
status: "expired",
progressPercent: 100,
requestedAt: "2026-07-20T07:44:00.000Z",
expiresAt: "2026-07-21T07:44:00.000Z",
downloadHref: null,
},
],
deletionRequest: null,
now: "2026-07-22T10:00:00.000Z",
});
type PreviewView = "dashboard" | "projects" | "project" | "settings";
function previewView(value: string | null): PreviewView {
return value === "dashboard" || value === "projects" || value === "project" || value === "settings" ? value : "settings";
}
export async function loader(_args: LoaderFunctionArgs): Promise<Response> {
if (process.env.NODE_ENV !== "development") {
throw new Response(null, { status: 404, headers: { "Cache-Control": "no-store" } });
}
return Response.json({ preview: true }, { headers: { "Cache-Control": "no-store" } });
}
export default function CustomerPortalSettingsPreviewRoute(): React.JSX.Element {
const [searchParams, setSearchParams] = useSearchParams();
const view = previewView(searchParams.get("view"));
const show = (nextView: PreviewView): void => setSearchParams({ view: nextView });
const noOp = (): void => undefined;
const navigationActions = {
onDashboard: () => show("dashboard"),
onProjects: () => show("projects"),
onSettings: () => show("settings"),
onLogout: noOp,
};
if (view === "dashboard") {
return <CustomerPortalDashboardPage vm={dashboardVm} actions={{ ...navigationActions, onOpenProject: () => show("project"), onDownloadDocument: noOp }} />;
}
if (view === "projects") {
return (
<CustomerPortalProjectsPage
vm={projectsVm}
portalName={portalName}
viewerLabel={viewerLabel}
actions={{ ...navigationActions, onOpenProject: () => show("project") }}
/>
);
}
if (view === "project") {
return (
<CustomerPortalProjectDetailPage
vm={projectDetailVm}
interactionsVM={interactionsVm}
portalName={portalName}
viewerLabel={viewerLabel}
actions={{
...navigationActions,
onBack: () => show("projects"),
onDownloadDocument: noOp,
onUploadFiles: noOp,
onSubmitComplaint: noOp,
}}
/>
);
}
const previewActions: PortalLifecyclePageActions = {
...navigationActions,
onUpdatePreference: noOp,
onRequestExport: noOp,
onDownloadExport: noOp,
onRequestDeletion: noOp,
onCancelDeletion: noOp,
};
return <CustomerPortalSettingsPage vm={lifecycleVm} portalName={portalName} viewerLabel={viewerLabel} actions={previewActions} />;
}