105 lines
4.8 KiB
TypeScript
105 lines
4.8 KiB
TypeScript
// AK-P4b Interim-UI (AD-28) — Task create preview screen composed from ~/ui.
|
|
// Presentational: the form posts to the route action (server-driven create); the
|
|
// loader injects the assignee picker options + optional entity pre-fill. No
|
|
// useLoaderData / server imports. Final Subframe optics land as a design-nachzug.
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
import { FeatherPlus } from "@subframe/core";
|
|
import type { TaskPriority } from "@hivegrid/view-models";
|
|
import { Button } from "~/ui/components/Button";
|
|
import { Card } from "~/ui/components/Card";
|
|
import { Select } from "~/ui/components/Select";
|
|
import { TextArea } from "~/ui/components/TextArea";
|
|
import { TextInput } from "~/ui/components/TextInput";
|
|
import { DateField } from "./DateField";
|
|
import { AppLink } from "~/components/app/AppLink";
|
|
|
|
const PRIORITIES: readonly TaskPriority[] = ["low", "normal", "high", "urgent"];
|
|
|
|
// The ~/ui Select forbids an empty-string option value, so the "creator (default)"
|
|
// choice uses a sentinel. The route action maps it back to "no explicit assignee".
|
|
export const TASK_CREATOR_ASSIGNEE = "__creator__";
|
|
|
|
export type TaskPickerOption = { readonly id: string; readonly label: string };
|
|
export type TaskNewPrefill = { readonly entityType: string; readonly entityId: string } | null;
|
|
|
|
export type TaskNewPageProps = {
|
|
assignableUsers: readonly TaskPickerOption[];
|
|
assignableGroups: readonly TaskPickerOption[];
|
|
prefill: TaskNewPrefill;
|
|
/** Back link to the task list (breadcrumb / cancel target). */
|
|
cancelHref: string;
|
|
};
|
|
|
|
export function TaskNewPage({ assignableUsers, assignableGroups, prefill, cancelHref }: TaskNewPageProps) {
|
|
const { t } = useTranslation();
|
|
|
|
return (
|
|
<div className="flex w-full max-w-[720px] flex-col gap-6 p-6" data-ui-id="ui.tasks.new">
|
|
|
|
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("tasks.new.title")}</span>
|
|
|
|
<Card>
|
|
<form method="post" className="flex w-full flex-col gap-4">
|
|
<TextInput label={t("tasks.detail.field.title")} showLabel>
|
|
<TextInput.Input name="title" required data-ui-id="ui.tasks.new.title" />
|
|
</TextInput>
|
|
<TextArea label={t("tasks.detail.field.description")} showLabel>
|
|
<TextArea.Input name="description" />
|
|
</TextArea>
|
|
<div className="flex flex-wrap items-end gap-4">
|
|
<Select className="max-w-[200px]" name="priority" label={t("tasks.detail.field.priority")} showLabel defaultValue="normal">
|
|
{PRIORITIES.map((priority) => (
|
|
<Select.Item key={priority} value={priority}>
|
|
{t(`tasks.priority.${priority}`)}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
<DateField label={t("tasks.detail.field.deadline")} name="deadline" />
|
|
</div>
|
|
<div className="flex flex-wrap items-end gap-4">
|
|
<Select className="max-w-[200px]" name="assigneeType" label={t("tasks.detail.field.assigneeType")} showLabel defaultValue="user">
|
|
<Select.Item value="user">{t("tasks.detail.assignee.user")}</Select.Item>
|
|
<Select.Item value="group">{t("tasks.detail.assignee.group")}</Select.Item>
|
|
</Select>
|
|
<Select className="max-w-[240px]" name="assigneeId" label={t("tasks.detail.field.assignee")} showLabel defaultValue={TASK_CREATOR_ASSIGNEE}>
|
|
<Select.Item value={TASK_CREATOR_ASSIGNEE}>{t("tasks.new.assignee.default")}</Select.Item>
|
|
{assignableUsers.map((user) => (
|
|
<Select.Item key={`u-${user.id}`} value={user.id}>
|
|
{user.label}
|
|
</Select.Item>
|
|
))}
|
|
{assignableGroups.map((group) => (
|
|
<Select.Item key={`g-${group.id}`} value={group.id}>
|
|
{group.label}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
</div>
|
|
|
|
{prefill ? (
|
|
<div data-ui-id="ui.tasks.new.prefill">
|
|
<input type="hidden" name="entityType" value={prefill.entityType} />
|
|
<input type="hidden" name="entityId" value={prefill.entityId} />
|
|
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
|
{t(`tasks.entity.${prefill.entityType}`)} · {prefill.entityId}
|
|
</span>
|
|
</div>
|
|
) : null}
|
|
|
|
<div className="flex items-center gap-2">
|
|
<Button type="submit" icon={<FeatherPlus />} data-ui-id="ui.tasks.new.submit">
|
|
{t("tasks.new.actions.create")}
|
|
</Button>
|
|
<AppLink href={cancelHref} className="no-underline" data-ui-id="ui.tasks.new.cancel">
|
|
<Button type="button" variant="tertiary">
|
|
{t("tasks.new.actions.cancel")}
|
|
</Button>
|
|
</AppLink>
|
|
</div>
|
|
</form>
|
|
</Card>
|
|
</div>
|
|
);
|
|
}
|