mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 09:42:53 +00:00
420 lines
12 KiB
Markdown
420 lines
12 KiB
Markdown
# EDR Admin Portal (Backoffice)
|
|
|
|
Comprehensive admin portal for the Ethio-Djibouti Railway passenger management system. Built with Next.js 14, TypeScript, and Tailwind CSS with full dark mode support and EDR branding.
|
|
|
|
## 🚀 Enhanced Features
|
|
|
|
### Complete Admin Module Coverage
|
|
- **Overview** - Dashboard with KPIs, revenue trends, and real-time metrics
|
|
- **Operations** - Bookings, Passengers, Tickets, Live Tracking, Agent Operations
|
|
- **Master Data** - Stations, Routes, Fleet Management, Schedules, Seat Classes
|
|
- **Financial** - Pricing & Fares, Payments, Wallet Management, Promotions
|
|
- **Customer Services** - Loyalty Program, Support Center, Notifications, Food & Dining
|
|
- **Security & Compliance** - Fraud Detection, Verifayda Integration, Audit Logs
|
|
- **Analytics & Reports** - Comprehensive reporting and operational analytics
|
|
- **System** - Settings and configuration management
|
|
|
|
### UI/UX Enhancements
|
|
- **EDR Branding** - Official blue, orange, and red color scheme
|
|
- **Dark Mode** - Full dark mode support with theme persistence
|
|
- **Collapsible Sidebar** - Space-efficient navigation with categorized sections
|
|
- **Responsive Design** - Mobile-first approach with adaptive layouts
|
|
- **Loading States** - Skeleton loaders and async action feedback
|
|
- **Interactive Components** - Sortable tables, action buttons, modals
|
|
|
|
### Technical Features
|
|
- **Real API Integration** - Connected to all EDR passenger API endpoints
|
|
- **Functional CRUD Operations** - Add, edit, delete with optimistic updates
|
|
- **Advanced Data Tables** - Sorting, filtering, pagination, bulk actions
|
|
- **Form Validation** - Client-side validation with error handling
|
|
- **State Management** - Zustand for auth and theme state
|
|
- **Query Management** - React Query for server state and caching
|
|
- **Type Safety** - Full TypeScript coverage with EDR domain types
|
|
|
|
## 📋 Prerequisites
|
|
|
|
- Node.js >= 20.x
|
|
- pnpm >= 9.x
|
|
- EDR Passenger API running on http://localhost:4000
|
|
|
|
## 🛠️ Installation
|
|
|
|
### 1. Install Dependencies
|
|
|
|
From the monorepo root:
|
|
```bash
|
|
pnpm install
|
|
```
|
|
|
|
Or from the backoffice directory:
|
|
```bash
|
|
cd apps/edr-passenger-web/backoffice
|
|
pnpm install
|
|
```
|
|
|
|
### 2. Environment Configuration
|
|
|
|
Copy the environment template:
|
|
```bash
|
|
cp .env.example .env.local
|
|
```
|
|
|
|
Edit `.env.local`:
|
|
```bash
|
|
# API Configuration
|
|
NEXT_PUBLIC_API_URL=http://localhost:4000
|
|
|
|
# IAM Configuration (Corporate Authentication)
|
|
NEXT_PUBLIC_IAM_ENABLED=false
|
|
NEXT_PUBLIC_IAM_API_URL=https://iam.tria-plc.com/api
|
|
```
|
|
|
|
### 3. Start Development Server
|
|
|
|
From the backoffice directory:
|
|
```bash
|
|
pnpm dev
|
|
```
|
|
|
|
Or from the monorepo root:
|
|
```bash
|
|
pnpm --filter @edr/passenger-backoffice run dev
|
|
```
|
|
|
|
The admin portal will be available at: **http://localhost:3001**
|
|
|
|
## 🔑 Login Credentials
|
|
|
|
Use these demo credentials to access the admin portal:
|
|
|
|
| Email | Password | Role |
|
|
|-------|----------|------|
|
|
| admin@edr-platform.com | admin123 | Admin |
|
|
|
|
**Note:** This is a stub authentication flow. TODO: Integrate with real backend auth endpoint.
|
|
|
|
## 📁 Enhanced Project Structure
|
|
|
|
```
|
|
backoffice/
|
|
├── src/
|
|
│ ├── app/ # Next.js App Router pages
|
|
│ │ ├── dashboard/ # Dashboard with KPIs
|
|
│ │ ├── bookings/ # Booking management
|
|
│ │ ├── passengers/ # Passenger management
|
|
│ │ ├── stations/ # Station master data
|
|
│ │ ├── routes/ # Route management
|
|
│ │ ├── fleet/ # Train & coach management
|
|
│ │ ├── schedules/ # Trip schedules
|
|
│ │ ├── seat-classes/ # Seat class configuration
|
|
│ │ ├── pricing/ # Fare rules & pricing
|
|
│ │ ├── payments/ # Payment management
|
|
│ │ ├── tickets/ # Ticket operations
|
|
│ │ ├── agents/ # Agent operations
|
|
│ │ ├── loyalty/ # Loyalty program
|
|
│ │ ├── wallet/ # Wallet management
|
|
│ │ ├── promotions/ # Promotion management
|
|
│ │ ├── support/ # Customer support
|
|
│ │ ├── notifications/ # Notification center
|
|
│ │ ├── fraud/ # Fraud detection
|
|
│ │ ├── verifayda/ # ID verification
|
|
│ │ ├── audit/ # Audit logs
|
|
│ │ ├── live/ # Live tracking
|
|
│ │ ├── food/ # Food & dining
|
|
│ │ ├── reports/ # Analytics & reports
|
|
│ │ ├── operational-reports/ # Operational reports
|
|
│ │ ├── settings/ # System settings
|
|
│ │ └── login/ # Authentication
|
|
│ ├── components/
|
|
│ │ ├── layout/ # Layout components
|
|
│ │ │ ├── Sidebar.tsx # Collapsible navigation
|
|
│ │ │ └── Header.tsx # Top header
|
|
│ │ ├── dashboard/ # Dashboard components
|
|
│ │ │ └── StatCard.tsx # KPI cards
|
|
│ │ └── ui/ # Enhanced UI components
|
|
│ │ ├── DataTable.tsx # Advanced data table
|
|
│ │ ├── ActionButton.tsx # Loading button
|
|
│ │ ├── Badge.tsx # Status badges
|
|
│ │ ├── Modal.tsx # Modal dialogs
|
|
│ │ └── Pagination.tsx # Pagination
|
|
│ ├── lib/
|
|
│ │ ├── api/ # Comprehensive API layer
|
|
│ │ │ ├── index.ts # All EDR API services
|
|
│ │ │ ├── bookings.ts # Booking operations
|
|
│ │ │ ├── passengers.ts # Passenger operations
|
|
│ │ │ ├── routes.ts # Route operations
|
|
│ │ │ └── dashboard.ts # Dashboard data
|
|
│ │ ├── api-client.ts # Axios client
|
|
│ │ ├── auth-store.ts # Authentication state
|
|
│ │ ├── theme-store.ts # Dark mode state
|
|
│ │ └── utils.ts # Utility functions
|
|
│ ├── types/
|
|
│ │ ├── index.ts # Main types
|
|
│ │ └── edr.ts # EDR domain types
|
|
│ └── styles/
|
|
│ └── globals.css # Enhanced styles with dark mode
|
|
├── .env.example # Environment template
|
|
├── .env.local # Local environment
|
|
├── next.config.js # Next.js configuration
|
|
├── tailwind.config.js # Enhanced Tailwind config
|
|
├── tsconfig.json # TypeScript configuration
|
|
└── package.json # Dependencies
|
|
```
|
|
|
|
## 🎨 EDR Design System
|
|
|
|
### Color Palette
|
|
- **Primary Blue**: #2563eb (EDR Blue)
|
|
- **Secondary Orange**: #f97316 (EDR Orange)
|
|
- **Accent Red**: #ef4444 (EDR Red)
|
|
- **Success**: #10b981
|
|
- **Warning**: #f59e0b
|
|
- **Danger**: #ef4444
|
|
|
|
### Components
|
|
|
|
#### Enhanced DataTable
|
|
```tsx
|
|
<DataTable
|
|
data={items}
|
|
columns={[
|
|
{ key: 'name', label: 'Name', sortable: true },
|
|
{ key: 'status', label: 'Status', render: (item) => <Badge variant="status" status={item.status}>{item.status}</Badge> },
|
|
]}
|
|
actions={[
|
|
{ label: 'Edit', onClick: handleEdit, variant: 'secondary', icon: Edit },
|
|
{ label: 'Delete', onClick: handleDelete, variant: 'danger', icon: Trash2 },
|
|
]}
|
|
loading={isLoading}
|
|
/>
|
|
```
|
|
|
|
#### ActionButton with Loading
|
|
```tsx
|
|
<ActionButton
|
|
onClick={handleSubmit}
|
|
variant="primary"
|
|
icon={Plus}
|
|
loading={mutation.isPending}
|
|
>
|
|
Create Item
|
|
</ActionButton>
|
|
```
|
|
|
|
## 🔌 Complete API Integration
|
|
|
|
### Available Services
|
|
- `stationsApi` - Station CRUD operations
|
|
- `fleetApi` - Train and coach management
|
|
- `schedulesApi` - Trip schedule operations
|
|
- `seatsApi` - Seat management and blocking
|
|
- `bookingsApi` - Booking lifecycle management
|
|
- `passengersApi` - Passenger operations
|
|
- `paymentsApi` - Payment processing
|
|
- `ticketsApi` - Ticket operations
|
|
- `agentsApi` - Agent management
|
|
- `loyaltyApi` - Loyalty program
|
|
- `walletApi` - Wallet operations
|
|
- `promotionsApi` - Promotion management
|
|
- `supportApi` - Customer support
|
|
- `notificationsApi` - Notification system
|
|
- `fraudApi` - Fraud detection
|
|
- `verifaydaApi` - ID verification
|
|
- `auditApi` - Audit logging
|
|
- `liveApi` - Live tracking
|
|
- `seatClassesApi` - Seat class management
|
|
- `foodApi` - Food & dining
|
|
|
|
### Real Data Integration
|
|
|
|
All components use real API endpoints:
|
|
|
|
```tsx
|
|
const { data, isLoading } = useQuery({
|
|
queryKey: ['stations', filters],
|
|
queryFn: () => stationsApi.getAll(filters),
|
|
});
|
|
|
|
const createMutation = useMutation({
|
|
mutationFn: stationsApi.create,
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['stations'] });
|
|
setShowModal(false);
|
|
},
|
|
});
|
|
```
|
|
|
|
## 🌙 Dark Mode Support
|
|
|
|
Full dark mode implementation with:
|
|
- System preference detection
|
|
- Manual toggle in sidebar
|
|
- Persistent theme storage
|
|
- Semantic color variables
|
|
- Smooth transitions
|
|
|
|
## 📱 Responsive Design
|
|
|
|
- Mobile-first approach
|
|
- Collapsible sidebar on mobile
|
|
- Adaptive table layouts
|
|
- Touch-friendly interactions
|
|
- Responsive grid systems
|
|
|
|
## 🔐 Enhanced Security
|
|
|
|
- JWT token management
|
|
- Automatic token refresh
|
|
- Role-based access control
|
|
- Audit trail logging
|
|
- Fraud detection integration
|
|
|
|
## 🚀 Performance Optimizations
|
|
|
|
- React Query caching
|
|
- Optimistic updates
|
|
- Lazy loading
|
|
- Code splitting
|
|
- Image optimization
|
|
|
|
## 📊 Advanced Features
|
|
|
|
### Functional CRUD Operations
|
|
- Create, Read, Update, Delete for all entities
|
|
- Form validation and error handling
|
|
- Optimistic UI updates
|
|
- Bulk operations support
|
|
|
|
### Data Management
|
|
- Advanced filtering and search
|
|
- Sortable columns
|
|
- Pagination with page size options
|
|
- Export functionality
|
|
- Real-time updates
|
|
|
|
### User Experience
|
|
- Loading states and skeletons
|
|
- Toast notifications
|
|
- Confirmation dialogs
|
|
- Keyboard shortcuts
|
|
- Accessibility compliance
|
|
|
|
## 🎯 Available Scripts
|
|
|
|
```bash
|
|
# Development
|
|
pnpm dev # Start dev server on port 3001
|
|
|
|
# Build
|
|
pnpm build # Build for production
|
|
|
|
# Production
|
|
pnpm start # Start production server
|
|
|
|
# Linting
|
|
pnpm lint # Run ESLint
|
|
|
|
# Type Checking
|
|
pnpm type-check # Run TypeScript compiler
|
|
```
|
|
|
|
## 🚀 Deployment
|
|
|
|
### Build for Production
|
|
|
|
```bash
|
|
pnpm build
|
|
```
|
|
|
|
### Start Production Server
|
|
|
|
```bash
|
|
pnpm start
|
|
```
|
|
|
|
### Environment Variables for Production
|
|
|
|
Ensure these are set in production:
|
|
- `NEXT_PUBLIC_API_URL` - Backend API URL
|
|
- `NEXT_PUBLIC_IAM_ENABLED` - Enable IAM authentication
|
|
- `NEXT_PUBLIC_IAM_API_URL` - Corporate IAM API URL
|
|
|
|
## 📝 Development Notes
|
|
|
|
### Adding New Pages
|
|
|
|
1. Create directory in `src/app/`
|
|
2. Add `page.tsx` and `layout.tsx`
|
|
3. Update sidebar navigation
|
|
4. Create API service if needed
|
|
5. Add types to `src/types/edr.ts`
|
|
|
|
### API Integration
|
|
|
|
1. Add service to `src/lib/api/index.ts`
|
|
2. Create types in `src/types/edr.ts`
|
|
3. Use React Query hooks in components
|
|
4. Handle loading and error states
|
|
|
|
## 🔧 Customization
|
|
|
|
### Theme Customization
|
|
|
|
Update `tailwind.config.js` for custom colors:
|
|
|
|
```js
|
|
theme: {
|
|
extend: {
|
|
colors: {
|
|
edr: {
|
|
blue: { /* custom blue shades */ },
|
|
orange: { /* custom orange shades */ },
|
|
red: { /* custom red shades */ },
|
|
},
|
|
},
|
|
},
|
|
}
|
|
```
|
|
|
|
### Component Styling
|
|
|
|
Use semantic color classes:
|
|
|
|
```tsx
|
|
<div className="bg-card text-card-foreground border-border">
|
|
<h1 className="text-foreground">Title</h1>
|
|
<p className="text-muted-foreground">Description</p>
|
|
</div>
|
|
```
|
|
|
|
## 📝 TODO
|
|
|
|
- [ ] Integrate with real backend authentication endpoint
|
|
- [ ] Implement IAM authentication for back-office users
|
|
- [ ] Add real-time WebSocket connections for live updates
|
|
- [ ] Implement advanced reporting with chart exports
|
|
- [ ] Add bulk operations for data management
|
|
- [ ] Implement advanced search with filters
|
|
- [ ] Add keyboard shortcuts for power users
|
|
- [ ] Implement role-based UI permissions
|
|
- [ ] Add comprehensive error boundary handling
|
|
- [ ] Implement offline support with service workers
|
|
|
|
## 🤝 Contributing
|
|
|
|
1. Create a feature branch
|
|
2. Follow the established patterns
|
|
3. Add proper TypeScript types
|
|
4. Test thoroughly
|
|
5. Submit a pull request
|
|
|
|
## 📧 Support
|
|
|
|
For technical support or questions:
|
|
- Email: support@edr-platform.com
|
|
- Backend API Docs: http://localhost:4000/api-docs
|
|
|
|
---
|
|
|
|
**Built with ❤️ for Ethio-Djibouti Railway**
|