feat: recorded import grants, unclaimed creators and claiming (#15)
Co-authored-by: dhkatz <[email protected]>
This commit was merged in pull request #15.
This commit is contained in:
1 parent
e6a97be894
commit
8f6dacba10
18 files changed
+5222
-26
No files matched your search
@@ -102,3 +102,13 @@ export async function revokeToken(_: ActionState, form: FormData): Promise<Actio
|
||||
return "Revoked.";
|
||||
});
|
||||
}
|
||||
|
||||
/** Claims what an admin recorded for an IMVU account of theirs (an unclaimed creator's products and grants). */
|
||||
export async function claimCreator(_: ActionState, form: FormData): Promise<ActionState> {
|
||||
return attempt(async () => {
|
||||
const r = unwrap(await api.account.claims({ imvu: field(form, "imvuId") }).post());
|
||||
done();
|
||||
revalidatePath("/imports");
|
||||
return `They're yours: ${r.products} product${r.products === 1 ? "" : "s"}. Manage them on the Imports page.`;
|
||||
});
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { api, getMe, isModerator, unwrap } from "@/lib/api";
|
||||
import { linkAccount, signOutComputers } from "./actions";
|
||||
import { claimCreator, linkAccount, signOutComputers } from "./actions";
|
||||
import { AgeCard } from "./age-card";
|
||||
import { ChallengeCard } from "./challenge-card";
|
||||
import { LinkCard } from "./link-card";
|
||||
@@ -64,6 +64,25 @@ export default async function Account({ searchParams }: { searchParams: Promise<
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{account.claims.map((c) => (
|
||||
<Card key={c.imvuId}>
|
||||
<CardHeader>
|
||||
<CardTitle>Your IMVU Products on T5DE</CardTitle>
|
||||
<CardDescription>
|
||||
Before you joined, you agreed with T5DE to bring {c.username}'s products here, and an admin recorded
|
||||
it. They're waiting for you: {c.products} imported product{c.products === 1 ? "" : "s"} and{" "}
|
||||
{c.grants} catalog{c.grants === 1 ? "" : "s"} hosting them. Claim them to manage them yourself, or to
|
||||
withdraw them.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<ActionForm action={claimCreator} fields={{ imvuId: c.imvuId }}>
|
||||
<SubmitButton pendingLabel="Claiming…">Claim them</SubmitButton>
|
||||
</ActionForm>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
|
||||
{challenges.map((c) => (
|
||||
<ChallengeCard key={c.imvuId} challenge={c} />
|
||||
))}
|
||||
|
||||
@@ -428,7 +428,9 @@ function GrantRow({
|
||||
<span className="font-medium">{g.imvuName || `IMVU account ${g.imvuId}`}</span>
|
||||
<span className="text-muted-foreground">(IMVU {g.imvuId})</span>
|
||||
<Tag tone={grantTone[g.status]}>{g.status}</Tag>
|
||||
{g.consentKind === "recorded" && <Tag>consent recorded by an admin</Tag>}
|
||||
{g.consentKind === "recorded" && (
|
||||
<Tag>{g.consentProven ? "consent recorded by an admin, proven" : "consent recorded by an admin"}</Tag>
|
||||
)}
|
||||
<span className="text-xs text-muted-foreground">
|
||||
<DateTime iso={g.createdAt} dateOnly />
|
||||
</span>
|
||||
|
||||
@@ -41,6 +41,7 @@ const tabs: { section: Section; href: string; label: string }[] = [
|
||||
{ section: "catalogs", href: "/console/catalogs", label: "Catalogs" },
|
||||
{ section: "cases", href: "/console/cases", label: "Cases" },
|
||||
{ section: "people", href: "/console/people", label: "People" },
|
||||
{ section: "imports", href: "/console/imports", label: "Imports" },
|
||||
{ section: "blocks", href: "/console/blocks", label: "Blocks" },
|
||||
{ section: "audit", href: "/console/audit", label: "Audit" },
|
||||
];
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
"use server";
|
||||
// Recorded grants from the console (docs/imports.md): admins record consent for IMVU creators who won't make an
|
||||
// account, prove it with a tagline code, and change or withdraw them until the creator claims them.
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { api, ApiError, unwrap } from "@/lib/api";
|
||||
import { attempt, field, type ActionState } from "@/lib/actions";
|
||||
import { productIDs } from "@/lib/imvu";
|
||||
|
||||
const done = () => revalidatePath("/console/imports");
|
||||
|
||||
/** Records a creator's consent: a grant for an unclaimed creator standing in for their IMVU account. */
|
||||
export async function recordGrant(_: ActionState, form: FormData): Promise<ActionState> {
|
||||
const scope = field(form, "scope") === "products" ? "products" : "shop";
|
||||
const list = productIDs(field(form, scope === "products" ? "products" : "exclude"));
|
||||
if (!list) return { error: "Products are IMVU product IDs or shop links, separated by spaces, commas or lines." };
|
||||
return attempt(async () => {
|
||||
const r = unwrap(
|
||||
await api.console.imports.grants.post({
|
||||
catalog: field(form, "catalog"),
|
||||
imvu: field(form, "imvu"),
|
||||
scope,
|
||||
...(scope === "products" ? { products: list } : { exclude: list }),
|
||||
listed: form.get("listed") === "on",
|
||||
evidence: field(form, "evidence"),
|
||||
}),
|
||||
);
|
||||
done();
|
||||
return `Recorded for ${r.grant.imvuName}. The catalog's team accepts it before anything is imported.`;
|
||||
});
|
||||
}
|
||||
|
||||
/** Proof without an account: a code for the creator's tagline, then checking it. */
|
||||
export async function grantProof(_: ActionState, form: FormData): Promise<ActionState> {
|
||||
const id = field(form, "id");
|
||||
return attempt(async () => {
|
||||
if (field(form, "intent") === "check") {
|
||||
unwrap(await api.console.imports.grants({ id }).proof.check.post());
|
||||
done();
|
||||
return "Proven: the code is in their tagline. They can take it out now.";
|
||||
}
|
||||
const { code } = unwrap(await api.console.imports.grants({ id }).proof.post());
|
||||
done();
|
||||
return `Send them this code to put in their IMVU tagline: ${code}`;
|
||||
});
|
||||
}
|
||||
|
||||
/** Changes what a recorded grant covers, or withdraws it. */
|
||||
export async function changeRecorded(_: ActionState, form: FormData): Promise<ActionState> {
|
||||
const id = field(form, "id");
|
||||
return attempt(async () => {
|
||||
if (field(form, "intent") === "withdraw") {
|
||||
const reason = field(form, "reason") || "Withdrawn at the creator's request.";
|
||||
const r = unwrap(await api.imports.grants({ id }).delete({ reason }));
|
||||
done();
|
||||
return r.withdrawn.length ? `Withdrawn. ${r.withdrawn.length} imported products were taken away.` : "Withdrawn.";
|
||||
}
|
||||
const scope = field(form, "scope") === "products" ? "products" : "shop";
|
||||
const list = productIDs(field(form, "list"));
|
||||
if (!list) throw new ApiError(400, "invalid", "Products are IMVU product IDs or shop links.");
|
||||
const r = unwrap(
|
||||
await api.imports.grants({ id }).patch({
|
||||
...(scope === "products" ? { products: list } : { exclude: list }),
|
||||
listed: form.get("listed") === "on",
|
||||
}),
|
||||
);
|
||||
done();
|
||||
return r.withdrawn.length
|
||||
? `Saved. ${r.withdrawn.length} imported products it no longer covers were taken away.`
|
||||
: "Saved.";
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,291 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
import { ActionForm, SubmitButton } from "@/components/forms";
|
||||
import { PageHeader, Tag } from "@/components/status";
|
||||
import { DateTime } from "@/components/time";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { api, unwrap } from "@/lib/api";
|
||||
import { ConsoleNav, requireConsole } from "../console-nav";
|
||||
import { changeRecorded, grantProof, recordGrant } from "./actions";
|
||||
|
||||
export const metadata: Metadata = { title: "Imports" };
|
||||
|
||||
type Recorded = Awaited<ReturnType<typeof load>>["grants"][number];
|
||||
const load = async () => unwrap(await api.console.imports.get());
|
||||
|
||||
const statusTone = {
|
||||
pending: "strong",
|
||||
active: "online",
|
||||
declined: "neutral",
|
||||
suspended: "danger",
|
||||
withdrawn: "neutral",
|
||||
} as const;
|
||||
const imvuShop = (id: number) => `https://www.imvu.com/shop/web_search.php?manufacturers_id=${id}`;
|
||||
|
||||
export default async function ConsoleImports() {
|
||||
const { console: c } = await requireConsole("/console/imports");
|
||||
if (!c.sections.includes("imports")) notFound();
|
||||
const data = await load();
|
||||
const open = data.grants.filter((g) => g.status !== "withdrawn" && g.status !== "declined");
|
||||
const ended = data.grants.filter((g) => g.status === "withdrawn" || g.status === "declined");
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader title="Imports">
|
||||
Consent recorded for IMVU creators who won't make an account, and the creators people ask for most.
|
||||
</PageHeader>
|
||||
<ConsoleNav />
|
||||
<div className="space-y-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Record a Creator's Consent</CardTitle>
|
||||
<CardDescription>
|
||||
For creators who agreed to have their IMVU products on T5DE but won't make an account. Their products
|
||||
belong to a placeholder until they join and link that IMVU account, when they can claim them. The
|
||||
catalog's team still accepts it.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{data.catalogs.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">No catalog takes imports yet.</p>
|
||||
) : (
|
||||
<ActionForm action={recordGrant} className="max-w-2xl space-y-4">
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<Field>
|
||||
<FieldLabel htmlFor="imvu">IMVU creator</FieldLabel>
|
||||
<Input id="imvu" name="imvu" required maxLength={64} placeholder="Username or account ID" />
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel htmlFor="catalog">Catalog</FieldLabel>
|
||||
<NativeSelect id="catalog" name="catalog">
|
||||
{data.catalogs.map((k) => (
|
||||
<NativeSelectOption key={k.id} value={k.id}>
|
||||
{k.name}
|
||||
</NativeSelectOption>
|
||||
))}
|
||||
</NativeSelect>
|
||||
</Field>
|
||||
</div>
|
||||
<fieldset className="space-y-2">
|
||||
<legend className="mb-2 text-sm font-medium">What they agreed to</legend>
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
<input type="radio" name="scope" value="shop" defaultChecked />
|
||||
Their whole shop, including new products (leave some out below)
|
||||
</label>
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
<input type="radio" name="scope" value="products" />
|
||||
Only the products listed below
|
||||
</label>
|
||||
</fieldset>
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<Field>
|
||||
<FieldLabel htmlFor="exclude">Leave out (whole shop)</FieldLabel>
|
||||
<Textarea
|
||||
id="exclude"
|
||||
name="exclude"
|
||||
rows={2}
|
||||
placeholder="IMVU product IDs or shop links"
|
||||
className="font-mono text-xs"
|
||||
/>
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel htmlFor="products">Products (only these)</FieldLabel>
|
||||
<Textarea
|
||||
id="products"
|
||||
name="products"
|
||||
rows={2}
|
||||
placeholder="IMVU product IDs or shop links"
|
||||
className="font-mono text-xs"
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
<input type="checkbox" name="listed" defaultChecked />
|
||||
Listed (shown in search; unlisted ones work by link)
|
||||
</label>
|
||||
<Field>
|
||||
<FieldLabel htmlFor="evidence">How they agreed</FieldLabel>
|
||||
<Textarea
|
||||
id="evidence"
|
||||
name="evidence"
|
||||
rows={2}
|
||||
required
|
||||
maxLength={1000}
|
||||
placeholder="Where and when, e.g. Discord DM, 2026-11-07"
|
||||
/>
|
||||
<FieldDescription>
|
||||
They agreed to: “{data.consent.text}” You can prove it afterwards with a code in their
|
||||
IMVU tagline.
|
||||
</FieldDescription>
|
||||
</Field>
|
||||
<SubmitButton pendingLabel="Recording…">Record</SubmitButton>
|
||||
</ActionForm>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{open.length > 0 && (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Recorded Grants</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="divide-y">
|
||||
{open.map((g) => (
|
||||
<RecordedRow key={g.id} grant={g} />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Most Asked For</CardTitle>
|
||||
<CardDescription>
|
||||
IMVU creators whose products T5DE users ask for: whom it's worth asking.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{data.creators.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">Nobody has asked for anything yet.</p>
|
||||
) : (
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>IMVU creator</TableHead>
|
||||
<TableHead className="text-right">People</TableHead>
|
||||
<TableHead className="text-right">Products</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{data.creators.map((k) => (
|
||||
<TableRow key={k.imvuCreator}>
|
||||
<TableCell>
|
||||
<a
|
||||
href={imvuShop(k.imvuCreator)}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="underline-offset-4 hover:underline"
|
||||
>
|
||||
{k.name || `IMVU account ${k.imvuCreator}`}
|
||||
</a>
|
||||
</TableCell>
|
||||
<TableCell className="text-right tabular-nums">{k.people}</TableCell>
|
||||
<TableCell className="text-right tabular-nums">{k.products}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{ended.length > 0 && (
|
||||
<details className="text-sm">
|
||||
<summary className="cursor-pointer text-muted-foreground hover:text-foreground">Ended</summary>
|
||||
<ul className="mt-2 divide-y">
|
||||
{ended.map((g) => (
|
||||
<li key={g.id} className="py-2">
|
||||
{g.imvuName || g.imvuId} → {g.catalogName} <Tag tone={statusTone[g.status]}>{g.status}</Tag>{" "}
|
||||
<span className="text-muted-foreground">{g.statusReason}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</details>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function RecordedRow({ grant: g }: { grant: Recorded }) {
|
||||
const list = g.scope === "products" ? g.products : g.exclude;
|
||||
return (
|
||||
<div className="space-y-3 py-4 first:pt-0 last:pb-0">
|
||||
<div className="flex flex-wrap items-center gap-2 text-sm">
|
||||
<span className="font-medium">{g.imvuName || `IMVU account ${g.imvuId}`}</span>
|
||||
<span className="text-muted-foreground">(IMVU {g.imvuId}) to</span>
|
||||
<span className="font-medium">{g.catalogName}</span>
|
||||
<Tag tone={statusTone[g.status]}>{g.status === "pending" ? "waiting for the catalog" : g.status}</Tag>
|
||||
{g.consentProven ? <Tag tone="online">proven</Tag> : <Tag>not proven</Tag>}
|
||||
{g.claimed && <Tag tone="strong">claimed</Tag>}
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{g.evidence} · recorded by {g.recordedBy || "someone"} on <DateTime iso={g.createdAt} dateOnly />
|
||||
</p>
|
||||
<p className="text-sm">
|
||||
{g.scope === "shop"
|
||||
? `The whole shop${g.exclude.length ? `, less ${g.exclude.length} left out` : ""}.`
|
||||
: `${g.products.length} chosen product${g.products.length === 1 ? "" : "s"}.`}{" "}
|
||||
{g.listed ? "Listed." : "Unlisted."}
|
||||
</p>
|
||||
{g.claimed ? (
|
||||
<p className="text-sm text-muted-foreground">The creator claimed it: they manage it now.</p>
|
||||
) : (
|
||||
<>
|
||||
{!g.consentProven && (
|
||||
<ActionForm action={grantProof} fields={{ id: g.id }}>
|
||||
<div className="flex flex-wrap items-center gap-2 text-sm">
|
||||
{g.proofCode ? (
|
||||
<>
|
||||
<span>
|
||||
Code for their tagline: <code className="font-mono">{g.proofCode}</code>
|
||||
</span>
|
||||
<SubmitButton name="intent" value="check" size="sm" variant="outline" pendingLabel="Checking…">
|
||||
Check their tagline
|
||||
</SubmitButton>
|
||||
</>
|
||||
) : (
|
||||
<SubmitButton name="intent" value="code" size="sm" variant="outline" pendingLabel="Making one…">
|
||||
Prove it with a tagline code
|
||||
</SubmitButton>
|
||||
)}
|
||||
</div>
|
||||
</ActionForm>
|
||||
)}
|
||||
<ActionForm action={changeRecorded} fields={{ id: g.id, scope: g.scope }} className="max-w-2xl space-y-2">
|
||||
<Field>
|
||||
<FieldLabel htmlFor={`list-${g.id}`}>{g.scope === "shop" ? "Left out" : "Products"}</FieldLabel>
|
||||
<Textarea
|
||||
id={`list-${g.id}`}
|
||||
name="list"
|
||||
rows={2}
|
||||
defaultValue={list.join("\n")}
|
||||
className="font-mono text-xs"
|
||||
/>
|
||||
</Field>
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
<input type="checkbox" name="listed" defaultChecked={g.listed} />
|
||||
Listed
|
||||
</label>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Input
|
||||
name="reason"
|
||||
maxLength={500}
|
||||
placeholder="Reason (if withdrawing)"
|
||||
aria-label="Reason"
|
||||
className="max-w-xs"
|
||||
/>
|
||||
<SubmitButton name="intent" value="save" variant="outline" pendingLabel="Saving…">
|
||||
Save
|
||||
</SubmitButton>
|
||||
<SubmitButton
|
||||
name="intent"
|
||||
value="withdraw"
|
||||
variant="outline"
|
||||
pendingLabel="Withdrawing…"
|
||||
confirm="Withdraw? Its imported products are taken away from everyone who has them."
|
||||
>
|
||||
Withdraw
|
||||
</SubmitButton>
|
||||
</div>
|
||||
</ActionForm>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -3,24 +3,13 @@
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { api, ApiError, unwrap } from "@/lib/api";
|
||||
import { attempt, field, type ActionState } from "@/lib/actions";
|
||||
import { productIDs } from "@/lib/imvu";
|
||||
|
||||
const done = () => {
|
||||
revalidatePath("/imports");
|
||||
revalidatePath("/library");
|
||||
};
|
||||
|
||||
/** IMVU product IDs in what someone typed or pasted: numbers, or shop links (`products_id=123`, `product-123`). */
|
||||
function productIDs(text: string): number[] | undefined {
|
||||
const out = new Set<number>();
|
||||
for (const part of text.split(/[\s,]+/).filter(Boolean)) {
|
||||
const m = part.match(/(?:products_id=|product-)(\d+)/) ?? part.match(/^(\d+)$/);
|
||||
const n = m ? Number(m[1]) : NaN;
|
||||
if (!Number.isSafeInteger(n) || n <= 0) return undefined;
|
||||
out.add(n);
|
||||
}
|
||||
return [...out];
|
||||
}
|
||||
|
||||
const answers = {
|
||||
added: "It's in your library.",
|
||||
queued: "Its creator lets T5DE have it: it'll be in your library once the catalog imports it.",
|
||||
|
||||
Reference in new issue
Block a user