import clsx from "clsx"; import { useTranslation } from "react-i18next"; import CheckIcon from "~/components/ui/icons/CheckIcon"; import ExclamationTriangleIcon from "~/components/ui/icons/ExclamationTriangleIcon"; import XIcon from "~/components/ui/icons/XIcon"; import TableSimple from "~/components/ui/tables/TableSimple"; import { NotificationChannelDto, NotificationChannels } from "../services/NotificationChannels"; import type { IGetTemplatesData } from "../services/.server/NotificationService"; export default function NotificationTemplatesTable({ items, onDelete, onSendPreview, }: { items: IGetTemplatesData | null; onDelete: (id: string) => void; onSendPreview: (item: NotificationChannelDto) => void; }) { const { t } = useTranslation(); const channelLabel = (item: NotificationChannelDto) => t(`notifications.admin.channelLabels.${item.name}`, { defaultValue: item.name.replace(/[-_.]+/g, " ").replace(/\b\w/g, (letter) => letter.toUpperCase()), }); const channelDescription = (item: NotificationChannelDto) => t(item.descriptionKey, { defaultValue: item.name.replace(/[-_.]+/g, " "), }); const roleLabel = (role: string) => t(`notifications.admin.roleLabels.${role}`, { defaultValue: role.replace(/([a-z0-9])([A-Z])/g, "$1 $2") }); function getCreated(i: NotificationChannelDto) { return items?.data?.find((f) => f.name === i.name); } function isValid(item: NotificationChannelDto, templates: IGetTemplatesData | null) { const existing = templates?.data?.find((f) => f.name === item.name); if (!existing || !existing.steps || existing.steps.length === 0) { return false; } return true; } return ( ( <> {!isValid(i, items) ? (
{channelLabel(i)}
) : (
{channelLabel(i)}
)} ), }, { name: "description", title: t("notifications.admin.templates.description"), className: "w-full", value: (i) => (
{channelDescription(i)}
), }, { name: "roles", title: t("notifications.admin.templates.roles"), value: (i) =>
{i.roles?.map((role) => roleLabel(role)).join(", ") || t("shared.notSet")}
, }, { name: "send", title: t("shared.preview"), value: (i) => (
), }, { name: "active", title: t("notifications.admin.templates.active"), value: (i) => (
{getCreated(i)?.active ? : }
), }, { name: "hasSteps", title: t("notifications.admin.templates.hasSteps"), value: (i) => (
{(getCreated(i)?.steps ?? []).length > 0 ? : }
), }, // { // name: "tags", // title: "Tags", // value: (i) => // getCreated(i) // ?.tags.map((f) => f) // .join(", "), // }, { name: "_id", title: t("notifications.admin.templates.provider"), value: (i) => ( <> {getCreated(i)?._id ? ( {t("notifications.admin.templates.openProvider")} ) : ( {t("shared.create")} )} ), }, // { // name: "delete", // title: "Delete", // value: (i) => ( //
// {i._id !== undefined && ( // // )} //
// ), // }, ]} >
); }