// AK-P17b Interim-UI (AD-28) — survey participation + item editor composed from // ~/ui (D-HR "Umfrage Teilnahme", archetype A3/A4). Pure presentational: answers // held in local state and submitted via the injected action (route maps them to // item: form fields); managers add/remove items. Final Subframe optics = // tracked design-nachzug. import { useState } from "react"; import { useTranslation } from "react-i18next"; import { FeatherPlus } from "@subframe/core"; import type { HrSurveyItem, HrSurveyItemType, HrSurveyParticipationVM } from "@hivegrid/view-models"; import { Alert } from "~/ui/components/Alert"; import { Button } from "~/ui/components/Button"; import { Card } from "~/ui/components/Card"; import { Checkbox } from "~/ui/components/Checkbox"; import { Dialog } from "~/ui/components/Dialog"; import { Select } from "~/ui/components/Select"; import { TextInput } from "~/ui/components/TextInput"; const ITEM_TYPES: readonly HrSurveyItemType[] = ["text", "rating_5", "nps", "choice", "boolean", "date"]; export type HrSurveyParticipationActions = { onSubmit: (answers: Record) => void; onAddItem: (input: { itemType: string; prompt: string; options: string; required: boolean }) => void; onRemoveItem: (itemId: string) => void; }; export type HrSurveyParticipationPageProps = { vm: HrSurveyParticipationVM; canManage: boolean; status: string; submitting: boolean; actions: HrSurveyParticipationActions; }; // Controlled answer field per item type. Date uses a native input styled with the // ~/ui design tokens (same sanctioned exception as the tasks DateField). function AnswerField({ item, value, onChange }: { item: HrSurveyItem; value: string; onChange: (v: string) => void }) { if (item.itemType === "boolean") { return onChange(c ? "true" : "")} />; } if (item.itemType === "choice") { return ( ); } if (item.itemType === "date") { return ( onChange(e.target.value)} className="h-9 rounded-[4px] border border-solid border-border-default bg-transparent px-3 text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary outline-none" /> ); } const numeric = item.itemType === "rating_5" || item.itemType === "nps"; return ( onChange(e.target.value)} /> ); } export function HrSurveyParticipationPage({ vm, canManage, status, submitting, actions }: HrSurveyParticipationPageProps) { const { t } = useTranslation(); const data = vm.data; const [answers, setAnswers] = useState>({}); const [addOpen, setAddOpen] = useState(false); const [item, setItem] = useState({ itemType: "text", prompt: "", options: "", required: false }); if (vm.status !== "ready" || !data) { return
; } function addItem() { if (!item.prompt.trim()) return; actions.onAddItem(item); setAddOpen(false); setItem({ itemType: "text", prompt: "", options: "", required: false }); } return (
{data.title} {data.description ? ( {data.description} ) : null}
{data.isAnonymous ? : null} {data.alreadySubmitted ? (
) : status === "open" ? (
{data.items.map((surveyItem) => (
{surveyItem.prompt} {surveyItem.required ? " *" : ""} setAnswers((s) => ({ ...s, [surveyItem.id]: v }))} />
))}
) : (
)} {canManage ? (
{t("hr.surveys.editor.title")}
{data.items.map((surveyItem) => (
{t(surveyItem.typeLabelKey)} · {surveyItem.prompt}
))}
) : null}
{t("hr.surveys.editor.add")}
setItem((s) => ({ ...s, prompt: e.target.value }))} /> setItem((s) => ({ ...s, options: e.target.value }))} /> setItem((s) => ({ ...s, required: c }))} />
); }