Skip to content

feat(customers): Task 11 — customer list and create/edit form#3

Merged
pysnooLab merged 3 commits intomainfrom
feat/task11-customers
Apr 7, 2026
Merged

feat(customers): Task 11 — customer list and create/edit form#3
pysnooLab merged 3 commits intomainfrom
feat/task11-customers

Conversation

@pysnooLab
Copy link
Copy Markdown
Collaborator

Summary

  • Adds useCustomers, useCreateCustomer, useUpdateCustomer hooks in src/features/customers/hooks/useCustomers.ts
  • Adds CustomerForm with zod validation, error display, and try/catch around mutateAsync
  • Adds CustomerList with inline create/edit, loading and error states
  • Wires /customers route (scoped to customer_manager role via RoleGuard)
  • Adds docs/WORKFLOW.md documenting the one-task-per-branch PR workflow

Deviations from plan

  • Fixed import { z } from "zod/v4"import { z } from "zod" (per CLAUDE.md convention)
  • Fixed z.email()z.string().email() (zod v3 API)
  • Added try/catch around mutateAsync calls (per CLAUDE.md error handling rules)
  • Added isError/error render state to CustomerList
  • queryFn throws when user is null instead of returning null

Test plan

  • Log in as customer manager — /customers route is accessible
  • Log in as admin or agent — route is blocked by RoleGuard
  • Customer list loads and shows customers scoped to the CM's company
  • "New Customer" → form creates a customer; "Edit" pre-fills and updates
  • Validation errors shown inline for invalid email / empty name

🤖 Generated with Claude Code

pysnooLab and others added 3 commits April 7, 2026 16:09
Implements Task 11 — customer management feature for customer managers.
Adds useCustomers/useCreateCustomer/useUpdateCustomer hooks, CustomerForm
with zod validation and error display, CustomerList with inline edit, and
wires /customers route. Also adds docs/WORKFLOW.md for the one-task-per-branch workflow.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Code review fixes:
- feat(customers): disable New Customer button until companyId resolves
- feat(customers): use TablesInsert/TablesUpdate in useCustomers mutations
- feat(customers): remove unused CustomerFormValues from types.ts
- feat(customers): add noValidate to CustomerForm (prevents browser constraint
  validation from blocking zodResolver in tests)

RLS fixes:
- fix(db): add WITH CHECK to customers_update_cm policy (migration 00010)

Signup bug fix:
- fix(db): normalize invite email to lowercase in create_invite (migration 00009)
- fix(db): make handle_new_user trigger compare emails case-insensitively
  Root cause: Supabase Auth normalizes emails to lowercase in auth.users but
  invites stored the email exactly as typed by the admin (e.g. testCM0@test.com
  vs testcm0@test.com), causing the trigger lookup to fail every time.

Tests:
- test(customers): add useCustomers.test.tsx (hooks — fetch, create, update, error)
- test(customers): add CustomerForm.test.tsx (validation, submit, cancel, edit mode)
- test(customers): add CustomerList.test.tsx (loading/error/empty/populated states,
  button guard, form toggle)
- test(customers): add tests/e2e/customers.spec.ts (full CM CRUD flow + access control)

Docs:
- docs: add required-tests-per-feature table to CLAUDE.md testing section
- docs: add userEvent.setup() and noValidate conventions to CLAUDE.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Added rule to CLAUDE.md: always run npx supabase db reset immediately
  after writing a new migration, without waiting for the user to ask
- Applied migrations 00009 and 00010 to local Supabase (db reset done)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@pysnooLab pysnooLab merged commit a6828d9 into main Apr 7, 2026
4 checks passed
@pysnooLab pysnooLab deleted the feat/task11-customers branch April 7, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant