Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/components/screens/leads/LeadNewPage.tsx
T

80 lines
3.8 KiB
TypeScript

// R-P7 (P7 Lead-Inbox) Interim-UI (AD-28) — manual lead entry (D-P7 "Manueller
// Lead-Eintrag", archetype A4), composed from ~/ui. Pure: holds the form draft and
// calls actions.onCreate; the route POSTs it. No useLoaderData. Final Subframe
// optics = tracked design-nachzug.
import { useState } from "react";
import { useTranslation } from "react-i18next";
import type { LeadQuelle } from "~/utils/integrations/leads/leadListQuery";
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
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";
const QUELLEN: readonly LeadQuelle[] = ["form", "email", "aircall", "manual", "custom"];
export type LeadNewFields = { quelle: string; vorname: string; nachname: string; email: string; telefon: string; message: string };
export type LeadNewPageActions = { onCreate: (fields: LeadNewFields) => void };
export type LeadNewPageProps = {
backHref: string;
submitting: boolean;
errorKey?: string | null;
actions: LeadNewPageActions;
};
export function LeadNewPage(props: LeadNewPageProps) {
const { t } = useTranslation();
const [fields, setFields] = useState<LeadNewFields>({ quelle: "manual", vorname: "", nachname: "", email: "", telefon: "", message: "" });
const set = (patch: Partial<LeadNewFields>) => setFields((s) => ({ ...s, ...patch }));
const hasIdentity = Boolean(fields.vorname.trim() || fields.nachname.trim() || fields.email.trim() || fields.telefon.trim() || fields.message.trim());
return (
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.leads.new">
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("leads.new.title")}</span>
{props.errorKey ? (
<div data-ui-id="ui.leads.new.error">
<BadgeFeedback farbe="subtle-negative">{t(props.errorKey)}</BadgeFeedback>
</div>
) : null}
<Card data-ui-id="ui.leads.new.form">
<div className="grid w-full gap-4 sm:grid-cols-2">
<Select label={t("leads.field.quelle")} showLabel value={fields.quelle} onValueChange={(v) => set({ quelle: v })}>
{QUELLEN.map((q) => (
<Select.Item key={q} value={q}>{t(`leads.quelle.${q}`)}</Select.Item>
))}
</Select>
<div />
<TextInput label={t("leads.field.vorname")} showLabel>
<TextInput.Input value={fields.vorname} onChange={(e) => set({ vorname: e.target.value })} data-ui-id="ui.leads.new.vorname" />
</TextInput>
<TextInput label={t("leads.field.nachname")} showLabel>
<TextInput.Input value={fields.nachname} onChange={(e) => set({ nachname: e.target.value })} />
</TextInput>
<TextInput label={t("leads.field.email")} showLabel>
<TextInput.Input type="email" value={fields.email} onChange={(e) => set({ email: e.target.value })} data-ui-id="ui.leads.new.email" />
</TextInput>
<TextInput label={t("leads.field.telefon")} showLabel>
<TextInput.Input value={fields.telefon} onChange={(e) => set({ telefon: e.target.value })} />
</TextInput>
</div>
<TextArea label={t("leads.field.message")} showLabel className="max-w-none">
<TextArea.Input value={fields.message} onChange={(e) => set({ message: e.target.value })} />
</TextArea>
<div className="flex">
<Button loading={props.submitting} disabled={!hasIdentity} onClick={() => props.actions.onCreate(fields)} data-ui-id="ui.leads.new.submit">
{t("leads.actions.create")}
</Button>
</div>
</Card>
</div>
);
}
export default LeadNewPage;