Skip to content

Open source CapCut alternative.

TypeScript

fix(site): keep the email dialog's shape while its row loads

David Le1dc175a00a0f
diff --git a/site/src/app/su/analytics/product/page.tsx b/site/src/app/su/analytics/product/page.tsx
index 34d2f87e..39f86ae0 100644
--- a/site/src/app/su/analytics/product/page.tsx
+++ b/site/src/app/su/analytics/product/page.tsx
@@ -34,9 +34,9 @@ import { useLocalPref } from "@/cut/lib/uiState";
import { cn } from "@/lib/utils";
import { DragBlock, useReorder } from "@/app/su/analytics/Reorder";
import { OutreachComposeDialog } from "@/app/su/outreach/ComposeDialog";
+import { Button } from "@/components/ui/button";
import { SuStandIn } from "@/app/su/SuStandIn";
import { useRowWindow } from "@/app/su/analytics/rowWindow";
-import { Button } from "@/components/ui/button";
import { useAnalyticsRollup } from "@/queries/analytics";
import { ApiError } from "@/queries/apiClient";
import { useOutreachAction, type OutreachRow } from "@/queries/outreach";
@@ -806,12 +806,12 @@ function ActivityGrid({
nothing. */}
<Button
aria-label={`Email ${user.name}`}
- className="absolute top-1/2 right-2 -translate-y-1/2 opacity-0 group-hover:opacity-100 focus-visible:opacity-100"
+ className="absolute inset-y-0 right-2 my-auto opacity-0 group-hover:opacity-100 focus-visible:opacity-100"
onClick={() => emailUser(user)}
- size="icon"
+ size="icon-sm"
variant="ghost"
>
- <Mail className="size-5" />
+ <Mail />
</Button>
<span className="flex items-center gap-1.5">
<span className="block max-w-56 truncate text-sm" title={user.name}>
diff --git a/site/src/app/su/outreach/ComposeDialog.tsx b/site/src/app/su/outreach/ComposeDialog.tsx
index 53ef5b92..b372c924 100644
--- a/site/src/app/su/outreach/ComposeDialog.tsx
+++ b/site/src/app/su/outreach/ComposeDialog.tsx
@@ -24,7 +24,6 @@ import {
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
-import { Skeleton } from "@/components/ui/skeleton";
import { Switch } from "@/components/ui/switch";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Textarea } from "@/components/ui/textarea";
@@ -209,11 +208,13 @@ export function OutreachComposeDialog({
// Each opening starts from whatever the last note went out from, so a run
// through a list is one click from ready; with nothing sent yet, the newest
// starting point, and with nothing saved at all, a blank note. The seed
- // lands in the render that first sees the row, and clears with it, so the
- // same row opened again starts fresh.
+ // lands in the render that first sees the person, whose row may still be
+ // on its way, and clears with them, so the same person opened again starts
+ // fresh.
+ const person = target?.email ?? opening?.email ?? null;
const [seededFor, setSeededFor] = useState<string | null>(null);
- if (target && seededFor !== target.id) {
- setSeededFor(target.id);
+ if (person && seededFor !== person) {
+ setSeededFor(person);
const start =
sources.find((option) => option.id === lastStart) ??
starts[0] ??
@@ -226,7 +227,7 @@ export function OutreachComposeDialog({
setCreditOffer(start.creditOffer);
setNaming(false);
setTestNotice(null);
- } else if (!target && seededFor !== null) {
+ } else if (!person && seededFor !== null) {
setSeededFor(null);
}
@@ -386,7 +387,7 @@ export function OutreachComposeDialog({
onOpenChange={(open) => {
if (!open) onClose();
}}
- open={target !== null || opening !== null}
+ open={person !== null}
>
<DialogContent className="grid max-h-[85vh] grid-rows-[auto_minmax(0,1fr)_auto] sm:max-w-5xl">
<DialogHeader>
@@ -395,181 +396,181 @@ export function OutreachComposeDialog({
</DialogHeader>
{/* The note and the person's past share the dialog; the tabs reset
- with each row so a new person opens on the note. */}
- {target === null ? (
- <ComposeSkeleton />
- ) : (
- <Tabs className="min-h-0 gap-3" defaultValue="note" key={target.id}>
- <TabsList variant="line">
- <TabsTrigger value="note">Note</TabsTrigger>
- <TabsTrigger value="history">History</TabsTrigger>
- </TabsList>
- <TabsContent className="min-h-0" value="history">
+ with each person so a new one opens on the note. */}
+ <Tabs className="min-h-0 gap-3" defaultValue="note" key={person ?? "none"}>
+ <TabsList variant="line">
+ <TabsTrigger value="note">Note</TabsTrigger>
+ <TabsTrigger value="history">History</TabsTrigger>
+ </TabsList>
+ <TabsContent className="min-h-0" value="history">
+ {target ? (
<UserHistoryPanel target={target} />
- </TabsContent>
- <TabsContent
- className="grid min-h-0 min-w-0 gap-4 md:grid-cols-[18rem_minmax(0,1fr)]"
- value="note"
- >
- <div className="flex min-h-0 flex-col gap-2 md:border-r md:pr-4">
- <span className="text-xs font-medium text-muted-foreground">
- Start from
- </span>
- <div className="min-h-0 flex-1 space-y-0.5 overflow-y-auto max-md:max-h-40">
- {sources.map((option) => (
- <div className="group/start relative" key={option.id}>
- <button
- className={cn(
- "w-full rounded-lg px-2 py-1.5 pr-8 text-left transition-colors",
- source === option.id
- ? "bg-accent text-accent-foreground"
- : "hover:bg-accent/50",
- )}
- onClick={() => pickSource(option.id)}
- type="button"
- >
- <span className="block truncate text-sm">
- {option.title}
+ ) : (
+ <p className="text-sm text-muted-foreground">Loading…</p>
+ )}
+ </TabsContent>
+ <TabsContent
+ className="grid min-h-0 min-w-0 gap-4 md:grid-cols-[18rem_minmax(0,1fr)]"
+ value="note"
+ >
+ <div className="flex min-h-0 flex-col gap-2 md:border-r md:pr-4">
+ <span className="text-xs font-medium text-muted-foreground">
+ Start from
+ </span>
+ <div className="min-h-0 flex-1 space-y-0.5 overflow-y-auto max-md:max-h-40">
+ {sources.map((option) => (
+ <div className="group/start relative" key={option.id}>
+ <button
+ className={cn(
+ "w-full rounded-lg px-2 py-1.5 pr-8 text-left transition-colors",
+ source === option.id
+ ? "bg-accent text-accent-foreground"
+ : "hover:bg-accent/50",
+ )}
+ onClick={() => pickSource(option.id)}
+ type="button"
+ >
+ <span className="block truncate text-sm">
+ {option.title}
+ </span>
+ {option.meta ? (
+ <span className="block truncate text-xs text-muted-foreground">
+ {option.meta}
</span>
- {option.meta ? (
- <span className="block truncate text-xs text-muted-foreground">
- {option.meta}
- </span>
- ) : null}
- </button>
- {option.remove ? (
- <Button
- aria-label={`Delete ${option.title}`}
- className="absolute top-1.5 right-1 opacity-0 group-hover/start:opacity-100 focus-visible:opacity-100"
- disabled={option.busy}
- onClick={option.remove}
- size="icon-xs"
- variant="ghost"
- >
- <XIcon />
- </Button>
) : null}
- </div>
- ))}
- </div>
- {naming ? (
- <div className="space-y-2">
- <Input
- aria-label="Template name"
- autoFocus
- maxLength={80}
- onChange={(event) => setTemplateName(event.target.value)}
- onKeyDown={(event) => {
- if (event.key === "Enter") submitTemplate();
- }}
- placeholder="Template name"
- value={templateName}
- />
- <div className="flex items-center gap-2">
- <Button
- className="flex-1"
- disabled={
- saveTemplate.isPending || templateName.trim() === ""
- }
- onClick={submitTemplate}
- size="sm"
- >
- {saveTemplate.isPending ? "Saving…" : "Save"}
- </Button>
+ </button>
+ {option.remove ? (
<Button
- onClick={() => setNaming(false)}
- size="sm"
+ aria-label={`Delete ${option.title}`}
+ className="absolute top-1.5 right-1 opacity-0 group-hover/start:opacity-100 focus-visible:opacity-100"
+ disabled={option.busy}
+ onClick={option.remove}
+ size="icon-xs"
variant="ghost"
>
- Cancel
+ <XIcon />
</Button>
- </div>
+ ) : null}
</div>
- ) : (
- <Button
- disabled={!sendable || selectedPromotion !== undefined}
- onClick={() => {
- setTemplateName(selectedTemplate?.name ?? "");
- setNaming(true);
- }}
- size="sm"
- variant="outline"
- >
- Save as template
- </Button>
- )}
- {saveTemplate.isError ? (
- <p className="text-xs text-destructive">
- Couldn&apos;t save that template. Try a different name.
- </p>
- ) : null}
- {deleteTemplate.isError ? (
- <p className="text-xs text-destructive">
- Couldn&apos;t delete that template.
- </p>
- ) : null}
+ ))}
</div>
-
- {selectedPromotion ? (
- <PromotionPreview
- promotion={selectedPromotion}
- issue={sendFailed ? sendIssue : undefined}
- />
- ) : (
- <div className="flex min-h-0 min-w-0 flex-col gap-2">
- <Label htmlFor="outreach-subject">Subject</Label>
+ {naming ? (
+ <div className="space-y-2">
<Input
- id="outreach-subject"
- maxLength={200}
- onChange={(event) => setSubject(event.target.value)}
- value={subject}
- />
- <Label className="mt-1" htmlFor="outreach-body">
- Message
- </Label>
- <Textarea
- className="min-h-40 flex-1 resize-none field-sizing-fixed"
- id="outreach-body"
- maxLength={5000}
- onChange={(event) => setBody(event.target.value)}
- ref={bodyField}
- value={body}
+ aria-label="Template name"
+ autoFocus
+ maxLength={80}
+ onChange={(event) => setTemplateName(event.target.value)}
+ onKeyDown={(event) => {
+ if (event.key === "Enter") submitTemplate();
+ }}
+ placeholder="Template name"
+ value={templateName}
/>
- <div className="flex flex-wrap items-center gap-1.5">
- <span className="text-xs text-muted-foreground">
- Blank line starts a paragraph. Insert:
- </span>
- {placeholders.map((name) => (
- <Button
- key={name}
- onClick={() => insertPlaceholder(name)}
- size="xs"
- variant="outline"
- >
- {`{{${name}}}`}
- </Button>
- ))}
+ <div className="flex items-center gap-2">
+ <Button
+ className="flex-1"
+ disabled={
+ saveTemplate.isPending || templateName.trim() === ""
+ }
+ onClick={submitTemplate}
+ size="sm"
+ >
+ {saveTemplate.isPending ? "Saving…" : "Save"}
+ </Button>
+ <Button
+ onClick={() => setNaming(false)}
+ size="sm"
+ variant="ghost"
+ >
+ Cancel
+ </Button>
</div>
- <CreditOfferFields
- idPrefix="outreach-offer"
- value={creditOffer}
- defaults={offerDefaults}
- onChange={setCreditOffer}
- hint="The note carries a link for AI credits; {{claimUrl}} is the link and {{claimBy}} the last day to claim."
- />
- {sendFailed ? (
- <p className="text-sm text-destructive">
- {sendIssue ??
- "That didn’t go through. The account may have unsubscribed since the last scan, or the text may name a placeholder that doesn’t exist."}
- </p>
- ) : testNotice ? (
- <p className="text-sm text-muted-foreground">{testNotice}</p>
- ) : null}
</div>
+ ) : (
+ <Button
+ disabled={!sendable || selectedPromotion !== undefined}
+ onClick={() => {
+ setTemplateName(selectedTemplate?.name ?? "");
+ setNaming(true);
+ }}
+ size="sm"
+ variant="outline"
+ >
+ Save as template
+ </Button>
)}
- </TabsContent>
- </Tabs>
- )}
+ {saveTemplate.isError ? (
+ <p className="text-xs text-destructive">
+ Couldn&apos;t save that template. Try a different name.
+ </p>
+ ) : null}
+ {deleteTemplate.isError ? (
+ <p className="text-xs text-destructive">
+ Couldn&apos;t delete that template.
+ </p>
+ ) : null}
+ </div>
+
+ {selectedPromotion ? (
+ <PromotionPreview
+ promotion={selectedPromotion}
+ issue={sendFailed ? sendIssue : undefined}
+ />
+ ) : (
+ <div className="flex min-h-0 min-w-0 flex-col gap-2">
+ <Label htmlFor="outreach-subject">Subject</Label>
+ <Input
+ id="outreach-subject"
+ maxLength={200}
+ onChange={(event) => setSubject(event.target.value)}
+ value={subject}
+ />
+ <Label className="mt-1" htmlFor="outreach-body">
+ Message
+ </Label>
+ <Textarea
+ className="min-h-40 flex-1 resize-none field-sizing-fixed"
+ id="outreach-body"
+ maxLength={5000}
+ onChange={(event) => setBody(event.target.value)}
+ ref={bodyField}
+ value={body}
+ />
+ <div className="flex flex-wrap items-center gap-1.5">
+ <span className="text-xs text-muted-foreground">
+ Blank line starts a paragraph. Insert:
+ </span>
+ {placeholders.map((name) => (
+ <Button
+ key={name}
+ onClick={() => insertPlaceholder(name)}
+ size="xs"
+ variant="outline"
+ >
+ {`{{${name}}}`}
+ </Button>
+ ))}
+ </div>
+ <CreditOfferFields
+ idPrefix="outreach-offer"
+ value={creditOffer}
+ defaults={offerDefaults}
+ onChange={setCreditOffer}
+ hint="The note carries a link for AI credits; {{claimUrl}} is the link and {{claimBy}} the last day to claim."
+ />
+ {sendFailed ? (
+ <p className="text-sm text-destructive">
+ {sendIssue ??
+ "That didn’t go through. The account may have unsubscribed since the last scan, or the text may name a placeholder that doesn’t exist."}
+ </p>
+ ) : testNotice ? (
+ <p className="text-sm text-muted-foreground">{testNotice}</p>
+ ) : null}
+ </div>
+ )}
+ </TabsContent>
+ </Tabs>
<DialogFooter>
{/* The footer column is reversed below sm, so ordering the toggles
@@ -661,29 +662,3 @@ function PromotionPreview({
</div>
);
}
-
-// The dialog's shape while the person's row is on its way: the tabs, the
-// start-from list and the note fields, as slabs.
-function ComposeSkeleton() {
- return (
- <div className="flex min-h-0 flex-col gap-3">
- <div className="flex gap-4 border-b pb-2">
- <Skeleton className="h-4 w-10" />
- <Skeleton className="h-4 w-14" />
- </div>
- <div className="grid min-h-0 gap-4 md:grid-cols-[18rem_minmax(0,1fr)]">
- <div className="space-y-2 md:border-r md:pr-4">
- <Skeleton className="h-3 w-16" />
- <Skeleton className="h-9 w-full" />
- <Skeleton className="h-9 w-full" />
- <Skeleton className="h-9 w-full" />
- </div>
- <div className="space-y-3">
- <Skeleton className="h-8 w-full" />
- <Skeleton className="h-40 w-full" />
- <Skeleton className="h-8 w-1/2" />
- </div>
- </div>
- </div>
- );
-}