Skip to content

Commit 24d90d1

Browse files
authored
Refine community invite limits (#3529)
## Summary - Simplify the community invite dialog around link sharing. - Add matching expiry and use-limit dropdowns, with sensible preset use caps. - Cover the default unlimited and selected-limit invite payloads. ## Validation - `pnpm -C desktop run build:e2e` - `pnpm -C desktop exec playwright test tests/e2e/invite-link-copy.spec.ts tests/e2e/invites-settings-screenshots.spec.ts --project=smoke` Signed-off-by: kenny lopez <[email protected]>
1 parent ce01e93 commit 24d90d1

4 files changed

Lines changed: 134 additions & 96 deletions

File tree

‎desktop/src/features/community-members/ui/CommunityInviteDialog.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as React from "react";
33
import {
44
Dialog,
55
DialogContent,
6+
DialogDescription,
67
DialogHeader,
78
DialogTitle,
89
} from "@/shared/ui/dialog";
@@ -29,12 +30,14 @@ export function CommunityInviteDialog({
2930
return (
3031
<Dialog onOpenChange={onOpenChange} open={open}>
3132
<DialogContent
32-
aria-describedby={undefined}
3333
className="max-h-[85vh] max-w-xl overflow-y-auto"
3434
data-testid="community-invite-dialog"
3535
>
36-
<DialogHeader className="space-y-0">
36+
<DialogHeader>
3737
<DialogTitle>Invite to community</DialogTitle>
38+
<DialogDescription>
39+
Anyone with this link can join this community.
40+
</DialogDescription>
3841
</DialogHeader>
3942

4043
<InviteLinkSection onTtlSecsChange={setTtlSecs} ttlSecs={ttlSecs} />

‎desktop/src/features/community-members/ui/InviteLinkSection.tsx‎

Lines changed: 88 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@ import { Button } from "@/shared/ui/button";
88
import {
99
DropdownMenu,
1010
DropdownMenuContent,
11-
DropdownMenuLabel,
1211
DropdownMenuRadioGroup,
1312
DropdownMenuRadioItem,
14-
DropdownMenuSeparator,
1513
DropdownMenuTrigger,
1614
} from "@/shared/ui/dropdown-menu";
17-
import { Input } from "@/shared/ui/input";
1815
import { Separator } from "@/shared/ui/separator";
1916
import { Spinner } from "@/shared/ui/spinner";
20-
import { Switch } from "@/shared/ui/switch";
2117

2218
const TTL_OPTIONS: { label: string; value: number }[] = [
2319
{ label: "1 day", value: 24 * 60 * 60 },
@@ -26,6 +22,15 @@ const TTL_OPTIONS: { label: string; value: number }[] = [
2622
{ label: "30 days", value: 30 * 24 * 60 * 60 },
2723
];
2824

25+
const MAX_USE_OPTIONS: { label: string; value: number | null }[] = [
26+
{ label: "No limit", value: null },
27+
{ label: "1 use", value: 1 },
28+
{ label: "3 uses", value: 3 },
29+
{ label: "5 uses", value: 5 },
30+
{ label: "10 uses", value: 10 },
31+
{ label: "25 uses", value: 25 },
32+
];
33+
2934
export const DEFAULT_INVITE_TTL_SECS = TTL_OPTIONS[1].value;
3035

3136
type CopyStatus = "idle" | "copying" | "copied";
@@ -45,16 +50,12 @@ export function InviteLinkSection({
4550
ttlSecs: number;
4651
}) {
4752
const [copyStatus, setCopyStatus] = React.useState<CopyStatus>("idle");
48-
const [maxUsesEnabled, setMaxUsesEnabled] = React.useState(true);
49-
const [maxUsesInput, setMaxUsesInput] = React.useState("3");
50-
const parsedMaxUses = Number(maxUsesInput);
51-
const maxUsesValid =
52-
!maxUsesEnabled ||
53-
(Number.isInteger(parsedMaxUses) &&
54-
parsedMaxUses >= 1 &&
55-
parsedMaxUses <= 10000);
53+
const [maxUses, setMaxUses] = React.useState<number | null>(null);
5654
const ttlLabel =
5755
TTL_OPTIONS.find((option) => option.value === ttlSecs)?.label ?? "3 days";
56+
const maxUsesLabel =
57+
MAX_USE_OPTIONS.find((option) => option.value === maxUses)?.label ??
58+
"No limit";
5859
const copyLabel =
5960
copyStatus === "copying"
6061
? "Copying…"
@@ -69,13 +70,10 @@ export function InviteLinkSection({
6970
}, [copyStatus]);
7071

7172
async function handleCopy() {
72-
if (copyStatus === "copying" || !maxUsesValid) return;
73+
if (copyStatus === "copying") return;
7374
setCopyStatus("copying");
7475
try {
75-
const invite = await mintInvite({
76-
ttlSecs,
77-
maxUses: maxUsesEnabled ? parsedMaxUses : null,
78-
});
76+
const invite = await mintInvite({ ttlSecs, maxUses });
7977
await writeTextToClipboard(invite.url);
8078
setCopyStatus("copied");
8179
toast.success("Invite link copied");
@@ -87,90 +85,87 @@ export function InviteLinkSection({
8785

8886
return (
8987
<section className="pt-2" data-testid="community-invite-link-section">
90-
<div className="flex items-center gap-3">
91-
<span className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-muted text-muted-foreground">
92-
<Link2 aria-hidden="true" className="h-4 w-4" />
93-
</span>
94-
<div className="min-w-0 flex-1">
95-
<h3 className="text-sm font-medium">Share with a link</h3>
96-
<p className="text-xs text-secondary-foreground/75">
97-
Anyone with the link can join this community.
98-
</p>
88+
<div className="space-y-5">
89+
<div className="flex items-center justify-between gap-4">
90+
<span className="text-sm font-medium">Expires after</span>
91+
<DropdownMenu>
92+
<DropdownMenuTrigger asChild>
93+
<Button
94+
aria-label="Choose invite expiry"
95+
className="h-8 shrink-0 gap-1.5 px-2 text-sm text-muted-foreground"
96+
data-testid="invite-link-ttl-trigger"
97+
disabled={copyStatus === "copying"}
98+
size="sm"
99+
type="button"
100+
variant="ghost"
101+
>
102+
{ttlLabel}
103+
<ChevronDown aria-hidden="true" className="h-3.5 w-3.5" />
104+
</Button>
105+
</DropdownMenuTrigger>
106+
<DropdownMenuContent align="end" className="w-40">
107+
<DropdownMenuRadioGroup
108+
onValueChange={(value) => onTtlSecsChange(Number(value))}
109+
value={String(ttlSecs)}
110+
>
111+
{TTL_OPTIONS.map((option) => (
112+
<DropdownMenuRadioItem
113+
data-testid={`invite-link-ttl-${option.value}`}
114+
key={option.value}
115+
value={String(option.value)}
116+
>
117+
{option.label}
118+
</DropdownMenuRadioItem>
119+
))}
120+
</DropdownMenuRadioGroup>
121+
</DropdownMenuContent>
122+
</DropdownMenu>
123+
</div>
124+
<div className="flex items-center justify-between gap-4">
125+
<span className="text-sm font-medium">Limit number of uses</span>
126+
<DropdownMenu>
127+
<DropdownMenuTrigger asChild>
128+
<Button
129+
aria-label="Choose maximum invite uses"
130+
className="h-8 shrink-0 gap-1.5 px-2 text-sm text-muted-foreground"
131+
data-testid="invite-link-max-uses-trigger"
132+
disabled={copyStatus === "copying"}
133+
size="sm"
134+
type="button"
135+
variant="ghost"
136+
>
137+
{maxUsesLabel}
138+
<ChevronDown aria-hidden="true" className="h-3.5 w-3.5" />
139+
</Button>
140+
</DropdownMenuTrigger>
141+
<DropdownMenuContent align="end" className="w-40">
142+
<DropdownMenuRadioGroup
143+
onValueChange={(value) =>
144+
setMaxUses(value === "no-limit" ? null : Number(value))
145+
}
146+
value={String(maxUses ?? "no-limit")}
147+
>
148+
{MAX_USE_OPTIONS.map((option) => (
149+
<DropdownMenuRadioItem
150+
data-testid={`invite-link-max-uses-${option.value ?? "no-limit"}`}
151+
key={option.value ?? "no-limit"}
152+
value={String(option.value ?? "no-limit")}
153+
>
154+
{option.label}
155+
</DropdownMenuRadioItem>
156+
))}
157+
</DropdownMenuRadioGroup>
158+
</DropdownMenuContent>
159+
</DropdownMenu>
99160
</div>
100-
<DropdownMenu>
101-
<DropdownMenuTrigger asChild>
102-
<Button
103-
aria-label="Choose invite expiry"
104-
className="h-8 shrink-0 gap-1.5 px-2 text-muted-foreground"
105-
data-testid="invite-link-ttl-trigger"
106-
disabled={copyStatus === "copying"}
107-
size="sm"
108-
type="button"
109-
variant="ghost"
110-
>
111-
{ttlLabel}
112-
<ChevronDown aria-hidden="true" className="h-3.5 w-3.5" />
113-
</Button>
114-
</DropdownMenuTrigger>
115-
<DropdownMenuContent align="end" className="w-40">
116-
<DropdownMenuLabel>Expires after</DropdownMenuLabel>
117-
<DropdownMenuSeparator />
118-
<DropdownMenuRadioGroup
119-
onValueChange={(value) => onTtlSecsChange(Number(value))}
120-
value={String(ttlSecs)}
121-
>
122-
{TTL_OPTIONS.map((option) => (
123-
<DropdownMenuRadioItem
124-
data-testid={`invite-link-ttl-${option.value}`}
125-
key={option.value}
126-
value={String(option.value)}
127-
>
128-
{option.label}
129-
</DropdownMenuRadioItem>
130-
))}
131-
</DropdownMenuRadioGroup>
132-
</DropdownMenuContent>
133-
</DropdownMenu>
134-
</div>
135-
<div className="mt-3 flex items-center gap-2 text-xs">
136-
<Switch
137-
checked={maxUsesEnabled}
138-
data-testid="invite-link-max-uses-switch"
139-
id="invite-max-uses"
140-
onCheckedChange={setMaxUsesEnabled}
141-
/>
142-
<label className="text-muted-foreground" htmlFor="invite-max-uses">
143-
Limit uses
144-
</label>
145-
{maxUsesEnabled ? (
146-
<Input
147-
className="h-7 w-20"
148-
data-testid="invite-link-max-uses-input"
149-
inputMode="numeric"
150-
max={10000}
151-
min={1}
152-
onChange={(event) => setMaxUsesInput(event.target.value)}
153-
placeholder="3"
154-
type="number"
155-
value={maxUsesInput}
156-
/>
157-
) : null}
158-
{maxUsesEnabled && !maxUsesValid ? (
159-
<span
160-
className="text-destructive"
161-
data-testid="invite-link-max-uses-error"
162-
>
163-
Enter a whole number from 1 to 10,000
164-
</span>
165-
) : null}
166161
</div>
167162
<Separator className="my-4 bg-input/40" />
168163
<div className="flex justify-end">
169164
<Button
170165
className="shrink-0 border-border shadow-none"
171166
data-copy-status={copyStatus}
172167
data-testid="copy-invite-link"
173-
disabled={copyStatus === "copying" || !maxUsesValid}
168+
disabled={copyStatus === "copying"}
174169
onClick={() => void handleCopy()}
175170
size="sm"
176171
type="button"

‎desktop/tests/e2e/invite-link-copy.spec.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ import { expect, test } from "@playwright/test";
33
import { installMockBridge } from "../helpers/bridge";
44
import { openSettings } from "../helpers/settings";
55

6+
let invitePayloads: Record<string, unknown>[];
7+
68
test.beforeEach(async ({ page }) => {
9+
invitePayloads = [];
710
await page.context().grantPermissions(["clipboard-read", "clipboard-write"], {
811
origin: "http://127.0.0.1:4173",
912
});
1013
await installMockBridge(page, {
1114
relayRequiresMembership: true,
1215
});
1316
await page.route("**/api/invites", async (route) => {
17+
invitePayloads.push(route.request().postDataJSON());
1418
await route.fulfill({
1519
contentType: "application/json",
1620
json: {
@@ -33,8 +37,12 @@ test("copies a freshly minted invite link without showing a URL or QR code", asy
3337
await page.getByTestId("community-invite-dialog-trigger").click();
3438
await expect(page.getByTestId("invite-link-url")).toHaveCount(0);
3539
await expect(page.getByTestId("invite-link-qr-code")).toHaveCount(0);
40+
await expect(page.getByTestId("invite-link-max-uses-trigger")).toHaveText(
41+
"No limit",
42+
);
3643
await page.getByTestId("copy-invite-link").click();
3744
await expect(page.getByTestId("copy-invite-link")).toContainText("Copied");
45+
expect(invitePayloads).toEqual([{ ttl_secs: 3 * 24 * 60 * 60 }]);
3846

3947
const payload = await page.evaluate(() => {
4048
const log = (
@@ -53,3 +61,25 @@ test("copies a freshly minted invite link without showing a URL or QR code", asy
5361
text: "buzz://join?relay=wss%3A%2F%2Frelay.example.com&code=qr-download-test",
5462
});
5563
});
64+
65+
test("sets a selected invite-use limit", async ({ page }) => {
66+
await page.goto("/");
67+
await openSettings(page, "community-members");
68+
await page.getByTestId("community-invite-dialog-trigger").click();
69+
70+
const maxUsesTrigger = page.getByTestId("invite-link-max-uses-trigger");
71+
await maxUsesTrigger.click();
72+
await expect(
73+
page.getByRole("menuitemradio", { name: "No limit" }),
74+
).toBeVisible();
75+
await expect(
76+
page.getByRole("menuitemradio", { name: "25 uses" }),
77+
).toBeVisible();
78+
await page.getByTestId("invite-link-max-uses-10").click();
79+
await expect(maxUsesTrigger).toHaveText("10 uses");
80+
await page.getByTestId("copy-invite-link").click();
81+
await expect(page.getByTestId("copy-invite-link")).toContainText("Copied");
82+
expect(invitePayloads).toEqual([
83+
{ max_uses: 10, ttl_secs: 3 * 24 * 60 * 60 },
84+
]);
85+
});

‎desktop/tests/e2e/invites-settings-screenshots.spec.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,25 @@ test("capture: share-style community invite dialog", async ({ page }) => {
7878
await expect(page.getByTestId("community-invite-email-field")).toHaveCount(0);
7979
await expect(page.getByPlaceholder("Type an email address")).toHaveCount(0);
8080
await expect(
81-
dialog.getByRole("heading", { name: "Share with a link" }),
81+
dialog.getByText("Anyone with this link can join this community."),
8282
).toBeVisible();
83+
await expect(dialog.getByText("Expires after")).toBeVisible();
84+
await expect(dialog.getByText("Limit number of uses")).toBeVisible();
85+
await expect(page.getByTestId("invite-link-max-uses-trigger")).toHaveText(
86+
"No limit",
87+
);
8388
await expect(page.getByTestId("copy-invite-link")).toHaveText("Copy link");
8489
await expect(page.getByTestId("invite-link-qr-code")).toHaveCount(0);
8590
await expect(page.getByTestId("invite-link-url")).toHaveCount(0);
8691

8792
const expiryTrigger = page.getByTestId("invite-link-ttl-trigger");
8893
await expect(expiryTrigger).toHaveText("3 days");
94+
await expect(expiryTrigger).toHaveCSS("font-size", "14px");
95+
await expect(
96+
dialog.getByText("Limit number of uses", { exact: true }),
97+
).toHaveCSS("font-size", "14px");
8998
await expiryTrigger.click();
99+
await expect(page.getByRole("menu")).not.toContainText("Expires after");
90100
await expect(
91101
page.getByRole("menuitemradio", { name: "1 day" }),
92102
).toBeVisible();

0 commit comments

Comments
 (0)