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
+163
@@ -0,0 +1,163 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPhoneCall } from "@subframe/core";
|
||||
import type { ClickToCallMode, ClickToCallNumber, ClickToCallVM } from "@hivegrid/view-models";
|
||||
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
|
||||
export type ClickToCallActions = {
|
||||
readonly onOpenChange: (open: boolean) => void;
|
||||
readonly onCall: (number: ClickToCallNumber, mode: Exclude<ClickToCallMode, "disabled">) => void | Promise<void>;
|
||||
};
|
||||
|
||||
export type ClickToCallDialogProps = {
|
||||
readonly open: boolean;
|
||||
readonly vm: ClickToCallVM;
|
||||
readonly actions: ClickToCallActions;
|
||||
readonly busy?: boolean;
|
||||
};
|
||||
|
||||
export type ClickToCallEntryPointProps = {
|
||||
readonly vm: ClickToCallVM;
|
||||
readonly onCall: ClickToCallActions["onCall"];
|
||||
readonly busy?: boolean;
|
||||
readonly onOpenChange?: (open: boolean) => void;
|
||||
/**
|
||||
* Look of the trigger. It defaults to the solid button of the detail headers;
|
||||
* a bar of equal actions (WF-P8 S02 quick actions) passes "tertiary" so the
|
||||
* call does not shout over the five buttons next to it.
|
||||
*/
|
||||
readonly variant?: "primary" | "tertiary";
|
||||
};
|
||||
|
||||
function preferredNumber(numbers: readonly ClickToCallNumber[]): ClickToCallNumber | null {
|
||||
return numbers.find((number) => number.primary) ?? numbers[0] ?? null;
|
||||
}
|
||||
|
||||
export function ClickToCallDialog({ open, vm, actions, busy = false }: ClickToCallDialogProps): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
const [selectedId, setSelectedId] = useState(preferredNumber(vm.numbers)?.id ?? null);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) setSelectedId(preferredNumber(vm.numbers)?.id ?? null);
|
||||
}, [open, vm.numbers]);
|
||||
|
||||
const selectedNumber = vm.numbers.find((number) => number.id === selectedId) ?? preferredNumber(vm.numbers);
|
||||
const disabled = vm.mode === "disabled" || !selectedNumber;
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={actions.onOpenChange}>
|
||||
<Dialog.Content className="w-[520px] max-w-[90vw] p-6" aria-label={t("telephony.clickToCall.title")}>
|
||||
<div className="flex w-full flex-col gap-6" data-ui-id="ui.telephony.clickToCall.dialog">
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("telephony.clickToCall.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t(vm.requiresSelection ? "telephony.clickToCall.selectBody" : "telephony.clickToCall.confirmBody")}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{vm.reasonKey ? (
|
||||
<Alert
|
||||
variant={vm.mode === "disabled" ? "error" : "warning"}
|
||||
title={t(vm.mode === "disabled" ? "telephony.clickToCall.unavailableTitle" : "telephony.clickToCall.fallbackTitle")}
|
||||
description={t(vm.reasonKey)}
|
||||
notDismissible
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{vm.numbers.length === 0 ? (
|
||||
<EmptyState
|
||||
variant="no-results"
|
||||
outlined
|
||||
title={t("telephony.clickToCall.empty.title")}
|
||||
body={t("telephony.clickToCall.empty.body")}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex w-full flex-col gap-2" role="radiogroup" aria-label={t("telephony.clickToCall.numberGroupLabel")}>
|
||||
{vm.numbers.map((number) => {
|
||||
const selected = number.id === selectedNumber?.id;
|
||||
return (
|
||||
<Button
|
||||
key={number.id}
|
||||
variant={selected ? "secondary" : "tertiary"}
|
||||
className="h-auto w-full justify-start py-3"
|
||||
onClick={() => setSelectedId(number.id)}
|
||||
role="radio"
|
||||
aria-checked={selected}
|
||||
aria-label={t("telephony.clickToCall.selectNumber", { label: number.label, number: number.e164 })}
|
||||
data-number-id={number.id}
|
||||
>
|
||||
<span className="flex w-full items-center justify-between gap-3">
|
||||
<span className="flex flex-col items-start gap-0.5">
|
||||
<span>{number.label}</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{number.e164}
|
||||
</span>
|
||||
</span>
|
||||
{number.primary ? (
|
||||
<BadgeFeedback farbe="subtle-information" size="small">
|
||||
{t("telephony.clickToCall.primary")}
|
||||
</BadgeFeedback>
|
||||
) : null}
|
||||
</span>
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex w-full items-center justify-end gap-2">
|
||||
<Button variant="tertiary" disabled={busy} onClick={() => actions.onOpenChange(false)}>
|
||||
{t("telephony.actions.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
icon={<FeatherPhoneCall />}
|
||||
loading={busy}
|
||||
disabled={busy || disabled}
|
||||
onClick={() => {
|
||||
if (selectedNumber && vm.mode !== "disabled") void actions.onCall(selectedNumber, vm.mode);
|
||||
}}
|
||||
>
|
||||
{t(vm.mode === "tel-fallback" ? "telephony.clickToCall.openPhoneApp" : "telephony.clickToCall.startCall")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reusable detail-screen entry point. It owns presentation state only; the
|
||||
* route decides how a connected provider or tel-fallback call is started.
|
||||
*/
|
||||
export function ClickToCallEntryPoint({ vm, onCall, busy = false, onOpenChange, variant = "primary" }: ClickToCallEntryPointProps): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const changeOpen = (nextOpen: boolean) => {
|
||||
setOpen(nextOpen);
|
||||
onOpenChange?.(nextOpen);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
variant={variant === "tertiary" ? "tertiary" : undefined}
|
||||
size={variant === "tertiary" ? "small" : undefined}
|
||||
icon={<FeatherPhoneCall />}
|
||||
disabled={busy}
|
||||
loading={busy}
|
||||
onClick={() => changeOpen(true)}
|
||||
data-ui-id="ui.telephony.clickToCall.open"
|
||||
>
|
||||
{t("telephony.clickToCall.open")}
|
||||
</Button>
|
||||
<ClickToCallDialog open={open} vm={vm} busy={busy} actions={{ onOpenChange: changeOpen, onCall }} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
+304
@@ -0,0 +1,304 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
FeatherArrowLeft,
|
||||
FeatherExternalLink,
|
||||
FeatherPhoneCall,
|
||||
FeatherSave,
|
||||
FeatherUserCheck,
|
||||
} from "@subframe/core";
|
||||
import type {
|
||||
TelephonyCallDetailData,
|
||||
TelephonyCallDetailVM,
|
||||
TelephonyCallStatus,
|
||||
TelephonyMatchConfidence,
|
||||
TelephonyMatchOption,
|
||||
} from "@hivegrid/view-models";
|
||||
|
||||
import { useLocaleFormatters } from "~/locale/format";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { TextArea } from "~/ui/components/TextArea";
|
||||
import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell";
|
||||
|
||||
export type TelephonyCallDetailActions = {
|
||||
readonly onBack: (listHref: string) => void;
|
||||
readonly onOverrideMatch: (callId: string, option: TelephonyMatchOption | null) => void | Promise<void>;
|
||||
readonly onSaveNote: (callId: string, noteMarkdown: string) => void | Promise<void>;
|
||||
readonly onCallBack: (callId: string) => void;
|
||||
readonly onRetry?: () => void | Promise<void>;
|
||||
};
|
||||
|
||||
export type TelephonyCallDetailPageProps = {
|
||||
readonly vm: TelephonyCallDetailVM;
|
||||
readonly actions: TelephonyCallDetailActions;
|
||||
readonly busy?: boolean;
|
||||
};
|
||||
|
||||
const NO_MATCH = "__no_match__";
|
||||
|
||||
type BadgeTone = "subtle-positive" | "subtle-warning" | "subtle-negative" | "subtle-information" | "subtle-neutral";
|
||||
|
||||
function callStatusTone(status: TelephonyCallStatus): BadgeTone {
|
||||
if (status === "answered" || status === "completed") return "subtle-positive";
|
||||
if (status === "ringing") return "subtle-information";
|
||||
if (status === "missed" || status === "failed") return "subtle-negative";
|
||||
return "subtle-neutral";
|
||||
}
|
||||
|
||||
function matchTone(confidence: TelephonyMatchConfidence): BadgeTone {
|
||||
if (confidence === "exact") return "subtle-positive";
|
||||
if (confidence === "manual") return "subtle-information";
|
||||
if (confidence === "soft") return "subtle-warning";
|
||||
return "subtle-neutral";
|
||||
}
|
||||
|
||||
function matchValue(call: TelephonyCallDetailData | null): string {
|
||||
if (!call?.matchedEntityType || !call.matchedEntityId) return NO_MATCH;
|
||||
return `${call.matchedEntityType}:${call.matchedEntityId}`;
|
||||
}
|
||||
|
||||
function optionValue(option: TelephonyMatchOption): string {
|
||||
return `${option.type}:${option.id}`;
|
||||
}
|
||||
|
||||
function formatDuration(seconds: number | null, emptyLabel: string): string {
|
||||
if (seconds === null) return emptyLabel;
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
return `${minutes}:${String(seconds % 60).padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
function DetailShell({ children }: { readonly children: React.ReactNode }): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<PageShell uiId="ui.telephony.callDetail.page">
|
||||
<PageHeader
|
||||
icon={<FeatherPhoneCall className={PAGE_HEADER_ICON_CLASS} />}
|
||||
title={t("telephony.callDetail.title")}
|
||||
subtitle={t("telephony.callDetail.subtitle")}
|
||||
/>
|
||||
<PageBody>{children}</PageBody>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
|
||||
function MetaItem({ label, value }: { readonly label: string; readonly value: React.ReactNode }): React.JSX.Element {
|
||||
return (
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{label}</span>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{value}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function TelephonyCallDetailPage({ vm, actions, busy = false }: TelephonyCallDetailPageProps): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
const formatters = useLocaleFormatters();
|
||||
const call = vm.status === "ready" ? vm.data : null;
|
||||
const [noteDraft, setNoteDraft] = useState(call?.noteMarkdown ?? "");
|
||||
const [selectedMatch, setSelectedMatch] = useState(matchValue(call));
|
||||
|
||||
useEffect(() => {
|
||||
setNoteDraft(call?.noteMarkdown ?? "");
|
||||
setSelectedMatch(matchValue(call));
|
||||
}, [call?.id, call?.matchedEntityId, call?.matchedEntityType, call?.noteMarkdown]);
|
||||
|
||||
if (vm.status === "idle" || vm.status === "loading") {
|
||||
return (
|
||||
<DetailShell>
|
||||
<Alert
|
||||
variant="neutral"
|
||||
title={t("telephony.callDetail.loading.title")}
|
||||
description={t("telephony.callDetail.loading.body")}
|
||||
notDismissible
|
||||
/>
|
||||
</DetailShell>
|
||||
);
|
||||
}
|
||||
|
||||
if (vm.status === "error") {
|
||||
return (
|
||||
<DetailShell>
|
||||
<EmptyState
|
||||
outlined
|
||||
variant="error"
|
||||
title={t("telephony.callDetail.error.title")}
|
||||
body={t(vm.error.messageKey)}
|
||||
action={
|
||||
actions.onRetry ? (
|
||||
<Button variant="tertiary" onClick={() => void actions.onRetry?.()}>
|
||||
{t("telephony.actions.retry")}
|
||||
</Button>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
</DetailShell>
|
||||
);
|
||||
}
|
||||
|
||||
if (vm.status === "empty" || !call) {
|
||||
return (
|
||||
<DetailShell>
|
||||
<EmptyState outlined variant="no-results" title={t("telephony.callDetail.empty.title")} body={t("telephony.callDetail.empty.body")} />
|
||||
</DetailShell>
|
||||
);
|
||||
}
|
||||
|
||||
const selectedOption = call.matchOptions.find((option) => optionValue(option) === selectedMatch) ?? null;
|
||||
const noteChanged = noteDraft !== call.noteMarkdown;
|
||||
const matchChanged = selectedMatch !== matchValue(call);
|
||||
|
||||
return (
|
||||
<DetailShell>
|
||||
<div className="flex w-full flex-wrap items-center justify-between gap-3">
|
||||
<Button variant="tertiary" icon={<FeatherArrowLeft />} onClick={() => actions.onBack(call.listHref)}>
|
||||
{t("telephony.actions.backToCalls")}
|
||||
</Button>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<BadgeFeedback farbe={call.direction === "inbound" ? "subtle-information" : "subtle-neutral"}>
|
||||
{t(`telephony.call.direction.${call.direction}`)}
|
||||
</BadgeFeedback>
|
||||
<BadgeFeedback farbe={callStatusTone(call.status)}>{t(`telephony.call.status.${call.status}`)}</BadgeFeedback>
|
||||
{call.canCallBack ? (
|
||||
<Button icon={<FeatherPhoneCall />} onClick={() => actions.onCallBack(call.id)}>
|
||||
{t("telephony.actions.callBack")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid w-full grid-cols-1 gap-4 lg:grid-cols-2">
|
||||
<Card data-ui-id="ui.telephony.callDetail.summary">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("telephony.callDetail.summary.title")}</span>
|
||||
<div className="grid w-full grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
<MetaItem label={t("telephony.callDetail.fields.from")} value={call.fromNumber} />
|
||||
<MetaItem label={t("telephony.callDetail.fields.to")} value={call.toNumber} />
|
||||
<MetaItem label={t("telephony.callDetail.fields.startedAt")} value={formatters.dateTime(call.startedAt)} />
|
||||
<MetaItem
|
||||
label={t("telephony.callDetail.fields.duration")}
|
||||
value={formatDuration(call.durationSeconds, t("telephony.common.notAvailable"))}
|
||||
/>
|
||||
<MetaItem
|
||||
label={t("telephony.callDetail.fields.user")}
|
||||
value={call.boundUserLabel ?? t("telephony.common.notAssigned")}
|
||||
/>
|
||||
<MetaItem label={t("telephony.callDetail.fields.provider")} value={t(`telephony.provider.${call.provider}`)} />
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card data-ui-id="ui.telephony.callDetail.recording">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("telephony.callDetail.recording.title")}</span>
|
||||
{call.recordingUrl ? (
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("telephony.callDetail.recording.body")}
|
||||
</span>
|
||||
<a
|
||||
href={call.recordingUrl}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="inline-flex items-center gap-2 text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-link-default underline"
|
||||
data-ui-id="ui.telephony.callDetail.recordingLink"
|
||||
>
|
||||
<FeatherExternalLink className="text-body-default-regular-0 font-body-default-regular-0" />
|
||||
{t("telephony.callDetail.recording.open")}
|
||||
</a>
|
||||
</div>
|
||||
) : (
|
||||
<Alert variant="neutral" description={t("telephony.callDetail.recording.unavailable")} notDismissible />
|
||||
)}
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<Card data-ui-id="ui.telephony.callDetail.match">
|
||||
<div className="flex w-full flex-wrap items-start justify-between gap-3">
|
||||
<div className="flex items-start gap-2">
|
||||
<FeatherUserCheck className="text-heading-3 font-heading-3 text-icon-neutral-tertiary" />
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("telephony.callDetail.match.title")}</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
||||
{t("telephony.callDetail.match.body")}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<BadgeFeedback farbe={matchTone(call.matchConfidence)}>{t(`telephony.call.match.${call.matchConfidence}`)}</BadgeFeedback>
|
||||
</div>
|
||||
|
||||
{call.canOverrideMatch ? (
|
||||
<div className="flex w-full flex-wrap items-end gap-3">
|
||||
<Select
|
||||
className="max-w-[480px] flex-1"
|
||||
showLabel
|
||||
label={t("telephony.callDetail.match.label")}
|
||||
value={selectedMatch}
|
||||
disabled={busy}
|
||||
onValueChange={setSelectedMatch}
|
||||
>
|
||||
<Select.Item value={NO_MATCH}>{t("telephony.callDetail.match.none")}</Select.Item>
|
||||
{call.matchOptions.map((option) => (
|
||||
<Select.Item key={optionValue(option)} value={optionValue(option)}>
|
||||
{option.label} · {t(`telephony.entityType.${option.type}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Button
|
||||
variant="secondary"
|
||||
disabled={busy || !matchChanged}
|
||||
loading={busy}
|
||||
onClick={() => void actions.onOverrideMatch(call.id, selectedMatch === NO_MATCH ? null : selectedOption)}
|
||||
>
|
||||
{t("telephony.callDetail.match.apply")}
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">
|
||||
{call.matchedEntityLabel ?? t("telephony.common.notAssigned")}
|
||||
</span>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
<Card data-ui-id="ui.telephony.callDetail.note">
|
||||
<div className="flex w-full flex-col gap-1">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("telephony.callDetail.note.title")}</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
||||
{t("telephony.callDetail.note.markdownHint")}
|
||||
</span>
|
||||
</div>
|
||||
{call.canEditNote ? (
|
||||
<>
|
||||
<TextArea className="max-w-none" showLabel label={t("telephony.callDetail.note.label")}>
|
||||
<TextArea.Input
|
||||
value={noteDraft}
|
||||
onChange={(event) => setNoteDraft(event.currentTarget.value)}
|
||||
placeholder={t("telephony.callDetail.note.placeholder")}
|
||||
disabled={busy}
|
||||
/>
|
||||
</TextArea>
|
||||
<div className="flex w-full justify-end">
|
||||
<Button
|
||||
icon={<FeatherSave />}
|
||||
disabled={busy || !noteChanged}
|
||||
loading={busy}
|
||||
onClick={() => void actions.onSaveNote(call.id, noteDraft)}
|
||||
>
|
||||
{t("telephony.callDetail.note.save")}
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
) : call.noteMarkdown ? (
|
||||
<pre className="w-full whitespace-pre-wrap font-body-default-regular-0 text-body-default-regular-0 text-text-neutral-primary">
|
||||
{call.noteMarkdown}
|
||||
</pre>
|
||||
) : (
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-tertiary">
|
||||
{t("telephony.callDetail.note.empty")}
|
||||
</span>
|
||||
)}
|
||||
</Card>
|
||||
</DetailShell>
|
||||
);
|
||||
}
|
||||
+241
@@ -0,0 +1,241 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPhoneCall } from "@subframe/core";
|
||||
import type {
|
||||
TelephonyCallListRow,
|
||||
TelephonyCallListVM,
|
||||
TelephonyCallStatus,
|
||||
TelephonyMatchConfidence,
|
||||
} from "@hivegrid/view-models";
|
||||
|
||||
import { useLocaleFormatters } from "~/locale/format";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { LinkButton } from "~/ui/components/LinkButton";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell";
|
||||
import { RefreshIconButton } from "../shared/RefreshIconButton";
|
||||
|
||||
export type TelephonyCallsActions = {
|
||||
readonly onOpenCall: (callId: string, detailHref: string) => void;
|
||||
readonly onRefresh?: () => void | Promise<void>;
|
||||
readonly onRetry?: () => void | Promise<void>;
|
||||
};
|
||||
|
||||
export type TelephonyCallsPageProps = {
|
||||
readonly vm: TelephonyCallListVM;
|
||||
readonly actions: TelephonyCallsActions;
|
||||
readonly busy?: boolean;
|
||||
};
|
||||
|
||||
type BadgeTone = "subtle-positive" | "subtle-warning" | "subtle-negative" | "subtle-information" | "subtle-neutral";
|
||||
|
||||
function callStatusTone(status: TelephonyCallStatus): BadgeTone {
|
||||
switch (status) {
|
||||
case "answered":
|
||||
case "completed":
|
||||
return "subtle-positive";
|
||||
case "ringing":
|
||||
return "subtle-information";
|
||||
case "missed":
|
||||
case "failed":
|
||||
return "subtle-negative";
|
||||
case "unknown":
|
||||
default:
|
||||
return "subtle-neutral";
|
||||
}
|
||||
}
|
||||
|
||||
function matchTone(confidence: TelephonyMatchConfidence): BadgeTone {
|
||||
if (confidence === "exact") return "subtle-positive";
|
||||
if (confidence === "manual") return "subtle-information";
|
||||
if (confidence === "soft") return "subtle-warning";
|
||||
return "subtle-neutral";
|
||||
}
|
||||
|
||||
function formatDuration(seconds: number | null, emptyLabel: string): string {
|
||||
if (seconds === null) return emptyLabel;
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const remainder = seconds % 60;
|
||||
return `${minutes}:${String(remainder).padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
function CallsShell({ actions, busy, children }: {
|
||||
readonly actions: TelephonyCallsActions;
|
||||
readonly busy: boolean;
|
||||
readonly children: React.ReactNode;
|
||||
}): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<PageShell uiId="ui.telephony.calls.page">
|
||||
<PageHeader
|
||||
icon={<FeatherPhoneCall className={PAGE_HEADER_ICON_CLASS} />}
|
||||
title={t("telephony.calls.title")}
|
||||
subtitle={t("telephony.calls.subtitle")}
|
||||
actions={
|
||||
actions.onRefresh ? (
|
||||
<RefreshIconButton
|
||||
busy={busy}
|
||||
onRefresh={() => void actions.onRefresh?.()}
|
||||
label={t("telephony.actions.refresh")}
|
||||
dataUiId="ui.telephony.calls.refresh"
|
||||
/>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
<PageBody>{children}</PageBody>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
|
||||
function Counterpart({ row }: { readonly row: TelephonyCallListRow }): React.JSX.Element {
|
||||
return (
|
||||
<div className="flex min-w-[180px] flex-col gap-0.5">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{row.counterpartLabel ?? row.phoneNumber}
|
||||
</span>
|
||||
{row.counterpartLabel ? (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{row.phoneNumber}</span>
|
||||
) : null}
|
||||
{row.noteSnippet ? (
|
||||
<span className="max-w-[320px] truncate text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
||||
{row.noteSnippet}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function TelephonyCallsPage({ vm, actions, busy = false }: TelephonyCallsPageProps): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
const formatters = useLocaleFormatters();
|
||||
|
||||
if (vm.status === "idle" || vm.status === "loading") {
|
||||
return (
|
||||
<CallsShell actions={actions} busy={busy}>
|
||||
<Alert variant="neutral" title={t("telephony.calls.loading.title")} description={t("telephony.calls.loading.body")} notDismissible />
|
||||
</CallsShell>
|
||||
);
|
||||
}
|
||||
|
||||
if (vm.status === "error") {
|
||||
return (
|
||||
<CallsShell actions={actions} busy={busy}>
|
||||
<EmptyState
|
||||
outlined
|
||||
variant="error"
|
||||
title={t("telephony.calls.error.title")}
|
||||
body={t(vm.error.messageKey)}
|
||||
action={
|
||||
actions.onRetry ? (
|
||||
<Button variant="tertiary" onClick={() => void actions.onRetry?.()}>
|
||||
{t("telephony.actions.retry")}
|
||||
</Button>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
</CallsShell>
|
||||
);
|
||||
}
|
||||
|
||||
if (vm.status === "empty" || !vm.data) {
|
||||
return (
|
||||
<CallsShell actions={actions} busy={busy}>
|
||||
<EmptyState outlined title={t("telephony.calls.unavailable.title")} body={t("telephony.calls.unavailable.body")} />
|
||||
</CallsShell>
|
||||
);
|
||||
}
|
||||
|
||||
if (vm.data.rows.length === 0) {
|
||||
return (
|
||||
<CallsShell actions={actions} busy={busy}>
|
||||
<EmptyState outlined title={t(vm.data.emptyHeadlineKey)} body={t(vm.data.emptyBodyKey)} />
|
||||
</CallsShell>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<CallsShell actions={actions} busy={busy}>
|
||||
<Alert
|
||||
variant="neutral"
|
||||
title={t(vm.data.canReadAll ? "telephony.calls.scope.all.title" : "telephony.calls.scope.own.title")}
|
||||
description={t(vm.data.canReadAll ? "telephony.calls.scope.all.body" : "telephony.calls.scope.own.body")}
|
||||
notDismissible
|
||||
/>
|
||||
|
||||
<div className="w-full overflow-x-auto rounded-md" data-ui-id="ui.telephony.calls.table">
|
||||
<Table
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("telephony.calls.columns.counterpart")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("telephony.calls.columns.direction")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("telephony.calls.columns.status")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("telephony.calls.columns.match")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("telephony.calls.columns.user")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("telephony.calls.columns.startedAt")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("telephony.calls.columns.duration")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("telephony.calls.columns.recording")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("telephony.calls.columns.action")}</Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{vm.data.rows.map((row) => (
|
||||
<Table.Row key={row.id} data-call-id={row.id}>
|
||||
<Table.Cell><Counterpart row={row} /></Table.Cell>
|
||||
<Table.Cell>
|
||||
<BadgeFeedback farbe={row.direction === "inbound" ? "subtle-information" : "subtle-neutral"} size="small">
|
||||
{t(`telephony.call.direction.${row.direction}`)}
|
||||
</BadgeFeedback>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<BadgeFeedback farbe={callStatusTone(row.status)} size="small">
|
||||
{t(`telephony.call.status.${row.status}`)}
|
||||
</BadgeFeedback>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<div className="flex min-w-[160px] flex-col gap-1">
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-primary">
|
||||
{row.matchedEntityLabel ?? t("telephony.common.notAssigned")}
|
||||
</span>
|
||||
<BadgeFeedback farbe={matchTone(row.matchConfidence)} size="small">
|
||||
{t(`telephony.call.match.${row.matchConfidence}`)}
|
||||
</BadgeFeedback>
|
||||
</div>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="whitespace-nowrap text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">
|
||||
{row.boundUserLabel ?? t("telephony.common.notAssigned")}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="whitespace-nowrap text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">
|
||||
{formatters.dateTime(row.startedAt)}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="whitespace-nowrap text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">
|
||||
{formatDuration(row.durationSeconds, t("telephony.common.notAvailable"))}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<BadgeFeedback farbe={row.hasRecording ? "subtle-positive" : "subtle-neutral"} size="small">
|
||||
{t(row.hasRecording ? "telephony.calls.recording.available" : "telephony.calls.recording.unavailable")}
|
||||
</BadgeFeedback>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<LinkButton
|
||||
size="small"
|
||||
onClick={() => actions.onOpenCall(row.id, row.detailHref)}
|
||||
aria-label={t("telephony.calls.openAria", { number: row.phoneNumber })}
|
||||
>
|
||||
{t("telephony.actions.open")}
|
||||
</LinkButton>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
</CallsShell>
|
||||
);
|
||||
}
|
||||
+281
@@ -0,0 +1,281 @@
|
||||
// @vitest-environment jsdom
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import React from "react";
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
buildTelephonyCallDetailVM,
|
||||
buildTelephonyCallListVM,
|
||||
buildTelephonySettingsVM,
|
||||
type ClickToCallVM,
|
||||
} from "@hivegrid/view-models";
|
||||
|
||||
import { ClickToCallDialog } from "./ClickToCallDialog";
|
||||
import { TelephonyCallDetailPage } from "./TelephonyCallDetailPage";
|
||||
import { TelephonyCallsPage } from "./TelephonyCallsPage";
|
||||
import { TelephonySettingsPage } from "./TelephonySettingsPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string, values?: Record<string, unknown>) => (values ? `${key}:${Object.values(values).join("/")}` : key),
|
||||
i18n: { language: "de" },
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("~/locale/format", () => ({
|
||||
useLocaleFormatters: () => ({
|
||||
number: (value: number) => String(value),
|
||||
date: (value: string) => value,
|
||||
dateTime: (value: string) => `date:${value}`,
|
||||
}),
|
||||
}));
|
||||
|
||||
const connection = {
|
||||
id: "connection_1",
|
||||
provider: "aircall" as const,
|
||||
label: "Aircall Berlin",
|
||||
externalCompanyName: "Werkstatt Berlin",
|
||||
status: "active" as const,
|
||||
lastHealthCheckAt: "2026-07-15T08:30:00.000Z",
|
||||
errorKey: null,
|
||||
bindings: [
|
||||
{
|
||||
id: "binding_1",
|
||||
providerUserId: "aircall_user_1",
|
||||
providerName: "Lena Werk",
|
||||
providerEmail: "lena@example.com",
|
||||
hivegridUserId: "user_1",
|
||||
hivegridUserLabel: "Lena Werk",
|
||||
match: "email" as const,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
describe("AK-P15a telephony interim screens", () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it("renders connection health and confirms disconnect before invoking the action", () => {
|
||||
const onHealthCheck = vi.fn();
|
||||
const onDisconnect = vi.fn();
|
||||
const vm = buildTelephonySettingsVM({
|
||||
connection,
|
||||
canManage: true,
|
||||
providerConfigured: true,
|
||||
connectHref: "/settings/telephony/connect",
|
||||
userOptions: [{ id: "user_1", label: "Lena Werk", email: "lena@example.com" }],
|
||||
});
|
||||
|
||||
render(
|
||||
<TelephonySettingsPage
|
||||
vm={vm}
|
||||
actions={{ onConnect: vi.fn(), onHealthCheck, onBindingChange: vi.fn(), onDisconnect }}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.getAllByText("Werkstatt Berlin").length).toBeGreaterThan(0);
|
||||
expect(screen.getByText("Lena Werk")).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "telephony.actions.checkHealth" }));
|
||||
expect(onHealthCheck).toHaveBeenCalledWith("connection_1");
|
||||
|
||||
fireEvent.click(screen.getByTestId("telephony-disconnect-trigger"));
|
||||
expect(screen.getByText("telephony.settings.disconnect.title")).toBeInTheDocument();
|
||||
const disconnectButtons = screen.getAllByRole("button", { name: "telephony.actions.disconnect" });
|
||||
fireEvent.click(disconnectButtons.at(-1)!);
|
||||
expect(onDisconnect).toHaveBeenCalledWith("connection_1");
|
||||
});
|
||||
|
||||
it("connects HalloPetra by API key and keeps the one-time webhook secret visible after revalidation", () => {
|
||||
const onConnectHalloPetra = vi.fn();
|
||||
const disconnectedVm = buildTelephonySettingsVM({
|
||||
connection: null,
|
||||
canManage: true,
|
||||
providerConfigured: true,
|
||||
connectHref: "/integrations/aircall/oauth/install",
|
||||
providerOptions: [
|
||||
{
|
||||
provider: "aircall",
|
||||
labelKey: "telephony.provider.aircall",
|
||||
connectionType: "oauth2",
|
||||
configured: true,
|
||||
connectHref: "/integrations/aircall/oauth/install",
|
||||
},
|
||||
{
|
||||
provider: "hallopetra",
|
||||
labelKey: "telephony.provider.hallopetra",
|
||||
connectionType: "api_key",
|
||||
configured: true,
|
||||
connectHref: "/settings/integrations/telephony",
|
||||
},
|
||||
],
|
||||
});
|
||||
const actions = {
|
||||
onConnect: vi.fn(),
|
||||
onConnectHalloPetra,
|
||||
onHealthCheck: vi.fn(),
|
||||
onBindingChange: vi.fn(),
|
||||
onDisconnect: vi.fn(),
|
||||
};
|
||||
const view = render(<TelephonySettingsPage vm={disconnectedVm} actions={actions} />);
|
||||
|
||||
fireEvent.click(
|
||||
screen.getByRole("button", {
|
||||
name: "telephony.actions.connectProvider:telephony.provider.hallopetra",
|
||||
}),
|
||||
);
|
||||
fireEvent.change(screen.getByTestId("hallopetra-api-key"), { target: { value: "provider-api-key" } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "telephony.actions.connect" }));
|
||||
expect(onConnectHalloPetra).toHaveBeenCalledWith("provider-api-key");
|
||||
|
||||
const connectedVm = buildTelephonySettingsVM({
|
||||
connection: {
|
||||
...connection,
|
||||
provider: "hallopetra",
|
||||
label: "HalloPetra",
|
||||
externalCompanyName: "HalloPetra",
|
||||
bindings: [],
|
||||
},
|
||||
canManage: true,
|
||||
providerConfigured: true,
|
||||
connectHref: "/integrations/aircall/oauth/install",
|
||||
});
|
||||
view.rerender(
|
||||
<TelephonySettingsPage
|
||||
vm={connectedVm}
|
||||
actions={actions}
|
||||
hallopetraSetup={{
|
||||
webhookUrl: "https://api.example.test/v1/webhooks/telephony/hallopetra",
|
||||
webhookSecret: "one-time-webhook-secret",
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.getByText("https://api.example.test/v1/webhooks/telephony/hallopetra")).toBeInTheDocument();
|
||||
expect(screen.getByText("Authorization: Bearer one-time-webhook-secret")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the call list and delegates detail navigation", () => {
|
||||
const onOpenCall = vi.fn();
|
||||
const vm = buildTelephonyCallListVM({
|
||||
canReadAll: false,
|
||||
rows: [
|
||||
{
|
||||
id: "call_1",
|
||||
direction: "inbound",
|
||||
status: "completed",
|
||||
phoneNumber: "+49301234567",
|
||||
counterpartLabel: "Musterbau GmbH",
|
||||
matchedEntityType: "contact",
|
||||
matchedEntityId: "contact_1",
|
||||
matchedEntityLabel: "Musterbau GmbH",
|
||||
matchConfidence: "exact",
|
||||
boundUserId: "user_1",
|
||||
boundUserLabel: "Lena Werk",
|
||||
startedAt: "2026-07-15T09:00:00.000Z",
|
||||
durationSeconds: 125,
|
||||
noteSnippet: "Rückruf am Freitag",
|
||||
hasRecording: true,
|
||||
detailHref: "/calls/call_1",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
render(<TelephonyCallsPage vm={vm} actions={{ onOpenCall }} />);
|
||||
|
||||
expect(screen.getAllByText("Musterbau GmbH").length).toBeGreaterThan(0);
|
||||
expect(screen.getByText("2:05")).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "telephony.calls.openAria:+49301234567" }));
|
||||
expect(onOpenCall).toHaveBeenCalledWith("call_1", "/calls/call_1");
|
||||
});
|
||||
|
||||
it("renders refresh as a compact icon action and disables it while busy", () => {
|
||||
const onRefresh = vi.fn();
|
||||
const vm = buildTelephonyCallListVM({ canReadAll: false, rows: [] });
|
||||
const { rerender } = render(
|
||||
<TelephonyCallsPage vm={vm} actions={{ onOpenCall: vi.fn(), onRefresh }} />,
|
||||
);
|
||||
|
||||
const refresh = screen.getByRole("button", { name: "telephony.actions.refresh" });
|
||||
expect(refresh).toHaveAttribute("data-ui-id", "ui.telephony.calls.refresh");
|
||||
fireEvent.click(refresh);
|
||||
expect(onRefresh).toHaveBeenCalledTimes(1);
|
||||
|
||||
rerender(<TelephonyCallsPage vm={vm} actions={{ onOpenCall: vi.fn(), onRefresh }} busy />);
|
||||
expect(screen.getByRole("button", { name: "telephony.actions.refresh" })).toBeDisabled();
|
||||
});
|
||||
|
||||
it("supports callback, recording link, match override, and Markdown note actions", () => {
|
||||
const onCallBack = vi.fn();
|
||||
const onSaveNote = vi.fn();
|
||||
const onOverrideMatch = vi.fn();
|
||||
const vm = buildTelephonyCallDetailVM({
|
||||
id: "call_1",
|
||||
provider: "aircall",
|
||||
direction: "outbound",
|
||||
status: "completed",
|
||||
fromNumber: "+49301111111",
|
||||
toNumber: "+49302222222",
|
||||
startedAt: "2026-07-15T09:00:00.000Z",
|
||||
answeredAt: "2026-07-15T09:00:04.000Z",
|
||||
endedAt: "2026-07-15T09:02:05.000Z",
|
||||
durationSeconds: 121,
|
||||
boundUserId: "user_1",
|
||||
boundUserLabel: "Lena Werk",
|
||||
matchedEntityType: "contact",
|
||||
matchedEntityId: "contact_1",
|
||||
matchedEntityLabel: "Musterbau GmbH",
|
||||
matchConfidence: "exact",
|
||||
noteMarkdown: "**Termin** vereinbart",
|
||||
recordingUrl: "https://dashboard.aircall.io/calls/call_1",
|
||||
matchOptions: [
|
||||
{ type: "contact", id: "contact_1", label: "Musterbau GmbH" },
|
||||
{ type: "project", id: "project_1", label: "Heizungstausch" },
|
||||
],
|
||||
canEditNote: true,
|
||||
canOverrideMatch: true,
|
||||
canCallBack: true,
|
||||
listHref: "/calls",
|
||||
});
|
||||
|
||||
render(
|
||||
<TelephonyCallDetailPage
|
||||
vm={vm}
|
||||
actions={{ onBack: vi.fn(), onOverrideMatch, onSaveNote, onCallBack }}
|
||||
/>,
|
||||
);
|
||||
|
||||
const recordingLink = screen.getByRole("link", { name: "telephony.callDetail.recording.open" });
|
||||
expect(recordingLink).toHaveAttribute("href", "https://dashboard.aircall.io/calls/call_1");
|
||||
fireEvent.click(screen.getByRole("button", { name: "telephony.actions.callBack" }));
|
||||
expect(onCallBack).toHaveBeenCalledWith("call_1");
|
||||
|
||||
fireEvent.click(screen.getByRole("combobox"));
|
||||
fireEvent.click(screen.getByRole("option", { name: "Heizungstausch · telephony.entityType.project" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "telephony.callDetail.match.apply" }));
|
||||
expect(onOverrideMatch).toHaveBeenCalledWith("call_1", vm.data?.matchOptions[1]);
|
||||
|
||||
fireEvent.change(screen.getByRole("textbox", { name: "telephony.callDetail.note.label" }), {
|
||||
target: { value: "## Nächster Schritt\nFreitag zurückrufen" },
|
||||
});
|
||||
fireEvent.click(screen.getByRole("button", { name: "telephony.callDetail.note.save" }));
|
||||
expect(onSaveNote).toHaveBeenCalledWith("call_1", "## Nächster Schritt\nFreitag zurückrufen");
|
||||
});
|
||||
|
||||
it("lets the user choose a number before starting click-to-call", () => {
|
||||
const onCall = vi.fn();
|
||||
const vm: ClickToCallVM = {
|
||||
mode: "provider",
|
||||
requiresSelection: true,
|
||||
reasonKey: null,
|
||||
numbers: [
|
||||
{ id: "phone_1", label: "Zentrale", e164: "+49301111111", primary: true },
|
||||
{ id: "phone_2", label: "Mobil", e164: "+491701234567", primary: false },
|
||||
],
|
||||
};
|
||||
|
||||
render(<ClickToCallDialog open vm={vm} actions={{ onOpenChange: vi.fn(), onCall }} />);
|
||||
|
||||
fireEvent.click(screen.getByRole("radio", { name: "telephony.clickToCall.selectNumber:Mobil/+491701234567" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "telephony.clickToCall.startCall" }));
|
||||
expect(onCall).toHaveBeenCalledWith(vm.numbers[1], "provider");
|
||||
});
|
||||
});
|
||||
+465
@@ -0,0 +1,465 @@
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherKey, FeatherLink, FeatherPhoneCall, FeatherRefreshCw, FeatherTrash2, FeatherUsers } from "@subframe/core";
|
||||
import type {
|
||||
TelephonyConnectionStatus,
|
||||
TelephonySettingsVM,
|
||||
TelephonyUserBindingRow,
|
||||
} from "@hivegrid/view-models";
|
||||
|
||||
import { useLocaleFormatters } from "~/locale/format";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
import { PAGE_HEADER_ICON_CLASS, PageBackLink, PageBody, PageHeader, PageIntro, PageShell } from "../shared/PageShell";
|
||||
|
||||
export type TelephonySettingsActions = {
|
||||
readonly onConnect: (connectHref: string) => void | Promise<void>;
|
||||
readonly onHealthCheck: (connectionId: string) => void | Promise<void>;
|
||||
readonly onConnectHalloPetra?: (apiKey: string) => void | Promise<void>;
|
||||
readonly onBindingChange: (bindingId: string, hivegridUserId: string | null) => void | Promise<void>;
|
||||
readonly onDisconnect: (connectionId: string) => void | Promise<void>;
|
||||
readonly onRetry?: () => void | Promise<void>;
|
||||
};
|
||||
|
||||
export type TelephonySettingsPageProps = {
|
||||
readonly vm: TelephonySettingsVM;
|
||||
readonly actions: TelephonySettingsActions;
|
||||
readonly busy?: boolean;
|
||||
/** Path back to the integrations catalog (settings/integrations). */
|
||||
readonly backHref?: string;
|
||||
/** Inside the Erweiterungen hub (AK-SET-01) the hub owns the header. */
|
||||
readonly embedded?: boolean;
|
||||
readonly hallopetraSetup?: { readonly webhookUrl: string; readonly webhookSecret: string } | null;
|
||||
};
|
||||
|
||||
const UNASSIGNED = "__unassigned__";
|
||||
|
||||
type BadgeTone = "subtle-positive" | "subtle-warning" | "subtle-negative" | "subtle-information" | "subtle-neutral";
|
||||
|
||||
function connectionTone(status: TelephonyConnectionStatus): BadgeTone {
|
||||
switch (status) {
|
||||
case "active":
|
||||
return "subtle-positive";
|
||||
case "connecting":
|
||||
return "subtle-information";
|
||||
case "error":
|
||||
return "subtle-negative";
|
||||
case "revoked":
|
||||
default:
|
||||
return "subtle-warning";
|
||||
}
|
||||
}
|
||||
|
||||
function bindingTone(match: TelephonyUserBindingRow["match"]): BadgeTone {
|
||||
if (match === "email") return "subtle-positive";
|
||||
if (match === "manual") return "subtle-information";
|
||||
return "subtle-warning";
|
||||
}
|
||||
|
||||
function SettingsShell({
|
||||
backHref,
|
||||
embedded = false,
|
||||
children,
|
||||
}: {
|
||||
readonly backHref?: string;
|
||||
/** Inside the Erweiterungen hub (AK-SET-01) the hub owns the header. */
|
||||
readonly embedded?: boolean;
|
||||
readonly children: React.ReactNode;
|
||||
}): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<PageShell uiId="ui.telephony.settings.page">
|
||||
{embedded ? null : (
|
||||
<PageHeader
|
||||
icon={<FeatherPhoneCall className={PAGE_HEADER_ICON_CLASS} />}
|
||||
title={t("telephony.settings.title")}
|
||||
subtitle={t("telephony.settings.subtitle")}
|
||||
/>
|
||||
)}
|
||||
<PageBody>
|
||||
{embedded ? (
|
||||
<PageIntro uiId="ui.telephony.settings.intro">{t("telephony.settings.subtitle")}</PageIntro>
|
||||
) : backHref ? (
|
||||
<PageBackLink to={backHref} label={t("integrations.connections.back")} uiId="ui.telephony.settings.back" />
|
||||
) : null}
|
||||
{children}
|
||||
</PageBody>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
|
||||
export function TelephonySettingsPage({
|
||||
vm,
|
||||
actions,
|
||||
busy = false,
|
||||
backHref,
|
||||
embedded = false,
|
||||
hallopetraSetup = null,
|
||||
}: TelephonySettingsPageProps): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
const formatters = useLocaleFormatters();
|
||||
const [disconnectOpen, setDisconnectOpen] = useState(false);
|
||||
const [hallopetraOpen, setHalloPetraOpen] = useState(false);
|
||||
const [hallopetraApiKey, setHalloPetraApiKey] = useState("");
|
||||
|
||||
if (vm.status === "idle" || vm.status === "loading") {
|
||||
return (
|
||||
<SettingsShell backHref={backHref} embedded={embedded}>
|
||||
<Alert
|
||||
variant="neutral"
|
||||
title={t("telephony.settings.loading.title")}
|
||||
description={t("telephony.settings.loading.body")}
|
||||
notDismissible
|
||||
/>
|
||||
</SettingsShell>
|
||||
);
|
||||
}
|
||||
|
||||
if (vm.status === "error") {
|
||||
return (
|
||||
<SettingsShell backHref={backHref} embedded={embedded}>
|
||||
<EmptyState
|
||||
outlined
|
||||
variant="error"
|
||||
title={t("telephony.settings.error.title")}
|
||||
body={t(vm.error.messageKey)}
|
||||
action={
|
||||
actions.onRetry ? (
|
||||
<Button variant="tertiary" onClick={() => void actions.onRetry?.()}>
|
||||
{t("telephony.actions.retry")}
|
||||
</Button>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
</SettingsShell>
|
||||
);
|
||||
}
|
||||
|
||||
if (vm.status === "empty" || !vm.data) {
|
||||
return (
|
||||
<SettingsShell backHref={backHref} embedded={embedded}>
|
||||
<EmptyState outlined title={t("telephony.settings.unavailable.title")} body={t("telephony.settings.unavailable.body")} />
|
||||
</SettingsShell>
|
||||
);
|
||||
}
|
||||
|
||||
const { connection, canManage, providerConfigured, connectHref, providerOptions, userOptions } = vm.data;
|
||||
const currentProviderConfigured = connection
|
||||
? (providerOptions.find((option) => option.provider === connection.provider)?.configured ?? providerConfigured)
|
||||
: providerConfigured;
|
||||
|
||||
return (
|
||||
<SettingsShell backHref={backHref} embedded={embedded}>
|
||||
{connection?.provider === "aircall" ? (
|
||||
<Alert
|
||||
variant="information"
|
||||
title={t("telephony.settings.companyAdmin.title")}
|
||||
description={t("telephony.settings.companyAdmin.body")}
|
||||
notDismissible
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{!connection ? (
|
||||
<div className="flex w-full flex-col gap-4" data-ui-id="ui.telephony.settings.providerSelection">
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("telephony.settings.providers.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("telephony.settings.providers.body")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="grid w-full grid-cols-1 gap-4 lg:grid-cols-2">
|
||||
{providerOptions.map((option) => (
|
||||
<Card key={option.provider} data-provider={option.provider}>
|
||||
<div className="flex w-full items-start justify-between gap-4">
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-body-large-0 font-body-large-0 text-text-neutral-primary">{t(option.labelKey)}</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
||||
{t(`telephony.settings.providers.${option.provider}.body`)}
|
||||
</span>
|
||||
</div>
|
||||
<BadgeFeedback farbe={option.connectionType === "api_key" ? "subtle-information" : "subtle-neutral"} size="small">
|
||||
{t(`telephony.settings.providers.connectionType.${option.connectionType}`)}
|
||||
</BadgeFeedback>
|
||||
</div>
|
||||
{!option.configured ? (
|
||||
<Alert variant="warning" title={t("telephony.settings.providers.notConfigured")} notDismissible />
|
||||
) : null}
|
||||
{canManage ? (
|
||||
<Button
|
||||
icon={option.provider === "hallopetra" ? <FeatherKey /> : <FeatherLink />}
|
||||
loading={busy}
|
||||
disabled={busy || !option.configured}
|
||||
onClick={() => {
|
||||
if (option.provider === "hallopetra") setHalloPetraOpen(true);
|
||||
else void actions.onConnect(option.connectHref);
|
||||
}}
|
||||
>
|
||||
{t("telephony.actions.connectProvider", { provider: t(option.labelKey) })}
|
||||
</Button>
|
||||
) : null}
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<Card data-ui-id="ui.telephony.settings.connection">
|
||||
<div className="flex w-full flex-wrap items-start justify-between gap-4">
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-body-large-0 font-body-large-0 text-text-neutral-primary">{connection.label}</span>
|
||||
<BadgeFeedback farbe={connectionTone(connection.status)}>{t(`telephony.connection.status.${connection.status}`)}</BadgeFeedback>
|
||||
</div>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
||||
{connection.externalCompanyName ?? t("telephony.settings.connection.companyUnknown")}
|
||||
</span>
|
||||
</div>
|
||||
{canManage ? (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{connection.status === "error" || connection.status === "revoked" ? (
|
||||
<Button
|
||||
variant="secondary"
|
||||
icon={<FeatherLink />}
|
||||
loading={busy}
|
||||
disabled={busy || !currentProviderConfigured}
|
||||
onClick={() => {
|
||||
if (connection.provider === "hallopetra") setHalloPetraOpen(true);
|
||||
else void actions.onConnect(connectHref);
|
||||
}}
|
||||
>
|
||||
{t("telephony.actions.reconnect")}
|
||||
</Button>
|
||||
) : null}
|
||||
<Button
|
||||
variant="tertiary"
|
||||
icon={<FeatherRefreshCw />}
|
||||
loading={busy}
|
||||
disabled={busy}
|
||||
onClick={() => void actions.onHealthCheck(connection.id)}
|
||||
>
|
||||
{t("telephony.actions.checkHealth")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
icon={<FeatherTrash2 />}
|
||||
disabled={busy}
|
||||
onClick={() => setDisconnectOpen(true)}
|
||||
data-testid="telephony-disconnect-trigger"
|
||||
>
|
||||
{t("telephony.actions.disconnect")}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="grid w-full grid-cols-1 gap-3 sm:grid-cols-3">
|
||||
<div className="flex flex-col gap-1 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-4 py-3">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">
|
||||
{t("telephony.settings.connection.provider")}
|
||||
</span>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">
|
||||
{t(`telephony.provider.${connection.provider}`)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-4 py-3">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">
|
||||
{t("telephony.settings.connection.company")}
|
||||
</span>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">
|
||||
{connection.externalCompanyName ?? t("telephony.settings.connection.companyUnknown")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-4 py-3">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">
|
||||
{t("telephony.settings.connection.lastHealthCheck")}
|
||||
</span>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">
|
||||
{connection.lastHealthCheckAt
|
||||
? formatters.dateTime(connection.lastHealthCheckAt)
|
||||
: t("telephony.settings.connection.neverChecked")}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{connection.errorKey ? (
|
||||
<Alert variant="error" title={t("telephony.settings.connection.errorTitle")} description={t(connection.errorKey)} notDismissible />
|
||||
) : null}
|
||||
</Card>
|
||||
|
||||
{connection.provider === "hallopetra" ? (
|
||||
<Alert
|
||||
variant="information"
|
||||
title={t("telephony.settings.hallopetra.inboundOnly.title")}
|
||||
description={t("telephony.settings.hallopetra.inboundOnly.body")}
|
||||
notDismissible
|
||||
/>
|
||||
) : (
|
||||
<div className="flex w-full flex-col gap-3" data-ui-id="ui.telephony.settings.bindings">
|
||||
<div className="flex items-center gap-2">
|
||||
<FeatherUsers className="text-body-large font-body-large text-icon-neutral-tertiary" />
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("telephony.settings.bindings.title")}</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
||||
{t("telephony.settings.bindings.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{connection.bindings.length === 0 ? (
|
||||
<EmptyState outlined title={t("telephony.settings.bindings.empty.title")} body={t("telephony.settings.bindings.empty.body")} />
|
||||
) : (
|
||||
<div className="w-full overflow-x-auto rounded-md">
|
||||
<Table
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("telephony.settings.bindings.columns.aircallUser")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("telephony.settings.bindings.columns.hivegridUser")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("telephony.settings.bindings.columns.match")}</Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{connection.bindings.map((binding) => (
|
||||
<Table.Row key={binding.id} data-binding-id={binding.id}>
|
||||
<Table.Cell>
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{binding.providerName}
|
||||
</span>
|
||||
{binding.providerEmail ? (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{binding.providerEmail}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Select
|
||||
className="min-w-[240px] max-w-[320px]"
|
||||
disabled={!canManage || busy}
|
||||
value={binding.hivegridUserId ?? UNASSIGNED}
|
||||
onValueChange={(value: string) =>
|
||||
void actions.onBindingChange(binding.id, value === UNASSIGNED ? null : value)
|
||||
}
|
||||
aria-label={t("telephony.settings.bindings.assignAria", { name: binding.providerName })}
|
||||
>
|
||||
<Select.Item value={UNASSIGNED}>{t("telephony.settings.bindings.unassigned")}</Select.Item>
|
||||
{userOptions.map((user) => (
|
||||
<Select.Item key={user.id} value={user.id}>
|
||||
{user.label} · {user.email}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<BadgeFeedback farbe={bindingTone(binding.match)} size="small">
|
||||
{t(`telephony.binding.match.${binding.match}`)}
|
||||
</BadgeFeedback>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Dialog open={disconnectOpen} onOpenChange={setDisconnectOpen}>
|
||||
<Dialog.Content className="w-[420px] max-w-[90vw] p-6">
|
||||
<div className="flex w-full flex-col gap-6" data-ui-id="ui.telephony.settings.disconnectConfirm">
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">
|
||||
{t("telephony.settings.disconnect.title")}
|
||||
</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("telephony.settings.disconnect.body")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex w-full items-center justify-end gap-2">
|
||||
<Button variant="tertiary" onClick={() => setDisconnectOpen(false)}>
|
||||
{t("telephony.actions.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
loading={busy}
|
||||
disabled={busy}
|
||||
onClick={() => void actions.onDisconnect(connection.id)}
|
||||
>
|
||||
{t("telephony.actions.disconnect")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</>
|
||||
)}
|
||||
|
||||
<Dialog open={hallopetraOpen} onOpenChange={setHalloPetraOpen}>
|
||||
<Dialog.Content className="w-[620px] max-w-[90vw] p-6">
|
||||
<div className="flex w-full flex-col gap-5" data-ui-id="ui.telephony.settings.hallopetraConnect">
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("telephony.settings.hallopetra.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("telephony.settings.hallopetra.body")}
|
||||
</span>
|
||||
</div>
|
||||
{hallopetraSetup ? (
|
||||
<>
|
||||
<Alert
|
||||
variant="success"
|
||||
title={t("telephony.settings.hallopetra.connected.title")}
|
||||
description={t("telephony.settings.hallopetra.connected.body")}
|
||||
notDismissible
|
||||
/>
|
||||
<div className="flex flex-col gap-3 rounded-md border border-solid border-border-default bg-surface-neutral-primary p-4">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-secondary">
|
||||
{t("telephony.settings.hallopetra.webhookUrl")}
|
||||
</span>
|
||||
<code className="break-all text-body-small-regular-150 text-text-neutral-primary">{hallopetraSetup.webhookUrl}</code>
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-secondary">
|
||||
{t("telephony.settings.hallopetra.webhookHeader")}
|
||||
</span>
|
||||
<code className="break-all text-body-small-regular-150 text-text-neutral-primary">
|
||||
Authorization: Bearer {hallopetraSetup.webhookSecret}
|
||||
</code>
|
||||
</div>
|
||||
<Alert variant="warning" title={t("telephony.settings.hallopetra.secretOnce")} notDismissible />
|
||||
</>
|
||||
) : (
|
||||
<TextInput className="w-full" label={t("telephony.settings.hallopetra.apiKey")} showLabel type="password">
|
||||
<TextInput.Input
|
||||
type="password"
|
||||
value={hallopetraApiKey}
|
||||
onChange={(event) => setHalloPetraApiKey(event.target.value)}
|
||||
autoComplete="off"
|
||||
data-testid="hallopetra-api-key"
|
||||
/>
|
||||
</TextInput>
|
||||
)}
|
||||
<div className="flex w-full justify-end gap-2">
|
||||
<Button variant="tertiary" disabled={busy} onClick={() => setHalloPetraOpen(false)}>
|
||||
{t(hallopetraSetup ? "telephony.actions.close" : "telephony.actions.cancel")}
|
||||
</Button>
|
||||
{!hallopetraSetup ? (
|
||||
<Button
|
||||
icon={<FeatherKey />}
|
||||
loading={busy}
|
||||
disabled={busy || !hallopetraApiKey.trim()}
|
||||
onClick={() => void actions.onConnectHalloPetra?.(hallopetraApiKey)}
|
||||
>
|
||||
{t("telephony.actions.connect")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</SettingsShell>
|
||||
);
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`AK-P15a telephony interim visual baseline > renders the settings, call list, detail, and click-to-call surfaces from ~/ui 1`] = `"<span data-radix-focus-guard="" tabindex="0" style="outline: none; opacity: 0; position: fixed; pointer-events: none;" data-aria-hidden="true" aria-hidden="true"></span><div data-aria-hidden="true" aria-hidden="true"><main data-ui-id="ui.telephony.interim.visualBaseline"><div class="flex w-full flex-col items-start" data-ui-id="ui.telephony.settings.page"><div class="flex w-full items-start gap-4 border-b border-solid border-border-default bg-surface-neutral-secondary px-6 py-5 mobile:flex-col mobile:px-4"><div class="flex grow shrink-0 basis-0 flex-col items-start gap-1"><div class="flex items-center gap-2"><span class="text-heading- font-heading- text-icon-neutral-tertiary icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span><h1 class="text-subtitle font-subtitle text-text-neutral-primary mobile:text-heading- mobile:font-heading-">telephony.settings.title</h1></div><p class="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">telephony.settings.subtitle</p></div></div><div class="flex w-full flex-col gap-6 p-6 mobile:p-4"><div class="group/3a65613d flex w-full flex-col items-start gap-2 rounded-md border border-solid border-border-information-subtle bg-surface-feedback-subtle-information px-4 py-5 relative"><div class="flex w-full items-start gap-3"><span class="text-heading-0 font-heading-0 text-icon-feedback-information icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span><span class="hidden text-heading-0 font-heading-0 text-icon-feedback-positive icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span><span class="hidden text-heading-0 font-heading-0 text-icon-feedback-warning icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span><span class="hidden text-heading-0 font-heading-0 text-icon-feedback-negative icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span><span class="hidden text-heading-0 font-heading-0 text-icon-neutral-secondary icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span><div class="flex grow shrink-0 basis-0 flex-col items-start gap-2"><span class="w-full whitespace-pre-wrap text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-information">telephony.settings.companyAdmin.title</span><span class="w-full whitespace-pre-wrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">telephony.settings.companyAdmin.body</span></div></div><div class="hidden items-start justify-center absolute top-3 right-3"><span class="text-body-default-regular-0 font-body-default-regular-0 text-icon-neutral-secondary icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span></div></div><div class="group/56067c50 flex w-full flex-col items-start gap-4 rounded-md border border-solid border-border-default bg-surface-neutral-secondary px-4 py-4 shadow-sm" data-ui-id="ui.telephony.settings.connection"><div class="flex w-full flex-wrap items-start justify-between gap-4"><div class="flex flex-col gap-1"><div class="flex flex-wrap items-center gap-2"><span class="text-body-large-0 font-body-large-0 text-text-neutral-primary">Aircall Berlin</span><div class="group/896531e4 flex h-6 items-center gap-2 rounded-round px-2.5 py-1 bg-surface-feedback-subtle-positive"><div class="flex h-1 w-1 flex-none flex-col items-start gap-2 rounded-round bg-icon-feedback-positive"></div><span class="whitespace-nowrap text-body-small-medium-0 font-body-small-medium-0 text-text-feedback-positive">telephony.connection.status.active</span></div></div><span class="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">Werkstatt Berlin</span></div><div class="flex flex-wrap items-center gap-2"><button class="group/3b777358 flex h-9 cursor-pointer items-center justify-center gap-3 rounded-md px-4 py-2.5 text-left focus-within:shadow-focus disabled:cursor-default disabled:bg-surface-neutral-disabled disabled:pointer-events-none hover:disabled:cursor-default hover:disabled:bg-surface-neutral-disabled active:disabled:cursor-default active:disabled:bg-surface-neutral-disabled border border-solid border-border-default bg-surface-neutral-primary hover:border hover:border-solid hover:border-border-strong hover:bg-surface-neutral-secondary active:bg-surface-neutral-tertiary" type="button"><span class="text-body-default-regular-0 font-body-default-regular-0 group-disabled/3b777358:text-icon-neutral-disabled text-icon-neutral-on-subtle icon-wrapper-module_root__-l6uP"><span class="icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span></span><div class="hidden h-4 w-4 flex-none items-center justify-center gap-2"><div class="text-body-extra-small-regular-150 font-body-extra-small-regular-150 group-disabled/3b777358:text-icon-neutral-disabled gLine truncated
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
import { createTelephonyInterimFixtureViewModels } from "@hivegrid/ui-mock";
|
||||
|
||||
import { ClickToCallDialog } from "./ClickToCallDialog";
|
||||
import { TelephonyCallDetailPage } from "./TelephonyCallDetailPage";
|
||||
import { TelephonyCallsPage } from "./TelephonyCallsPage";
|
||||
import { TelephonySettingsPage } from "./TelephonySettingsPage";
|
||||
|
||||
export const TELEPHONY_INTERIM_VISUAL_SCREENS = ["settings", "calls", "call-detail", "click-to-call"] as const;
|
||||
|
||||
export type TelephonyInterimVisualScreen = (typeof TELEPHONY_INTERIM_VISUAL_SCREENS)[number];
|
||||
|
||||
const noOp = (): void => undefined;
|
||||
|
||||
/** Shared AD-28 fixture for markup snapshots and Chromium pixel baselines. */
|
||||
export function TelephonyInterimVisualFixture({ screen }: { readonly screen: TelephonyInterimVisualScreen }): React.JSX.Element {
|
||||
const vm = createTelephonyInterimFixtureViewModels();
|
||||
|
||||
switch (screen) {
|
||||
case "settings":
|
||||
return (
|
||||
<TelephonySettingsPage
|
||||
vm={vm.settings}
|
||||
actions={{ onConnect: noOp, onHealthCheck: noOp, onBindingChange: noOp, onDisconnect: noOp }}
|
||||
/>
|
||||
);
|
||||
case "calls":
|
||||
return <TelephonyCallsPage vm={vm.calls} actions={{ onOpenCall: noOp, onRefresh: noOp }} />;
|
||||
case "call-detail":
|
||||
return (
|
||||
<TelephonyCallDetailPage
|
||||
vm={vm.callDetail}
|
||||
actions={{ onBack: noOp, onOverrideMatch: noOp, onSaveNote: noOp, onCallBack: noOp }}
|
||||
/>
|
||||
);
|
||||
case "click-to-call":
|
||||
return <ClickToCallDialog open vm={vm.clickToCall} actions={{ onOpenChange: noOp, onCall: noOp }} />;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
// @vitest-environment jsdom
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import React from "react";
|
||||
import { render } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { TELEPHONY_INTERIM_VISUAL_SCREENS, TelephonyInterimVisualFixture } from "./telephony-interim.visual-fixture";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string, values?: Record<string, unknown>) => (values ? `${key}:${Object.values(values).join("/")}` : key),
|
||||
i18n: { language: "de" },
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("~/locale/format", () => ({
|
||||
useLocaleFormatters: () => ({
|
||||
number: (value: number) => String(value),
|
||||
date: (value: string) => value,
|
||||
dateTime: (value: string) => `date:${value}`,
|
||||
}),
|
||||
}));
|
||||
|
||||
describe("AK-P15a telephony interim visual baseline", () => {
|
||||
it("renders the settings, call list, detail, and click-to-call surfaces from ~/ui", () => {
|
||||
render(
|
||||
<main data-ui-id="ui.telephony.interim.visualBaseline">
|
||||
{TELEPHONY_INTERIM_VISUAL_SCREENS.map((screen) => (
|
||||
<TelephonyInterimVisualFixture key={screen} screen={screen} />
|
||||
))}
|
||||
</main>,
|
||||
);
|
||||
|
||||
expect(document.querySelectorAll("[data-ui-id='ui.telephony.settings.page']")).toHaveLength(1);
|
||||
expect(document.querySelectorAll("[data-ui-id='ui.telephony.calls.page']")).toHaveLength(1);
|
||||
expect(document.querySelectorAll("[data-ui-id='ui.telephony.callDetail.page']")).toHaveLength(1);
|
||||
expect(document.querySelectorAll("[data-ui-id='ui.telephony.clickToCall.dialog']")).toHaveLength(1);
|
||||
|
||||
const stableMarkup = document.body.innerHTML.replace(/<svg\b[^>]*>[\s\S]*?<\/svg>/gu, '<svg data-visual-icon="true"></svg>');
|
||||
expect(stableMarkup).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user