# Task 11 — Volunteer Master

Captain's screen for managing the city's volunteer roster.

## Files

```
apps/web/src/app/captain/volunteers/page.tsx           # list
apps/web/src/app/captain/volunteers/new/page.tsx       # add form
apps/web/src/app/captain/volunteers/[id]/page.tsx      # detail / edit
```

## List page

- Search input (name / phone / username)
- Locality filter dropdown
- Role filter chips: "All / Captains / Volunteers / Inactive"
- List of cards. Each row:
  - Avatar (initials)
  - Name + phone
  - Locality chip
  - Lifetime vihars + this-month count
  - Tap → detail
- "+ Add Volunteer" FAB

## Add form

| Field | Validation |
|---|---|
| Full name | min 2, max 150 |
| Phone | Indian mobile regex from shared schema |
| Username | min 3, alphanumeric + dot/underscore/dash |
| Home locality | dropdown |
| Roles | toggles: Volunteer (default ON), Captain (default OFF, confirm dialog) |
| Initial password | auto-generate suggestion (random 8-char), show copy button |

POST to `/api/users` with `createUserSchema` shape:
```json
{
  "username": "rajesh.m",
  "fullName": "Rajesh Mehta",
  "phone": "9876543210",
  "homeLocalityId": 1,
  "isCaptain": false,
  "isVolunteer": true,
  "initialPassword": "Walkeshwar2026"
}
```

After save, show a confirmation card:
- Username + initial password (in a copy-able block)
- Pre-built WhatsApp message: "Welcome to Vihar Sewa..." with credentials
- "Share via WhatsApp" button (constructs `wa.me/91{phone}?text=...`)

## Detail / edit page

- Read-only display of all fields.
- "Edit" button toggles edit mode.
- Editable: name, locality, roles, isActive (toggle to deactivate).
- "Reset password" action: generates new random, captain shares with volunteer.
- Personal stats summary (this user's lifetime vihars, total km, recent activity).
- PATCH to `/api/users/{id}`.

## Acceptance

1. Open `/captain/volunteers`. List loads.
2. Search "raj" — list filters.
3. Tap "+ Add Volunteer" — form opens.
4. Fill fields, generate password, submit. New row appears.
5. After save, share-credentials sheet appears; tap WhatsApp link, message opens
   prefilled to that volunteer's phone.
6. Tap a volunteer row → detail.
7. Edit name, save — list reflects update.
8. Deactivate a volunteer — they vanish from "Active" filter, appear in "Inactive".

## Gotchas

- Username uniqueness is per-city; the API enforces it. Show clean error if 409.
- Phone is also per-city unique. Same handling.
- Generating a password client-side: use `crypto.getRandomValues` not `Math.random`.
- The "Captain" toggle should require an explicit confirm: "Make {name} a captain?
  They will be able to plan vihars and manage volunteers."
- Don't let a captain demote themselves (UI guard in addition to server guard).

## Out of scope

- Bulk import from CSV — Phase 2 (give a one-time admin script for now)
- SMS-based password reset — Phase 2
- Volunteer self-signup — Phase 3
