1
0
Fork 0
polaris-task-force/src/components/frontend/awards/RibbonStudio.tsx
Z8MB1E 9c3870cf79 fix(mobile): meet the 24px tap-target floor across the app
Session A measured 159 targets under the WCAG 2.5.8 minimum on 42 routes;
this brings that to zero. Mostly one-line spacing changes: small caption
labels and text links were 14-21px tall because shadcn Label/Button use
leading-none and bare text links carry no vertical padding.

- shared Dialog close button: p-1 with right-3/top-3 so the 24px hit box
  keeps the icon where it was
- tour card: Skip all tours (13 routes), All boards on standings cards (6)
- detail pages: 27 Back links, journals All journals, wiki category
  links, voiceover card titles, factions batch link
- dashboard: 7 View all / View full record links
- account preferences: mute rows min-h-6, radio and tours labels, plus
  contacts filter labels and the campaigns show-completed label
- ribbon studio: mirror label and stripe/module remove buttons
- helpdesk ticket titles, radio tick-sound label
2026-10-12 22:17:51 -04:00

144 lines
5.5 KiB
TypeScript

"use client";
import { useState, type FormEvent } from "react";
import { useRouter } from "next/navigation";
import { toast } from "sonner";
import { submitRibbonDesign } from "@/app/(frontend)/awards/design/actions";
import { DEFAULT_RIBBON } from "@/components/awards/ribbonDesign/constants";
import { DeviceEditor, RibbonPreview, StripeEditor } from "@/components/awards/ribbonDesign/parts";
import type { RibbonDesign } from "@/components/awards/ribbonDesign/types";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Checkbox } from "@/components/ui/checkbox";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea";
import { validateRibbonDesign } from "@/lib/awards/ribbonValidation";
export function RibbonStudio() {
const router = useRouter();
const [design, setDesign] = useState<RibbonDesign>(DEFAULT_RIBBON);
const [name, setName] = useState("");
const [description, setDescription] = useState("");
const [submitting, setSubmitting] = useState(false);
const validation = validateRibbonDesign(design);
const submitDisabled =
submitting || !validation.ok || name.trim().length === 0 || description.trim().length === 0;
async function handleSubmit(event: FormEvent<HTMLFormElement>) {
event.preventDefault();
if (!validation.ok) {
toast.error(validation.error);
return;
}
setSubmitting(true);
try {
const result = await submitRibbonDesign({ name, description, design });
if (!result.success) {
toast.error(result.error ?? "Could not submit this ribbon.");
return;
}
toast.success("Ribbon submitted for review");
setDesign(DEFAULT_RIBBON);
setName("");
setDescription("");
router.refresh();
} catch (error) {
toast.error(error instanceof Error ? error.message : "Could not submit this ribbon.");
} finally {
setSubmitting(false);
}
}
return (
<Card>
<CardHeader className="gap-1">
<CardTitle>Design your ribbon</CardTitle>
<CardDescription>
Build the stripe pattern, place devices, and send the finished design to the award team.
</CardDescription>
</CardHeader>
<CardContent>
<form className="flex flex-col gap-6" onSubmit={handleSubmit}>
<div className="grid min-w-0 gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(16rem,0.75fr)]">
<div className="flex min-w-0 flex-col gap-4">
<div className="flex flex-col gap-1.5">
<Label htmlFor="ribbon-name">Name</Label>
<Input
id="ribbon-name"
value={name}
maxLength={60}
onChange={(event) => setName(event.target.value)}
placeholder="For example, Operation Northern Star"
/>
<p className="text-right text-xs text-muted-foreground">{name.length}/60</p>
</div>
<div className="flex flex-col gap-1.5">
<Label htmlFor="ribbon-description">Description</Label>
<Textarea
id="ribbon-description"
value={description}
maxLength={300}
rows={5}
onChange={(event) => setDescription(event.target.value)}
placeholder="What should this ribbon recognize?"
/>
<p className="text-right text-xs text-muted-foreground">{description.length}/300</p>
</div>
<div className="flex items-start gap-3 rounded-md border border-border p-3">
<Checkbox
id="ribbon-mirrored"
checked={design.mirrored}
onCheckedChange={(checked) =>
setDesign((current) => ({ ...current, mirrored: checked === true }))
}
/>
<div className="flex flex-col gap-1">
<Label htmlFor="ribbon-mirrored" className="py-1.5">
Mirror stripe pattern
</Label>
<p className="text-xs text-muted-foreground">
Reflect the pattern across the center for a balanced ribbon.
</p>
</div>
</div>
</div>
<div className="flex min-w-0 flex-col gap-5">
<div className="flex flex-col gap-2">
<Label>Preview</Label>
<RibbonPreview design={design} />
</div>
<StripeEditor
stripes={design.stripes}
onChange={(stripes) => setDesign((current) => ({ ...current, stripes }))}
/>
<DeviceEditor
devices={design.devices}
onChange={(devices) => setDesign((current) => ({ ...current, devices }))}
/>
</div>
</div>
{!validation.ok && <p className="text-sm text-destructive">{validation.error}</p>}
<div className="flex flex-wrap items-center justify-between gap-3">
<p className="text-xs text-muted-foreground">
Submissions are reviewed before they can be awarded.
</p>
<Button type="submit" disabled={submitDisabled}>
{submitting ? "Submitting..." : "Submit for review"}
</Button>
</div>
</form>
</CardContent>
</Card>
);
}