Settings pages
The pages behind the gear icon: a profile form with a save bar, notification switches, plan and billing, and the team with roles and invites. Real labels, fieldsets and checks throughout.
4 blocks below, each one file and one command. They wear whichever DressCode theme you install, in light and dark.
Profile form
Photo from initials, name, email, business name, time zone and a short bio, checked as you go, with a save bar that appears only when something changed.
npx shadcn@latest add https://dresscodeui.com/r/dresscode/settings-profile.json"use client"
// Settings, profile: the photo (initials until one is chosen), name, email, business name, time zone and a
// short bio. Each field is checked when it loses focus and again on save; errors sit under the field and
// are tied to it. The save bar only appears once something differs from what was saved, with a way to
// discard. Wire onSubmit to your own endpoint (and the photo to your upload); nothing is sent here.
import { Check, CircleAlert, Upload } from "lucide-react"
import { type ChangeEvent, type FormEvent, type ReactNode, useId, useRef, useState } from "react"
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { Textarea } from "@/components/ui/textarea"
import { cn } from "@/lib/utils"
const KEYFRAMES = `@keyframes dc-save-bar-in { from { opacity: 0; transform: translateY(8px) } }`
const TIMEZONES = [
{ value: "America/Los_Angeles", label: "Pacific Time, Los Angeles (GMT−8)" },
{ value: "America/Denver", label: "Mountain Time, Denver (GMT−7)" },
{ value: "America/Chicago", label: "Central Time, Chicago (GMT−6)" },
{ value: "America/New_York", label: "Eastern Time, New York (GMT−5)" },
{ value: "Europe/London", label: "London (GMT+0)" },
{ value: "Europe/Berlin", label: "Berlin (GMT+1)" },
{ value: "Asia/Tokyo", label: "Tokyo (GMT+9)" },
{ value: "Australia/Sydney", label: "Sydney (GMT+11)" },
]
const BIO_MAX = 160
type Values = { name: string; email: string; business: string; timezone: string; bio: string }
type Field = keyof Values
const INITIAL: Values = {
name: "Ada Ruiz",
email: "ada@ruizstudio.co",
business: "Ruiz Studio",
timezone: "America/Los_Angeles",
bio: "Brand and web designer in Portland, working with small food and hospitality businesses.",
}
const ORDER: Field[] = ["name", "email", "business", "timezone", "bio"]
function check(field: Field, v: string): string {
const t = v.trim()
if (field === "name") return !t ? "Enter your name." : t.length > 60 ? "Keep your name under 60 characters." : ""
if (field === "email") return !t ? "Enter your email address." : /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t) ? "" : "That doesn't look like an email address."
if (field === "business") return !t ? "Enter the business name clients see on invoices." : ""
if (field === "bio") return v.length > BIO_MAX ? `Keep it to ${BIO_MAX} characters. You are ${v.length - BIO_MAX} over.` : ""
return ""
}
const initialsOf = (name: string) =>
name
.trim()
.split(/\s+/)
.filter(Boolean)
.map((w) => w[0])
.filter((_, i, all) => i === 0 || i === all.length - 1)
.join("")
.toUpperCase() || "?"
function Row({ label, htmlFor, labelId, hint, hintId, children }: { label: string; htmlFor?: string; labelId?: string; hint?: ReactNode; hintId?: string; children: ReactNode }) {
return (
<div className="grid gap-x-8 gap-y-2.5 px-5 py-5 sm:grid-cols-[200px_minmax(0,1fr)] sm:px-6">
<div className="sm:pt-[9px]">
{htmlFor ? (
<Label htmlFor={htmlFor} className="text-[14px]">
{label}
</Label>
) : (
<p id={labelId} className="text-[14px] leading-none font-medium">
{label}
</p>
)}
{hint ? (
<p id={hintId} className="mt-1.5 text-[13px] leading-snug text-muted-foreground">
{hint}
</p>
) : null}
</div>
<div className="min-w-0">{children}</div>
</div>
)
}
function ErrorText({ id, children }: { id: string; children: string }) {
return children ? (
<p id={id} className="mt-1.5 flex items-start gap-1.5 text-[13px] text-destructive">
<CircleAlert className="mt-px size-3.5 shrink-0" aria-hidden="true" />
{children}
</p>
) : null
}
export default function SettingsProfile() {
const id = useId()
const fid = (f: Field | "photo" | "file") => `${id}-${f}`
const fileRef = useRef<HTMLInputElement>(null)
const [saved, setSaved] = useState<Values>(INITIAL)
const [values, setValues] = useState<Values>(INITIAL)
const [photo, setPhoto] = useState<string | null>(null)
const [savedPhoto, setSavedPhoto] = useState<string | null>(null)
const [errors, setErrors] = useState<Partial<Record<Field, string>>>({})
const [announce, setAnnounce] = useState("")
const [justSaved, setJustSaved] = useState(false)
const dirty = ORDER.some((f) => values[f] !== saved[f]) || photo !== savedPhoto
const errorCount = Object.values(errors).filter(Boolean).length
const set = (f: Field, v: string) => {
setValues((all) => ({ ...all, [f]: v }))
setJustSaved(false)
// Clear an error as soon as the field is fixed; new errors wait for blur or save.
if (errors[f] && !check(f, v)) setErrors((all) => ({ ...all, [f]: "" }))
if (f === "bio" && v.length > BIO_MAX) setErrors((all) => ({ ...all, bio: check("bio", v) }))
}
const blur = (f: Field) => setErrors((all) => ({ ...all, [f]: check(f, values[f]) }))
const describedBy = (f: Field, ...extra: string[]) => [...extra, errors[f] ? `${fid(f)}-error` : ""].filter(Boolean).join(" ") || undefined
const pickPhoto = (e: ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0]
e.target.value = ""
if (!file) return
if (photo && photo !== savedPhoto) URL.revokeObjectURL(photo)
setPhoto(URL.createObjectURL(file))
setJustSaved(false)
}
const removePhoto = () => {
if (photo && photo !== savedPhoto) URL.revokeObjectURL(photo)
setPhoto(null)
setJustSaved(false)
}
const discard = () => {
if (photo && photo !== savedPhoto) URL.revokeObjectURL(photo)
setValues(saved)
setPhoto(savedPhoto)
setErrors({})
setAnnounce("Changes discarded.")
}
const onSubmit = (e: FormEvent) => {
e.preventDefault()
const next = Object.fromEntries(ORDER.map((f) => [f, check(f, values[f])])) as Record<Field, string>
setErrors(next)
const bad = ORDER.filter((f) => next[f])
if (bad.length) {
setAnnounce(`${bad.length} ${bad.length === 1 ? "field needs" : "fields need"} a fix before saving.`)
document.getElementById(fid(bad[0]))?.focus()
return
}
// Send `values` (and the photo) to your API here.
if (savedPhoto && savedPhoto !== photo) URL.revokeObjectURL(savedPhoto)
const clean = { ...values, name: values.name.trim(), email: values.email.trim(), business: values.business.trim() }
setValues(clean)
setSaved(clean)
setSavedPhoto(photo)
setJustSaved(true)
setAnnounce("Profile saved.")
}
const emailChanged = values.email.trim() !== saved.email && !check("email", values.email)
const bioLeft = BIO_MAX - values.bio.length
return (
<section aria-labelledby={`${id}-title`} className="mx-auto w-full max-w-[880px] px-5 py-10 sm:px-8">
<style href="dc-save-bar" precedence="default">
{KEYFRAMES}
</style>
<h2 id={`${id}-title`} className="dc-h text-[24px] leading-tight sm:text-[28px]">
Profile
</h2>
<p className="mt-1.5 text-[15px] text-muted-foreground">How you show up on invoices, in reminders and to your team.</p>
<form noValidate onSubmit={onSubmit} className="mt-6">
<div className="dc-card divide-y divide-border">
<Row label="Photo" labelId={fid("photo")} hint="On invoices and reminders. A square image, at least 256 px." hintId={`${fid("photo")}-hint`}>
<div role="group" aria-labelledby={fid("photo")} aria-describedby={`${fid("photo")}-hint`} className="flex flex-wrap items-center gap-4">
<Avatar className="size-16 after:hidden" aria-hidden="true">
{photo ? <AvatarImage src={photo} alt="" /> : null}
<AvatarFallback className="bg-[color:var(--dc-highlight)] text-[20px] font-bold text-[color:var(--dc-highlight-fg)]">{initialsOf(values.name)}</AvatarFallback>
</Avatar>
<span className="sr-only">{photo ? "A new photo is chosen." : `No photo; your initials, ${initialsOf(values.name)}, show instead.`}</span>
<div className="flex flex-wrap gap-2">
<Button type="button" variant="outline" onClick={() => fileRef.current?.click()}>
<Upload aria-hidden="true" /> {photo ? "Change photo" : "Upload photo"}
</Button>
<Button type="button" variant="ghost" className="dc-flat text-muted-foreground" onClick={removePhoto} disabled={!photo}>
Remove
</Button>
</div>
<input ref={fileRef} id={fid("file")} type="file" accept="image/png,image/jpeg,image/webp" hidden onChange={pickPhoto} />
</div>
</Row>
<Row label="Full name" htmlFor={fid("name")}>
<Input
id={fid("name")}
autoComplete="name"
value={values.name}
onChange={(e) => set("name", e.target.value)}
onBlur={() => blur("name")}
aria-invalid={errors.name ? true : undefined}
aria-describedby={describedBy("name")}
className="h-9"
/>
<ErrorText id={`${fid("name")}-error`}>{errors.name ?? ""}</ErrorText>
</Row>
<Row label="Email" htmlFor={fid("email")} hint="Where reminders, receipts and sign-in links go." hintId={`${fid("email")}-hint`}>
<Input
id={fid("email")}
type="email"
autoComplete="email"
value={values.email}
onChange={(e) => set("email", e.target.value)}
onBlur={() => blur("email")}
aria-invalid={errors.email ? true : undefined}
aria-describedby={describedBy("email", `${fid("email")}-hint`, emailChanged ? `${fid("email")}-note` : "")}
className="h-9"
/>
<ErrorText id={`${fid("email")}-error`}>{errors.email ?? ""}</ErrorText>
{emailChanged && !errors.email ? (
<p id={`${fid("email")}-note`} className="mt-1.5 text-[13px] text-muted-foreground">
We will send a link to confirm the new address. Until then, mail goes to {saved.email}.
</p>
) : null}
</Row>
<Row label="Business name" htmlFor={fid("business")} hint="Printed at the top of every invoice." hintId={`${fid("business")}-hint`}>
<Input
id={fid("business")}
autoComplete="organization"
value={values.business}
onChange={(e) => set("business", e.target.value)}
onBlur={() => blur("business")}
aria-invalid={errors.business ? true : undefined}
aria-describedby={describedBy("business", `${fid("business")}-hint`)}
className="h-9"
/>
<ErrorText id={`${fid("business")}-error`}>{errors.business ?? ""}</ErrorText>
</Row>
<Row label="Time zone" htmlFor={fid("timezone")} hint="Reminders go out at 9:00 in this zone." hintId={`${fid("timezone")}-hint`}>
<Select items={TIMEZONES} value={values.timezone} onValueChange={(v) => v != null && set("timezone", String(v))}>
<SelectTrigger id={fid("timezone")} aria-describedby={`${fid("timezone")}-hint`} className="w-full bg-[color:var(--card)] data-[size=default]:h-9">
<SelectValue />
</SelectTrigger>
<SelectContent>
{TIMEZONES.map((tz) => (
<SelectItem key={tz.value} value={tz.value}>
{tz.label}
</SelectItem>
))}
</SelectContent>
</Select>
</Row>
<Row label="Bio" htmlFor={fid("bio")} hint="A line or two for the footer of your invoices and your client portal." hintId={`${fid("bio")}-hint`}>
<Textarea
id={fid("bio")}
rows={3}
value={values.bio}
onChange={(e) => set("bio", e.target.value)}
onBlur={() => blur("bio")}
aria-invalid={errors.bio ? true : undefined}
aria-describedby={describedBy("bio", `${fid("bio")}-hint`, `${fid("bio")}-count`)}
className="min-h-[88px] resize-none"
/>
<div className="mt-1.5 flex items-start justify-between gap-3">
<ErrorText id={`${fid("bio")}-error`}>{errors.bio ?? ""}</ErrorText>
<p id={`${fid("bio")}-count`} className={cn("dc-num ml-auto shrink-0 text-[12px] text-muted-foreground", bioLeft < 0 && "font-semibold text-destructive")}>
{values.bio.length} / {BIO_MAX}
<span className="sr-only"> characters</span>
</p>
</div>
<p className="sr-only" aria-live="polite">
{bioLeft <= 20 && bioLeft >= 0 ? `${bioLeft} characters left.` : ""}
</p>
</Row>
</div>
<p className="sr-only" role="status">
{announce}
</p>
{dirty ? (
<div className="sticky bottom-4 z-10 mt-4">
<div className="dc-card flex animate-[dc-save-bar-in_200ms_ease-out] flex-wrap items-center gap-x-4 gap-y-3 px-4 py-3 motion-reduce:animate-none sm:px-5">
<p className="flex min-w-0 items-center gap-2 text-[14px] font-medium">
{errorCount ? (
<>
<CircleAlert className="size-4 shrink-0 text-destructive" aria-hidden="true" />
{errorCount === 1 ? "1 field needs a fix" : `${errorCount} fields need a fix`}
</>
) : (
<>
<span className="size-2 shrink-0 rounded-full bg-[color:var(--dc-accent)]" aria-hidden="true" />
Unsaved changes
</>
)}
</p>
<div className="ml-auto flex gap-2">
<Button type="button" variant="ghost" className="dc-flat" onClick={discard}>
Discard
</Button>
<Button type="submit" className="font-semibold">
Save changes
</Button>
</div>
</div>
</div>
) : justSaved ? (
<p className="mt-4 flex animate-[dc-save-bar-in_200ms_ease-out] items-center gap-2 px-1 text-[14px] text-muted-foreground motion-reduce:animate-none">
<span className="grid size-6 place-items-center rounded-full bg-[color:var(--dc-highlight)] text-[color:var(--dc-highlight-fg)]">
<Check className="size-3.5" aria-hidden="true" />
</span>
Saved. New invoices use these details.
</p>
) : null}
</form>
</section>
)
}Notifications
Email and push switches for each event, in groups for invoices, payments, clients and product news, with a pause-all control and a reset to the defaults.
npx shadcn@latest add https://dresscodeui.com/r/dresscode/settings-notifications.json"use client"
// Settings, notifications: what Orbit tells you about and where, as email and push switches per event,
// in four groups (each a fieldset with its legend). Pause everything for an hour, until the morning or a
// week; failed payments still reach you by email. Changes save as you go (the status line says so) and
// "Reset to defaults" puts the starting choices back. Wire `save` to your own endpoint.
import { BellOff, BellRing, Check, Mail, Minus, RotateCcw, Smartphone } from "lucide-react"
import { useId, useState } from "react"
import { Button } from "@/components/ui/button"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { Switch } from "@/components/ui/switch"
import { cn } from "@/lib/utils"
type Channel = "email" | "push"
type Event = {
id: string
label: string
body: string
email: boolean
/** null: this event has no push notification. */
push: boolean | null
/** Email can't be turned off for this one. */
lockedEmail?: boolean
}
const GROUPS: { id: string; title: string; body: string; events: Event[] }[] = [
{
id: "invoices",
title: "Invoices",
body: "What happens to the invoices you send.",
events: [
{ id: "viewed", label: "Invoice viewed", body: "The first time a client opens an invoice.", email: false, push: true },
{ id: "overdue", label: "Invoice overdue", body: "The morning after the due date passes.", email: true, push: true },
{ id: "reminder", label: "Reminder sent", body: "Each time Orbit sends a reminder for you.", email: false, push: false },
],
},
{
id: "payments",
title: "Payments",
body: "Money coming in and going out to your bank.",
events: [
{ id: "received", label: "Payment received", body: "By card, bank transfer or a payment you record.", email: true, push: true },
{ id: "failed", label: "Payment failed", body: "A card is declined or a transfer bounces. Email is always on.", email: true, push: true, lockedEmail: true },
{ id: "payout", label: "Payout sent", body: "When money leaves for your bank account.", email: true, push: false },
],
},
{
id: "clients",
title: "Clients",
body: "Replies and changes from the people you bill.",
events: [
{ id: "replied", label: "Client replied", body: "An answer to an invoice or a reminder.", email: true, push: true },
{ id: "details", label: "Billing details changed", body: "A client updates their billing email or address.", email: true, push: false },
{ id: "added", label: "Client added by a teammate", body: "Someone on your team adds a new client.", email: false, push: false },
],
},
{
id: "news",
title: "Product news",
body: "From the Orbit team, by email only.",
events: [
{ id: "features", label: "New features", body: "A short note when something ships, about once a month.", email: true, push: null },
{ id: "tips", label: "Tips for getting paid faster", body: "A few ideas a quarter, from studios like yours.", email: false, push: null },
],
},
]
type Prefs = Record<string, { email: boolean; push: boolean | null }>
const DEFAULTS: Prefs = Object.fromEntries(GROUPS.flatMap((g) => g.events.map((e) => [e.id, { email: e.email, push: e.push }])))
const PAUSES = [
{ value: "hour", label: "For 1 hour", until: "until 10:41" },
{ value: "morning", label: "Until tomorrow", until: "until tomorrow at 9:00" },
{ value: "week", label: "For a week", until: "until Tuesday, Dec 1" },
]
const cols = "grid grid-cols-[minmax(0,1fr)_52px_52px] items-center gap-x-2 sm:grid-cols-[minmax(0,1fr)_72px_72px] sm:gap-x-3"
export default function SettingsNotifications() {
const id = useId()
const [prefs, setPrefs] = useState<Prefs>(DEFAULTS)
const [pauseFor, setPauseFor] = useState("morning")
const [paused, setPaused] = useState<string | null>(null)
const [status, setStatus] = useState("Changes save as you go.")
// Send the change to your API here; the status line confirms it.
const save = (next: Prefs, message: string) => {
setPrefs(next)
setStatus(message)
}
const toggle = (e: Event, channel: Channel, on: boolean) =>
save({ ...prefs, [e.id]: { ...prefs[e.id], [channel]: on } }, `Saved: ${e.label.toLowerCase()} by ${channel} ${on ? "on" : "off"}.`)
const isDefault = Object.keys(DEFAULTS).every((k) => prefs[k].email === DEFAULTS[k].email && prefs[k].push === DEFAULTS[k].push)
const pause = PAUSES.find((p) => p.value === (paused ?? pauseFor))!
return (
<section aria-labelledby={`${id}-title`} className="mx-auto w-full max-w-[880px] px-5 py-10 sm:px-8">
<div className="flex flex-col gap-2 sm:flex-row sm:items-end sm:justify-between">
<div>
<h2 id={`${id}-title`} className="dc-h text-[24px] leading-tight sm:text-[28px]">
Notifications
</h2>
<p className="mt-1.5 text-[15px] text-muted-foreground">Choose what Orbit tells you about, and where.</p>
</div>
<p role="status" className="flex items-center gap-1.5 text-[13px] text-muted-foreground">
{status.startsWith("Changes") ? null : <Check className="size-3.5 text-[color:var(--dc-accent)]" aria-hidden="true" />}
{status.startsWith("Saved") ? "All changes saved" : status}
<span className="sr-only">{status.startsWith("Saved") ? status : ""}</span>
</p>
</div>
<div
className={cn(
"dc-card mt-6 flex flex-col gap-4 p-5 sm:flex-row sm:items-center sm:px-6",
paused && "bg-[color:color-mix(in_oklab,var(--dc-accent)_7%,var(--card))]",
)}
>
<div className="flex min-w-0 flex-1 items-start gap-4">
<span className="dc-icon shrink-0" aria-hidden="true">
{paused ? <BellOff className="size-[18px]" /> : <BellRing className="size-[18px]" />}
</span>
<div className="min-w-0">
<p id={`${id}-pause`} className="text-[15px] font-semibold">
{paused ? `Paused ${pause.until}` : "Pause all notifications"}
</p>
<p id={`${id}-pause-hint`} className="mt-0.5 text-[13px] text-pretty text-muted-foreground">
{paused
? "Nothing is sent until then, except failed payments by email. Your choices below stay as they are."
: "Take a break from every email and push. Failed payments still reach you by email."}
</p>
</div>
</div>
{paused ? (
<Button
variant="outline"
className="shrink-0 self-start sm:self-auto"
onClick={() => {
setPaused(null)
setStatus("Saved: notifications resumed.")
}}
>
Resume now
</Button>
) : (
<div className="flex shrink-0 flex-wrap gap-2" role="group" aria-labelledby={`${id}-pause`} aria-describedby={`${id}-pause-hint`}>
<Select items={PAUSES} value={pauseFor} onValueChange={(v) => v != null && setPauseFor(String(v))}>
<SelectTrigger aria-label="How long to pause" className="w-[150px] bg-[color:var(--card)]">
<SelectValue />
</SelectTrigger>
<SelectContent>
{PAUSES.map((p) => (
<SelectItem key={p.value} value={p.value}>
{p.label}
</SelectItem>
))}
</SelectContent>
</Select>
<Button
className="font-semibold"
onClick={() => {
setPaused(pauseFor)
setStatus(`Saved: notifications paused ${pause.until}.`)
}}
>
<BellOff aria-hidden="true" /> Pause all
</Button>
</div>
)}
</div>
<div className="dc-card mt-4 overflow-hidden">
{GROUPS.map((g) => (
<div key={g.id} className="relative border-t border-border px-5 pt-5 pb-2 first:border-t-0 sm:px-6">
<fieldset aria-describedby={`${id}-${g.id}-body`} className="min-w-0">
<legend className="pr-[120px] text-[15px] font-semibold sm:pr-[160px]">{g.title}</legend>
<p id={`${id}-${g.id}-body`} className="mt-0.5 pr-[120px] text-[13px] text-muted-foreground sm:pr-[160px]">
{g.body}
</p>
<ul className="mt-2 divide-y divide-border">
{g.events.map((e) => {
const p = prefs[e.id]
const labelId = `${id}-${e.id}`
return (
<li key={e.id} className={cn(cols, "py-3", paused && "[&>div:first-child]:opacity-70")}>
<div className="min-w-0">
<p id={labelId} className="text-[14px] font-medium">
{e.label}
</p>
<p id={`${labelId}-body`} className="mt-0.5 text-[13px] leading-snug text-muted-foreground">
{e.body}
</p>
</div>
<div className="flex justify-center">
<Switch
checked={p.email}
disabled={paused != null || e.lockedEmail}
onCheckedChange={(on) => toggle(e, "email", on)}
aria-label={`${e.label} by email`}
aria-describedby={`${labelId}-body`}
/>
</div>
<div className="flex justify-center">
{p.push === null ? (
<span className="grid size-[18px] place-items-center text-muted-foreground/60">
<Minus className="size-4" aria-hidden="true" />
<span className="sr-only">{e.label}: no push notification</span>
</span>
) : (
<Switch
checked={p.push}
disabled={paused != null}
onCheckedChange={(on) => toggle(e, "push", on)}
aria-label={`${e.label} by push`}
aria-describedby={`${labelId}-body`}
/>
)}
</div>
</li>
)
})}
</ul>
</fieldset>
<div aria-hidden="true" className={cn(cols, "absolute top-5 right-5 grid-cols-[52px_52px] text-[12px] font-medium text-muted-foreground sm:right-6 sm:grid-cols-[72px_72px]")}>
<span className="flex items-center justify-center gap-1">
<Mail className="hidden size-3.5 sm:block" /> Email
</span>
<span className="flex items-center justify-center gap-1">
<Smartphone className="hidden size-3.5 sm:block" /> Push
</span>
</div>
</div>
))}
<div className="flex flex-col gap-3 border-t border-border bg-[color:color-mix(in_oklab,var(--foreground)_3%,transparent)] px-5 py-4 sm:flex-row sm:items-center sm:justify-between sm:px-6">
<p className="text-[13px] text-muted-foreground">
Email goes to <span className="font-medium text-foreground">ada@ruizstudio.co</span>. Push goes to the Orbit app on your phone.
</p>
<Button
variant="ghost"
className="dc-flat -ml-2.5 shrink-0 self-start sm:-mr-2.5 sm:ml-0 sm:self-auto"
disabled={isDefault}
onClick={() => save(DEFAULTS, "Saved: back to the default choices.")}
>
<RotateCcw aria-hidden="true" /> Reset to defaults
</Button>
</div>
</div>
</section>
)
}Plan and billing
The current plan with its renewal date and a plan change dialog, usage meters, the card on file and a history of bills to download.
npx shadcn@latest add https://dresscodeui.com/r/dresscode/settings-billing.json"use client"
// Settings, plan and billing: the current plan with its renewal date and a dialog to change it (a plan
// that can't hold your team says so and can't be picked), what this month has used, the card on file,
// where bills go, and every bill with a link to its PDF. Card details never touch this page: "Update"
// should open your payment provider's own secure form. Wire the plan change to your billing API.
import { Check, CreditCard, Download, FileText, Hash, MapPin, ShieldCheck, TriangleAlert } from "lucide-react"
import { type FormEvent, useId, useState } from "react"
import { Button } from "@/components/ui/button"
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"
import { Progress, ProgressLabel } from "@/components/ui/progress"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
import { cn } from "@/lib/utils"
const MEMBERS = 4
const PLANS = [
{ id: "pro", name: "Pro", price: 12, seats: 1, note: "One person, unlimited invoices and reminders." },
{ id: "team", name: "Team", price: 39, seats: 5, note: "Up to 5 seats, roles and multi-currency." },
{ id: "studio", name: "Studio", price: 79, seats: 15, note: "Up to 15 seats, approvals and priority support." },
] as const
type PlanId = (typeof PLANS)[number]["id"]
const FEATURES: Record<PlanId, string[]> = {
pro: ["1 seat", "Unlimited invoices", "Reminders and late fees", "Your logo and colors"],
team: ["5 seats and roles", "Unlimited invoices", "Reminders and late fees", "Multi-currency"],
studio: ["15 seats and roles", "Approvals before sending", "Multi-currency", "Priority support"],
}
const usage = (seats: number) => [
{ label: "Seats", used: MEMBERS, of: seats, figure: `${MEMBERS} of ${seats}`, note: seats - MEMBERS === 1 ? "1 seat left" : `${seats - MEMBERS} seats left` },
{ label: "Text reminders", used: 38, of: 100, figure: "38 of 100", note: "Resets on Dec 1" },
{ label: "File storage", used: 1.2, of: 10, figure: "1.2 of 10 GB", note: "Receipts and attachments" },
]
const BILLS = [
// The upcoming bill follows the plan (see below).
{ number: "ORB-1240", date: "Dec 1, 2026", item: "Team plan, monthly", amount: "$39.00", status: "Upcoming" },
{ number: "ORB-1182", date: "Nov 1, 2026", item: "Team plan, monthly", amount: "$39.00", status: "Paid" },
{ number: "ORB-1094", date: "Oct 1, 2026", item: "Team plan, monthly", amount: "$39.00", status: "Paid" },
{ number: "ORB-1031", date: "Sep 14, 2026", item: "Upgrade to Team, rest of September", amount: "$17.40", status: "Paid" },
{ number: "ORB-0987", date: "Sep 1, 2026", item: "Pro plan, monthly", amount: "$12.00", status: "Paid" },
{ number: "ORB-0912", date: "Aug 1, 2026", item: "Pro plan, monthly", amount: "$12.00", status: "Paid" },
] as const
const money = (n: number) => `$${n.toFixed(2)}`
export default function SettingsBilling() {
const id = useId()
const [plan, setPlan] = useState<PlanId>("team")
const [next, setNext] = useState<PlanId | null>(null)
const [open, setOpen] = useState(false)
const [choice, setChoice] = useState<PlanId>("team")
const [announce, setAnnounce] = useState("")
const current = PLANS.find((p) => p.id === plan)!
const scheduled = next ? PLANS.find((p) => p.id === next)! : null
const picked = PLANS.find((p) => p.id === choice)!
const tooSmall = picked.seats < MEMBERS
// Upgrades start now (the rest of November is charged pro rata: 7 of 30 days); downgrades on Dec 1.
const upgrade = picked.price > current.price
const prorated = ((picked.price - current.price) * 7) / 30
const confirm = (e: FormEvent) => {
e.preventDefault()
if (tooSmall || choice === plan) return
// Send the change to your billing API here.
if (upgrade) {
setPlan(choice)
setNext(null)
setAnnounce(`You're on ${picked.name} now. ${money(prorated)} is charged today.`)
} else {
setNext(choice)
setAnnounce(`${picked.name} starts on Dec 1. You keep ${current.name} until then.`)
}
setOpen(false)
}
return (
<section aria-labelledby={`${id}-title`} className="mx-auto w-full max-w-[880px] px-5 py-10 sm:px-8">
<h2 id={`${id}-title`} className="dc-h text-[24px] leading-tight sm:text-[28px]">
Plan and billing
</h2>
<p className="mt-1.5 text-[15px] text-muted-foreground">Your plan, what this month has used and every bill so far.</p>
<p className="sr-only" role="status">
{announce}
</p>
<div className="mt-6 grid gap-4 md:grid-cols-[minmax(0,1.25fr)_minmax(0,1fr)]">
<article aria-labelledby={`${id}-plan`} className="dc-card flex flex-col p-5 sm:p-6">
<p className="text-[13px] text-muted-foreground">Current plan</p>
<div className="mt-1 flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1">
<h3 id={`${id}-plan`} className="dc-h text-[26px] leading-tight">
{current.name}
</h3>
<p>
<span className="dc-num text-[26px] font-semibold tracking-tight">${current.price}</span>
<span className="text-[14px] text-muted-foreground"> / month</span>
</p>
</div>
<p className="mt-1 text-[14px] text-muted-foreground">
{scheduled ? (
<>
Changes to <span className="font-medium text-foreground">{scheduled.name}</span> on Dec 1, 2026, then ${scheduled.price} a month.
</>
) : (
<>
Renews on <span className="font-medium text-foreground">Dec 1, 2026</span>. Member since March 2025.
</>
)}
</p>
<ul className="mt-5 grid gap-x-4 gap-y-2 text-[14px] sm:grid-cols-2">
{FEATURES[plan].map((f) => (
<li key={f} className="flex items-start gap-2">
<Check className="mt-0.5 size-4 shrink-0 text-[color:var(--dc-accent)]" aria-hidden="true" />
{f}
</li>
))}
</ul>
<dl className="mt-5 grid grid-cols-3 gap-3 rounded-[calc(var(--radius)+2px)] bg-[color:color-mix(in_oklab,var(--foreground)_4%,transparent)] px-4 py-3">
<div className="min-w-0">
<dt className="text-[12px] text-muted-foreground">Billed</dt>
<dd className="mt-0.5 text-[14px] font-medium">Monthly</dd>
</div>
<div className="min-w-0">
<dt className="text-[12px] text-muted-foreground">Next bill</dt>
<dd className="dc-num mt-0.5 text-[14px] font-medium">{money(scheduled ? scheduled.price : current.price)}</dd>
</div>
<div className="min-w-0">
<dt className="text-[12px] text-muted-foreground">Paid with</dt>
<dd className="mt-0.5 truncate text-[14px] font-medium">
Visa <span className="dc-num">4242</span>
</dd>
</div>
</dl>
<div className="mt-auto flex flex-wrap items-center gap-2 pt-5">
<Button
className="font-semibold"
onClick={() => {
setChoice(next ?? plan)
setOpen(true)
}}
>
Change plan
</Button>
{scheduled ? (
<Button
variant="ghost"
className="dc-flat text-muted-foreground"
onClick={() => {
setNext(null)
setAnnounce(`Change cancelled. You stay on ${current.name}.`)
}}
>
Keep {current.name}
</Button>
) : (
<Button variant="ghost" className="dc-flat text-muted-foreground" nativeButton={false} render={<a href="#cancel-plan" />}>
Cancel plan
</Button>
)}
</div>
</article>
<article aria-labelledby={`${id}-usage`} className="dc-card flex flex-col p-5 sm:p-6">
<div className="flex items-baseline justify-between gap-3">
<h3 id={`${id}-usage`} className="text-[15px] font-semibold">
Usage this month
</h3>
<p className="text-[13px] text-muted-foreground">Nov 1 to 30</p>
</div>
<ul className="mt-4 grid flex-1 content-between gap-5">
{usage(current.seats).map((u) => (
<li key={u.label}>
<Progress
value={(u.used / u.of) * 100}
aria-valuetext={`${u.figure} used`}
className="gap-x-3 gap-y-2 [&_[data-slot=progress-indicator]]:rounded-full [&_[data-slot=progress-indicator]]:bg-[color:var(--chart-1)] [&_[data-slot=progress-track]]:h-2 [&_[data-slot=progress-track]]:bg-[color:color-mix(in_oklab,var(--foreground)_10%,transparent)]"
>
<ProgressLabel className="text-[14px] font-medium">{u.label}</ProgressLabel>
<span className="dc-num ml-auto text-[13px] font-medium">{u.figure}</span>
</Progress>
<p className="mt-1.5 text-[12px] text-muted-foreground">{u.note}</p>
</li>
))}
</ul>
<p className="mt-5 border-t border-border pt-3 text-[13px] text-muted-foreground">
<span className="dc-num font-medium text-foreground">23</span> invoices sent. Unlimited on every paid plan.
</p>
</article>
</div>
<div className="mt-4 grid gap-4 md:grid-cols-[minmax(0,1.25fr)_minmax(0,1fr)]">
<article aria-labelledby={`${id}-card`} className="dc-card flex flex-col p-5 sm:p-6">
<h3 id={`${id}-card`} className="text-[15px] font-semibold">
Payment method
</h3>
<div className="mt-4 flex items-center gap-3">
<span className="grid h-10 w-14 shrink-0 place-items-center rounded-[calc(var(--radius)-1px)] border border-border bg-[color:color-mix(in_oklab,var(--foreground)_4%,transparent)]" aria-hidden="true">
<CreditCard className="size-5 text-muted-foreground" />
</span>
<div className="min-w-0 flex-1">
<p className="text-[14px] font-medium">
Visa ending <span className="dc-num">4242</span>
</p>
<p className="text-[13px] text-muted-foreground">
Expires <span className="dc-num">08/2028</span>
</p>
</div>
{/* Open your payment provider's hosted card form here. */}
<Button variant="outline" nativeButton={false} render={<a href="#update-card" />}>
Update
</Button>
</div>
<p className="mt-auto flex items-start gap-1.5 pt-4 text-[12px] text-muted-foreground">
<ShieldCheck className="mt-px size-3.5 shrink-0" aria-hidden="true" />
Card details are kept by our payment provider, never on Orbit.
</p>
</article>
<article aria-labelledby={`${id}-details`} className="dc-card flex flex-col p-5 sm:p-6">
<div className="flex items-center justify-between gap-3">
<h3 id={`${id}-details`} className="text-[15px] font-semibold">
Billing details
</h3>
<Button variant="ghost" size="sm" className="dc-flat -mr-2 text-[color:var(--dc-accent)]" nativeButton={false} render={<a href="#billing-details" />}>
Edit
</Button>
</div>
<dl className="mt-3 grid gap-2.5 text-[14px]">
<div className="flex items-start gap-2.5">
<dt className="mt-0.5">
<FileText className="size-4 text-muted-foreground" aria-hidden="true" />
<span className="sr-only">Bills go to</span>
</dt>
<dd className="min-w-0 break-words">ada@ruizstudio.co</dd>
</div>
<div className="flex items-start gap-2.5">
<dt className="mt-0.5">
<MapPin className="size-4 text-muted-foreground" aria-hidden="true" />
<span className="sr-only">Address</span>
</dt>
<dd className="min-w-0">Ruiz Studio, 418 SE Ash St, Portland, OR 97214</dd>
</div>
<div className="flex items-start gap-2.5">
<dt className="mt-0.5">
<Hash className="size-4 text-muted-foreground" aria-hidden="true" />
<span className="sr-only">Tax ID</span>
</dt>
<dd className="min-w-0 text-muted-foreground">No tax ID on bills</dd>
</div>
</dl>
</article>
</div>
<article aria-labelledby={`${id}-history`} className="dc-card mt-4 overflow-hidden">
<div className="flex flex-wrap items-center justify-between gap-3 px-5 pt-5 pb-3 sm:px-6">
<div>
<h3 id={`${id}-history`} className="text-[15px] font-semibold">
Billing history
</h3>
<p className="mt-0.5 text-[13px] text-muted-foreground">Every bill, as a PDF for your records.</p>
</div>
<Button variant="outline" size="sm" nativeButton={false} render={<a href="#bills-2026.zip" />}>
<Download aria-hidden="true" /> Download all
</Button>
</div>
<Table className="text-[14px]">
<TableHeader>
<TableRow className="hover:bg-transparent">
<TableHead className="h-9 pl-5 text-[12px] text-muted-foreground sm:pl-6">Date</TableHead>
<TableHead className="hidden h-9 text-[12px] text-muted-foreground sm:table-cell">Description</TableHead>
<TableHead className="h-9 text-right text-[12px] text-muted-foreground">Amount</TableHead>
<TableHead className="hidden h-9 text-[12px] text-muted-foreground min-[420px]:table-cell">Status</TableHead>
<TableHead className="h-9 pr-5 text-right text-[12px] text-muted-foreground sm:pr-6">
<span className="sr-only">Download</span>
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{[{ ...BILLS[0], item: `${(scheduled ?? current).name} plan, monthly`, amount: money((scheduled ?? current).price) }, ...BILLS.slice(1)].map((b) => (
<TableRow key={b.number} className="hover:bg-muted/40">
<TableCell className="py-3 pl-5 whitespace-normal sm:pl-6">
<span className="block font-medium">{b.date}</span>
<span className="dc-num block text-[12px] text-muted-foreground">
{b.number}
<span className="sm:hidden"> · {b.item}</span>
</span>
</TableCell>
<TableCell className="hidden py-3 whitespace-normal text-muted-foreground sm:table-cell">{b.item}</TableCell>
<TableCell className="dc-num py-3 text-right font-medium">{b.amount}</TableCell>
<TableCell className="hidden py-3 min-[420px]:table-cell">
<span className={cn("dc-pill", b.status === "Paid" ? "dc-pill-hl" : "dc-pill-line")}>{b.status}</span>
</TableCell>
<TableCell className="py-3 pr-5 text-right sm:pr-6">
{b.status === "Paid" ? (
// Point href at the bill's PDF (and add `download`).
<a
href={`#${b.number}.pdf`}
className="inline-flex items-center gap-1.5 rounded-[var(--radius)] px-1.5 py-1 text-[13px] font-medium text-[color:var(--dc-accent)] outline-none hover:underline focus-visible:ring-3 focus-visible:ring-ring/50"
>
<Download className="size-3.5" aria-hidden="true" /> PDF
<span className="sr-only">, bill {b.number} from {b.date}</span>
</a>
) : (
<span className="px-1.5 text-[13px] text-muted-foreground">Not yet</span>
)}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</article>
<Dialog open={open} onOpenChange={setOpen}>
<DialogContent className="dc-card gap-5 p-5 ring-0 sm:max-w-[480px]">
<form onSubmit={confirm} className="grid gap-5" noValidate>
<DialogHeader>
<DialogTitle className="dc-h text-[19px]">Change plan</DialogTitle>
<DialogDescription>
Your team has {MEMBERS} members. Upgrades start today; a smaller plan starts when this month ends.
</DialogDescription>
</DialogHeader>
<fieldset className="min-w-0">
<legend className="sr-only">Plan</legend>
<RadioGroup value={choice} onValueChange={(v) => setChoice(v as PlanId)} className="gap-2">
{PLANS.map((p) => (
<label
key={p.id}
className="flex cursor-pointer items-start gap-3 rounded-[calc(var(--radius)+2px)] border border-border p-3 transition-colors hover:bg-muted/50 has-data-checked:border-[color:var(--dc-accent)] has-data-checked:bg-[color:color-mix(in_oklab,var(--dc-accent)_6%,transparent)]"
>
<RadioGroupItem value={p.id} className="mt-0.5" aria-describedby={`${id}-${p.id}-note`} />
<span className="min-w-0 flex-1">
<span className="flex items-center gap-2 text-[14px] font-medium">
{p.name}
{p.id === plan ? <span className="dc-pill dc-pill-muted">Current</span> : null}
</span>
<span id={`${id}-${p.id}-note`} className="block text-[13px] text-muted-foreground">
{p.note}
</span>
</span>
<span className="dc-num shrink-0 text-[14px] font-semibold">
${p.price}
<span className="font-sans text-[12px] font-normal text-muted-foreground">/mo</span>
</span>
</label>
))}
</RadioGroup>
</fieldset>
<div aria-live="polite" className="min-h-[44px]">
{tooSmall ? (
<p className="flex items-start gap-2 rounded-[calc(var(--radius)+2px)] bg-[color:color-mix(in_oklab,var(--dc-danger)_10%,var(--card))] px-3 py-2.5 text-[13px] leading-snug">
<TriangleAlert className="mt-0.5 size-4 shrink-0 text-[color:var(--dc-danger)]" aria-hidden="true" />
{picked.name} has {picked.seats} seat. Remove {MEMBERS - picked.seats} members from your team first.
</p>
) : choice === plan ? (
<p className="px-0.5 py-2.5 text-[13px] text-muted-foreground">This is your plan now.</p>
) : upgrade ? (
<p className="px-0.5 py-2.5 text-[13px] text-muted-foreground">
<span className="dc-num font-medium text-foreground">{money(prorated)}</span> today for the rest of November, then ${picked.price} a month from Dec 1.
</p>
) : (
<p className="px-0.5 py-2.5 text-[13px] text-muted-foreground">
{picked.name} starts on Dec 1 at ${picked.price} a month. You keep {current.name} until then.
</p>
)}
</div>
<DialogFooter className="-mx-5 -mb-5 rounded-b-[var(--dc-radius-card)] border-border px-5 py-4">
<DialogClose render={<Button type="button" variant="outline" />}>Cancel</DialogClose>
<Button type="submit" className="font-semibold" disabled={tooSmall || choice === plan}>
{choice === plan ? "Choose a plan" : upgrade ? `Upgrade to ${picked.name}` : `Switch to ${picked.name}`}
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
</section>
)
}Team and invites
Members with their roles, an invite form, pending invites to resend or revoke, removal behind a confirm dialog and the seat count.
npx shadcn@latest add https://dresscodeui.com/r/dresscode/settings-team.json"use client"
// Settings, team: invite by email with a role, the members with their roles (the owner's is fixed),
// removal behind a confirm dialog, and pending invites to resend or revoke. Invites hold a seat, so the
// seat count includes them and the form says when every seat is taken. The address is checked on blur
// and on send (format, already a member, already invited). Wire the actions to your own API.
import { Check, CircleAlert, Mail, RefreshCw, Send, Trash2 } from "lucide-react"
import { type FormEvent, useId, useState } from "react"
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Progress } from "@/components/ui/progress"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { cn } from "@/lib/utils"
type Role = "Admin" | "Accountant" | "Viewer"
type Member = { name: string; email: string; role: Role | "Owner"; active: string; you?: boolean }
type Invite = { email: string; role: Role; sent: string; resent?: boolean }
const SEATS = 6
const ROLES: { value: Role; label: string; note: string }[] = [
{ value: "Admin", label: "Admin", note: "Sends invoices, refunds payments and manages the team." },
{ value: "Accountant", label: "Accountant", note: "Sees every payment and exports for taxes. Can't send invoices." },
{ value: "Viewer", label: "Viewer", note: "Can look at invoices and reports. Can't change anything." },
]
const MEMBERS: Member[] = [
{ name: "Ada Ruiz", email: "ada@ruizstudio.co", role: "Owner", active: "Now", you: true },
{ name: "Marco Bell", email: "marco@ruizstudio.co", role: "Admin", active: "2 hours ago" },
{ name: "Priya Nair", email: "priya@nairbooks.com", role: "Accountant", active: "Yesterday" },
{ name: "Sam Okafor", email: "sam@ruizstudio.co", role: "Viewer", active: "Nov 12" },
]
const INVITES: Invite[] = [{ email: "jo@ruizstudio.co", role: "Admin", sent: "Nov 22" }]
const initials = (name: string) =>
name
.split(/\s+/)
.map((w) => w[0])
.join("")
.slice(0, 2)
.toUpperCase()
export default function SettingsTeam() {
const id = useId()
const [members, setMembers] = useState(MEMBERS)
const [invites, setInvites] = useState(INVITES)
const [email, setEmail] = useState("")
const [role, setRole] = useState<Role>("Viewer")
const [error, setError] = useState("")
const [sentTo, setSentTo] = useState("")
// The member being removed stays set while the dialog closes, so its title doesn't flicker.
const [removing, setRemoving] = useState<Member | null>(null)
const [confirming, setConfirming] = useState(false)
const [announce, setAnnounce] = useState("")
const used = members.length + invites.length
const full = used >= SEATS
const check = (v: string) => {
const t = v.trim().toLowerCase()
if (!t) return "Enter an email address."
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)) return "That doesn't look like an email address."
const m = members.find((x) => x.email === t)
if (m) return `${m.name} is already on the team.`
if (invites.some((x) => x.email === t)) return `${t} already has an invite. You can resend it below.`
return ""
}
const invite = (e: FormEvent) => {
e.preventDefault()
if (full) return
const msg = check(email)
setError(msg)
if (msg) {
document.getElementById(`${id}-email`)?.focus()
return
}
// Send the invite from your API here.
const t = email.trim().toLowerCase()
setInvites((all) => [{ email: t, role, sent: "Just now" }, ...all])
setEmail("")
setSentTo(t)
setAnnounce(`Invite sent to ${t} as ${role}.`)
}
const roleNote = ROLES.find((r) => r.value === role)!.note
return (
<section aria-labelledby={`${id}-title`} className="mx-auto w-full max-w-[880px] px-5 py-10 sm:px-8">
<div className="flex flex-col gap-4 sm:flex-row sm:items-end sm:justify-between">
<div>
<h2 id={`${id}-title`} className="dc-h text-[24px] leading-tight sm:text-[28px]">
Team
</h2>
<p className="mt-1.5 text-[15px] text-muted-foreground">Who can see and send invoices for Ruiz Studio.</p>
</div>
<div className="w-full sm:w-[220px]">
<div className="flex items-baseline justify-between gap-3 text-[13px]">
<p id={`${id}-seats`}>
<span className="dc-num font-semibold">
{used} of {SEATS}
</span>{" "}
<span className="text-muted-foreground">seats used</span>
</p>
<a href="#seats" className="rounded-[4px] font-medium text-[color:var(--dc-accent)] outline-none hover:underline focus-visible:ring-3 focus-visible:ring-ring/50">
Add seats
</a>
</div>
<Progress
value={(used / SEATS) * 100}
aria-labelledby={`${id}-seats`}
aria-valuetext={`${used} of ${SEATS} seats used, invites included`}
className="mt-2 [&_[data-slot=progress-indicator]]:rounded-full [&_[data-slot=progress-indicator]]:bg-[color:var(--chart-1)] [&_[data-slot=progress-track]]:h-1.5 [&_[data-slot=progress-track]]:bg-[color:color-mix(in_oklab,var(--foreground)_10%,transparent)]"
/>
</div>
</div>
<p className="sr-only" role="status">
{announce}
</p>
<form noValidate onSubmit={invite} aria-labelledby={`${id}-invite`} className="dc-card mt-6 p-5 sm:p-6">
<h3 id={`${id}-invite`} className="text-[15px] font-semibold">
Invite someone
</h3>
<div className="mt-4 grid gap-3 sm:grid-cols-[minmax(0,1fr)_170px_auto] sm:items-end">
<div className="grid gap-1.5">
<Label htmlFor={`${id}-email`} className="text-[13px]">
Email address
</Label>
<Input
id={`${id}-email`}
type="email"
autoComplete="off"
placeholder="name@studio.com"
value={email}
disabled={full}
onChange={(e) => {
setEmail(e.target.value)
setSentTo("")
if (error && !check(e.target.value)) setError("")
}}
onBlur={() => email && setError(check(email))}
aria-invalid={error ? true : undefined}
aria-describedby={error ? `${id}-email-error` : full ? `${id}-full` : undefined}
className="h-9"
/>
</div>
<div className="grid gap-1.5">
<Label htmlFor={`${id}-role`} className="text-[13px]">
Role
</Label>
<Select items={ROLES} value={role} onValueChange={(v) => v != null && setRole(v as Role)} disabled={full}>
<SelectTrigger id={`${id}-role`} aria-describedby={`${id}-role-note`} className="w-full bg-[color:var(--card)] data-[size=default]:h-9">
<SelectValue />
</SelectTrigger>
<SelectContent>
{ROLES.map((r) => (
<SelectItem key={r.value} value={r.value}>
{r.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<Button type="submit" className="h-9 px-4 font-semibold" disabled={full}>
<Send aria-hidden="true" /> Send invite
</Button>
</div>
<div className="mt-2.5 min-h-5 text-[13px]">
{error ? (
<p id={`${id}-email-error`} className="flex items-start gap-1.5 text-destructive">
<CircleAlert className="mt-px size-3.5 shrink-0" aria-hidden="true" />
{error}
</p>
) : sentTo ? (
<p className="flex items-start gap-1.5">
<Check className="mt-0.5 size-3.5 shrink-0 text-[color:var(--dc-accent)]" aria-hidden="true" />
<span>
Invite sent to <span className="font-medium break-all">{sentTo}</span>. The link works for 7 days.
{full ? <span className="text-muted-foreground"> That was your last free seat.</span> : null}
</span>
</p>
) : full ? (
<p id={`${id}-full`} className="text-muted-foreground">
All {SEATS} seats are in use. Revoke an invite or{" "}
<a href="#seats" className="rounded-[4px] font-medium text-[color:var(--dc-accent)] outline-none hover:underline focus-visible:ring-3 focus-visible:ring-ring/50">
add a seat
</a>{" "}
to invite someone new.
</p>
) : (
<p id={`${id}-role-note`} className="text-muted-foreground">
{role}: {roleNote}
</p>
)}
</div>
</form>
<article aria-labelledby={`${id}-members`} className="dc-card mt-4 overflow-hidden">
<div className="flex items-baseline justify-between gap-3 px-5 pt-5 pb-2 sm:px-6">
<h3 id={`${id}-members`} className="text-[15px] font-semibold">
Members
</h3>
<p className="text-[13px] text-muted-foreground">{members.length} people</p>
</div>
<ul className="divide-y divide-border">
{members.map((m) => (
<li
key={m.email}
className="grid grid-cols-[36px_minmax(0,1fr)_auto] items-center gap-x-3 gap-y-2 px-5 py-3.5 sm:grid-cols-[36px_minmax(0,1fr)_100px_150px_32px] sm:px-6"
>
<span
aria-hidden="true"
className={cn(
"grid size-9 place-items-center rounded-full text-[12px] font-bold",
m.you ? "bg-[color:var(--dc-highlight)] text-[color:var(--dc-highlight-fg)]" : "bg-[color:color-mix(in_oklab,var(--foreground)_8%,transparent)] text-foreground",
)}
>
{initials(m.name)}
</span>
<div className="min-w-0">
<p className="flex items-center gap-2 text-[14px] font-medium">
<span className="truncate">{m.name}</span>
{m.you ? <span className="dc-pill dc-pill-muted shrink-0">You</span> : null}
</p>
<p className="truncate text-[13px] text-muted-foreground">{m.email}</p>
</div>
<p className="hidden text-[13px] text-muted-foreground sm:block">
<span className="sr-only">Last active: </span>
{m.active}
</p>
<div className="col-start-2 sm:col-start-auto">
{m.role === "Owner" ? (
<span className="dc-pill dc-pill-hl">Owner</span>
) : (
<Select
items={ROLES}
value={m.role}
onValueChange={(v) => {
if (v == null) return
setMembers((all) => all.map((x) => (x.email === m.email ? { ...x, role: v as Role } : x)))
setAnnounce(`${m.name} is now ${v === "Admin" || v === "Accountant" ? "an" : "a"} ${v}.`)
}}
>
<SelectTrigger size="sm" aria-label={`Role for ${m.name}`} className="w-full min-w-[130px] bg-[color:var(--card)]">
<SelectValue />
</SelectTrigger>
<SelectContent>
{ROLES.map((r) => (
<SelectItem key={r.value} value={r.value}>
{r.label}
</SelectItem>
))}
</SelectContent>
</Select>
)}
</div>
<div className="col-start-3 row-start-1 flex justify-end sm:col-start-auto sm:row-start-auto">
{m.role !== "Owner" ? (
<Button
variant="ghost"
size="icon-sm"
className="dc-flat text-muted-foreground hover:text-destructive"
aria-label={`Remove ${m.name}`}
onClick={() => {
setRemoving(m)
setConfirming(true)
}}
>
<Trash2 />
</Button>
) : null}
</div>
</li>
))}
</ul>
</article>
<article aria-labelledby={`${id}-pending`} className="dc-card mt-4 overflow-hidden">
<div className="flex flex-col gap-0.5 px-5 pt-5 pb-2 sm:flex-row sm:items-baseline sm:justify-between sm:gap-3 sm:px-6">
<h3 id={`${id}-pending`} className="text-[15px] font-semibold">
Pending invites
</h3>
<p className="text-[13px] text-muted-foreground">Each holds a seat until it is accepted</p>
</div>
{invites.length ? (
<ul className="divide-y divide-border">
{invites.map((inv) => (
<li key={inv.email} className="grid grid-cols-[36px_minmax(0,1fr)] items-center gap-x-3 gap-y-1.5 px-5 py-3.5 sm:grid-cols-[36px_minmax(0,1fr)_auto] sm:px-6">
<span aria-hidden="true" className="grid size-9 place-items-center rounded-full border border-dashed border-input text-muted-foreground">
<Mail className="size-4" />
</span>
<div className="min-w-0">
<p className="truncate text-[14px] font-medium">{inv.email}</p>
<p className="text-[13px] text-muted-foreground">
{inv.role} · {inv.resent ? "sent again just now" : `invited ${inv.sent === "Just now" ? "just now" : inv.sent}`}
</p>
</div>
<div className="col-start-2 -ml-2.5 flex gap-1 sm:col-start-auto sm:ml-0">
<Button
variant="ghost"
size="sm"
className="dc-flat"
disabled={inv.resent}
onClick={() => {
setInvites((all) => all.map((x) => (x.email === inv.email ? { ...x, resent: true } : x)))
setAnnounce(`Invite sent again to ${inv.email}.`)
}}
>
{inv.resent ? <Check aria-hidden="true" /> : <RefreshCw aria-hidden="true" />}
{inv.resent ? "Sent" : "Resend"}
<span className="sr-only"> invite to {inv.email}</span>
</Button>
<Button
variant="ghost"
size="sm"
className="dc-flat text-muted-foreground hover:text-destructive"
onClick={() => {
setInvites((all) => all.filter((x) => x.email !== inv.email))
setSentTo("")
setAnnounce(`Invite to ${inv.email} revoked. ${used - 1} of ${SEATS} seats used.`)
}}
>
Revoke<span className="sr-only"> invite to {inv.email}</span>
</Button>
</div>
</li>
))}
</ul>
) : (
<p className="px-5 pt-1 pb-5 text-[14px] text-muted-foreground sm:px-6">No pending invites. New ones show here until they are accepted.</p>
)}
</article>
<AlertDialog open={confirming} onOpenChange={setConfirming}>
<AlertDialogContent className="dc-card ring-0">
<AlertDialogHeader>
<AlertDialogTitle className="dc-h text-[18px]">Remove {removing?.name}?</AlertDialogTitle>
<AlertDialogDescription>
They lose access to Ruiz Studio right away. Invoices they sent stay, with their name in the history.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter className="rounded-b-[var(--dc-radius-card)] border-border">
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
variant="destructive"
onClick={() => {
if (!removing) return
setMembers((all) => all.filter((x) => x.email !== removing.email))
setSentTo("")
setAnnounce(`${removing.name} removed. ${used - 1} of ${SEATS} seats used.`)
setConfirming(false)
}}
>
<Trash2 aria-hidden="true" /> Remove
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</section>
)
}