⌘K
Search
Search pages, pieces and blocks.
Settings/Settings in the App Shell (Strip): the sections in the top row's switcher, a 400 wide form centred under it, Save at its foot, Delete behind an Alert Dialog.
components/blocks/settings.tsx
"use client"
import * as React from "react"
import { AsteriskIcon } from "@/components/icons"import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger,} from "@/components/ui/alert-dialog"import { AppShell, type AppShellNavItem } from "@/components/ui/app-shell"import { Breadcrumb, BreadcrumbList, BreadcrumbSection, BreadcrumbSwitcher } from "@/components/ui/breadcrumb"import { Button } from "@/components/ui/button"import { DescriptionDetails, DescriptionItem, DescriptionList, DescriptionTerm } from "@/components/ui/description-list"import { DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator } from "@/components/ui/dropdown-menu"import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel, FieldSeparator, FieldTitle } from "@/components/ui/field"import { InputGroup, InputGroupInput, InputGroupTextarea } from "@/components/ui/input-group"import { PageHeader } from "@/components/ui/page-header"import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"import { Switch } from "@/components/ui/switch"
// Settings: the school's settings in the App Shell (Strip), the Settings// row chosen. The top row says where the page sits: "Settings / Profile",// the second part a switcher that opens the sections in a Dropdown Menu// (Danger zone in red under a separator). Under it the section's form,// 400 wide, centred in the panel: Profile, Notifications and Lessons as// fields with Save at their foot, Payouts as a Description List, Danger// zone with Delete behind an Alert Dialog. The same on a phone.
type SectionId = "profile" | "notifications" | "lessons" | "payouts" | "danger"
const settingsSections: { id: SectionId; label: string }[] = [ { id: "profile", label: "Profile" }, { id: "notifications", label: "Notifications" }, { id: "lessons", label: "Lessons" }, { id: "payouts", label: "Payouts" }, { id: "danger", label: "Danger zone" },]
const lengths = [ { value: "60", label: "60 minutes" }, { value: "90", label: "90 minutes" }, { value: "120", label: "2 hours" },]
const windows = [ { value: "12", label: "12 hours before" }, { value: "24", label: "24 hours before" }, { value: "48", label: "48 hours before" },]
const notifications = [ { key: "new-booking", label: "New bookings", line: "An email for every lesson booked.", on: true }, { key: "weather-hold", label: "Weather holds", line: "When a lesson moves for the swell or the wind.", on: true }, { key: "weekly", label: "Weekly summary", line: "Bookings and payouts, every Monday at 08:00.", on: false },]
const stripNav = ["Overview", "Bookings", "Calendar", "Schools", "Instructors", "Students", "Lessons", "Payouts", "Reviews", "Messages", "Reports"]
function SettingsBlock() { const [section, setSection] = React.useState<SectionId>("profile") const current = settingsSections.find((each) => each.id === section) ?? settingsSections[0] const nav: AppShellNavItem[] = stripNav.map((label) => ({ label, count: label === "Bookings" ? "104" : undefined }))
return ( <AppShell id="mare-settings" brand={{ name: "Maré", logo: <AsteriskIcon /> }} nav={nav} settings={{ label: "Settings", active: true }} header={ <PageHeader look="toprow"> <Breadcrumb> <BreadcrumbList> <BreadcrumbSection>Settings</BreadcrumbSection> <BreadcrumbSwitcher label={current.label} aria-label={`Settings view: ${current.label}`}> <DropdownMenuRadioGroup value={section} onValueChange={(value) => { const next = settingsSections.find((each) => each.id === value) if (next) setSection(next.id) }} > {settingsSections.map(({ id, label }) => ( <React.Fragment key={id}> {id === "danger" && <DropdownMenuSeparator />} <DropdownMenuRadioItem value={id} variant={id === "danger" ? "destructive" : undefined} closeOnClick> {label} </DropdownMenuRadioItem> </React.Fragment> ))} </DropdownMenuRadioGroup> </BreadcrumbSwitcher> </BreadcrumbList> </Breadcrumb> </PageHeader> } > <section aria-label={current.label} className="mx-auto flex w-full max-w-100 flex-col"> {section === "profile" && ( <form className="flex flex-col gap-4" onSubmit={(event) => event.preventDefault()}> <FieldGroup className="gap-3"> <Field> <InputGroup> <InputGroupInput id="settings-name" label="School name" defaultValue="Maré Ericeira" /> </InputGroup> </Field> <Field> <InputGroup> <InputGroupInput id="settings-email" label="Contact email" type="email" defaultValue="ericeira@mare.pt" /> </InputGroup> </Field> <Field> <InputGroup> <InputGroupTextarea id="settings-notes" label="Notes" className="min-h-28" defaultValue="Boards and wetsuits included. Meet at the beach hut by the north car park." /> </InputGroup> </Field> </FieldGroup> <Button type="submit" size="lg" className="w-full"> Save profile </Button> </form> )}
{section === "notifications" && ( <form className="flex flex-col gap-4" onSubmit={(event) => event.preventDefault()}> <FieldGroup className="gap-3"> {notifications.map(({ key, label, line, on }, index) => ( <React.Fragment key={key}> {index > 0 && <FieldSeparator />} <Field orientation="horizontal"> <FieldContent> <FieldLabel htmlFor={`settings-${key}`}>{label}</FieldLabel> <FieldDescription>{line}</FieldDescription> </FieldContent> <Switch id={`settings-${key}`} defaultChecked={on} /> </Field> </React.Fragment> ))} </FieldGroup> <Button type="submit" size="lg" className="w-full"> Save notifications </Button> </form> )}
{section === "lessons" && ( <form className="flex flex-col gap-4" onSubmit={(event) => event.preventDefault()}> <FieldGroup className="gap-3"> <Field> <FieldLabel htmlFor="settings-length">Lesson length</FieldLabel> <Select items={lengths} defaultValue="90"> <SelectTrigger id="settings-length" className="w-full"> <SelectValue /> </SelectTrigger> <SelectContent> {lengths.map((each) => ( <SelectItem key={each.value} value={each.value}> {each.label} </SelectItem> ))} </SelectContent> </Select> </Field> <Field> <FieldLabel htmlFor="settings-cancel">Free cancellation</FieldLabel> <Select items={windows} defaultValue="24"> <SelectTrigger id="settings-cancel" className="w-full"> <SelectValue /> </SelectTrigger> <SelectContent> {windows.map((each) => ( <SelectItem key={each.value} value={each.value}> {each.label} </SelectItem> ))} </SelectContent> </Select> <FieldDescription>Later than this, the lesson is paid in full.</FieldDescription> </Field> </FieldGroup> <Button type="submit" size="lg" className="w-full"> Save lessons </Button> </form> )}
{section === "payouts" && ( <div className="flex flex-col gap-4"> <DescriptionList layout="columns"> <DescriptionItem> <DescriptionTerm>Paid to</DescriptionTerm> <DescriptionDetails numeric>Account ending 4821</DescriptionDetails> </DescriptionItem> <DescriptionItem> <DescriptionTerm>Schedule</DescriptionTerm> <DescriptionDetails>Every Friday</DescriptionDetails> </DescriptionItem> <DescriptionItem> <DescriptionTerm>Next payout</DescriptionTerm> <DescriptionDetails numeric>€1,840.00 on Fri 4 Dec</DescriptionDetails> </DescriptionItem> </DescriptionList> <Button variant="secondary" size="lg" className="w-full"> Change bank account </Button> </div> )}
{section === "danger" && ( <Field> <FieldContent> <FieldTitle>Delete Maré Ericeira</FieldTitle> <FieldDescription> Removes the school, its 41 upcoming lessons and their bookings. Students are refunded in full. </FieldDescription> </FieldContent> <AlertDialog> <AlertDialogTrigger render={<Button variant="destructive" size="lg" className="w-full" />}> Delete school </AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Delete Maré Ericeira?</AlertDialogTitle> <AlertDialogDescription> Its 41 upcoming lessons are cancelled and every student is refunded. This cannot be undone. </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Keep school</AlertDialogCancel> <AlertDialogAction variant="destructive">Delete school</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent> </AlertDialog> </Field> )} </section> </AppShell> )}
export { SettingsBlock }