Rebuild Share and Delete Account from the privacy designs.

Share asks the person who holds the pen to confirm their community agreed before a link turns on, and deleting an account lists each owned Rule with PDF and RULE.md export. Case-study Share copies the page link instead of opening the privacy modal, and the sign-in banner stays below the header so Share remains clickable.
This commit is contained in:
adilallo committed 2026-11-09 19:54:09 -07:00
1 parent 5cbda35e32
commit b6795c1f18
28 files changed
+1467 -377

No files matched your search

+2
View File
@@ -89,7 +89,9 @@ export function partnerLogoPath(slug: string): string {
export type ShareIconName =
| "check"
| "discord"
| "language"
| "link"
| "lock"
| "mail"
| "signal"
| "slack";
+104
View File
@@ -1,4 +1,6 @@
import type { CreateFlowState } from "../../app/(app)/create/types";
import type { RuleShareSettings } from "../ruleShareTypes";
import { isRuleVisibility } from "../ruleVisibility";
import { migrateLegacyCreateFlowState } from "./migrateLegacyCreateFlowState";
const jsonHeaders = { "Content-Type": "application/json" };
@@ -750,6 +752,108 @@ export async function duplicateUseCaseTemplate(
}
}
export type FetchRuleShareResult =
| { ok: true; share: RuleShareSettings }
| { ok: false; status: number; error: string };
function isRuleShareSettings(value: unknown): value is RuleShareSettings {
if (!value || typeof value !== "object") return false;
const o = value as Record<string, unknown>;
return (
isRuleVisibility(o.visibility) &&
typeof o.shareUrl === "string" &&
typeof o.title === "string" &&
typeof o.ownerEmail === "string" &&
Array.isArray(o.readers)
);
}
export async function fetchRuleShare(
ruleId: string,
): Promise<FetchRuleShareResult> {
try {
const res = await fetch(
`/api/rules/${encodeURIComponent(ruleId)}/share`,
{ credentials: "include" },
);
if (!res.ok) {
const data = await safeParseJsonResponse(res);
return {
ok: false as const,
status: res.status,
error: readApiErrorMessage(data),
};
}
const data = await safeParseJsonResponse(res);
const share =
data && typeof data === "object" && "share" in data
? (data as { share: unknown }).share
: null;
if (!isRuleShareSettings(share)) {
return {
ok: false as const,
status: res.status,
error: DRAFT_SAVE_NETWORK_ERROR,
};
}
return { ok: true as const, share };
} catch {
return {
ok: false as const,
status: 0,
error: DRAFT_SAVE_NETWORK_ERROR,
};
}
}
export async function patchRuleShare(
ruleId: string,
visibility: "private" | "shared_by_link",
communityAgreed?: boolean,
): Promise<FetchRuleShareResult> {
try {
const res = await fetch(
`/api/rules/${encodeURIComponent(ruleId)}/share`,
{
method: "PATCH",
credentials: "include",
headers: jsonHeaders,
body: JSON.stringify({
visibility,
...(communityAgreed !== undefined ? { communityAgreed } : {}),
}),
},
);
if (!res.ok) {
const data = await safeParseJsonResponse(res);
return {
ok: false as const,
status: res.status,
error: readApiErrorMessage(data),
};
}
const data = await safeParseJsonResponse(res);
const share =
data && typeof data === "object" && "share" in data
? (data as { share: unknown }).share
: null;
if (!isRuleShareSettings(share)) {
return {
ok: false as const,
status: res.status,
error: DRAFT_SAVE_NETWORK_ERROR,
};
}
return { ok: true as const, share };
} catch {
return {
ok: false as const,
status: 0,
error: DRAFT_SAVE_NETWORK_ERROR,
};
}
}
export type DeleteAccountResult = { ok: true } | { ok: false; error: string };
/**