Open source CapCut alternative.
TypeScript
feat(site): outreach templates default to the unsubscribe footer and reply tracking
David Le2e44edbad772
diff --git a/site/prisma/Marketing.prisma b/site/prisma/Marketing.prismaindex 112ba1c6..8a7ade41 100644--- a/site/prisma/Marketing.prisma+++ b/site/prisma/Marketing.prisma@@ -48,8 +48,8 @@ model OutreachTemplate {body String// The send toggles the template opens with: the opt-out footer, and routing// replies through the signed alias that marks the row replied.- unsubscribeLink Boolean @default(false)- trackReplies Boolean @default(false)+ unsubscribeLink Boolean @default(true)+ trackReplies Boolean @default(true)// The super user who last saved it.actorUserId String?createdAt DateTime @default(now())diff --git a/site/prisma/migrations/20260828063703/migration.sql b/site/prisma/migrations/20260828063703/migration.sqlindex 2708a45a..52846289 100644--- a/site/prisma/migrations/20260828063703/migration.sql+++ b/site/prisma/migrations/20260828063703/migration.sql@@ -1,3 +1,3 @@-- AlterTable-ALTER TABLE "OutreachTemplate" ADD COLUMN "trackReplies" BOOLEAN NOT NULL DEFAULT false,-ADD COLUMN "unsubscribeLink" BOOLEAN NOT NULL DEFAULT false;+ALTER TABLE "OutreachTemplate" ADD COLUMN "trackReplies" BOOLEAN NOT NULL DEFAULT true,+ADD COLUMN "unsubscribeLink" BOOLEAN NOT NULL DEFAULT true;diff --git a/site/src/app/su/outreach/drafts.ts b/site/src/app/su/outreach/drafts.tsindex de5983a5..f3104e9f 100644--- a/site/src/app/su/outreach/drafts.ts+++ b/site/src/app/su/outreach/drafts.ts@@ -9,6 +9,7 @@ import { useLocalPref } from "@/cut/lib/uiState";// timestamps for a conversation, never the words. The two send toggles ride// along, so a start point recalls how it went out as well as what it said.export type OutreachDraft = {+ id: string;subject: string;body: string;unsubscribeLink: boolean;@@ -16,9 +17,12 @@ export type OutreachDraft = {savedAt: string;};-// The toggles are optional on disk: entries written before they existed read-// as off, which is how those notes went out.+// The toggles and the id are optional on disk. Entries written before the+// toggles existed read as on: every note back then carried the opt-out footer+// and the tracked reply alias. An entry without an id is identified by its+// timestamp.type StoredDraft = {+ id?: string;subject: string;body: string;unsubscribeLink?: boolean;@@ -37,6 +41,7 @@ function isDraft(value: unknown): value is StoredDraft {typeof draft.subject === "string" &&typeof draft.body === "string" &&typeof draft.savedAt === "string" &&+ (draft.id === undefined || typeof draft.id === "string") &&(draft.unsubscribeLink === undefined ||typeof draft.unsubscribeLink === "boolean") &&(draft.trackReplies === undefined || typeof draft.trackReplies === "boolean")@@ -54,8 +59,8 @@ export function useLastOutreachStart(): [string | null, (id: string) => void] {export function useOutreachDrafts(): {drafts: OutreachDraft[];- remember: (draft: Omit<OutreachDraft, "savedAt">) => string;- forget: (savedAt: string) => void;+ remember: (draft: Omit<OutreachDraft, "id" | "savedAt">) => string;+ forget: (id: string) => void;} {const [stored, setStored] = useLocalPref<StoredDraft[]>(KEY, [], (value) =>Array.isArray(value) && value.every(isDraft),@@ -63,37 +68,46 @@ export function useOutreachDrafts(): {const drafts: OutreachDraft[] = stored.map((draft) => ({...draft,- trackReplies: draft.trackReplies ?? false,- unsubscribeLink: draft.unsubscribeLink ?? false,+ id: draft.id ?? draft.savedAt,+ trackReplies: draft.trackReplies ?? true,+ unsubscribeLink: draft.unsubscribeLink ?? true,}));const remember = useCallback(- ({ body, subject, trackReplies, unsubscribeLink }: Omit<OutreachDraft, "savedAt">) => {- // Sending the same note twice moves the entry up rather than doubling it.- const rest = stored.filter(- (draft) =>- draft.subject !== subject ||- draft.body !== body ||- (draft.unsubscribeLink ?? false) !== unsubscribeLink ||- (draft.trackReplies ?? false) !== trackReplies,- );+ ({+ body,+ subject,+ trackReplies,+ unsubscribeLink,+ }: Omit<OutreachDraft, "id" | "savedAt">) => {+ const id = crypto.randomUUID();const savedAt = new Date().toISOString();- setStored(- [{ body, savedAt, subject, trackReplies, unsubscribeLink }, ...rest].slice(- 0,- LIMIT,- ),- );- return savedAt;+ setStored((current) => {+ // Sending the same note twice moves the entry up rather than doubling it.+ const rest = current.filter(+ (draft) =>+ draft.subject !== subject ||+ draft.body !== body ||+ (draft.unsubscribeLink ?? true) !== unsubscribeLink ||+ (draft.trackReplies ?? true) !== trackReplies,+ );+ return [+ { body, id, savedAt, subject, trackReplies, unsubscribeLink },+ ...rest,+ ].slice(0, LIMIT);+ });+ return id;},- [stored, setStored],+ [setStored],);const forget = useCallback(- (savedAt: string) => {- setStored(stored.filter((draft) => draft.savedAt !== savedAt));+ (id: string) => {+ setStored((current) =>+ current.filter((draft) => (draft.id ?? draft.savedAt) !== id),+ );},- [stored, setStored],+ [setStored],);return { drafts, forget, remember };diff --git a/site/src/cut/lib/uiState.ts b/site/src/cut/lib/uiState.tsindex dc19264f..bdb700c0 100644--- a/site/src/cut/lib/uiState.ts+++ b/site/src/cut/lib/uiState.ts@@ -69,7 +69,7 @@ export function useLocalPref<T>(key: string,fallback: T,accept: (v: unknown) => boolean-): [T, (v: T) => void] {+): [T, (v: T | ((prev: T) => T)) => void] {const [value, setValue] = useState<T>(() => {if (typeof window === "undefined") return fallback;try {@@ -81,14 +81,19 @@ export function useLocalPref<T>(return fallback;}});+ // Updater form goes through the live previous value, so two writers in the+ // same tick both land instead of the second clobbering the first.const set = useCallback(- (v: T) => {- setValue(v);- try {- localStorage.setItem(key, JSON.stringify(v));- } catch {- // Private-mode quota — the choice just won't stick across reloads.- }+ (v: T | ((prev: T) => T)) => {+ setValue((prev) => {+ const next = typeof v === "function" ? (v as (prev: T) => T)(prev) : v;+ try {+ localStorage.setItem(key, JSON.stringify(next));+ } catch {+ // Private-mode quota — the choice just won't stick across reloads.+ }+ return next;+ });},[key]);