Files
community-rule/app/components/cards/Rule/Rule.container.tsx
T
adilallo 6498d52541 Skip setup questions on the template path and collect name, photo, and description without recommendations.
Customize opens a dialog then walks the template decks; Use without changes lands on final review with Has Name Field. Template cards stay first, the engine is not called, and the catalog no longer shows a recommended tag.
2026-11-09 17:34:33 -07:00

156 lines
4.5 KiB
TypeScript

"use client";
import { memo } from "react";
import { useTranslation } from "../../../contexts/MessagesContext";
import { RuleView } from "./Rule.view";
import type { RuleProps } from "./Rule.types";
declare global {
interface Window {
gtag?: (
_command: string,
_eventName: string,
_params?: Record<string, unknown>,
) => void;
analytics?: {
track: (_eventName: string, _params?: Record<string, unknown>) => void;
};
}
}
/**
* Figma: "Card / Rule" — e.g. profile `22143:900771` when **Has bottom link** is on
* (`hasBottomLinks` + `bottomLinks` / optional `bottomStatusLabel`).
*/
const RuleContainer = memo<RuleProps>(
({
title,
description,
onDescriptionClick,
descriptionEmptyHint,
descriptionEditAriaLabel,
onTitleClick,
titleEditAriaLabel,
icon,
backgroundColor = "bg-[var(--color-community-teal-100)]",
className = "",
onClick,
href,
expanded = false,
size: sizeProp,
categories,
logoUrl,
logoAlt,
communityInitials,
hideCategoryAddButton = false,
interactive,
hasBottomLinks = false,
bottomStatusLabel,
bottomLinks,
recommended = false,
templateGridFigmaShell = false,
fluidWidth = false,
descriptionAtBottom = false,
surfaceColor,
hasNameField = false,
nameValue,
nameLabel,
namePlaceholder,
onNameChange,
descriptionLabel,
descriptionPlaceholder,
descriptionHelperText,
onDescriptionChange,
onLogoClick,
logoUploadAriaLabel,
}) => {
const size = sizeProp ?? "L";
const isInteractive = interactive ?? !hasBottomLinks;
const t = useTranslation("ruleCard");
const cardAriaLabel = t("ariaLabel")?.replace("{title}", title) || title;
const recommendedLabel = t("recommendedLabel");
const handleClick = () => {
if (!isInteractive || hasBottomLinks) return;
// Basic analytics event tracking
if (typeof window !== "undefined" && window.gtag) {
window.gtag("event", "template_selected", {
template_name: title,
template_type: "governance_pattern",
});
}
// Custom analytics event for other tracking systems
if (typeof window !== "undefined" && window.analytics) {
window.analytics.track("Template Selected", {
templateName: title,
templateType: "governance_pattern",
});
}
if (onClick) onClick();
};
const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
if (!isInteractive || hasBottomLinks) return;
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
handleClick();
}
};
return (
<RuleView
title={title}
description={description}
onDescriptionClick={onDescriptionClick}
descriptionEmptyHint={descriptionEmptyHint}
descriptionEditAriaLabel={descriptionEditAriaLabel}
onTitleClick={onTitleClick}
titleEditAriaLabel={titleEditAriaLabel}
icon={icon}
backgroundColor={backgroundColor}
className={className}
href={isInteractive && !hasBottomLinks ? href : undefined}
onClick={isInteractive && !hasBottomLinks ? handleClick : undefined}
onKeyDown={
isInteractive && !hasBottomLinks && !href ? handleKeyDown : undefined
}
expanded={expanded}
size={size}
categories={categories}
logoUrl={logoUrl}
logoAlt={logoAlt}
communityInitials={communityInitials}
hideCategoryAddButton={hideCategoryAddButton}
interactive={isInteractive}
hasBottomLinks={hasBottomLinks}
bottomStatusLabel={bottomStatusLabel}
bottomLinks={bottomLinks}
recommended={recommended}
templateGridFigmaShell={templateGridFigmaShell}
fluidWidth={fluidWidth}
descriptionAtBottom={descriptionAtBottom}
surfaceColor={surfaceColor}
cardAriaLabel={cardAriaLabel}
recommendedLabel={recommendedLabel}
hasNameField={hasNameField}
nameValue={nameValue}
nameLabel={nameLabel}
namePlaceholder={namePlaceholder}
onNameChange={onNameChange}
descriptionLabel={descriptionLabel}
descriptionPlaceholder={descriptionPlaceholder}
descriptionHelperText={descriptionHelperText}
onDescriptionChange={onDescriptionChange}
onLogoClick={onLogoClick}
logoUploadAriaLabel={logoUploadAriaLabel}
/>
);
},
);
RuleContainer.displayName = "Rule";
export default RuleContainer;