Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+174
@@ -0,0 +1,174 @@
|
||||
// R-P6 (P6 CRM core) Interim-UI (AD-28) — create-contact screen (D-CRM
|
||||
// "Kontakt anlegen", archetype A4), composed from ~/ui. Pure/presentational: it
|
||||
// holds the form draft and calls actions.onCheckDuplicates (live hard/soft hits,
|
||||
// DoD 4) + actions.onCreate; the route runs the fetcher/submit. No useLoaderData/
|
||||
// useFetcher. Final Subframe optics = tracked design-nachzug.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
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 { TextInput } from "~/ui/components/TextInput";
|
||||
import { AppLink } from "~/components/app/AppLink";
|
||||
|
||||
export type KontaktNewDuplicateCard = { id: string; displayName: string; primaerEmail: string | null; primaerTelefon: string | null; detailHref: string };
|
||||
export type KontaktNewDuplicates = { hard: readonly KontaktNewDuplicateCard[]; soft: readonly KontaktNewDuplicateCard[] };
|
||||
|
||||
export type KontaktNewFields = {
|
||||
kontaktTyp: string;
|
||||
kontaktStatus: string;
|
||||
vorname: string;
|
||||
nachname: string;
|
||||
orgName: string;
|
||||
orgMerkmal: string;
|
||||
email: string;
|
||||
telefon: string;
|
||||
zustaendigerUserId: string;
|
||||
};
|
||||
|
||||
export type KontaktNewPageActions = {
|
||||
onCheckDuplicates: (fields: KontaktNewFields) => void;
|
||||
onCreate: (fields: KontaktNewFields) => void;
|
||||
};
|
||||
|
||||
export type KontaktNewPageProps = {
|
||||
moduleActive: boolean;
|
||||
ownerOptions: readonly { id: string; label: string }[];
|
||||
defaultOwnerId: string;
|
||||
backHref: string;
|
||||
listLabelKey: string;
|
||||
duplicates: KontaktNewDuplicates | null;
|
||||
submitting: boolean;
|
||||
errorKey?: string | null;
|
||||
actions: KontaktNewPageActions;
|
||||
};
|
||||
|
||||
export function KontaktNewPage(props: KontaktNewPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const [fields, setFields] = useState<KontaktNewFields>({
|
||||
kontaktTyp: "privatperson",
|
||||
kontaktStatus: "kontakt",
|
||||
vorname: "",
|
||||
nachname: "",
|
||||
orgName: "",
|
||||
orgMerkmal: "",
|
||||
email: "",
|
||||
telefon: "",
|
||||
zustaendigerUserId: props.defaultOwnerId,
|
||||
});
|
||||
const set = (patch: Partial<KontaktNewFields>) => setFields((s) => ({ ...s, ...patch }));
|
||||
const isOrg = fields.kontaktTyp === "organisation";
|
||||
const dup = props.duplicates;
|
||||
|
||||
if (!props.moduleActive) {
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.crm.new">
|
||||
<div data-ui-id="ui.crm.new.locked">
|
||||
<BadgeFeedback farbe="subtle-neutral">{t("crm.locked.headline")}</BadgeFeedback>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.crm.new">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("crm.new.title")}</span>
|
||||
|
||||
{props.errorKey ? (
|
||||
<div data-ui-id="ui.crm.new.error">
|
||||
<BadgeFeedback farbe="subtle-negative">{t(props.errorKey)}</BadgeFeedback>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{dup && (dup.hard.length > 0 || dup.soft.length > 0) ? (
|
||||
<Card variant={dup.hard.length > 0 ? "negative" : "warning"} data-ui-id="ui.crm.new.duplicates">
|
||||
{dup.hard.length > 0 ? (
|
||||
<div className="flex flex-col gap-1" data-ui-id="ui.crm.new.duplicates.hard">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-negative">{t("crm.new.duplicates.hard")}</span>
|
||||
{dup.hard.map((card) => (
|
||||
<AppLink key={card.id} href={card.detailHref} className="text-body-small-regular-0 font-body-small-regular-0 text-text-feedback-link-default">
|
||||
{card.displayName}
|
||||
{card.primaerEmail ? ` · ${card.primaerEmail}` : ""}
|
||||
{card.primaerTelefon ? ` · ${card.primaerTelefon}` : ""}
|
||||
</AppLink>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
{dup.soft.length > 0 ? (
|
||||
<div className="flex flex-col gap-1" data-ui-id="ui.crm.new.duplicates.soft">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("crm.new.duplicates.soft")}</span>
|
||||
{dup.soft.map((card) => (
|
||||
<AppLink key={card.id} href={card.detailHref} className="text-body-small-regular-0 font-body-small-regular-0 text-text-feedback-link-default">
|
||||
{card.displayName}
|
||||
{card.primaerEmail ? ` · ${card.primaerEmail}` : ""}
|
||||
</AppLink>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</Card>
|
||||
) : null}
|
||||
|
||||
<Card data-ui-id="ui.crm.new.form">
|
||||
<div className="grid w-full gap-4 sm:grid-cols-2">
|
||||
<Select label={t("crm.fields.type")} showLabel value={fields.kontaktTyp} onValueChange={(v) => set({ kontaktTyp: v })}>
|
||||
<Select.Item value="privatperson">{t("crm.kontaktTyp.privatperson")}</Select.Item>
|
||||
<Select.Item value="organisation">{t("crm.kontaktTyp.organisation")}</Select.Item>
|
||||
</Select>
|
||||
<Select label={t("crm.fields.status")} showLabel value={fields.kontaktStatus} onValueChange={(v) => set({ kontaktStatus: v })}>
|
||||
{(["kontakt", "kunde", "bestandskunde"] as const).map((st) => (
|
||||
<Select.Item key={st} value={st}>{t(`crm.kontaktStatus.${st}`)}</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
|
||||
{isOrg ? (
|
||||
<>
|
||||
<TextInput label={t("crm.fields.orgName")} showLabel>
|
||||
<TextInput.Input value={fields.orgName} onChange={(e) => set({ orgName: e.target.value })} onBlur={() => props.actions.onCheckDuplicates(fields)} data-ui-id="ui.crm.new.orgName" />
|
||||
</TextInput>
|
||||
<Select label={t("crm.fields.orgMerkmal")} showLabel value={fields.orgMerkmal || "__none__"} onValueChange={(v) => set({ orgMerkmal: v === "__none__" ? "" : v })}>
|
||||
<Select.Item value="__none__">{t("crm.fields.none")}</Select.Item>
|
||||
{(["gmbh", "kg", "oeffentliche_einrichtung", "sonstige"] as const).map((m) => (
|
||||
<Select.Item key={m} value={m}>{t(`crm.orgMerkmal.${m}`)}</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<TextInput label={t("crm.fields.vorname")} showLabel>
|
||||
<TextInput.Input value={fields.vorname} onChange={(e) => set({ vorname: e.target.value })} onBlur={() => props.actions.onCheckDuplicates(fields)} data-ui-id="ui.crm.new.vorname" />
|
||||
</TextInput>
|
||||
<TextInput label={t("crm.fields.nachname")} showLabel>
|
||||
<TextInput.Input value={fields.nachname} onChange={(e) => set({ nachname: e.target.value })} onBlur={() => props.actions.onCheckDuplicates(fields)} data-ui-id="ui.crm.new.nachname" />
|
||||
</TextInput>
|
||||
</>
|
||||
)}
|
||||
|
||||
<TextInput label={t("crm.fields.email")} showLabel>
|
||||
<TextInput.Input type="email" value={fields.email} onChange={(e) => set({ email: e.target.value })} onBlur={() => props.actions.onCheckDuplicates(fields)} data-ui-id="ui.crm.new.email" />
|
||||
</TextInput>
|
||||
<TextInput label={t("crm.fields.telefon")} showLabel>
|
||||
<TextInput.Input value={fields.telefon} onChange={(e) => set({ telefon: e.target.value })} onBlur={() => props.actions.onCheckDuplicates(fields)} data-ui-id="ui.crm.new.telefon" />
|
||||
</TextInput>
|
||||
<Select label={t("crm.fields.owner")} showLabel value={fields.zustaendigerUserId} onValueChange={(v) => set({ zustaendigerUserId: v })}>
|
||||
{props.ownerOptions.map((option) => (
|
||||
<Select.Item key={option.id} value={option.id}>{option.label}</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Button loading={props.submitting} onClick={() => props.actions.onCreate(fields)} data-ui-id="ui.crm.new.submit">
|
||||
{t("crm.actions.create")}
|
||||
</Button>
|
||||
<Button variant="neutral" onClick={() => props.actions.onCheckDuplicates(fields)} data-ui-id="ui.crm.new.checkDuplicates">
|
||||
{t("crm.actions.checkDuplicates")}
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default KontaktNewPage;
|
||||
Reference in new issue
Block a user