Merge pull request 'Show the Profile empty state, phone layout, and Rules you belong to' (#106) from adilallo/feature/CR-304-CR-306-profile into main
Reviewed-on: #106
This commit was merged in pull request #106.
This commit is contained in:
commit
44010c7b73
12 files changed
+577
-140
No files matched your search
@@ -60,6 +60,7 @@ export default function ProfilePageClient() {
|
|||||||
const [sessionLoaded, setSessionLoaded] = useState(false);
|
const [sessionLoaded, setSessionLoaded] = useState(false);
|
||||||
const [user, setUser] = useState<{ id: string; email: string } | null>(null);
|
const [user, setUser] = useState<{ id: string; email: string } | null>(null);
|
||||||
const [rules, setRules] = useState<MyPublishedRule[]>([]);
|
const [rules, setRules] = useState<MyPublishedRule[]>([]);
|
||||||
|
const [rulesLoaded, setRulesLoaded] = useState(false);
|
||||||
const [rulesError, setRulesError] = useState(false);
|
const [rulesError, setRulesError] = useState(false);
|
||||||
const [draft, setDraft] = useState<
|
const [draft, setDraft] = useState<
|
||||||
Awaited<ReturnType<typeof fetchServerDraftForProfile>>
|
Awaited<ReturnType<typeof fetchServerDraftForProfile>>
|
||||||
@@ -92,6 +93,7 @@ export default function ProfilePageClient() {
|
|||||||
setSessionLoaded(true);
|
setSessionLoaded(true);
|
||||||
if (!u) {
|
if (!u) {
|
||||||
setRules([]);
|
setRules([]);
|
||||||
|
setRulesLoaded(false);
|
||||||
setRulesError(false);
|
setRulesError(false);
|
||||||
setDraft(null);
|
setDraft(null);
|
||||||
return;
|
return;
|
||||||
@@ -101,10 +103,11 @@ export default function ProfilePageClient() {
|
|||||||
fetchServerDraftForProfile(),
|
fetchServerDraftForProfile(),
|
||||||
]);
|
]);
|
||||||
if (r === null) {
|
if (r === null) {
|
||||||
setRules([]);
|
setRulesLoaded(false);
|
||||||
setRulesError(true);
|
setRulesError(true);
|
||||||
} else {
|
} else {
|
||||||
setRules(r);
|
setRules(r);
|
||||||
|
setRulesLoaded(true);
|
||||||
setRulesError(false);
|
setRulesError(false);
|
||||||
}
|
}
|
||||||
setDraft(d);
|
setDraft(d);
|
||||||
@@ -435,6 +438,7 @@ export default function ProfilePageClient() {
|
|||||||
profileLgUp={isProfileLgUp}
|
profileLgUp={isProfileLgUp}
|
||||||
profileListSize={isProfileXlUp ? "l" : "m"}
|
profileListSize={isProfileXlUp ? "l" : "m"}
|
||||||
rules={rules}
|
rules={rules}
|
||||||
|
rulesLoaded={rulesLoaded}
|
||||||
rulesError={rulesError}
|
rulesError={rulesError}
|
||||||
draft={draft}
|
draft={draft}
|
||||||
showDraftCard={showDraftCard}
|
showDraftCard={showDraftCard}
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
import { useId, useMemo } from "react";
|
import { useId, useMemo } from "react";
|
||||||
import Button from "../../../components/buttons/Button";
|
import Button from "../../../components/buttons/Button";
|
||||||
|
import NoRules from "../../../components/cards/NoRules";
|
||||||
import Rule from "../../../components/cards/Rule";
|
import Rule from "../../../components/cards/Rule";
|
||||||
import TextInput from "../../../components/controls/TextInput";
|
import TextInput from "../../../components/controls/TextInput";
|
||||||
import List from "../../../components/layout/List";
|
import List from "../../../components/layout/List";
|
||||||
import type { ListItem, ListSize } from "../../../components/layout/List";
|
import type { ListItem, ListSize } from "../../../components/layout/List";
|
||||||
import ListEntry from "../../../components/layout/ListEntry";
|
|
||||||
import Icon from "../../../components/asset/icon";
|
import Icon from "../../../components/asset/icon";
|
||||||
import Dialog from "../../../components/modals/Dialog";
|
import Dialog from "../../../components/modals/Dialog";
|
||||||
import DeleteAccount from "../../../components/modals/DeleteAccount";
|
import DeleteAccount from "../../../components/modals/DeleteAccount";
|
||||||
@@ -29,6 +29,14 @@ function draftBodyTextFromState(
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function communityInitialsFromTitle(title: string): string {
|
||||||
|
return title.trim().charAt(0).toUpperCase() || "·";
|
||||||
|
}
|
||||||
|
|
||||||
|
function fillName(template: string, name: string): string {
|
||||||
|
return template.replace(/\{\{name\}\}/g, name);
|
||||||
|
}
|
||||||
|
|
||||||
export type ProfilePageViewProps = {
|
export type ProfilePageViewProps = {
|
||||||
userEmail: string;
|
userEmail: string;
|
||||||
/** `M` below `lg` (1024px); `L` at `lg`+ per Figma Card / Rule. Breakpoints: `md` (640px) → `lg` (1024px) only. */
|
/** `M` below `lg` (1024px); `L` at `lg`+ per Figma Card / Rule. Breakpoints: `md` (640px) → `lg` (1024px) only. */
|
||||||
@@ -38,6 +46,8 @@ export type ProfilePageViewProps = {
|
|||||||
/** `m` = {@link List} M; `l` = List L at `xl` per Figma `22143:900256`. */
|
/** `m` = {@link List} M; `l` = List L at `xl` per Figma `22143:900256`. */
|
||||||
profileListSize: Extract<ListSize, "m" | "l">;
|
profileListSize: Extract<ListSize, "m" | "l">;
|
||||||
rules: MyPublishedRule[];
|
rules: MyPublishedRule[];
|
||||||
|
/** True only after `fetchMyPublishedRules` succeeds. Dismissing the warning does not set this. */
|
||||||
|
rulesLoaded: boolean;
|
||||||
rulesError: boolean;
|
rulesError: boolean;
|
||||||
draft: ServerDraftForProfile | null;
|
draft: ServerDraftForProfile | null;
|
||||||
showDraftCard: boolean;
|
showDraftCard: boolean;
|
||||||
@@ -107,7 +117,7 @@ export function ProfilePageSignedOutView({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full bg-[var(--color-surface-default-primary)] text-[var(--color-content-default-primary)]">
|
<div className="w-full bg-[var(--color-surface-default-primary)] text-[var(--color-content-default-primary)]">
|
||||||
<div className="flex flex-col gap-6 px-4 pt-4 pb-4 md:px-8 lg:gap-10 lg:px-16">
|
<div className="flex flex-col gap-8 px-5 pt-2 pb-8 md:px-8 lg:gap-10 lg:px-16">
|
||||||
<header
|
<header
|
||||||
className={
|
className={
|
||||||
profileLgUp
|
profileLgUp
|
||||||
@@ -153,9 +163,9 @@ export function ProfilePageSignedOutView({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Figma: mobile `22143:900762`; tablet `md` `22143:900534` (`@theme --breakpoint-md` 640px);
|
* Figma: phone `25032:88248` / empty `25032:88410` (320–639);
|
||||||
* desktop `lg` `21962:17220` (`@theme --breakpoint-lg` 1024px);
|
* several Rules `25206:93086`; belong-to phone `25219:136704` and desktop `25219:136446`;
|
||||||
* `xl` `22143:900247` (same content spacing as lg; list + section type at `xl` — `List` L `21844:4405`).
|
* desktop empty `25032:88574`; `xl` list + section type `22143:900247` (`List` L `21844:4405`).
|
||||||
*/
|
*/
|
||||||
export function ProfilePageView({
|
export function ProfilePageView({
|
||||||
userEmail,
|
userEmail,
|
||||||
@@ -163,6 +173,7 @@ export function ProfilePageView({
|
|||||||
profileLgUp,
|
profileLgUp,
|
||||||
profileListSize,
|
profileListSize,
|
||||||
rules,
|
rules,
|
||||||
|
rulesLoaded,
|
||||||
rulesError,
|
rulesError,
|
||||||
draft,
|
draft,
|
||||||
showDraftCard,
|
showDraftCard,
|
||||||
@@ -207,9 +218,30 @@ export function ProfilePageView({
|
|||||||
const t = useTranslation("pages.profile");
|
const t = useTranslation("pages.profile");
|
||||||
const tLogin = useTranslation("pages.login");
|
const tLogin = useTranslation("pages.login");
|
||||||
const titleId = useId();
|
const titleId = useId();
|
||||||
const welcomeTitle = t("welcomeTitle").replace(/\{\{name\}\}/g, userEmail);
|
const ownedRules = useMemo(
|
||||||
const welcomeBody =
|
() => rules.filter((rule) => rule.role === "owner"),
|
||||||
rules.length > 0 ? t("welcomeBodyFirstRule") : t("welcomeBodyNoRules");
|
[rules],
|
||||||
|
);
|
||||||
|
const belongToRules = useMemo(
|
||||||
|
() => rules.filter((rule) => rule.role === "stakeholder"),
|
||||||
|
[rules],
|
||||||
|
);
|
||||||
|
const welcomeTitle = fillName(
|
||||||
|
showDraftCard || ownedRules.length === 0
|
||||||
|
? t("welcomeTitleReturn")
|
||||||
|
: t("welcomeTitle"),
|
||||||
|
userEmail,
|
||||||
|
);
|
||||||
|
const welcomeBody = showDraftCard
|
||||||
|
? t("welcomeBodyReturn")
|
||||||
|
: ownedRules.length > 0
|
||||||
|
? t("welcomeBodyFirstRule")
|
||||||
|
: undefined;
|
||||||
|
const showEmptyYourRules =
|
||||||
|
rulesLoaded &&
|
||||||
|
ownedRules.length === 0 &&
|
||||||
|
!showDraftCard &&
|
||||||
|
!rulesError;
|
||||||
|
|
||||||
const profileOptionsItems = useMemo((): ListItem[] => {
|
const profileOptionsItems = useMemo((): ListItem[] => {
|
||||||
return [
|
return [
|
||||||
@@ -245,16 +277,32 @@ export function ProfilePageView({
|
|||||||
leadingIcon: "mail",
|
leadingIcon: "mail",
|
||||||
showDescription: false,
|
showDescription: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "delete-account",
|
||||||
|
title: t("deleteAccount"),
|
||||||
|
description: "",
|
||||||
|
onClick: onOpenDeleteAccount,
|
||||||
|
leadingIcon: "warning",
|
||||||
|
variant: "danger",
|
||||||
|
showDescription: false,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
}, [t, onSignOut, onOpenEmailChange, onStartNewCustomRule]);
|
}, [
|
||||||
|
t,
|
||||||
|
onSignOut,
|
||||||
|
onOpenEmailChange,
|
||||||
|
onOpenDeleteAccount,
|
||||||
|
onStartNewCustomRule,
|
||||||
|
]);
|
||||||
|
|
||||||
const ruleCardShellClass =
|
const ruleCardShellClass =
|
||||||
"w-full !max-w-full cursor-default !gap-3 !rounded-[12px] shadow-[0_0_48px_rgba(0,0,0,0.1)] lg:!rounded-[24px] lg:shadow-[0_0_24px_rgba(0,0,0,0.1)]";
|
"w-full !max-w-full !gap-3 !rounded-[12px] shadow-[0_0_48px_rgba(0,0,0,0.1)] lg:!rounded-[24px] lg:shadow-[0_0_24px_rgba(0,0,0,0.1)]";
|
||||||
|
const ownedRuleCardShellClass = `${ruleCardShellClass} cursor-default`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="w-full bg-[var(--color-surface-default-primary)] text-[var(--color-content-default-primary)]">
|
<div className="w-full bg-[var(--color-surface-default-primary)] text-[var(--color-content-default-primary)]">
|
||||||
<div className="flex flex-col gap-6 px-4 pt-4 pb-4 md:px-8 lg:gap-10 lg:px-16">
|
<div className="flex flex-col gap-8 px-5 pt-2 pb-8 md:px-8 lg:gap-10 lg:px-16">
|
||||||
<header
|
<header
|
||||||
className={
|
className={
|
||||||
profileLgUp
|
profileLgUp
|
||||||
@@ -278,116 +326,144 @@ export function ProfilePageView({
|
|||||||
>
|
>
|
||||||
{welcomeTitle}
|
{welcomeTitle}
|
||||||
</h1>
|
</h1>
|
||||||
<p className="max-w-[640px] text-small-paragraph text-[var(--color-content-default-tertiary)] md:text-medium-paragraph">
|
{welcomeBody ? (
|
||||||
{welcomeBody}
|
<p className="max-w-[640px] text-small-paragraph text-[var(--color-content-default-tertiary)] md:text-medium-paragraph">
|
||||||
</p>
|
{welcomeBody}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div className="flex flex-col gap-8 lg:flex-row lg:flex-nowrap lg:items-start lg:gap-8">
|
<div className="flex flex-col gap-10 lg:flex-row lg:flex-nowrap lg:items-start lg:gap-8">
|
||||||
<section
|
<div className="flex min-w-0 w-full flex-col gap-10 lg:min-w-0 lg:flex-1">
|
||||||
className="flex min-w-0 w-full flex-col gap-3 lg:min-w-0 lg:flex-1 lg:gap-6"
|
<section
|
||||||
aria-labelledby="profile-rules-heading"
|
className="flex min-w-0 w-full flex-col gap-4 lg:gap-6"
|
||||||
>
|
aria-labelledby="profile-rules-heading"
|
||||||
<h2
|
|
||||||
id="profile-rules-heading"
|
|
||||||
className={profileSectionHeadingClass}
|
|
||||||
style={{ fontVariationSettings: "'opsz' 14, 'wdth' 100" }}
|
|
||||||
>
|
>
|
||||||
{t("yourRulesHeading")}
|
<h2
|
||||||
</h2>
|
id="profile-rules-heading"
|
||||||
<div className="flex flex-col gap-3">
|
className={profileSectionHeadingClass}
|
||||||
{showDraftCard && draft?.hasDraft ? (
|
style={{ fontVariationSettings: "'opsz' 14, 'wdth' 100" }}
|
||||||
<Rule
|
>
|
||||||
title={(() => {
|
{t("yourRulesHeading")}
|
||||||
const raw = draft.state.title;
|
</h2>
|
||||||
const s = typeof raw === "string" ? raw.trim() : "";
|
{showEmptyYourRules ? (
|
||||||
return s || t("draftHeading");
|
<NoRules
|
||||||
})()}
|
title={t("emptyCardTitle")}
|
||||||
description={draftBodyTextFromState(draft.state)}
|
description={t("emptyCardBody")}
|
||||||
expanded
|
createLabel={t("emptyCardCreate")}
|
||||||
size={ruleCardSize}
|
browseLabel={t("emptyCardBrowse")}
|
||||||
hasBottomLinks
|
onCreate={onStartNewCustomRule}
|
||||||
bottomStatusLabel={t("draftInProgressBadge")}
|
browseHref="/templates?fromFlow=1"
|
||||||
bottomLinks={[
|
|
||||||
{
|
|
||||||
id: "continue",
|
|
||||||
label: t("continueDraft"),
|
|
||||||
onClick: onContinueDraft,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "delete-draft",
|
|
||||||
label: t("deleteRule"),
|
|
||||||
onClick: onDeleteDraft,
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
communityInitials={(() => {
|
|
||||||
const raw = draft.state.title;
|
|
||||||
const s = typeof raw === "string" ? raw.trim() : "";
|
|
||||||
return s.charAt(0).toUpperCase() || "·";
|
|
||||||
})()}
|
|
||||||
backgroundColor="bg-[var(--color-surface-invert-brand-teal)]"
|
|
||||||
className={ruleCardShellClass}
|
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : (
|
||||||
{rules.map((rule) => (
|
<div className="flex flex-col gap-3">
|
||||||
<Rule
|
{showDraftCard && draft?.hasDraft ? (
|
||||||
key={rule.id}
|
<Rule
|
||||||
title={rule.title}
|
title={(() => {
|
||||||
description={rule.summary ?? undefined}
|
const raw = draft.state.title;
|
||||||
expanded
|
const s = typeof raw === "string" ? raw.trim() : "";
|
||||||
size={ruleCardSize}
|
return s || t("draftHeading");
|
||||||
hasBottomLinks
|
})()}
|
||||||
bottomStatusLabel={
|
description={draftBodyTextFromState(draft.state)}
|
||||||
rule.role === "stakeholder"
|
expanded
|
||||||
? undefined
|
size={ruleCardSize}
|
||||||
: t("finishedBadge")
|
hasBottomLinks
|
||||||
}
|
bottomStatusLabel={t("draftInProgressBadge")}
|
||||||
bottomLinks={
|
bottomLinks={[
|
||||||
rule.role === "stakeholder"
|
{
|
||||||
? [
|
id: "continue",
|
||||||
{
|
label: t("continueDraft"),
|
||||||
id: "view",
|
onClick: onContinueDraft,
|
||||||
label: t("viewPublic"),
|
},
|
||||||
href: `/invite/${encodeURIComponent(rule.id)}`,
|
{
|
||||||
},
|
id: "delete-draft",
|
||||||
]
|
label: t("deleteRule"),
|
||||||
: [
|
onClick: onDeleteDraft,
|
||||||
{
|
},
|
||||||
id: "invite",
|
]}
|
||||||
label: t("inviteMembers"),
|
communityInitials={communityInitialsFromTitle(
|
||||||
onClick: () => onInviteMembers(rule.id),
|
typeof draft.state.title === "string"
|
||||||
},
|
? draft.state.title
|
||||||
{
|
: "",
|
||||||
id: "dup",
|
)}
|
||||||
label: t("duplicate"),
|
backgroundColor="bg-[var(--color-surface-invert-brand-teal)]"
|
||||||
onClick: () => onDuplicateRule(rule.id),
|
className={ownedRuleCardShellClass}
|
||||||
},
|
/>
|
||||||
{
|
) : null}
|
||||||
id: "del",
|
{ownedRules.map((rule) => (
|
||||||
label: t("deleteRule"),
|
<Rule
|
||||||
onClick: () => onDeleteRule(rule.id),
|
key={rule.id}
|
||||||
},
|
title={rule.title}
|
||||||
]
|
description={rule.summary ?? undefined}
|
||||||
}
|
expanded
|
||||||
communityInitials={
|
size={ruleCardSize}
|
||||||
rule.title.trim().charAt(0).toUpperCase() || "·"
|
hasBottomLinks
|
||||||
}
|
bottomStatusLabel={t("finishedBadge")}
|
||||||
backgroundColor="bg-[var(--color-surface-invert-brand-teal)]"
|
bottomLinks={[
|
||||||
className={ruleCardShellClass}
|
{
|
||||||
/>
|
id: "invite",
|
||||||
))}
|
label: t("inviteMembers"),
|
||||||
</div>
|
onClick: () => onInviteMembers(rule.id),
|
||||||
{rules.length === 0 && !rulesError && !showDraftCard ? (
|
},
|
||||||
<p className="text-small-paragraph text-[var(--color-content-default-tertiary)]">
|
{
|
||||||
{t("yourRulesEmpty")}
|
id: "dup",
|
||||||
</p>
|
label: t("duplicate"),
|
||||||
|
onClick: () => onDuplicateRule(rule.id),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "del",
|
||||||
|
label: t("deleteRule"),
|
||||||
|
onClick: () => onDeleteRule(rule.id),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
communityInitials={communityInitialsFromTitle(
|
||||||
|
rule.title,
|
||||||
|
)}
|
||||||
|
backgroundColor="bg-[var(--color-surface-invert-brand-teal)]"
|
||||||
|
className={ownedRuleCardShellClass}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{belongToRules.length > 0 ? (
|
||||||
|
<section
|
||||||
|
className="flex min-w-0 w-full flex-col gap-4 lg:gap-6"
|
||||||
|
aria-labelledby="profile-belong-to-heading"
|
||||||
|
>
|
||||||
|
<h2
|
||||||
|
id="profile-belong-to-heading"
|
||||||
|
className={profileSectionHeadingClass}
|
||||||
|
style={{ fontVariationSettings: "'opsz' 14, 'wdth' 100" }}
|
||||||
|
>
|
||||||
|
{t("rulesYouBelongToHeading")}
|
||||||
|
</h2>
|
||||||
|
<div className="flex flex-col gap-3">
|
||||||
|
{belongToRules.map((rule) => (
|
||||||
|
<Rule
|
||||||
|
key={rule.id}
|
||||||
|
title={rule.title}
|
||||||
|
description={rule.summary ?? undefined}
|
||||||
|
expanded
|
||||||
|
size={ruleCardSize}
|
||||||
|
href={`/invite/${encodeURIComponent(rule.id)}`}
|
||||||
|
communityInitials={communityInitialsFromTitle(
|
||||||
|
rule.title,
|
||||||
|
)}
|
||||||
|
backgroundColor="bg-[var(--color-surface-invert-brand-kiwi)]"
|
||||||
|
className={ruleCardShellClass}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
) : null}
|
) : null}
|
||||||
</section>
|
</div>
|
||||||
|
|
||||||
<section
|
<section
|
||||||
className="flex min-w-0 w-full flex-col gap-3 lg:min-w-0 lg:flex-1 lg:gap-6"
|
className="flex min-w-0 w-full flex-col gap-4 lg:min-w-0 lg:flex-1 lg:gap-6"
|
||||||
aria-labelledby="profile-options-heading"
|
aria-labelledby="profile-options-heading"
|
||||||
>
|
>
|
||||||
<h2
|
<h2
|
||||||
@@ -405,22 +481,6 @@ export function ProfilePageView({
|
|||||||
leadingIcon="edit"
|
leadingIcon="edit"
|
||||||
/>
|
/>
|
||||||
</nav>
|
</nav>
|
||||||
<section
|
|
||||||
aria-label={t("deleteAccount")}
|
|
||||||
className="w-full overflow-hidden rounded-[12px] border border-[var(--color-border-default-negative-primary)] bg-[var(--color-surface-default-negative-secondary)]"
|
|
||||||
>
|
|
||||||
<ListEntry
|
|
||||||
title={t("deleteAccount")}
|
|
||||||
description=""
|
|
||||||
showDescription={false}
|
|
||||||
onClick={onOpenDeleteAccount}
|
|
||||||
size={profileListSize}
|
|
||||||
leadingIcon="edit"
|
|
||||||
variant="danger"
|
|
||||||
topDivider={false}
|
|
||||||
bottomDivider={false}
|
|
||||||
/>
|
|
||||||
</section>
|
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Figma: "Card / No Rules" (25032:50447)
|
||||||
|
* https://www.figma.com/design/agv0VBLiBlcnSAaiAORgPR/Community-Rule-System?node-id=25032-50447
|
||||||
|
*/
|
||||||
|
import { memo } from "react";
|
||||||
|
import { NoRulesView } from "./NoRules.view";
|
||||||
|
import type { NoRulesProps } from "./NoRules.types";
|
||||||
|
|
||||||
|
const NoRulesContainer = memo<NoRulesProps>((props) => {
|
||||||
|
return <NoRulesView {...props} />;
|
||||||
|
});
|
||||||
|
|
||||||
|
NoRulesContainer.displayName = "NoRules";
|
||||||
|
|
||||||
|
export default NoRulesContainer;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
export type NoRulesProps = {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
createLabel: string;
|
||||||
|
browseLabel: string;
|
||||||
|
onCreate: () => void;
|
||||||
|
browseHref: string;
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type NoRulesViewProps = NoRulesProps;
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { memo } from "react";
|
||||||
|
import Button from "../../buttons/Button";
|
||||||
|
import NavigationLink from "../../navigation/Link";
|
||||||
|
import type { NoRulesViewProps } from "./NoRules.types";
|
||||||
|
|
||||||
|
export const NoRulesView = memo(function NoRulesView({
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
createLabel,
|
||||||
|
browseLabel,
|
||||||
|
onCreate,
|
||||||
|
browseHref,
|
||||||
|
className = "",
|
||||||
|
}: NoRulesViewProps) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`flex w-full flex-col items-start gap-4 rounded-[var(--radius-300)] border border-dashed border-[var(--color-border-default-secondary)] p-8 ${className}`.trim()}
|
||||||
|
data-figma-node="25032:50447"
|
||||||
|
>
|
||||||
|
<h3 className="w-full font-bricolage-grotesque text-small-heading text-[var(--color-content-default-primary)]">
|
||||||
|
{title}
|
||||||
|
</h3>
|
||||||
|
<p className="w-full text-medium-paragraph text-[var(--color-content-default-secondary)]">
|
||||||
|
{description}
|
||||||
|
</p>
|
||||||
|
<div className="flex w-full flex-wrap items-center gap-x-4 gap-y-3 pt-2">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
size="large"
|
||||||
|
buttonType="filled"
|
||||||
|
palette="default"
|
||||||
|
onClick={onCreate}
|
||||||
|
>
|
||||||
|
{createLabel}
|
||||||
|
</Button>
|
||||||
|
<NavigationLink
|
||||||
|
href={browseHref}
|
||||||
|
type="primary"
|
||||||
|
theme="dark"
|
||||||
|
leadingIcon={false}
|
||||||
|
trailingIcon={false}
|
||||||
|
>
|
||||||
|
{browseLabel}
|
||||||
|
</NavigationLink>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
NoRulesView.displayName = "NoRulesView";
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export { default } from "./NoRules.container";
|
||||||
|
export type { NoRulesProps } from "./NoRules.types";
|
||||||
@@ -7,7 +7,7 @@ Quick map from the Figma file **Community Rule System** (`agv0VBLiBlcnSAaiAORgPR
|
|||||||
| [Utility](https://www.figma.com/design/agv0VBLiBlcnSAaiAORgPR/Community-Rule-System?node-id=20515-15809) | `utility/` | Create chrome, tag, scroll, sidebar, dividers, etc. |
|
| [Utility](https://www.figma.com/design/agv0VBLiBlcnSAaiAORgPR/Community-Rule-System?node-id=20515-15809) | `utility/` | Create chrome, tag, scroll, sidebar, dividers, etc. |
|
||||||
| [Asset](https://www.figma.com/design/agv0VBLiBlcnSAaiAORgPR/Community-Rule-System?node-id=1240-9089) | **`app/components/asset/`**, **`public/assets/template-mark/`**, **`public/assets/vector/`** | Components under **`asset/`**; flat kebab **`*.svg`** in **`template-mark/`** & **`vector/`** (see conventions below). |
|
| [Asset](https://www.figma.com/design/agv0VBLiBlcnSAaiAORgPR/Community-Rule-System?node-id=1240-9089) | **`app/components/asset/`**, **`public/assets/template-mark/`**, **`public/assets/vector/`** | Components under **`asset/`**; flat kebab **`*.svg`** in **`template-mark/`** & **`vector/`** (see conventions below). |
|
||||||
| [Button](https://www.figma.com/design/agv0VBLiBlcnSAaiAORgPR/Community-Rule-System?node-id=497-3016) | `buttons/` | PascalCase package per primitive — **`Button/`**, **`InlineTextButton/`** (see conventions below). |
|
| [Button](https://www.figma.com/design/agv0VBLiBlcnSAaiAORgPR/Community-Rule-System?node-id=497-3016) | `buttons/` | PascalCase package per primitive — **`Button/`**, **`InlineTextButton/`** (see conventions below). |
|
||||||
| [Card](https://www.figma.com/design/agv0VBLiBlcnSAaiAORgPR/Community-Rule-System?node-id=17865-24349) | `cards/` | One PascalCase package per surface—**`Selection/`** (Figma **Card / CardSelection**), **`CardStack/`**, **`Rule/`** (Figma **Card / Rule**), **`Icon/`**, **`CaseStudy/`**, **`Mini/`**, **`Stat/`** (Figma **Card / Stat**), **`Step/`** (Figma **Card / Step**), **`TemplateReviewCard/`** (see conventions below). |
|
| [Card](https://www.figma.com/design/agv0VBLiBlcnSAaiAORgPR/Community-Rule-System?node-id=17865-24349) | `cards/` | One PascalCase package per surface—**`Selection/`** (Figma **Card / CardSelection**), **`CardStack/`**, **`Rule/`** (Figma **Card / Rule**), **`NoRules/`** (Figma **Card / No Rules**), **`Icon/`**, **`CaseStudy/`**, **`Mini/`**, **`Stat/`** (Figma **Card / Stat**), **`Step/`** (Figma **Card / Step**), **`TemplateReviewCard/`** (see conventions below). |
|
||||||
| [Control](https://www.figma.com/design/agv0VBLiBlcnSAaiAORgPR/Community-Rule-System?node-id=5944-58611) | `controls/` | Checkbox, radio, text field, select, toggle, switch, incrementer, upload, multi-select, chip, … (see **Control conventions** below). **`InfoMessageBox`** canonical here. |
|
| [Control](https://www.figma.com/design/agv0VBLiBlcnSAaiAORgPR/Community-Rule-System?node-id=5944-58611) | `controls/` | Checkbox, radio, text field, select, toggle, switch, incrementer, upload, multi-select, chip, … (see **Control conventions** below). **`InfoMessageBox`** canonical here. |
|
||||||
| [Layout](https://www.figma.com/design/agv0VBLiBlcnSAaiAORgPR/Community-Rule-System?node-id=21836-20542) | `layout/` | **`List/`**, **`ListEntry/`**, **`ListItem/`** + **`listSizeLayout.ts`**. **Tabs** / **Accordion** are in Figma only—**not** in code yet (see **Layout conventions**). |
|
| [Layout](https://www.figma.com/design/agv0VBLiBlcnSAaiAORgPR/Community-Rule-System?node-id=21836-20542) | `layout/` | **`List/`**, **`ListEntry/`**, **`ListItem/`** + **`listSizeLayout.ts`**. **Tabs** / **Accordion** are in Figma only—**not** in code yet (see **Layout conventions**). |
|
||||||
| [Modals](https://www.figma.com/design/agv0VBLiBlcnSAaiAORgPR/Community-Rule-System?node-id=5944-47704) | `modals/` | Alert, Create, Dialog, Login, Tooltip, **`ModalHeader`** / **`ModalFooter`** (see **Modals conventions**). |
|
| [Modals](https://www.figma.com/design/agv0VBLiBlcnSAaiAORgPR/Community-Rule-System?node-id=5944-47704) | `modals/` | Alert, Create, Dialog, Login, Tooltip, **`ModalHeader`** / **`ModalFooter`** (see **Modals conventions**). |
|
||||||
@@ -194,6 +194,7 @@ Inventory aligns with [**CR-104**](https://linear.app/community-rule/issue/CR-10
|
|||||||
|
|
||||||
- **Pattern:** follow the **container / view / types** split (**`Selection/`**, **`CardStack/`**, **`Rule/`**, **`Icon/`**, **`Mini/`**) unless a component stays a single module (**`Step/`** uses one **`Step.tsx`** + **`index.tsx`** only).
|
- **Pattern:** follow the **container / view / types** split (**`Selection/`**, **`CardStack/`**, **`Rule/`**, **`Icon/`**, **`Mini/`**) unless a component stays a single module (**`Step/`** uses one **`Step.tsx`** + **`index.tsx`** only).
|
||||||
- **`Rule/`** — Figma **Card / Rule**. **`Rule.container.tsx`**, **`Rule.view.tsx`**, **`Rule.types.ts`**.
|
- **`Rule/`** — Figma **Card / Rule**. **`Rule.container.tsx`**, **`Rule.view.tsx`**, **`Rule.types.ts`**.
|
||||||
|
- **`NoRules/`** — Figma **Card / No Rules** ([25032:50447](https://www.figma.com/design/agv0VBLiBlcnSAaiAORgPR/Community-Rule-System?node-id=25032-50447)). Empty state on Profile **Your Rules**.
|
||||||
- **`Selection/`** — Figma **Card / CardSelection** (e.g. `16775:28762`): optional recommended/selected **`Tag`**, label, support text. Stacked layout uses `orientation="horizontal"`; row + info icon + tag right uses `orientation="vertical"`.
|
- **`Selection/`** — Figma **Card / CardSelection** (e.g. `16775:28762`): optional recommended/selected **`Tag`**, label, support text. Stacked layout uses `orientation="horizontal"`; row + info icon + tag right uses `orientation="vertical"`.
|
||||||
- **`Stat/`** — Figma **Card / Stat** (metric tile + decorative shape). Composed by **`sections/Stats`** on **`/about`**.
|
- **`Stat/`** — Figma **Card / Stat** (metric tile + decorative shape). Composed by **`sections/Stats`** on **`/about`**.
|
||||||
- **`Step/`** — Figma **Card / Step** (numbered step tile + text). Shipped on the home page via **`sections/CardSteps`**. Not the **Progress / Stepper** wizard control.
|
- **`Step/`** — Figma **Card / Step** (numbered step tile + text). Shipped on the home page via **`sections/CardSteps`**. Not the **Progress / Stepper** wizard control.
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
{
|
{
|
||||||
"pageTitle": "Your profile",
|
"pageTitle": "Your profile",
|
||||||
"welcomeTitle": "Congrats {{name}}!",
|
"welcomeTitle": "Congrats, {{name}}",
|
||||||
|
"welcomeTitleReturn": "Welcome back, {{name}}",
|
||||||
"welcomeBodyFirstRule": "Invite the people in your community to read it.",
|
"welcomeBodyFirstRule": "Invite the people in your community to read it.",
|
||||||
|
"welcomeBodyReturn": "Pick up where you left off or start a new Rule.",
|
||||||
"welcomeBodyNoRules": "Create your first CommunityRule to capture how your group makes decisions—then link it from your community resources as you grow.",
|
"welcomeBodyNoRules": "Create your first CommunityRule to capture how your group makes decisions—then link it from your community resources as you grow.",
|
||||||
"yourOptionsHeading": "Your options",
|
"yourOptionsHeading": "Your options",
|
||||||
"optionCreateCustom": "Create new custom Rule",
|
"optionCreateCustom": "Create new custom Rule",
|
||||||
@@ -13,7 +15,12 @@
|
|||||||
"signInCta": "Log in",
|
"signInCta": "Log in",
|
||||||
"loading": "Loading…",
|
"loading": "Loading…",
|
||||||
"yourRulesHeading": "Your Rules",
|
"yourRulesHeading": "Your Rules",
|
||||||
|
"rulesYouBelongToHeading": "Rules you belong to",
|
||||||
"yourRulesEmpty": "You have not finished a rule yet. Create one to see it here.",
|
"yourRulesEmpty": "You have not finished a rule yet. Create one to see it here.",
|
||||||
|
"emptyCardTitle": "No Rules yet",
|
||||||
|
"emptyCardBody": "Start from a template, or write your first over a few short meetings with the free kit.",
|
||||||
|
"emptyCardCreate": "Create rule",
|
||||||
|
"emptyCardBrowse": "Browse templates",
|
||||||
"draftHeading": "Saved in progress",
|
"draftHeading": "Saved in progress",
|
||||||
"draftInProgressBadge": "Draft",
|
"draftInProgressBadge": "Draft",
|
||||||
"finishedBadge": "Finished",
|
"finishedBadge": "Finished",
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import NoRules from "../../app/components/cards/NoRules";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
title: "Components/Cards/NoRules",
|
||||||
|
component: NoRules,
|
||||||
|
parameters: {
|
||||||
|
layout: "centered",
|
||||||
|
backgrounds: { default: "dark" },
|
||||||
|
docs: {
|
||||||
|
description: {
|
||||||
|
component:
|
||||||
|
"Empty state for Your Rules on Profile when a member has no Rules yet.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
argTypes: {
|
||||||
|
title: { control: "text" },
|
||||||
|
description: { control: "text" },
|
||||||
|
createLabel: { control: "text" },
|
||||||
|
browseLabel: { control: "text" },
|
||||||
|
browseHref: { control: "text" },
|
||||||
|
onCreate: { action: "create" },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Default = {
|
||||||
|
args: {
|
||||||
|
title: "No Rules yet",
|
||||||
|
description:
|
||||||
|
"Start from a template, or write your first over a few short meetings with the free kit.",
|
||||||
|
createLabel: "Create rule",
|
||||||
|
browseLabel: "Browse templates",
|
||||||
|
browseHref: "/templates?fromFlow=1",
|
||||||
|
className: "max-w-[560px]",
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import "@testing-library/jest-dom/vitest";
|
||||||
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
import userEvent from "@testing-library/user-event";
|
||||||
|
import NoRules from "../../../app/components/cards/NoRules";
|
||||||
|
import { renderWithProviders, screen } from "../../utils/test-utils";
|
||||||
|
|
||||||
|
describe("NoRules", () => {
|
||||||
|
it("renders the empty-state copy, create action, and templates link", async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
|
const onCreate = vi.fn();
|
||||||
|
renderWithProviders(
|
||||||
|
<NoRules
|
||||||
|
title="No Rules yet"
|
||||||
|
description="Start from a template, or write your first over a few short meetings with the free kit."
|
||||||
|
createLabel="Create rule"
|
||||||
|
browseLabel="Browse templates"
|
||||||
|
browseHref="/templates?fromFlow=1"
|
||||||
|
onCreate={onCreate}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(screen.getByRole("heading", { name: "No Rules yet" })).toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
screen.getByText(
|
||||||
|
"Start from a template, or write your first over a few short meetings with the free kit.",
|
||||||
|
),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
|
||||||
|
await user.click(screen.getByRole("button", { name: "Create rule" }));
|
||||||
|
expect(onCreate).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
screen.getByRole("link", { name: "Browse templates" }),
|
||||||
|
).toHaveAttribute("href", "/templates?fromFlow=1");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -27,6 +27,7 @@ function viewProps(
|
|||||||
profileLgUp: true,
|
profileLgUp: true,
|
||||||
profileListSize: "l",
|
profileListSize: "l",
|
||||||
rules: [],
|
rules: [],
|
||||||
|
rulesLoaded: true,
|
||||||
rulesError: false,
|
rulesError: false,
|
||||||
draft: null,
|
draft: null,
|
||||||
showDraftCard: false,
|
showDraftCard: false,
|
||||||
@@ -72,7 +73,7 @@ function viewProps(
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("ProfilePageView", () => {
|
describe("ProfilePageView", () => {
|
||||||
test("puts delete account in its own danger area", () => {
|
test("puts delete account in the options list as a danger row", () => {
|
||||||
render(<ProfilePageView {...viewProps()} />);
|
render(<ProfilePageView {...viewProps()} />);
|
||||||
|
|
||||||
const options = screen.getByRole("navigation", {
|
const options = screen.getByRole("navigation", {
|
||||||
@@ -81,16 +82,12 @@ describe("ProfilePageView", () => {
|
|||||||
expect(
|
expect(
|
||||||
within(options).getByRole("button", { name: copy.optionCreateCustom }),
|
within(options).getByRole("button", { name: copy.optionCreateCustom }),
|
||||||
).toBeInTheDocument();
|
).toBeInTheDocument();
|
||||||
expect(
|
|
||||||
within(options).queryByRole("button", { name: copy.deleteAccount }),
|
|
||||||
).not.toBeInTheDocument();
|
|
||||||
expect(screen.queryByText(copy.deleteAccountIntro)).not.toBeInTheDocument();
|
expect(screen.queryByText(copy.deleteAccountIntro)).not.toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
screen.queryByRole("region", { name: copy.deleteAccount }),
|
||||||
|
).not.toBeInTheDocument();
|
||||||
|
|
||||||
const danger = screen.getByRole("region", { name: copy.deleteAccount });
|
const deleteAccount = within(options).getByRole("button", {
|
||||||
expect(danger.className).toContain(
|
|
||||||
"border-[var(--color-border-default-negative-primary)]",
|
|
||||||
);
|
|
||||||
const deleteAccount = within(danger).getByRole("button", {
|
|
||||||
name: copy.deleteAccount,
|
name: copy.deleteAccount,
|
||||||
});
|
});
|
||||||
const deleteTitle = within(deleteAccount).getByText(copy.deleteAccount);
|
const deleteTitle = within(deleteAccount).getByText(copy.deleteAccount);
|
||||||
@@ -105,6 +102,59 @@ describe("ProfilePageView", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("shows the No Rules card when the person has no owned Rule", async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
|
const onStartNewCustomRule = vi.fn();
|
||||||
|
render(
|
||||||
|
<ProfilePageView {...viewProps({ onStartNewCustomRule })} />,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
screen.getByRole("heading", {
|
||||||
|
name: copy.welcomeTitleReturn.replace("{{name}}", "dani@example.com"),
|
||||||
|
}),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText(copy.welcomeBodyFirstRule)).not.toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
screen.getByRole("heading", { name: copy.emptyCardTitle }),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(copy.emptyCardBody)).toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
screen.getByRole("link", { name: copy.emptyCardBrowse }),
|
||||||
|
).toHaveAttribute("href", "/templates?fromFlow=1");
|
||||||
|
|
||||||
|
await user.click(
|
||||||
|
screen.getByRole("button", { name: copy.emptyCardCreate }),
|
||||||
|
);
|
||||||
|
expect(onStartNewCustomRule).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("keeps the No Rules card hidden when a failed load warning is dismissed", () => {
|
||||||
|
const { rerender } = render(
|
||||||
|
<ProfilePageView
|
||||||
|
{...viewProps({ rulesLoaded: false, rulesError: true })}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(screen.getByText(copy.rulesLoadBannerTitle)).toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
screen.queryByRole("heading", { name: copy.emptyCardTitle }),
|
||||||
|
).not.toBeInTheDocument();
|
||||||
|
|
||||||
|
rerender(
|
||||||
|
<ProfilePageView
|
||||||
|
{...viewProps({ rulesLoaded: false, rulesError: false })}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
screen.queryByText(copy.rulesLoadBannerTitle),
|
||||||
|
).not.toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
screen.queryByRole("heading", { name: copy.emptyCardTitle }),
|
||||||
|
).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
test("asks for confirmation before deleting the account", async () => {
|
test("asks for confirmation before deleting the account", async () => {
|
||||||
const user = userEvent.setup();
|
const user = userEvent.setup();
|
||||||
const onOpenDeleteAccount = vi.fn();
|
const onOpenDeleteAccount = vi.fn();
|
||||||
@@ -193,4 +243,102 @@ describe("ProfilePageView", () => {
|
|||||||
screen.getByRole("button", { name: copy.deleteRule }),
|
screen.getByRole("button", { name: copy.deleteRule }),
|
||||||
).toBeInTheDocument();
|
).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("lists invited Rules under Rules you belong to, not Your Rules", () => {
|
||||||
|
render(
|
||||||
|
<ProfilePageView
|
||||||
|
{...viewProps({
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
id: "rule-owned",
|
||||||
|
title: "Garden coop",
|
||||||
|
summary: "How we share the plots.",
|
||||||
|
createdAt: "2026-11-01T00:00:00.000Z",
|
||||||
|
updatedAt: "2026-11-01T00:00:00.000Z",
|
||||||
|
role: "owner",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "rule-invited",
|
||||||
|
title: "Hawthorn Row Seed Library",
|
||||||
|
summary: "Neighbors save seeds each fall.",
|
||||||
|
createdAt: "2026-10-01T00:00:00.000Z",
|
||||||
|
updatedAt: "2026-10-01T00:00:00.000Z",
|
||||||
|
role: "stakeholder",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
screen.getByRole("heading", { name: copy.rulesYouBelongToHeading }),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
screen.getByRole("link", { name: /Hawthorn Row Seed Library/ }),
|
||||||
|
).toHaveAttribute("href", "/invite/rule-invited");
|
||||||
|
expect(
|
||||||
|
screen.queryByRole("button", { name: copy.viewPublic }),
|
||||||
|
).not.toBeInTheDocument();
|
||||||
|
|
||||||
|
const yourRules = screen.getByRole("region", {
|
||||||
|
name: copy.yourRulesHeading,
|
||||||
|
});
|
||||||
|
expect(within(yourRules).getByText("Garden coop")).toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
within(yourRules).queryByText("Hawthorn Row Seed Library"),
|
||||||
|
).not.toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
within(yourRules).getByRole("button", { name: copy.inviteMembers }),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("hides Rules you belong to when nothing was shared with this address", () => {
|
||||||
|
render(
|
||||||
|
<ProfilePageView
|
||||||
|
{...viewProps({
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
id: "rule-1",
|
||||||
|
title: "Garden coop",
|
||||||
|
summary: "How we share the plots.",
|
||||||
|
createdAt: "2026-11-01T00:00:00.000Z",
|
||||||
|
updatedAt: "2026-11-01T00:00:00.000Z",
|
||||||
|
role: "owner",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
screen.queryByRole("heading", { name: copy.rulesYouBelongToHeading }),
|
||||||
|
).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("uses the return-visit greeting when a draft is in progress", () => {
|
||||||
|
render(
|
||||||
|
<ProfilePageView
|
||||||
|
{...viewProps({
|
||||||
|
showDraftCard: true,
|
||||||
|
draft: {
|
||||||
|
hasDraft: true,
|
||||||
|
updatedAt: "2026-11-01T00:00:00.000Z",
|
||||||
|
state: { title: "Alder Court Tenants Union" },
|
||||||
|
} as ProfilePageViewProps["draft"],
|
||||||
|
})}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
screen.getByRole("heading", {
|
||||||
|
name: copy.welcomeTitleReturn.replace("{{name}}", "dani@example.com"),
|
||||||
|
}),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(copy.welcomeBodyReturn)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText("Alder Court Tenants Union")).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(copy.draftInProgressBadge)).toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
screen.getByRole("button", { name: copy.continueDraft }),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
|||||||
const isDatabaseConfiguredMock = vi.fn();
|
const isDatabaseConfiguredMock = vi.fn();
|
||||||
const findUniqueMock = vi.fn();
|
const findUniqueMock = vi.fn();
|
||||||
const findManyMock = vi.fn();
|
const findManyMock = vi.fn();
|
||||||
|
const stakeholderFindManyMock = vi.fn();
|
||||||
const browserHoldsClaimForHashMock = vi.fn();
|
const browserHoldsClaimForHashMock = vi.fn();
|
||||||
const isRuleAdminEmailMock = vi.fn();
|
const isRuleAdminEmailMock = vi.fn();
|
||||||
const logAdminRuleReadMock = vi.fn();
|
const logAdminRuleReadMock = vi.fn();
|
||||||
@@ -17,6 +18,9 @@ vi.mock("../../lib/server/db", () => ({
|
|||||||
findUnique: (...args: unknown[]) => findUniqueMock(...args),
|
findUnique: (...args: unknown[]) => findUniqueMock(...args),
|
||||||
findMany: (...args: unknown[]) => findManyMock(...args),
|
findMany: (...args: unknown[]) => findManyMock(...args),
|
||||||
},
|
},
|
||||||
|
ruleStakeholder: {
|
||||||
|
findMany: (...args: unknown[]) => stakeholderFindManyMock(...args),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -37,6 +41,7 @@ import {
|
|||||||
getReadablePublishedRule,
|
getReadablePublishedRule,
|
||||||
listListedPublishedRules,
|
listListedPublishedRules,
|
||||||
listListedPublishedRulesForSitemap,
|
listListedPublishedRulesForSitemap,
|
||||||
|
listProfileRulesForUser,
|
||||||
} from "../../lib/server/publishedRules";
|
} from "../../lib/server/publishedRules";
|
||||||
import { LISTED_PUBLISHED_RULE_WHERE } from "../../lib/publishedRuleAccess";
|
import { LISTED_PUBLISHED_RULE_WHERE } from "../../lib/publishedRuleAccess";
|
||||||
import { RULE_VISIBILITY } from "../../lib/ruleVisibility";
|
import { RULE_VISIBILITY } from "../../lib/ruleVisibility";
|
||||||
@@ -62,6 +67,7 @@ beforeEach(() => {
|
|||||||
isDatabaseConfiguredMock.mockReset();
|
isDatabaseConfiguredMock.mockReset();
|
||||||
findUniqueMock.mockReset();
|
findUniqueMock.mockReset();
|
||||||
findManyMock.mockReset();
|
findManyMock.mockReset();
|
||||||
|
stakeholderFindManyMock.mockReset();
|
||||||
browserHoldsClaimForHashMock.mockReset();
|
browserHoldsClaimForHashMock.mockReset();
|
||||||
isRuleAdminEmailMock.mockReset();
|
isRuleAdminEmailMock.mockReset();
|
||||||
logAdminRuleReadMock.mockReset();
|
logAdminRuleReadMock.mockReset();
|
||||||
@@ -256,3 +262,60 @@ describe("listListedPublishedRulesForSitemap", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("listProfileRulesForUser", () => {
|
||||||
|
it("returns null when the database is not configured", async () => {
|
||||||
|
isDatabaseConfiguredMock.mockReturnValue(false);
|
||||||
|
expect(await listProfileRulesForUser("user-1", 50)).toBeNull();
|
||||||
|
expect(findManyMock).not.toHaveBeenCalled();
|
||||||
|
expect(stakeholderFindManyMock).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps owned Rules as owner and invited Rules as stakeholder, newest first", async () => {
|
||||||
|
isDatabaseConfiguredMock.mockReturnValue(true);
|
||||||
|
const owned = {
|
||||||
|
id: "owned-1",
|
||||||
|
title: "Garden coop",
|
||||||
|
summary: "Plots",
|
||||||
|
createdAt: new Date("2026-10-01T00:00:00.000Z"),
|
||||||
|
updatedAt: new Date("2026-11-01T00:00:00.000Z"),
|
||||||
|
};
|
||||||
|
const invited = {
|
||||||
|
id: "invited-1",
|
||||||
|
title: "Hawthorn Row",
|
||||||
|
summary: "Seeds",
|
||||||
|
createdAt: new Date("2026-09-01T00:00:00.000Z"),
|
||||||
|
updatedAt: new Date("2026-11-02T00:00:00.000Z"),
|
||||||
|
};
|
||||||
|
findManyMock.mockResolvedValueOnce([owned]);
|
||||||
|
stakeholderFindManyMock.mockResolvedValueOnce([{ rule: invited }]);
|
||||||
|
|
||||||
|
const listed = await listProfileRulesForUser("user-1", 50);
|
||||||
|
|
||||||
|
expect(stakeholderFindManyMock).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
where: { userId: "user-1" },
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(listed).toEqual([
|
||||||
|
{ ...invited, role: "stakeholder" },
|
||||||
|
{ ...owned, role: "owner" },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not list an invited Rule the person also holds the pen for as stakeholder", async () => {
|
||||||
|
isDatabaseConfiguredMock.mockReturnValue(true);
|
||||||
|
const owned = {
|
||||||
|
id: "same-1",
|
||||||
|
title: "Garden coop",
|
||||||
|
summary: "Plots",
|
||||||
|
createdAt: new Date("2026-10-01T00:00:00.000Z"),
|
||||||
|
updatedAt: new Date("2026-11-01T00:00:00.000Z"),
|
||||||
|
};
|
||||||
|
findManyMock.mockResolvedValueOnce([owned]);
|
||||||
|
stakeholderFindManyMock.mockResolvedValueOnce([{ rule: owned }]);
|
||||||
|
|
||||||
|
const listed = await listProfileRulesForUser("user-1", 50);
|
||||||
|
expect(listed).toEqual([{ ...owned, role: "owner" }]);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user