Merge pull request #71 from Tria-plc/revert-70-alpha

Build related issues resolution
This commit is contained in:
Stephanos A.
2026-06-02 19:41:58 +03:00
committed by GitHub
42 changed files with 546 additions and 631 deletions

View File

@@ -201,22 +201,11 @@ export class GuestBookingService {
}
}
// Generate unique phone number
let guestPhone = firstPassenger.phone || `+251${uniqueId.replace(/[^0-9]/g, '').slice(0, 9)}`;
// Check if phone exists and generate unique one if it does
if (firstPassenger.phone) {
const existingUserByPhone = await this.prisma.user.findUnique({ where: { phone: firstPassenger.phone } });
if (existingUserByPhone) {
guestPhone = `+251${uniqueId.replace(/[^0-9]/g, '').slice(0, 9)}`;
}
}
const tempUser = await this.prisma.user.create({
data: {
fullName: firstPassenger.passengerName,
email: guestEmail,
phone: guestPhone,
phone: firstPassenger.phone || `+251${uniqueId.replace(/[^0-9]/g, '').slice(0, 9)}`,
passwordHash: await bcrypt.hash(Math.random().toString(36), 10),
role: 'PASSENGER',
},

View File

@@ -58,7 +58,7 @@ export default function AuditLogsPage() {
const actions = [
{
label: 'View Details',
onClick: (log: any) => { window.location.href = `/audit/${log.id}`; },
onClick: (log: any) => window.location.href = `/audit/${log.id}`,
variant: 'secondary' as const,
icon: Eye,
},

View File

@@ -193,7 +193,7 @@ export default function CoachesPage() {
columns={columns}
data={coaches}
actions={actions}
loading={isLoading}
isLoading={isLoading}
/>
</div>

View File

@@ -27,7 +27,7 @@ export default function DashboardPage() {
const recentBookings = Array.isArray(recentBookingsData)
? recentBookingsData
: (recentBookingsData as any)?.items || (recentBookingsData as any)?.data || [];
: recentBookingsData?.items || recentBookingsData?.data || [];
const columns = [
{ key: 'reference', label: 'Reference', render: (item: any) => item.bookingRef || item.reference },
@@ -49,7 +49,7 @@ export default function DashboardPage() {
<div className="space-y-6">
<div>
<h1 className="text-3xl font-bold text-foreground">Dashboard</h1>
<p className="text-muted-foreground mt-1">Welcome back! Here&apos;s what&apos;s happening today.</p>
<p className="text-muted-foreground mt-1">Welcome back! Here's what's happening today.</p>
</div>
<div className="grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-4">

View File

@@ -65,7 +65,7 @@ export default function PassengersPage() {
},
];
const actions: any[] = [
const actions = [
// TODO: Create passenger detail page
// {
// label: 'View Details',

View File

@@ -136,17 +136,15 @@ export default function RoutesPage() {
const generateRouteCode = (originId: string, destId: string) => {
if (!originId || !destId) return '';
const stationsList = Array.isArray(stations) ? stations : (stations as any)?.items || [];
const origin = stationsList.find((s: any) => s.id === originId);
const dest = stationsList.find((s: any) => s.id === destId);
const origin = stations?.items?.find((s: any) => s.id === originId);
const dest = stations?.items?.find((s: any) => s.id === destId);
return origin && dest ? `${origin.code}-${dest.code}` : '';
};
const generateRouteName = (originId: string, destId: string) => {
if (!originId || !destId) return '';
const stationsList = Array.isArray(stations) ? stations : (stations as any)?.items || [];
const origin = stationsList.find((s: any) => s.id === originId);
const dest = stationsList.find((s: any) => s.id === destId);
const origin = stations?.items?.find((s: any) => s.id === originId);
const dest = stations?.items?.find((s: any) => s.id === destId);
return origin && dest ? `${origin.name} - ${dest.name}` : '';
};
@@ -274,7 +272,7 @@ export default function RoutesPage() {
disabled={!!editingRoute}
>
<option value="">Select Origin</option>
{(Array.isArray(stations) ? stations : (stations as any)?.items || []).map((station: any) => (
{stations?.items?.map((station: any) => (
<option key={station.id} value={station.id}>
{station.name} ({station.code})
</option>
@@ -291,7 +289,7 @@ export default function RoutesPage() {
disabled={!!editingRoute}
>
<option value="">Select Destination</option>
{(Array.isArray(stations) ? stations : (stations as any)?.items || []).map((station: any) => (
{stations?.items?.map((station: any) => (
<option key={station.id} value={station.id}>
{station.name} ({station.code})
</option>
@@ -375,8 +373,8 @@ export default function RoutesPage() {
<div className="flex-1 font-medium">
{originStationId ? (
<span>
{(Array.isArray(stations) ? stations : (stations as any)?.items || []).find((s: any) => s.id === originStationId)?.name || 'Unknown'}
{' '}({(Array.isArray(stations) ? stations : (stations as any)?.items || []).find((s: any) => s.id === originStationId)?.code || 'N/A'})
{stations?.items?.find((s: any) => s.id === originStationId)?.name || 'Unknown'}
{' '}({stations?.items?.find((s: any) => s.id === originStationId)?.code || 'N/A'})
</span>
) : (
<span className="text-muted-foreground">Select origin station above</span>
@@ -401,7 +399,7 @@ export default function RoutesPage() {
required
>
<option value="">Select Station</option>
{(Array.isArray(stations) ? stations : (stations as any)?.items || []).filter((s: any) =>
{stations?.items?.filter((s: any) =>
s.id !== originStationId &&
s.id !== destinationStationId &&
!stops.some((st, idx) => idx !== index && st.stationId === s.id)
@@ -457,8 +455,8 @@ export default function RoutesPage() {
<div className="flex-1 font-medium">
{destinationStationId ? (
<span>
{(Array.isArray(stations) ? stations : (stations as any)?.items || []).find((s: any) => s.id === destinationStationId)?.name || 'Unknown'}
{' '}({(Array.isArray(stations) ? stations : (stations as any)?.items || []).find((s: any) => s.id === destinationStationId)?.code || 'N/A'})
{stations?.items?.find((s: any) => s.id === destinationStationId)?.name || 'Unknown'}
{' '}({stations?.items?.find((s: any) => s.id === destinationStationId)?.code || 'N/A'})
</span>
) : (
<span className="text-muted-foreground">Select destination station above</span>

View File

@@ -125,7 +125,7 @@ export default function SeatClassesPage() {
</div>
<DataTable
data={(Array.isArray(data) ? data : (data as any)?.items) || []}
data={data?.items || data || []}
columns={columns}
actions={actions}
loading={isLoading}

View File

@@ -1,19 +1,18 @@
import { apiClient } from '@/lib/api-client';
import { PaginatedResponse } from '@edr/types';
const buildQuery = (params?: any) => {
if (!params) return '';
const cleanParams = Object.fromEntries(
Object.entries(params).filter(([_, value]) => value !== '' && value !== undefined && value !== null)
);
return Object.keys(cleanParams).length ? `?${new URLSearchParams(cleanParams as Record<string, string>).toString()}` : '';
};
// Bookings API
export const bookingsApi = {
getAll: async (params?: any) => {
const response = await apiClient.get<any>(`/bookings${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const cleanParams = Object.fromEntries(
Object.entries(params || {}).filter(([_, value]) => value !== '' && value !== undefined && value !== null)
);
const query = new URLSearchParams(cleanParams).toString();
const response = await apiClient.get<any>(`/bookings${query ? `?${query}` : ''}`);
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
getById: (id: string) => apiClient.get<any>(`/bookings/${id}`),
cancel: (id: string, data?: any) => apiClient.post<any>(`/bookings/${id}/cancel`, data),
@@ -23,18 +22,32 @@ export const bookingsApi = {
// Passengers API
export const passengersApi = {
getAll: async (params?: any) => {
const response = await apiClient.get<any>(`/passengers${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const cleanParams = Object.fromEntries(
Object.entries(params || {}).filter(([_, value]) => value !== '' && value !== undefined && value !== null)
);
const query = new URLSearchParams(cleanParams).toString();
const response = await apiClient.get<any>(`/passengers${query ? `?${query}` : ''}`);
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
getById: (id: string) => apiClient.get<any>(`/passengers/${id}`),
verify: (nationalId: string) => apiClient.post<any>('/passengers/verify-fayda', { nationalId }),
};
// Stations API
export const stationsApi = {
getAll: async (params?: any) => {
const response = await apiClient.get<any>(`/stations${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const cleanParams = Object.fromEntries(
Object.entries(params || {}).filter(([_, value]) => value !== '' && value !== undefined && value !== null)
);
const query = new URLSearchParams(cleanParams).toString();
const response = await apiClient.get<any>(`/stations${query ? `?${query}` : ''}`);
// Handle wrapped response: { success, data: [...], timestamp }
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
getById: (id: string) => apiClient.get<any>(`/stations/${id}`),
create: (data: any) => apiClient.post<any>('/stations', data),
@@ -45,12 +58,26 @@ export const stationsApi = {
// Fleet API
export const fleetApi = {
getTrains: async (params?: any) => {
const response = await apiClient.get<any>(`/fleet/trains${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const cleanParams = Object.fromEntries(
Object.entries(params || {}).filter(([_, value]) => value !== '' && value !== undefined && value !== null)
);
const query = new URLSearchParams(cleanParams).toString();
const response = await apiClient.get<any>(`/fleet/trains${query ? `?${query}` : ''}`);
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
getCoaches: async (params?: any) => {
const response = await apiClient.get<any>(`/fleet/coaches${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const cleanParams = Object.fromEntries(
Object.entries(params || {}).filter(([_, value]) => value !== '' && value !== undefined && value !== null)
);
const query = new URLSearchParams(cleanParams).toString();
const response = await apiClient.get<any>(`/fleet/coaches${query ? `?${query}` : ''}`);
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
createTrain: (data: any) => apiClient.post<any>('/fleet/trains', data),
updateTrain: (id: string, data: any) => apiClient.patch<any>(`/fleet/trains/${id}`, data),
@@ -63,8 +90,12 @@ export const fleetApi = {
// Schedules API
export const schedulesApi = {
getAll: async (params?: any) => {
const response = await apiClient.get<any>(`/schedules${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const query = new URLSearchParams(params).toString();
const response = await apiClient.get<any>(`/schedules${query ? `?${query}` : ''}`);
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
getById: (id: string) => apiClient.get<any>(`/schedules/${id}`),
create: (data: any) => apiClient.post<any>('/schedules', data),
@@ -94,8 +125,12 @@ export const seatsApi = {
// Payments API
export const paymentsApi = {
getAll: async (params?: any) => {
const response = await apiClient.get<any>(`/payments${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const query = new URLSearchParams(params).toString();
const response = await apiClient.get<any>(`/payments${query ? `?${query}` : ''}`);
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
getById: (id: string) => apiClient.get<any>(`/payments/${id}`),
refund: (id: string, data: any) => apiClient.post<any>(`/payments/${id}/refund`, data),
@@ -105,8 +140,12 @@ export const paymentsApi = {
// Tickets API
export const ticketsApi = {
getAll: async (params?: any) => {
const response = await apiClient.get<any>(`/tickets${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const query = new URLSearchParams(params).toString();
const response = await apiClient.get<any>(`/tickets${query ? `?${query}` : ''}`);
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
getById: (id: string) => apiClient.get<any>(`/tickets/${id}`),
validate: (ticketId: string, data: any) => apiClient.post<any>(`/tickets/${ticketId}/validate`, data),
@@ -116,8 +155,12 @@ export const ticketsApi = {
// Agents API
export const agentsApi = {
getAll: async (params?: any) => {
const response = await apiClient.get<any>(`/agents${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const query = new URLSearchParams(params).toString();
const response = await apiClient.get<any>(`/agents${query ? `?${query}` : ''}`);
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
getById: (id: string) => apiClient.get<any>(`/agents/${id}`),
create: (data: any) => apiClient.post<any>('/agents', data),
@@ -131,8 +174,12 @@ export const agentsApi = {
// Loyalty API
export const loyaltyApi = {
getAccounts: async (params?: any) => {
const response = await apiClient.get<any>(`/loyalty/accounts${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const query = new URLSearchParams(params).toString();
const response = await apiClient.get<any>(`/loyalty/accounts${query ? `?${query}` : ''}`);
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
getAccount: (passengerId: string) => apiClient.get<any>(`/loyalty/accounts/${passengerId}`),
adjustPoints: (accountId: string, data: any) => apiClient.post<any>(`/loyalty/accounts/${accountId}/adjust`, data),
@@ -143,8 +190,12 @@ export const loyaltyApi = {
// Wallet API
export const walletApi = {
getAccounts: async (params?: any) => {
const response = await apiClient.get<any>(`/wallet/accounts${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const query = new URLSearchParams(params).toString();
const response = await apiClient.get<any>(`/wallet/accounts${query ? `?${query}` : ''}`);
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
getAccount: (passengerId: string) => apiClient.get<any>(`/wallet/accounts/${passengerId}`),
adjustBalance: (accountId: string, data: any) => apiClient.post<any>(`/wallet/accounts/${accountId}/adjust`, data),
@@ -154,8 +205,12 @@ export const walletApi = {
// Promotions API
export const promotionsApi = {
getAll: async (params?: any) => {
const response = await apiClient.get<any>(`/promos${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const query = new URLSearchParams(params).toString();
const response = await apiClient.get<any>(`/promos${query ? `?${query}` : ''}`);
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
getById: (id: string) => apiClient.get<any>(`/promos/${id}`),
create: (data: any) => apiClient.post<any>('/promos', data),
@@ -166,8 +221,12 @@ export const promotionsApi = {
// Support API
export const supportApi = {
getConversations: async (params?: any) => {
const response = await apiClient.get<any>(`/support/conversations${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const query = new URLSearchParams(params).toString();
const response = await apiClient.get<any>(`/support/conversations${query ? `?${query}` : ''}`);
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
getConversation: (id: string) => apiClient.get<any>(`/support/conversations/${id}`),
updateStatus: (id: string, status: string) => apiClient.patch<any>(`/support/conversations/${id}/status`, { status }),
@@ -183,16 +242,24 @@ export const notificationsApi = {
updateTemplate: (id: string, data: any) => apiClient.patch<any>(`/notifications/templates/${id}`, data),
send: (data: any) => apiClient.post<any>('/notifications/send', data),
getHistory: async (params?: any) => {
const response = await apiClient.get<any>(`/notifications/history${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const query = new URLSearchParams(params).toString();
const response = await apiClient.get<any>(`/notifications/history${query ? `?${query}` : ''}`);
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
};
// Fraud API
export const fraudApi = {
getAlerts: async (params?: any) => {
const response = await apiClient.get<any>(`/fraud/alerts${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const query = new URLSearchParams(params).toString();
const response = await apiClient.get<any>(`/fraud/alerts${query ? `?${query}` : ''}`);
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
acknowledgeAlert: (id: string) => apiClient.patch<any>(`/fraud/alerts/${id}/acknowledge`),
getRules: () => apiClient.get<any[]>('/fraud/rules'),
@@ -203,8 +270,12 @@ export const fraudApi = {
// Verifayda API
export const verifaydaApi = {
getVerifications: async (params?: any) => {
const response = await apiClient.get<any>(`/passengers/verifications${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const query = new URLSearchParams(params).toString();
const response = await apiClient.get<any>(`/passengers/verifications${query ? `?${query}` : ''}`);
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
verify: (nationalId: string) => apiClient.post<any>('/passengers/verify-fayda', { nationalId }),
getStats: () => apiClient.get<any>('/passengers/verification-stats'),
@@ -213,8 +284,12 @@ export const verifaydaApi = {
// Audit API
export const auditApi = {
getLogs: async (params?: any) => {
const response = await apiClient.get<any>(`/audit/logs${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const query = new URLSearchParams(params).toString();
const response = await apiClient.get<any>(`/audit/logs${query ? `?${query}` : ''}`);
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
getLog: (id: string) => apiClient.get<any>(`/audit/logs/${id}`),
};
@@ -241,8 +316,12 @@ export const foodApi = {
getCategories: () => apiClient.get<any[]>('/food/categories'),
getMenuItems: (scheduleId: string) => apiClient.get<any[]>(`/food/menu/${scheduleId}`),
getOrders: async (params?: any) => {
const response = await apiClient.get<any>(`/food/orders${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const query = new URLSearchParams(params).toString();
const response = await apiClient.get<any>(`/food/orders${query ? `?${query}` : ''}`);
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
updateOrderStatus: (orderId: string, status: string) => apiClient.patch<any>(`/food/orders/${orderId}/status`, { status }),
createMenuItem: (data: any) => apiClient.post<any>('/food/menu-items', data),
@@ -251,8 +330,12 @@ export const foodApi = {
// Reports API
export const reportsApi = {
getOperationalReports: async (params?: any) => {
const response = await apiClient.get<any>(`/reports/operational${buildQuery(params)}`);
return response?.data ? (Array.isArray(response.data) ? { items: response.data } : response) : (Array.isArray(response) ? { items: response } : response);
const query = new URLSearchParams(params).toString();
const response = await apiClient.get<any>(`/reports/operational${query ? `?${query}` : ''}`);
if (response?.data) {
return Array.isArray(response.data) ? { items: response.data } : response;
}
return Array.isArray(response) ? { items: response } : response;
},
getRevenue: (params?: any) => apiClient.get<any>('/reports/revenue', { params }),
getOccupancy: (params?: any) => apiClient.get<any>('/reports/occupancy', { params }),

File diff suppressed because one or more lines are too long

View File

@@ -14,13 +14,6 @@ Modern Next.js 14 web application for the Ethio-Djibouti Railway passenger booki
7. **Payment** - Choose payment method and process payment
8. **Confirmation** - View PNR, tickets with QR codes
### Dashboard (Backoffice)
- **Dashboard** - Overview of passenger operations
- **Tickets** - Issue, view, and manage tickets
- **Schedules** - View train schedules and details
- **Stations** - Browse station directory
- **Passengers** - Passenger management
### Key Capabilities
- **Fayda 2.0 Integration** - Ethiopian national ID verification
- **Age-Based Pricing** - First child travels free
@@ -47,7 +40,7 @@ Modern Next.js 14 web application for the Ethio-Djibouti Railway passenger booki
### Prerequisites
- Node.js >= 20.x
- pnpm >= 9.x
- EDR Passenger API running on port 4000
- EDR Passenger API running on port 3002
### Installation
@@ -59,7 +52,7 @@ pnpm install
cp .env.example .env.local
# Update .env.local with API URL
NEXT_PUBLIC_API_URL=http://localhost:4000
NEXT_PUBLIC_API_URL=http://localhost:3002
```
### Development
@@ -86,13 +79,6 @@ pnpm start
```
src/
├── app/ # Next.js App Router pages
│ ├── (dashboard)/ # Dashboard route group
│ │ ├── dashboard/ # Overview page
│ │ ├── tickets/ # Ticket management
│ │ ├── schedules/ # Schedule views
│ │ ├── stations/ # Station directory
│ │ ├── passengers/ # Passenger management
│ │ └── layout.tsx # Dashboard layout wrapper
│ ├── booking/
│ │ ├── search/ # Search trains
│ │ ├── results/ # Search results
@@ -103,33 +89,19 @@ src/
│ │ ├── payment/ # Payment processing
│ │ └── confirmation/ # Booking confirmation
│ ├── login/ # Login page
│ ├── profile/ # User profile
│ ├── guide/ # Travel guide
│ ├── layout.tsx # Root layout
│ ├── page.tsx # Home (redirects to dashboard)
│ ├── providers.tsx # React Query + Theme provider
│ ├── page.tsx # Home (redirects to search)
│ ├── providers.tsx # React Query provider
│ └── globals.css # Global styles
├── components/ # Reusable components
│ ├── schedules/ # Schedule components
│ ├── tickets/ # Ticket components
│ ├── seats/ # Seat selector
│ ├── AppHeader.tsx # Navigation header
│ └── ThemeProvider.tsx # Theme context
├── lib/ # Core utilities
│ ├── api-client.ts # Axios client with interceptors
│ ├── auth-store.ts # Auth state (Zustand)
│ ├── booking-store.ts # Booking flow state (Zustand)
│ └── payment-store.ts # Payment state (Zustand)
├── hooks/ # Custom React hooks
── useSchedules.ts # Schedule queries
│ ├── useStations.ts # Station queries
│ └── useTickets.ts # Ticket queries
├── services/ # API service layer
│ ├── schedules.service.ts
│ ├── stations.service.ts
│ └── tickets.service.ts
└── types/ # TypeScript types
└── index.ts
├── types/ # TypeScript types
── index.ts
└── hooks/ # Custom React hooks
```
## State Management

View File

@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>EDR Passenger Portal</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

View File

@@ -2,10 +2,6 @@
const nextConfig = {
reactStrictMode: true,
transpilePackages: ['@edr/types', '@edr/ui-common'],
output: 'standalone',
experimental: {
cpus: 1,
},
};
export default nextConfig;

View File

@@ -0,0 +1,53 @@
import {
useNavigate,
useLocation,
Routes,
Route,
Navigate,
} from "react-router-dom";
import { DashboardLayout, type SidebarItem } from "@edr/ui-common";
import TicketsPage from "./pages/tickets/TicketsPage";
import TicketDetailPage from "./pages/tickets/TicketDetailPage";
import BookTicketPage from "./pages/tickets/BookTicketPage";
import SchedulesPage from "./pages/schedules/SchedulesPage";
import ScheduleDetailPage from "./pages/schedules/ScheduleDetailPage";
import StationsPage from "./pages/stations/StationsPage";
import PassengersPage from "./pages/passengers/PassengersPage";
import DashboardPage from "./pages/dashboard/DashboardPage";
const sidebarItems: SidebarItem[] = [
{ label: "Dashboard", href: "/" },
{ label: "Tickets", href: "/tickets" },
{ label: "Schedules", href: "/schedules" },
{ label: "Stations", href: "/stations" },
{ label: "Passengers", href: "/passengers" },
];
const App = () => {
const navigate = useNavigate();
const location = useLocation();
return (
<DashboardLayout
title="EDR Passenger"
sidebarItems={sidebarItems}
activeHref={location.pathname}
onNavigate={navigate}
>
<Routes>
<Route path="/" element={<DashboardPage />} />
<Route path="/tickets" element={<TicketsPage />} />
<Route path="/tickets/new" element={<BookTicketPage />} />
<Route path="/tickets/:id" element={<TicketDetailPage />} />
<Route path="/schedules" element={<SchedulesPage />} />
<Route path="/schedules/:id" element={<ScheduleDetailPage />} />
<Route path="/stations" element={<StationsPage />} />
<Route path="/passengers" element={<PassengersPage />} />
<Route path="*" element={<Navigate to="/" replace />} />
</Routes>
</DashboardLayout>
);
};
export default App;

View File

@@ -9,8 +9,6 @@ import { CheckCircle, Download, Share2, Copy, Printer, Mail, Train } from 'lucid
import { QRCodeSVG } from 'qrcode.react';
import { format } from 'date-fns';
export const dynamic = 'force-dynamic';
export default function ConfirmationPage() {
const router = useRouter();
const { bookingId, pnr, selectedSchedule, passengers, clearBooking } = useBookingStore();
@@ -20,7 +18,7 @@ export default function ConfirmationPage() {
mutationFn: () => apiClient.patch(`/bookings/${bookingId}/confirm`, { status: 'SUCCEEDED' }),
});
useQuery({
const { data: booking } = useQuery({
queryKey: ['booking', bookingId],
queryFn: async () => {
try {
@@ -43,8 +41,7 @@ export default function ConfirmationPage() {
if (bookingId && !confirmMutation.isSuccess && !confirmMutation.isPending) {
confirmMutation.mutate();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [bookingId, confirmMutation]);
}, [bookingId]);
const copyPNR = () => {
if (pnr) {

View File

@@ -3,8 +3,6 @@
import { usePathname } from 'next/navigation';
import { ProgressIndicator } from '@/components/ProgressIndicator';
export const dynamic = 'force-dynamic';
export default function BookingLayout({
children,
}: {

View File

@@ -10,8 +10,6 @@ import { apiClient } from '@/lib/api-client';
import { useState, useEffect } from 'react';
import { CheckCircle, ExternalLink, Loader2 } from 'lucide-react';
export const dynamic = 'force-dynamic';
const passengerSchema = z.object({
name: z.string().min(2, 'Name is required'),
dateOfBirth: z.string().min(1, 'Date of birth is required'),
@@ -50,7 +48,7 @@ type FormData = z.infer<typeof formSchema>;
export default function PassengersPage() {
const router = useRouter();
const { searchCriteria, setPassengers, setCreateAccount } = useBookingStore();
const { user, isAuthenticated, updateUser } = useAuthStore();
const { user, isAuthenticated, logout, updateUser } = useAuthStore();
const [faydaEnabled, setFaydaEnabled] = useState(true);
const [verificationStatus, setVerificationStatus] = useState<Record<number, 'success' | 'error'>>({});
const [updatingUser, setUpdatingUser] = useState(false);
@@ -61,7 +59,7 @@ export default function PassengersPage() {
const { register, control, handleSubmit, setValue, watch, formState: { errors } } = useForm<FormData>({
resolver: zodResolver(formSchema),
defaultValues: {
passengers: Array.from({ length: totalPassengers }, () => ({
passengers: Array.from({ length: totalPassengers }, (_, i) => ({
name: '',
dateOfBirth: '',
gender: undefined,

View File

@@ -9,8 +9,6 @@ import { ArrowRight, Clock, Calendar, Users, ChevronLeft, Loader2, Check, Chevro
import { format } from 'date-fns';
import { useState } from 'react';
export const dynamic = 'force-dynamic';
export default function ResultsPage() {
const router = useRouter();
const searchParams = useSearchParams();
@@ -41,11 +39,11 @@ export default function ResultsPage() {
const { data: results, isLoading, error } = useQuery<Schedule[]>({
queryKey: ['search', searchData],
queryFn: async (): Promise<Schedule[]> => {
queryFn: async () => {
console.log('Searching with criteria:', searchData);
const response = await apiClient.post('/search', searchData) as Schedule[];
const response = await apiClient.post('/search', searchData);
console.log('Search results:', response);
console.log('Number of results:', Array.isArray(response) ? response.length : 0);
console.log('Number of results:', response?.length || 0);
return response;
},
enabled: !!searchData.originStationId && !!searchData.destinationStationId,
@@ -92,8 +90,8 @@ export default function ResultsPage() {
trainNumber: schedule.trainNumber,
origin: schedule.origin?.name || 'Origin',
destination: schedule.destination?.name || 'Destination',
departureTime: schedule.departureAt || schedule.departureTime || '',
arrivalTime: schedule.arrivalAt || schedule.arrivalTime || '',
departureTime: schedule.departureAt || schedule.departureTime,
arrivalTime: schedule.arrivalAt || schedule.arrivalTime,
duration: durationStr,
baseFareAdult: selectedClassFare.baseFareMinor,
baseFareChild: selectedClassFare.baseFareMinor,
@@ -142,7 +140,7 @@ export default function ResultsPage() {
</div>
<h2 className="text-2xl font-bold mb-3 text-gray-900 dark:text-gray-100">No Trains Found</h2>
<p className="text-gray-600 dark:text-gray-400 mb-8">
We couldn&apos;t find any trains matching your search criteria. Try adjusting your dates or route.
We couldn't find any trains matching your search criteria. Try adjusting your dates or route.
</p>
<button onClick={() => router.push(buildSearchUrl())} className="btn-primary">
Modify Search

View File

@@ -209,9 +209,9 @@ export default function ReviewPage() {
const baseFare = passengers.reduce((sum, p, i) => {
// Get the fare per passenger from the schedule
const farePerPassenger = selectedSchedule.baseFareAdult ||
(selectedSchedule as any).baseFare ||
(selectedSchedule as any).fareAdult ||
(selectedSchedule as any).price ||
selectedSchedule.baseFare ||
selectedSchedule.fareAdult ||
selectedSchedule.price ||
0;
console.log(`Passenger ${i}: ${p.name}, fare = ${farePerPassenger}`);

View File

@@ -8,12 +8,10 @@ import { useQuery } from '@tanstack/react-query';
import { apiClient } from '@/lib/api-client';
import { useBookingStore } from '@/lib/booking-store';
import { Station } from '@/types';
import { Train, MapPin, Calendar, ArrowRight, ArrowLeftRight, Plus, Minus, Search } from 'lucide-react';
import { Train, MapPin, Calendar, Users, ArrowRight, ArrowLeftRight, Plus, Minus, Search } from 'lucide-react';
import { useEffect } from 'react';
import ModernDatePicker from '@/components/ModernDatePicker';
export const dynamic = 'force-dynamic';
const searchSchema = z.object({
originStationId: z.string().min(1, 'Please select origin station'),
destinationStationId: z.string().min(1, 'Please select destination station'),
@@ -35,8 +33,8 @@ export default function SearchPage() {
const { data: stations, isLoading, error } = useQuery<Station[]>({
queryKey: ['stations'],
queryFn: async (): Promise<Station[]> => {
const response = await apiClient.get('/stations') as Station[];
queryFn: async () => {
const response = await apiClient.get('/stations');
return response;
},
});
@@ -96,10 +94,10 @@ export default function SearchPage() {
};
const getStationByName = (name: string) => {
if (!stations || !Array.isArray(stations)) return null;
const exactMatch = stations.find((s: Station) => s.name.toLowerCase() === name.toLowerCase());
if (!stations) return null;
const exactMatch = stations.find(s => s.name.toLowerCase() === name.toLowerCase());
if (exactMatch) return exactMatch;
return stations.find((s: Station) => s.name.toLowerCase().includes(name.toLowerCase()));
return stations.find(s => s.name.toLowerCase().includes(name.toLowerCase()));
};
const handlePopularRoute = (fromName: string, toName: string) => {
@@ -157,7 +155,7 @@ export default function SearchPage() {
disabled={isLoading}
>
<option value="">Select departure station</option>
{Array.isArray(stations) && stations.map((s: Station) => (
{stations?.map((s) => (
<option key={s.id} value={s.id}>{s.name}</option>
))}
</select>
@@ -186,7 +184,7 @@ export default function SearchPage() {
disabled={isLoading}
>
<option value="">Select arrival station</option>
{Array.isArray(stations) && stations.map((s: Station) => (
{stations?.map((s) => (
<option key={s.id} value={s.id} disabled={s.id === originId}>{s.name}</option>
))}
</select>

View File

@@ -4,16 +4,16 @@ import { useRouter } from 'next/navigation';
import { useBookingStore } from '@/lib/booking-store';
import { useQuery, useMutation } from '@tanstack/react-query';
import { apiClient } from '@/lib/api-client';
import { useState, useEffect, useMemo } from 'react';
import { useState, useEffect } from 'react';
import { Seat, Coach } from '@/types';
import CustomModal from '@/components/CustomModal';
export const dynamic = 'force-dynamic';
export default function SeatsPage() {
const router = useRouter();
const { selectedSchedule, passengers, setSeatHold, setPassengers, searchCriteria } = useBookingStore();
const [selectedSeats, setSelectedSeats] = useState<string[]>([]);
const [selectedCoach, setSelectedCoach] = useState<string | null>(null);
const [timeLeft, setTimeLeft] = useState<number | null>(null);
const [modalState, setModalState] = useState({
isOpen: false,
title: '',
@@ -32,14 +32,14 @@ export default function SeatsPage() {
if (seatMapData) {
console.log('Seat map data:', seatMapData);
console.log('Is array?', Array.isArray(seatMapData));
console.log('Has coaches?', (seatMapData as any)?.coaches);
console.log('Has coaches?', seatMapData?.coaches);
}
}, [seatMapData]);
const holdMutation = useMutation({
mutationFn: async (seatIds: string[]) => {
// Create temporary passenger IDs for the hold
const passengersForHold = passengers.slice(0, seatIds.length).map((_, i) => ({
const passengersForHold = passengers.slice(0, seatIds.length).map((p, i) => ({
passengerId: `temp-${Date.now()}-${i}`, // Temporary ID for guest booking
seatId: seatIds[i],
}));
@@ -60,7 +60,7 @@ export default function SeatsPage() {
});
// Extract coaches and seats from seat map data
const coaches = useMemo(() => (seatMapData as any)?.coaches || [], [seatMapData]);
const coaches = seatMapData?.coaches || [];
// Debug: Log coaches
useEffect(() => {
@@ -78,11 +78,10 @@ export default function SeatsPage() {
? coaches.filter((c: any) => {
// seatClass can be either a string or an object with a name property
const seatClassName = typeof c.seatClass === 'string' ? c.seatClass : (c.seatClass?.name || c.coachClass || '');
const selectedClass = selectedSchedule.selectedSeatClass || '';
console.log('Comparing:', seatClassName, 'with', selectedClass);
return seatClassName === selectedClass ||
seatClassName.replace(/_/g, ' ').toLowerCase() === selectedClass.toLowerCase() ||
seatClassName.toLowerCase() === selectedClass.toLowerCase();
console.log('Comparing:', seatClassName, 'with', selectedSchedule.selectedSeatClass);
return seatClassName === selectedSchedule.selectedSeatClass ||
seatClassName.replace(/_/g, ' ').toLowerCase() === selectedSchedule.selectedSeatClass.toLowerCase() ||
seatClassName.toLowerCase() === selectedSchedule.selectedSeatClass.toLowerCase();
})
: coaches;
@@ -93,7 +92,7 @@ export default function SeatsPage() {
}, [filteredCoaches]);
const selectedCoachData = filteredCoaches.find((c: any) => c.id === selectedCoach);
const seats = useMemo(() => selectedCoachData?.seats || [], [selectedCoachData]);
const seats = selectedCoachData?.seats || [];
// Debug seats
useEffect(() => {

View File

@@ -95,7 +95,7 @@ export default function HowToGuidePage() {
<div className="bg-gray-50 dark:bg-gray-800 p-4 rounded-lg space-y-3">
<div>
<p className="text-sm font-semibold text-gray-900 dark:text-gray-100 mb-1">For Ethiopian Citizens:</p>
<p className="text-sm text-gray-700 dark:text-gray-300">Click &quot;Verify with Fayda&quot; to auto-fill your details using your national ID.</p>
<p className="text-sm text-gray-700 dark:text-gray-300">Click "Verify with Fayda" to auto-fill your details using your national ID.</p>
</div>
<div>
<p className="text-sm font-semibold text-gray-900 dark:text-gray-100 mb-1">For International Travelers:</p>

View File

@@ -9,8 +9,6 @@ import { useBookingStore } from '@/lib/booking-store';
import { useState } from 'react';
import { Train } from 'lucide-react';
export const dynamic = 'force-dynamic';
const loginSchema = z.object({
email: z.string().email('Invalid email address'),
password: z.string().min(6, 'Password must be at least 6 characters'),

View File

@@ -5,9 +5,9 @@ import { useRouter } from 'next/navigation';
import { useAuthStore } from '@/lib/auth-store';
import { useTheme } from '@/components/ThemeProvider';
import {
User, Settings, Ticket, Calendar, MapPin,
Download, Trash2, Lock, Bell, CreditCard,
MapPinned, Palette, CheckCircle,
User, Settings, Ticket, ChevronRight, Calendar, MapPin,
Download, Trash2, Lock, Bell, CreditCard, Globe,
MapPinned, Palette, CheckCircle, XCircle, Clock,
Eye, Edit, LogOut, X
} from 'lucide-react';
import { apiClient } from '@/lib/api-client';
@@ -84,11 +84,11 @@ export default function ProfilePage() {
}
}, [isInitialized, isAuthenticated, user, router, fetchProfile]);
const { data: bookings, isLoading: loadingBookings } = useQuery<Booking[]>({
const { data: bookings, isLoading: loadingBookings } = useQuery({
queryKey: ['user-bookings'],
queryFn: async (): Promise<Booking[]> => {
queryFn: async () => {
try {
return await apiClient.get('/bookings/my-bookings') as Booking[];
return await apiClient.get('/bookings/my-bookings');
} catch {
return [];
}
@@ -98,7 +98,7 @@ export default function ProfilePage() {
const updateProfileMutation = useMutation({
mutationFn: (data: any) => apiClient.patch('/auth/profile', data),
onSuccess: (response: any) => {
onSuccess: (response) => {
const updatedData = response.data || response;
updateUser(updatedData);
setShowEditProfile(false);
@@ -143,7 +143,7 @@ export default function ProfilePage() {
const downloadDataMutation = useMutation({
mutationFn: () => apiClient.get('/auth/download-data'),
onSuccess: (data: any) => {
onSuccess: (data) => {
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');

View File

@@ -1,13 +1,15 @@
'use client';
import { Train, User, BookOpen, LogIn } from 'lucide-react';
import { Train, LogOut, User, BookOpen, LogIn } from 'lucide-react';
import ThemeToggle from './ThemeToggle';
import Link from 'next/link';
import { useAuthStore } from '@/lib/auth-store';
import { useRouter } from 'next/navigation';
import { useEffect } from 'react';
export default function AppHeader() {
const { user, isAuthenticated, initialize } = useAuthStore();
const router = useRouter();
useEffect(() => {
initialize();

View File

@@ -29,7 +29,7 @@ export default function DualCalendarPicker({
}: DualCalendarPickerProps) {
const [isOpen, setIsOpen] = useState(false);
const [calendarType, setCalendarType] = useState<'gregorian' | 'ethiopian'>('gregorian');
const [, setCurrentDate] = useState(value || new Date());
const [currentDate, setCurrentDate] = useState(value || new Date());
const [viewMonth, setViewMonth] = useState(value?.getMonth() || new Date().getMonth());
const [viewYear, setViewYear] = useState(value?.getFullYear() || new Date().getFullYear());

View File

@@ -1,19 +1,11 @@
import type { Passenger } from "@edr/types";
import { Table, type TableColumn } from "@edr/ui-common";
interface ISchedule {
id: string;
trainCode: string;
status: string;
departureTime: string;
arrivalTime: string;
basePrice: number;
}
export interface ScheduleTableProps {
schedules: ISchedule[];
schedules: Passenger.ISchedule[];
}
const columns: TableColumn<ISchedule>[] = [
const columns: TableColumn<Passenger.ISchedule>[] = [
{ key: "trainCode", header: "Train" },
{ key: "status", header: "Status" },
{

View File

@@ -99,7 +99,7 @@ export function ethiopianToGregorian(ethDate: EthiopianDate): Date {
/**
* Get day of year from date (1-366)
*/
export function getDayOfYear(date: Date): number {
function getDayOfYear(date: Date): number {
const start = new Date(date.getFullYear(), 0, 0);
const diff = date.getTime() - start.getTime();
const oneDay = 1000 * 60 * 60 * 24;
@@ -109,7 +109,7 @@ export function getDayOfYear(date: Date): number {
/**
* Convert day of year to Date object
*/
export function dayOfYearToDate(year: number, dayOfYear: number): Date {
function dayOfYearToDate(year: number, dayOfYear: number): Date {
const date = new Date(year, 0);
date.setDate(dayOfYear);
return date;

View File

@@ -0,0 +1,18 @@
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { BrowserRouter } from "react-router-dom";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import App from "./App";
const queryClient = new QueryClient();
createRoot(document.getElementById("root")!).render(
<StrictMode>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<App />
</BrowserRouter>
</QueryClientProvider>
</StrictMode>,
);

View File

@@ -0,0 +1,13 @@
const DashboardPage = () => (
<div className="flex flex-col gap-4">
<h1 className="text-2xl font-semibold text-gray-900">
Passenger Dashboard
</h1>
<p className="text-sm text-gray-600">
Daily ridership, ticket sales, occupancy by class, and schedule status go
here.
</p>
</div>
);
export default DashboardPage;

View File

@@ -0,0 +1,10 @@
const PassengersPage = () => (
<div className="flex flex-col gap-4">
<h1 className="text-2xl font-semibold text-gray-900">Passengers</h1>
<p className="text-sm text-gray-600">
Passenger directory. Connect to <code>/passengers</code> when ready.
</p>
</div>
);
export default PassengersPage;

View File

@@ -0,0 +1,36 @@
import { useParams } from "react-router-dom";
import { useSchedule } from "@/hooks/useSchedules";
const ScheduleDetailPage = () => {
const { id } = useParams<{ id: string }>();
const { data, isLoading } = useSchedule(id ?? "");
if (isLoading) return <div className="text-sm text-gray-500">Loading</div>;
if (!data)
return <div className="text-sm text-red-600">Schedule not found.</div>;
return (
<div className="flex flex-col gap-3">
<h1 className="text-2xl font-semibold text-gray-900">
Schedule {data.trainCode}
</h1>
<dl className="grid grid-cols-2 gap-2 text-sm">
<dt className="text-gray-500">Status</dt>
<dd className="text-gray-900">{data.status}</dd>
<dt className="text-gray-500">Departure</dt>
<dd className="text-gray-900">
{new Date(data.departureTime).toLocaleString()}
</dd>
<dt className="text-gray-500">Arrival</dt>
<dd className="text-gray-900">
{new Date(data.arrivalTime).toLocaleString()}
</dd>
<dt className="text-gray-500">Base price</dt>
<dd className="text-gray-900">{data.basePrice.toFixed(2)}</dd>
</dl>
</div>
);
};
export default ScheduleDetailPage;

View File

@@ -0,0 +1,20 @@
import ScheduleTable from "../../components/schedules/ScheduleTable";
import { useSchedules } from "../../hooks/useSchedules";
const SchedulesPage = () => {
const { data, isLoading } = useSchedules();
const items = data ?? [];
return (
<div className="flex flex-col gap-4">
<h1 className="text-2xl font-semibold text-gray-900">Schedules</h1>
{isLoading ? (
<div className="text-sm text-gray-500">Loading</div>
) : (
<ScheduleTable schedules={items} />
)}
</div>
);
};
export default SchedulesPage;

View File

@@ -0,0 +1,32 @@
import { Table, type TableColumn } from "@edr/ui-common";
import type { Passenger } from "@edr/types";
import { useStations } from "../../hooks/useStations";
const columns: TableColumn<Passenger.IStation>[] = [
{ key: "code", header: "Code" },
{ key: "name", header: "Name" },
{ key: "city", header: "City" },
{ key: "country", header: "Country" },
];
const StationsPage = () => {
const { data, isLoading } = useStations();
return (
<div className="flex flex-col gap-4">
<h1 className="text-2xl font-semibold text-gray-900">Stations</h1>
{isLoading ? (
<div className="text-sm text-gray-500">Loading</div>
) : (
<Table
columns={columns}
data={data ?? []}
rowKey={(row) => row.id}
emptyMessage="No stations"
/>
)}
</div>
);
};
export default StationsPage;

View File

@@ -0,0 +1,32 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { useNavigate } from "react-router-dom";
import TicketForm from "../../components/tickets/TicketForm";
import { ticketsService } from "../../services/tickets.service";
const BookTicketPage = () => {
const navigate = useNavigate();
const queryClient = useQueryClient();
const mutation = useMutation({
mutationFn: ticketsService.create,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["tickets"] });
navigate("/tickets");
},
});
return (
<div className="max-w-lg">
<h1 className="mb-4 text-2xl font-semibold text-gray-900">
Issue ticket
</h1>
<TicketForm
onSubmit={mutation.mutate}
isSubmitting={mutation.isPending}
/>
</div>
);
};
export default BookTicketPage;

View File

@@ -0,0 +1,38 @@
import { useParams } from "react-router-dom";
import { useTicket } from "../../hooks/useTickets";
const TicketDetailPage = () => {
const { id } = useParams<{ id: string }>();
const { data, isLoading } = useTicket(id ?? "");
if (isLoading) return <div className="text-sm text-gray-500">Loading</div>;
if (!data)
return <div className="text-sm text-red-600">Ticket not found.</div>;
return (
<div className="flex flex-col gap-3">
<h1 className="text-2xl font-semibold text-gray-900">
Ticket {data.reference}
</h1>
<dl className="grid grid-cols-2 gap-2 text-sm">
<dt className="text-gray-500">Passenger ID</dt>
<dd className="text-gray-900">{data.passengerId}</dd>
<dt className="text-gray-500">Schedule ID</dt>
<dd className="text-gray-900">{data.scheduleId}</dd>
<dt className="text-gray-500">Seat ID</dt>
<dd className="text-gray-900">{data.seatId}</dd>
<dt className="text-gray-500">Status</dt>
<dd className="text-gray-900">{data.status}</dd>
<dt className="text-gray-500">Issued</dt>
<dd className="text-gray-900">
{new Date(data.issuedAt).toLocaleString()}
</dd>
<dt className="text-gray-500">Price paid</dt>
<dd className="text-gray-900">{data.pricePaid.toFixed(2)}</dd>
</dl>
</div>
);
};
export default TicketDetailPage;

View File

@@ -0,0 +1,28 @@
import { Link } from "react-router-dom";
import { Button } from "@edr/ui-common";
import TicketTable from "../../components/tickets/TicketTable";
import { useTickets } from "../../hooks/useTickets";
const TicketsPage = () => {
const { data, isLoading } = useTickets();
const items = data?.items ?? [];
return (
<div className="flex flex-col gap-4">
<div className="flex items-center justify-between">
<h1 className="text-2xl font-semibold text-gray-900">Tickets</h1>
<Link to="/tickets/new">
<Button>Issue ticket</Button>
</Link>
</div>
{isLoading ? (
<div className="text-sm text-gray-500">Loading</div>
) : (
<TicketTable tickets={items} />
)}
</div>
);
};
export default TicketsPage;

View File

@@ -1,7 +1,7 @@
import axios from "axios";
export const api = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4000',
baseURL: import.meta.env.VITE_API_URL,
});
// TODO: integrate @edr/auth — add a request interceptor here that attaches

View File

@@ -0,0 +1,9 @@
/// <reference types="vite/client" />
interface ImportMetaEnv {
readonly VITE_API_URL: string;
}
interface ImportMeta {
readonly env: ImportMetaEnv;
}

View File

@@ -0,0 +1,9 @@
{
"extends": "@edr/tsconfig/react.json",
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"useDefineForClassFields": true,
"skipLibCheck": true
},
"include": ["src"]
}

View File

@@ -0,0 +1,14 @@
{
"extends": "@edr/tsconfig/base.json",
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2022",
"lib": ["ES2023"],
"module": "ESNext",
"moduleResolution": "Bundler",
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"noEmit": true
},
"include": ["vite.config.ts"]
}

View File

@@ -0,0 +1,14 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
export default defineConfig({
plugins: [react()],
server: {
port: 5174,
host: "0.0.0.0",
},
// test: {
// environment: "jsdom",
// globals: true,
// },
});

2
pnpm-lock.yaml generated
View File

@@ -222,7 +222,7 @@ importers:
version: 11.1.0(chokidar@4.0.3)(prettier@3.8.3)(typescript@5.9.3)
'@nestjs/testing':
specifier: ^11.1.19
version: 11.1.23(@nestjs/common@11.1.23(class-transformer@0.5.1)(class-validator@0.14.4)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.23)(@nestjs/platform-express@11.1.23)
version: 11.1.23(@nestjs/common@11.1.23(class-transformer@0.5.1)(class-validator@0.14.4)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.23)(@nestjs/microservices@11.1.24)(@nestjs/platform-express@11.1.23)
'@types/bcrypt':
specifier: ^5.0.2
version: 5.0.2