4.5 KiB
4.5 KiB
Story 2.1: Individual Client Account Management
Epic Reference
Epic 2: User Management System
User Story
As an admin, I want to create, view, edit, and search individual client accounts, So that I can manage client information and provide them platform access.
Story Context
Existing System Integration
- Integrates with: Users table, Fortify authentication
- Technology: Livewire Volt, Flux UI forms
- Follows pattern: Admin CRUD patterns, class-based Volt components
- Touch points: User model, admin dashboard
Acceptance Criteria
Create Individual Client
- Form with required fields:
- Full Name (required)
- National ID Number (required, unique)
- Email Address (required, unique)
- Phone Number (required)
- Password (admin-set, required)
- Preferred Language (Arabic/English dropdown)
- Validation for all required fields
- Duplicate email/National ID prevention with clear error message
- Password strength indicator (optional)
- Success message on creation
List View
- Display all individual clients (user_type = 'individual')
- Columns: Name, Email, National ID, Phone, Status, Created Date
- Pagination (10/25/50 per page)
- Default sort by created date (newest first)
Search & Filter
- Search by name, email, or National ID
- Filter by status (active/deactivated/all)
- Real-time search with debounce (300ms)
- Clear filters button
Edit Client
- Edit all client information
- Cannot change user_type from this form
- Validation same as create
- Success message on update
View Client Profile
- Display all client information
- Show consultation history summary
- Show timeline history summary
- Quick links to related records
Quality Requirements
- Bilingual form labels and messages
- Proper form validation with error display
- Audit log entries for all operations
- Tests for CRUD operations
Technical Notes
User Model Scope
// In User model
public function scopeIndividual($query)
{
return $query->where('user_type', 'individual');
}
Volt Component Structure
<?php
use App\Models\User;
use Livewire\Volt\Component;
use Livewire\WithPagination;
new class extends Component {
use WithPagination;
public string $search = '';
public string $statusFilter = '';
public function updatedSearch()
{
$this->resetPage();
}
public function with(): array
{
return [
'clients' => User::individual()
->when($this->search, fn($q) => $q->where(function($q) {
$q->where('name', 'like', "%{$this->search}%")
->orWhere('email', 'like', "%{$this->search}%")
->orWhere('national_id', 'like', "%{$this->search}%");
}))
->when($this->statusFilter, fn($q) => $q->where('status', $this->statusFilter))
->latest()
->paginate(10),
];
}
};
Validation Rules
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:255'],
'national_id' => ['required', 'string', 'unique:users,national_id'],
'email' => ['required', 'email', 'unique:users,email'],
'phone' => ['required', 'string'],
'password' => ['required', 'string', 'min:8'],
'preferred_language' => ['required', 'in:ar,en'],
];
}
Admin Logging
// After creating user
AdminLog::create([
'admin_id' => auth()->id(),
'action_type' => 'create',
'target_type' => 'user',
'target_id' => $user->id,
'new_values' => $user->only(['name', 'email', 'national_id']),
'ip_address' => request()->ip(),
]);
Definition of Done
- Create individual client form works
- List view displays all individual clients
- Search and filter functional
- Edit client works with validation
- View profile shows complete information
- Duplicate prevention works
- Audit logging implemented
- Bilingual support complete
- Tests pass for all CRUD operations
- Code formatted with Pint
Dependencies
- Epic 1: Authentication system, database schema, bilingual support
Risk Assessment
- Primary Risk: Duplicate National ID from different sources
- Mitigation: Database unique constraint + form validation
- Rollback: Remove user and notify if duplicate discovered
Estimation
Complexity: Medium Estimated Effort: 4-5 hours