# Crew profile

Edit a crew member’s name and shift availability, then save the changes to their ID.

[View Crew profile on CyberSpec](https://www.cyberspec.dev/sink/profile-editor)

## Installation

Use a React 19 project with shadcn configured. Render the installed components inside the Cyber root, and import your global stylesheet in the app entry point.

```sh
bunx --bun shadcn@latest add https://www.cyberspec.dev/r/profile-editor.json
```

## Usage

```tsx
import { Cyber } from "@/components/ui/cyber"
import Recipe from "@/components/recipes/profile-editor"

export default function App() {
  return (
    <Cyber>
      <Recipe />
    </Cyber>
  )
}
```

## Source

```tsx
"use client"

import "./recipe-layout.css"
import { useState } from "react"
import { Avatar } from "@/components/ui/avatar"
import { Button } from "@/components/ui/button"
import { Switch } from "@/components/ui/switch"
import { TextField } from "@/components/ui/text-field"

export default function ProfileEditor() {
  const [saved, setSaved] = useState({ name: "Mara Voss", available: true })
  const [name, setName] = useState(saved.name)
  const [available, setAvailable] = useState(saved.available)
  const [message, setMessage] = useState("")
  const dirty = name.trim() !== saved.name || available !== saved.available

  return (
    <form className="sink-stack" onSubmit={(event) => {
      event.preventDefault()
      if (!dirty || !name.trim()) return
      setSaved({ name: name.trim(), available })
      setName(name.trim())
      setMessage("Profile updated.")
    }}>
      <div className="sink-row">
        <Avatar name={saved.name} size="lg" decorative shape="hex" />
        <div style={{ minWidth: 0 }}>
          <strong style={{ overflowWrap: "anywhere" }}>{saved.name}</strong>
          <div className="sink-note">{saved.available ? "Available for a shift" : "Off duty"}</div>
        </div>
      </div>
      <TextField label="Display name" value={name} maxLength={32} required onValueChange={(next) => {
        setName(next)
        setMessage("")
      }} />
      <Switch label="Available for a shift" checked={available} onCheckedChange={(next) => {
        setAvailable(next)
        setMessage("")
      }} />
      <div className="sink-row">
        <Button type="submit" size="sm" disabled={!dirty || !name.trim()}>Save profile</Button>
        <span className="sink-note" role="status">{dirty ? "Unsaved changes" : message}</span>
      </div>
    </form>
  )
}
```

## Components in this recipe

- [Avatar](https://www.cyberspec.dev/components/sidebar/avatar.md) — A portrait in a cut frame, with initials over a generated scanline field when there's no image.
- [Text field](https://www.cyberspec.dev/components/sidebar/text-field.md) — A labelled text input in a cut frame, with a hint, an error and an optional icon.
- [Switch](https://www.cyberspec.dev/components/sidebar/switch.md) — A block that slides across a cut track and lights, with its state printed beside it.
- [Button](https://www.cyberspec.dev/components/sidebar/button.md) — A cut-corner button with a raised tab, five tones, and a press flash. Enable the cipher prop to scramble the label and briefly tear the frame on hover.

## Resources

- [All kitchen sink recipes](https://www.cyberspec.dev/sink.md)
- [Recipe source on GitHub](https://github.com/agnelnieves/cyberspec/blob/main/registry/cyber/recipes/profile-editor.tsx)
- [Recipe layout stylesheet](https://github.com/agnelnieves/cyberspec/blob/main/registry/cyber/recipes/recipe-layout.css)
- [Shadcn registry item](https://www.cyberspec.dev/r/profile-editor.json)
