Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | 1x 1x 1x 1x 39x 39x 39x 39x 40x 5x 40x 1x 8x 39x 39x 3x 36x 1x 1x 39x 39x 1x 38x 39x 38x 1x 39x 1x 3x 2x 1x 1x 1x 41x 41x 41x 41x 41x 39x 3x 41x 41x 41x 41x 41x 2x 41x 39x 2x | import { useNavigate } from "@tanstack/react-router";
import { Check, UserPlus } from "lucide-react";
import { useMemo, useState } from "react";
import { Button } from "../../../components/ui/button";
import {
Card,
CardContent,
CardHeader,
CardTitle,
} from "../../../components/ui/card";
import { EmptyState } from "../../../components/ui/empty-state";
import { PageHeader } from "../../../components/ui/page-header";
import { StatusBadge } from "../../../components/ui/status-badge";
import {
useRrmMarkReplied,
useRrmSignups,
} from "../../../hooks/queries/useRrmQueries";
import type {
RrmSignup,
RrmSubmissionSummary,
} from "../../../lib/api/admin/rrm";
import { getErrorMessage } from "../../../lib/api/base";
import { partnerAppInviteUrl } from "../../../lib/rrm/invite-link";
import {
formatDateTime,
formatRelative,
LOCALE_LABELS,
RrmStageBadge,
} from "./prospects";
/**
* RRM sign-ups (F-21).
*
* Every other RRM screen works the 455 scraped prospects. This one is the
* opposite lens: only rows with `source = "organic"` — people who filled in
* the go.interioring.com/partners form themselves. It's the number the whole
* page exists to produce, so it gets its own screen instead of being a filter
* an operator has to remember to apply on Prospects.
*/
const PAGE_SIZE = 20;
const COLUMN_COUNT = 9;
const SKELETON_KEYS = ["a", "b", "c", "d", "e", "f", "g", "h"];
const HEADER_CELL =
"px-4 py-3 text-left text-xs font-medium text-foreground-muted uppercase tracking-wider";
// ─── WhatsApp number formatting ──────────────────────────────────────────────
/**
* Numbers are stored normalised (country code + 10 digits, no punctuation).
* An operator reading this column is about to open WhatsApp, so it is
* rendered the way a phone would show it rather than as a raw digit string.
*/
function formatWhatsApp(phoneNorm: string): string {
const digits = phoneNorm.replace(/\D/g, "");
const local =
digits.startsWith("91") && digits.length === 12 ? digits.slice(2) : digits;
Eif (local.length === 10) {
return `+91 ${local.slice(0, 5)} ${local.slice(5)}`;
}
return phoneNorm;
}
/**
* What they told us. A referral names the homeowner they are vouching for —
* the row an open `confirm_intent` task is waiting on — so it reads
* differently from a bare expression of interest even though both are
* "a sign-up" to every other screen.
*/
export function formatSubmitted(submission: RrmSubmissionSummary): string {
if (submission.cta === "interest") return "Interested";
const name = submission.contactName ?? "contact";
return submission.contactProject
? `Referral → ${name}, ${submission.contactProject}`
: `Referral → ${name}`;
}
// ─── Table pieces ────────────────────────────────────────────────────────────
function SkeletonRows() {
return (
<>
{SKELETON_KEYS.map((key) => (
<tr key={key} data-testid="rrm-signups-skeleton-row">
<td colSpan={COLUMN_COUNT} className="px-4 py-3">
<div className="h-5 bg-background-muted rounded animate-pulse" />
</td>
</tr>
))}
</>
);
}
/**
* Owns its own mutation so pending/error state stays per-row — a shared
* mutation instance across the table would make every row's button disable
* together the moment any one of them was clicked.
*/
function RepliedCell({
prospectId,
repliedAt,
}: {
prospectId: string;
repliedAt: string | null;
}) {
const markReplied = useRrmMarkReplied();
if (repliedAt) {
return (
<span
data-testid="rrm-signups-replied"
data-replied="yes"
className="inline-flex items-center gap-1.5 text-sm font-medium text-success"
title={formatDateTime(repliedAt)}
>
<Check className="h-4 w-4" aria-hidden="true" />
<span>Replied</span>
</span>
);
}
return (
<div className="flex flex-col items-start gap-1">
<div className="flex items-center gap-2">
<span
data-testid="rrm-signups-replied"
data-replied="no"
className="text-sm text-foreground-muted"
>
Not yet
</span>
<Button
type="button"
variant="ghost"
size="sm"
data-testid="rrm-signups-mark-replied"
disabled={markReplied.isPending}
onClick={(e) => {
// Otherwise this click also bubbles into the row's onClick and
// opens the prospect detail page underneath the operator.
e.stopPropagation();
markReplied.mutate(prospectId);
}}
>
Mark replied
</Button>
</div>
{markReplied.isError && (
<span
data-testid="rrm-signups-mark-replied-error"
className="text-xs text-error"
>
{getErrorMessage(markReplied.error)}
</span>
)}
</div>
);
}
function SubmittedCell({ signup }: { signup: RrmSignup }) {
const { latestSubmission } = signup;
if (!latestSubmission) {
return <span className="text-sm text-foreground-muted">—</span>;
}
return (
<div data-testid="rrm-signups-submitted">
<p className="text-sm text-foreground-default">
{formatSubmitted(latestSubmission)}
</p>
{latestSubmission.duplicateOfSubmissionId && (
<p className="text-xs text-foreground-muted">
Already referred — first submission wins
</p>
)}
{signup.submissionCount > 1 && (
<p className="text-xs text-foreground-subtle">
+{signup.submissionCount - 1} more
</p>
)}
</div>
);
}
function SourceCell({ sourceDetail }: { sourceDetail: string | null }) {
if (!sourceDetail) {
return (
<span
data-testid="rrm-signups-source"
className="text-sm text-foreground-muted"
>
—
</span>
);
}
return (
<span
data-testid="rrm-signups-source"
className="inline-flex rounded bg-background-muted px-1.5 py-0.5 font-mono text-xs text-foreground-muted"
>
{sourceDetail}
</span>
);
}
function SignupRow({
signup,
onOpen,
}: {
signup: RrmSignup;
onOpen: (id: string) => void;
}) {
return (
<tr
data-testid="rrm-signups-row"
data-prospect-id={signup.id}
tabIndex={0}
className="cursor-pointer hover:bg-background-muted focus-visible:outline-none focus-visible:bg-background-muted transition-colors"
onClick={() => onOpen(signup.id)}
onKeyDown={(e) => {
// A keydown on the "Mark replied" button bubbles up here too — only
// act on the row itself, not on something focused inside it.
if (e.target !== e.currentTarget) return;
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
onOpen(signup.id);
}
}}
>
<td
className="px-4 py-3 text-sm text-foreground-muted whitespace-nowrap"
data-testid="rrm-signups-signed-up"
>
<span title={formatDateTime(signup.dateCreated)}>
{formatRelative(signup.dateCreated)}
</span>
</td>
<td className="px-4 py-3">
<p className="text-sm font-medium text-foreground-default">
{signup.name ?? "Unnamed"}
</p>
{signup.firmName && (
<p className="text-xs text-foreground-muted">{signup.firmName}</p>
)}
</td>
<td className="px-4 py-3">
<SubmittedCell signup={signup} />
</td>
<td className="px-4 py-3">
<SourceCell
sourceDetail={signup.latestSubmission?.sourceDetail ?? null}
/>
</td>
<td className="px-4 py-3 text-sm text-foreground-default font-mono whitespace-nowrap">
{formatWhatsApp(signup.phoneNorm)}
</td>
<td className="px-4 py-3">
<StatusBadge status={LOCALE_LABELS[signup.locale]} variant="default" />
</td>
<td className="px-4 py-3">
<RrmStageBadge stage={signup.stage} />
</td>
<td className="px-4 py-3">
<div className="flex items-center gap-2">
<RepliedCell prospectId={signup.id} repliedAt={signup.repliedAt} />
{/* Nothing in the product otherwise tells a sign-up the partner app exists. */}
{!signup.doNotContact && (
<Button asChild variant="ghost" size="sm">
<a
href={partnerAppInviteUrl(signup)}
target="_blank"
rel="noopener noreferrer"
data-testid="rrm-signups-send-app-link"
// Same reason as Mark replied: keep the row's onClick from
// opening the detail page under the operator.
onClick={(e) => e.stopPropagation()}
>
Send app link
</a>
</Button>
)}
</div>
</td>
<td
className="px-4 py-3 text-xs text-foreground-muted"
data-testid="rrm-signups-consent"
>
{signup.consentVersion ?? "—"}
</td>
</tr>
);
}
// ─── Page ────────────────────────────────────────────────────────────────────
export function AdminRrmSignupsPage() {
const navigate = useNavigate();
const [page, setPage] = useState(1);
const { data, isLoading, error } = useRrmSignups({ page, limit: PAGE_SIZE });
const items = useMemo(() => data?.data ?? [], [data]);
/**
* Sorted client-side rather than trusting response order: this is the
* column the screen exists to answer ("who signed up most recently"), and
* the filters contract makes no ordering guarantee.
*/
const rows = useMemo(
() =>
[...items].sort(
(a, b) =>
new Date(b.dateCreated).getTime() - new Date(a.dateCreated).getTime(),
),
[items],
);
const total = data?.meta?.total;
const totalPages = data?.meta?.totalPages;
const hasPrev = page > 1;
const hasNext =
totalPages !== undefined ? page < totalPages : items.length === PAGE_SIZE;
const countLabel =
total === undefined
? `${items.length} ${items.length === 1 ? "person has" : "people have"} signed up through the partner page`
: `${total.toLocaleString("en-IN")} ${total === 1 ? "person has" : "people have"} signed up through the partner page`;
function openProspect(id: string) {
navigate({ to: `/admin/rrm/prospects/${id}` });
}
return (
<div className="space-y-6" data-testid="rrm-signups-page">
<PageHeader
title="Sign-ups"
description="Everyone who filled in the partner page form at go.interioring.com/partners."
/>
<Card>
<CardHeader>
<CardTitle className="text-lg" data-testid="rrm-signups-count">
{isLoading ? "Loading sign-ups…" : countLabel}
</CardTitle>
</CardHeader>
<CardContent className="p-0">
{error ? (
<div
data-testid="rrm-signups-error"
className="p-6 text-sm text-error"
>
Could not load sign-ups. Refresh the page to try again.
</div>
) : (
<div className="overflow-x-auto">
<table className="w-full text-sm" data-testid="rrm-signups-table">
<thead className="bg-background-subtle border-b border-border-default">
<tr>
<th className={HEADER_CELL}>Signed up</th>
<th className={HEADER_CELL}>Name / firm</th>
<th className={HEADER_CELL}>Submitted</th>
<th className={HEADER_CELL}>Came from</th>
<th className={HEADER_CELL}>WhatsApp</th>
<th className={HEADER_CELL}>Language</th>
<th className={HEADER_CELL}>Stage</th>
<th className={HEADER_CELL}>Replied?</th>
<th className={HEADER_CELL}>Consent</th>
</tr>
</thead>
<tbody className="divide-y divide-border-default">
{isLoading ? (
<SkeletonRows />
) : rows.length === 0 ? (
<tr>
<td colSpan={COLUMN_COUNT} className="px-4 py-12">
<EmptyState
icon={UserPlus}
title="No sign-ups yet"
description="The partner page is live — nobody has submitted the form yet. Sign-ups will appear here the moment the first one comes in."
/>
</td>
</tr>
) : (
rows.map((signup) => (
<SignupRow
key={signup.id}
signup={signup}
onOpen={openProspect}
/>
))
)}
</tbody>
</table>
</div>
)}
{!isLoading && !error && (hasPrev || hasNext) && (
<div
className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 px-4 py-3 border-t border-border-default"
data-testid="rrm-signups-pagination"
>
<p className="text-sm text-foreground-muted">
{totalPages === undefined
? `Page ${page}`
: `Page ${page} of ${totalPages}`}
{total !== undefined
? ` · ${total.toLocaleString("en-IN")} total`
: ""}
</p>
<div className="flex gap-2">
<Button
variant="outline"
size="sm"
data-testid="rrm-signups-prev"
onClick={() => setPage((p) => Math.max(1, p - 1))}
disabled={!hasPrev}
>
Previous
</Button>
<Button
variant="outline"
size="sm"
data-testid="rrm-signups-next"
onClick={() => setPage((p) => p + 1)}
disabled={!hasNext}
>
Next
</Button>
</div>
</div>
)}
</CardContent>
</Card>
</div>
);
}
export default AdminRrmSignupsPage;
|