Skip to content

fix(accounts): improve customer deletion flow and handle relationship constraints#86

Merged
CFBruna merged 29 commits intov2/monorepo-migrationfrom
fix/customer-api-csrf-and-document-types
Feb 21, 2026
Merged

fix(accounts): improve customer deletion flow and handle relationship constraints#86
CFBruna merged 29 commits intov2/monorepo-migrationfrom
fix/customer-api-csrf-and-document-types

Conversation

@CFBruna
Copy link
Owner

@CFBruna CFBruna commented Feb 21, 2026

What Changed

  • Backend (accounts/views.py): Overrode the destroy method in CustomerViewSet to catch Django's ProtectedError. Customers with associated relationships (pets, sales) now return a clean 400 Bad Request instead of triggering a 500 Internal Server Error.
  • Frontend (features/accounts/hooks/useCustomers.ts): Added onSuccess and onError handlers to the deleteCustomer mutation, triggering localized Toast notifications.
  • Frontend (features/accounts/components/CustomerList): Replaced the native window.confirm dialog with a responsive and accessible Shadcn UI Dialog for the delete confirmation step.
  • i18n: Added delete_success and delete_error internationalization keys across English, Portuguese, and Spanish translation files.
  • Chores/Tests (tests/test_forms.py & store/tasks.py): Resolved lingering validation errors in PetAdminForm tests and patched Bandit B311 security warnings by moving pseudo-random generation to secrets.

Why

When attempting to delete a Customer that had linked entities (such as pets or sales), the backend threw an unhandled ProtectedError, causing a 500 server crash with no UI feedback for the user in the shop interface. This PR implements a safe deletion lifecycle: confirming the action gracefully in the UI, catching relational database constraints, and providing clear, localized error/success toast feedback.

How to Test

  • In the Shop UI, navigate to the Customers list.
  • Attempt to delete a customer who owns a pet or has a sale history. Verify the new Dialog appears, and upon confirming, a red toast explains that linked records prevent deletion.
  • Create a dummy customer with no relations. Attempt to delete them and verify the green success toast.
  • Run uv run pytest and verify the accounts and pets test suites pass.
  • Run npm run lint and verify no ESLint warnings remain.

Checklist

  • Service layer architecture followed
  • No ORM in views
  • No hardcoded strings (frontend and backend)
  • Translation keys added to en, pt, es
  • Tests added or updated
  • uv run pytest passes
  • npm run build passes
  • Turing Test passed (works with PYG .env)

- Make Customer.user nullable and SET_NULL
- Add email and name to Customer for anonymous or walk-in customers
- Update CustomerService to support Flow A (with email/user) and Flow B (no user)
- Update CustomerViewSet, serializers, and forms for new flows
- Fix related typing issues in other apps
- Update tests to reflect new requirements and edge cases
- Add write-only name to CustomerSerializer
- Simplify perform_create fallback logic to only use serializer validated_data
- Simplify __str__ of Customer model
- Update CustomerService.quick_register docstring
- Fix test for Customer __str__ without user
…rong password validation

- Add tax_id_type and tax_id fields to shop registration
- Implement regex-based strong password validation using Zod
- Map backend 400 Bad Request registration errors to form fields
- Strip 'confirm_password' from mutation payload
…nd i18n

- Create ShopLoginPage and ShopProfilePage
- Introduce useShopLogin hook for token generation
- Refactor PublicLayout Header to dynamically render user DropdownMenu upon authentication
- Add 'Remember Me' inputs for native browser credential savings
- Add complete en/pt/es translations for accounts, layout, and registration
- Remove validate_email, validate_phone, and validate_tax_id from CustomerSerializer
- Correct has_permission in CustomerPermission to handle register actions
- Revert shop profile routes to /shop/profile
- Replace any-types and English assertions in useRegistrationForm with correct defaults
- Replace hardcoded SelectItems in CustomerForm and RegistrationForm with translations
- Insert missing generic i18n keys for accounts fields and shop flows into locale bundles
- Fix default remember parameter in AuthContext to prevent unwanted persistence
- Pass remember=false to login upon registration in useAuthMutations
- Implement localStorage persistence for login identifier in useShopLogin
- Replace any casting with LoginApiError type in useShopLogin error handling
- Add username/current-password autocomplete to ShopLoginPage
- Add email/new-password autocomplete to RegistrationForm
- Improve password manager compatibility for auth flows
- Add .prettierrc with tabWidth=2
- Format all frontend source files
- Fix LoginApiError typing broken by strict linting post-format
- Catch ProtectedError in CustomerViewSet destroy method
- Return 400 Bad Request with a human-readable message instead of 500 Server Error when attempting to delete a customer with linked records (e.g., pets or sales)
- Replace native window.confirm with Shadcn Dialog for deletion confirmation
- Add localized success and error toast notifications upon deletion
- Enforce i18n standards for new text strings in pt, en, and es
- Ensure success toast follows the correct green visual styling
@CFBruna CFBruna merged commit d9a048f into v2/monorepo-migration Feb 21, 2026
1 check passed
@CFBruna CFBruna deleted the fix/customer-api-csrf-and-document-types branch February 21, 2026 14:24
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