Connect frontend to real API — rooms, bookings, housekeeping, calendar
- src/lib/api.ts: central API client with JWT auto-refresh, snake_case→camelCase transform - src/contexts/AuthContext.tsx: real login via POST /api/auth/login - src/pages/RoomsPage.tsx: load rooms from API, create/update via API - src/pages/BookingsPage.tsx: load bookings + rooms from API - src/pages/HousekeepingPage.tsx: load today's tasks from API, update status via API - src/pages/CalendarPage.tsx: load rooms + bookings from API - src/types/index.ts: fix HousekeepingTask.priority to match DB (medium/urgent) - backend/src/routes/rooms.ts: update to use new column names (max_guests, base_rate) + all new fields - backend/src/routes/bookings.ts: update price_per_night→base_rate, add paid_amount to PATCH - backend/migrations/003_fix_constraints.sql: fix rooms.status values, add paid_amount, inquiry status, other source - public/robots.txt + index.html: noindex for SPA inner pages Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { createContext, useContext, useState } from 'react'
|
||||
import type { User, AuthSession } from '../types'
|
||||
import { MOCK_USERS } from '../data/mockData'
|
||||
import { api, ApiError } from '../lib/api'
|
||||
|
||||
interface AuthContextValue {
|
||||
session: AuthSession | null
|
||||
@@ -17,18 +17,21 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
return stored ? JSON.parse(stored) : null
|
||||
})
|
||||
|
||||
const login = async (email: string, _password: string): Promise<User | null> => {
|
||||
// Mock authentication — in production, call POST /auth/login
|
||||
await new Promise(r => setTimeout(r, 800))
|
||||
const user = MOCK_USERS.find(u => u.email.toLowerCase() === email.toLowerCase())
|
||||
if (!user) return null
|
||||
const s: AuthSession = { user, token: 'mock-jwt-token-' + user.id }
|
||||
setSession(s)
|
||||
sessionStorage.setItem('hotelsync-session', JSON.stringify(s))
|
||||
return user
|
||||
const login = async (email: string, password: string): Promise<User | null> => {
|
||||
try {
|
||||
const { access_token, user } = await api.auth.login(email, password)
|
||||
const s: AuthSession = { user, token: access_token }
|
||||
setSession(s)
|
||||
sessionStorage.setItem('hotelsync-session', JSON.stringify(s))
|
||||
return user
|
||||
} catch (err) {
|
||||
if (err instanceof ApiError && err.status === 401) return null
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
const logout = () => {
|
||||
const logout = async () => {
|
||||
try { await api.auth.logout() } catch { /* ignore */ }
|
||||
setSession(null)
|
||||
sessionStorage.removeItem('hotelsync-session')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user