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
+241
@@ -0,0 +1,241 @@
|
||||
// R-P6 Interim-UI (AD-28) — "Neuer Kontakt" as a modal on the contact/organisation
|
||||
// browser, mirroring the automation list pattern ("Neue Automation starten").
|
||||
// Presentational only: it holds the form draft, reports blur events through
|
||||
// actions.onCheckDuplicates (live hard/soft hits, DoD 4) and posts to the create
|
||||
// route (`createHref`) with the same field contract as the standalone KontaktNewPage,
|
||||
// so the route action stays untouched. No useLoaderData / useFetcher (DoD A.5).
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPlus, FeatherX } from "@subframe/core";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { IconButton } from "~/ui/components/IconButton";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
import type { KontaktNewDuplicates, KontaktNewFields } from "./KontaktNewPage";
|
||||
import { AppLink } from "~/components/app/AppLink";
|
||||
|
||||
const ORG_MERKMAL_NONE = "__none__";
|
||||
|
||||
export type KontaktNewDialogProps = {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
/** Route that owns the create action (the standalone /contacts/new route). */
|
||||
createHref: string;
|
||||
ownerOptions: readonly { id: string; label: string }[];
|
||||
defaultOwnerId: string;
|
||||
/** Organisation browser pre-selects the organisation type. */
|
||||
defaultKontaktTyp?: string;
|
||||
duplicates?: KontaktNewDuplicates | null;
|
||||
onCheckDuplicates?: (fields: KontaktNewFields) => void;
|
||||
};
|
||||
|
||||
export function KontaktNewDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
createHref,
|
||||
ownerOptions,
|
||||
defaultOwnerId,
|
||||
defaultKontaktTyp = "privatperson",
|
||||
duplicates = null,
|
||||
onCheckDuplicates,
|
||||
}: KontaktNewDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
const [fields, setFields] = useState<KontaktNewFields>({
|
||||
kontaktTyp: defaultKontaktTyp,
|
||||
kontaktStatus: "kontakt",
|
||||
vorname: "",
|
||||
nachname: "",
|
||||
orgName: "",
|
||||
orgMerkmal: "",
|
||||
email: "",
|
||||
telefon: "",
|
||||
zustaendigerUserId: defaultOwnerId,
|
||||
});
|
||||
const set = (patch: Partial<KontaktNewFields>) => setFields((state) => ({ ...state, ...patch }));
|
||||
const checkDuplicates = () => onCheckDuplicates?.(fields);
|
||||
const isOrg = fields.kontaktTyp === "organisation";
|
||||
const hasIdentity = Boolean(isOrg ? fields.orgName.trim() : fields.vorname.trim() || fields.nachname.trim());
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<Dialog.Content className="w-[560px] max-w-[92vw] p-0">
|
||||
<form method="post" action={createHref} className="flex w-full flex-col" data-ui-id="ui.crm.new.dialog">
|
||||
<input type="hidden" name="intent" value="create" />
|
||||
<div className="flex w-full items-start justify-between gap-3 border-b border-solid border-border-default bg-surface-neutral-secondary px-6 py-5 mobile:px-4">
|
||||
<div className="flex flex-col items-start gap-1">
|
||||
<span className="text-heading- font-heading- text-text-neutral-primary">{t("crm.new.title")}</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("crm.new.subtitle")}</span>
|
||||
</div>
|
||||
<IconButton
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="small"
|
||||
icon={<FeatherX />}
|
||||
aria-label={t("shared.cancel")}
|
||||
onClick={() => onOpenChange(false)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex w-full flex-col gap-4 px-6 py-5 max-h-[65vh] overflow-y-auto mobile:px-4">
|
||||
{duplicates && (duplicates.hard.length > 0 || duplicates.soft.length > 0) ? (
|
||||
<div
|
||||
className="flex w-full flex-col gap-2 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-4 py-3"
|
||||
data-ui-id="ui.crm.new.dialog.duplicates"
|
||||
>
|
||||
{duplicates.hard.length > 0 ? (
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-negative">{t("crm.new.duplicates.hard")}</span>
|
||||
{duplicates.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}` : ""}
|
||||
</AppLink>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
{duplicates.soft.length > 0 ? (
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("crm.new.duplicates.soft")}</span>
|
||||
{duplicates.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}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="grid w-full gap-4 sm:grid-cols-2">
|
||||
<Select
|
||||
name="kontaktTyp"
|
||||
label={t("crm.fields.type")}
|
||||
showLabel
|
||||
value={fields.kontaktTyp}
|
||||
onValueChange={(value: string) => set({ kontaktTyp: value })}
|
||||
>
|
||||
<Select.Item value="privatperson">{t("crm.kontaktTyp.privatperson")}</Select.Item>
|
||||
<Select.Item value="organisation">{t("crm.kontaktTyp.organisation")}</Select.Item>
|
||||
</Select>
|
||||
<Select
|
||||
name="kontaktStatus"
|
||||
label={t("crm.fields.status")}
|
||||
showLabel
|
||||
value={fields.kontaktStatus}
|
||||
onValueChange={(value: string) => set({ kontaktStatus: value })}
|
||||
>
|
||||
{(["kontakt", "kunde", "bestandskunde"] as const).map((status) => (
|
||||
<Select.Item key={status} value={status}>
|
||||
{t(`crm.kontaktStatus.${status}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
|
||||
{isOrg ? (
|
||||
<>
|
||||
<TextInput label={t("crm.fields.orgName")} showLabel>
|
||||
<TextInput.Input
|
||||
name="orgName"
|
||||
autoFocus
|
||||
value={fields.orgName}
|
||||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => set({ orgName: event.target.value })}
|
||||
onBlur={checkDuplicates}
|
||||
data-ui-id="ui.crm.new.dialog.orgName"
|
||||
/>
|
||||
</TextInput>
|
||||
<Select
|
||||
name="orgMerkmal"
|
||||
label={t("crm.fields.orgMerkmal")}
|
||||
showLabel
|
||||
value={fields.orgMerkmal || ORG_MERKMAL_NONE}
|
||||
onValueChange={(value: string) => set({ orgMerkmal: value === ORG_MERKMAL_NONE ? "" : value })}
|
||||
>
|
||||
<Select.Item value={ORG_MERKMAL_NONE}>{t("crm.fields.none")}</Select.Item>
|
||||
{(["gmbh", "kg", "oeffentliche_einrichtung", "sonstige"] as const).map((merkmal) => (
|
||||
<Select.Item key={merkmal} value={merkmal}>
|
||||
{t(`crm.orgMerkmal.${merkmal}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<TextInput label={t("crm.fields.vorname")} showLabel>
|
||||
<TextInput.Input
|
||||
name="vorname"
|
||||
autoFocus
|
||||
value={fields.vorname}
|
||||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => set({ vorname: event.target.value })}
|
||||
onBlur={checkDuplicates}
|
||||
data-ui-id="ui.crm.new.dialog.vorname"
|
||||
/>
|
||||
</TextInput>
|
||||
<TextInput label={t("crm.fields.nachname")} showLabel>
|
||||
<TextInput.Input
|
||||
name="nachname"
|
||||
value={fields.nachname}
|
||||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => set({ nachname: event.target.value })}
|
||||
onBlur={checkDuplicates}
|
||||
data-ui-id="ui.crm.new.dialog.nachname"
|
||||
/>
|
||||
</TextInput>
|
||||
</>
|
||||
)}
|
||||
|
||||
<TextInput label={t("crm.fields.email")} showLabel>
|
||||
<TextInput.Input
|
||||
name="email"
|
||||
type="email"
|
||||
value={fields.email}
|
||||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => set({ email: event.target.value })}
|
||||
onBlur={checkDuplicates}
|
||||
data-ui-id="ui.crm.new.dialog.email"
|
||||
/>
|
||||
</TextInput>
|
||||
<TextInput label={t("crm.fields.telefon")} showLabel>
|
||||
<TextInput.Input
|
||||
name="telefon"
|
||||
value={fields.telefon}
|
||||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => set({ telefon: event.target.value })}
|
||||
onBlur={checkDuplicates}
|
||||
data-ui-id="ui.crm.new.dialog.telefon"
|
||||
/>
|
||||
</TextInput>
|
||||
<Select
|
||||
name="zustaendigerUserId"
|
||||
label={t("crm.fields.owner")}
|
||||
showLabel
|
||||
value={fields.zustaendigerUserId}
|
||||
onValueChange={(value: string) => set({ zustaendigerUserId: value })}
|
||||
>
|
||||
{ownerOptions.map((option) => (
|
||||
<Select.Item key={option.id} value={option.id}>
|
||||
{option.label}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex w-full items-center justify-end gap-2 border-t border-solid border-border-default bg-surface-neutral-secondary px-6 py-4 mobile:flex-col-reverse mobile:items-stretch mobile:px-4">
|
||||
<Button
|
||||
type="button"
|
||||
className="mobile:w-full"
|
||||
variant="tertiary"
|
||||
onClick={() => onOpenChange(false)}
|
||||
data-ui-id="ui.crm.new.dialog.cancel"
|
||||
>
|
||||
{t("shared.cancel")}
|
||||
</Button>
|
||||
<Button type="submit" className="mobile:w-full" icon={<FeatherPlus />} disabled={!hasIdentity} data-ui-id="ui.crm.new.dialog.submit">
|
||||
{t("crm.actions.create")}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user