Show the Profile empty state, phone layout, and Rules you belong to.

This commit is contained in:
adilallo committed 2026-11-11 11:33:21 -07:00
1 parent b1ae274ff6
commit c332b26683
4 files changed
+383 -138

No files matched your search

+182 -128
View File
@@ -2,11 +2,11 @@
import { useId, useMemo } from "react";
import Button from "../../../components/buttons/Button";
import NoRules from "../../../components/cards/NoRules";
import Rule from "../../../components/cards/Rule";
import TextInput from "../../../components/controls/TextInput";
import List 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 Dialog from "../../../components/modals/Dialog";
import DeleteAccount from "../../../components/modals/DeleteAccount";
@@ -29,6 +29,14 @@ function draftBodyTextFromState(
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 = {
userEmail: string;
/** `M` below `lg` (1024px); `L` at `lg`+ per Figma Card / Rule. Breakpoints: `md` (640px) → `lg` (1024px) only. */
@@ -107,7 +115,7 @@ export function ProfilePageSignedOutView({
return (
<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
className={
profileLgUp
@@ -153,9 +161,9 @@ export function ProfilePageSignedOutView({
}
/**
* Figma: mobile `22143:900762`; tablet `md` `22143:900534` (`@theme --breakpoint-md` 640px);
* desktop `lg` `21962:17220` (`@theme --breakpoint-lg` 1024px);
* `xl` `22143:900247` (same content spacing as lg; list + section type at `xl` — `List` L `21844:4405`).
* Figma: phone `25032:88248` / empty `25032:88410` (320–639);
* several Rules `25206:93086`; belong-to phone `25219:136704` and desktop `25219:136446`;
* desktop empty `25032:88574`; `xl` list + section type `22143:900247` (`List` L `21844:4405`).
*/
export function ProfilePageView({
userEmail,
@@ -207,9 +215,27 @@ export function ProfilePageView({
const t = useTranslation("pages.profile");
const tLogin = useTranslation("pages.login");
const titleId = useId();
const welcomeTitle = t("welcomeTitle").replace(/\{\{name\}\}/g, userEmail);
const welcomeBody =
rules.length > 0 ? t("welcomeBodyFirstRule") : t("welcomeBodyNoRules");
const ownedRules = useMemo(
() => rules.filter((rule) => rule.role === "owner"),
[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 =
ownedRules.length === 0 && !showDraftCard && !rulesError;
const profileOptionsItems = useMemo((): ListItem[] => {
return [
@@ -245,16 +271,32 @@ export function ProfilePageView({
leadingIcon: "mail",
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 =
"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 (
<>
<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
className={
profileLgUp
@@ -278,116 +320,144 @@ export function ProfilePageView({
>
{welcomeTitle}
</h1>
<p className="max-w-[640px] text-small-paragraph text-[var(--color-content-default-tertiary)] md:text-medium-paragraph">
{welcomeBody}
</p>
{welcomeBody ? (
<p className="max-w-[640px] text-small-paragraph text-[var(--color-content-default-tertiary)] md:text-medium-paragraph">
{welcomeBody}
</p>
) : null}
</>
)}
</header>
<div className="flex flex-col gap-8 lg:flex-row lg:flex-nowrap lg:items-start lg:gap-8">
<section
className="flex min-w-0 w-full flex-col gap-3 lg:min-w-0 lg:flex-1 lg:gap-6"
aria-labelledby="profile-rules-heading"
>
<h2
id="profile-rules-heading"
className={profileSectionHeadingClass}
style={{ fontVariationSettings: "'opsz' 14, 'wdth' 100" }}
<div className="flex flex-col gap-10 lg:flex-row lg:flex-nowrap lg:items-start lg:gap-8">
<div className="flex min-w-0 w-full flex-col gap-10 lg:min-w-0 lg:flex-1">
<section
className="flex min-w-0 w-full flex-col gap-4 lg:gap-6"
aria-labelledby="profile-rules-heading"
>
{t("yourRulesHeading")}
</h2>
<div className="flex flex-col gap-3">
{showDraftCard && draft?.hasDraft ? (
<Rule
title={(() => {
const raw = draft.state.title;
const s = typeof raw === "string" ? raw.trim() : "";
return s || t("draftHeading");
})()}
description={draftBodyTextFromState(draft.state)}
expanded
size={ruleCardSize}
hasBottomLinks
bottomStatusLabel={t("draftInProgressBadge")}
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}
<h2
id="profile-rules-heading"
className={profileSectionHeadingClass}
style={{ fontVariationSettings: "'opsz' 14, 'wdth' 100" }}
>
{t("yourRulesHeading")}
</h2>
{showEmptyYourRules ? (
<NoRules
title={t("emptyCardTitle")}
description={t("emptyCardBody")}
createLabel={t("emptyCardCreate")}
browseLabel={t("emptyCardBrowse")}
onCreate={onStartNewCustomRule}
browseHref="/templates?fromFlow=1"
/>
) : null}
{rules.map((rule) => (
<Rule
key={rule.id}
title={rule.title}
description={rule.summary ?? undefined}
expanded
size={ruleCardSize}
hasBottomLinks
bottomStatusLabel={
rule.role === "stakeholder"
? undefined
: t("finishedBadge")
}
bottomLinks={
rule.role === "stakeholder"
? [
{
id: "view",
label: t("viewPublic"),
href: `/invite/${encodeURIComponent(rule.id)}`,
},
]
: [
{
id: "invite",
label: t("inviteMembers"),
onClick: () => onInviteMembers(rule.id),
},
{
id: "dup",
label: t("duplicate"),
onClick: () => onDuplicateRule(rule.id),
},
{
id: "del",
label: t("deleteRule"),
onClick: () => onDeleteRule(rule.id),
},
]
}
communityInitials={
rule.title.trim().charAt(0).toUpperCase() || "·"
}
backgroundColor="bg-[var(--color-surface-invert-brand-teal)]"
className={ruleCardShellClass}
/>
))}
</div>
{rules.length === 0 && !rulesError && !showDraftCard ? (
<p className="text-small-paragraph text-[var(--color-content-default-tertiary)]">
{t("yourRulesEmpty")}
</p>
) : (
<div className="flex flex-col gap-3">
{showDraftCard && draft?.hasDraft ? (
<Rule
title={(() => {
const raw = draft.state.title;
const s = typeof raw === "string" ? raw.trim() : "";
return s || t("draftHeading");
})()}
description={draftBodyTextFromState(draft.state)}
expanded
size={ruleCardSize}
hasBottomLinks
bottomStatusLabel={t("draftInProgressBadge")}
bottomLinks={[
{
id: "continue",
label: t("continueDraft"),
onClick: onContinueDraft,
},
{
id: "delete-draft",
label: t("deleteRule"),
onClick: onDeleteDraft,
},
]}
communityInitials={communityInitialsFromTitle(
typeof draft.state.title === "string"
? draft.state.title
: "",
)}
backgroundColor="bg-[var(--color-surface-invert-brand-teal)]"
className={ownedRuleCardShellClass}
/>
) : null}
{ownedRules.map((rule) => (
<Rule
key={rule.id}
title={rule.title}
description={rule.summary ?? undefined}
expanded
size={ruleCardSize}
hasBottomLinks
bottomStatusLabel={t("finishedBadge")}
bottomLinks={[
{
id: "invite",
label: t("inviteMembers"),
onClick: () => onInviteMembers(rule.id),
},
{
id: "dup",
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}
</section>
</div>
<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"
>
<h2
@@ -405,22 +475,6 @@ export function ProfilePageView({
leadingIcon="edit"
/>
</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>
</div>
</div>