import { MouseEventHandler, ReactNode, useRef } from "react"; import clsx from "clsx"; import LinkOrAhref from "./LinkOrAhref"; import ConfirmModal, { RefConfirmModal } from "../modals/ConfirmModal"; import { Button } from "../button"; import { useLocation, useMatches } from "react-router"; import { useRootData } from "~/utils/data/useRootData"; import AnalyticsHelper from "~/utils/helpers/AnalyticsHelper"; import { useTranslation } from "react-i18next"; interface Props { className?: string; type?: "button" | "submit" | "reset" | undefined; to?: string; target?: undefined | "_blank"; rel?: string; disabled?: boolean; destructive?: boolean; children: ReactNode; onClick?: MouseEventHandler; reloadDocument?: boolean; prefetch?: "intent" | "render" | "none"; confirmation?: { title: string; description: string; }; event?: { action: string; category: string; label: string; value: string }; sendEvent?: boolean; } export default function ButtonTertiary({ className = "", type = "button", onClick, disabled, destructive, to, target, rel, children, reloadDocument, prefetch, confirmation, event, sendEvent, }: Props) { const { t } = useTranslation(); const refConfirm = useRef(null); let location = useLocation(); const rootData = useRootData(); const matches = useMatches(); function onClicked(e: React.MouseEvent) { if (onClick) { onClick(e); } if (!event || !sendEvent) { return; } const routeMatch = matches.find((m) => m.pathname == location.pathname); AnalyticsHelper.addEvent({ url: location.pathname, route: routeMatch?.id, rootData, action: event.action, category: event.category, label: event.label, value: event.value, }); } return ( {(() => { if (!to || disabled) { return ( ); } else { return ( ); } })()} ); }