Initial commit: HotelSync PMS v0.1.0

- React 18 + TypeScript + Vite + Tailwind CSS
- Шахматка бронирований (drag-to-book)
- Страницы: Calendar, Bookings, Rooms, Housekeeping, Channels, API Docs, Settings
- Роли: super_admin, hotel_manager, housekeeper
- Светлая/тёмная тема
- Docker + Nginx конфигурация
- Лендинг hotelsync.ru
This commit is contained in:
2026-03-10 20:38:32 +03:00
commit 420d55d57e
45 changed files with 7274 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
import { createContext, useContext, useState } from 'react'
import type { User, AuthSession } from '../types'
import { MOCK_USERS } from '../data/mockData'
interface AuthContextValue {
session: AuthSession | null
user: User | null
login: (email: string, password: string) => Promise<boolean>
logout: () => void
}
const AuthContext = createContext<AuthContextValue | null>(null)
export function AuthProvider({ children }: { children: React.ReactNode }) {
const [session, setSession] = useState<AuthSession | null>(() => {
const stored = sessionStorage.getItem('hotelsync-session')
return stored ? JSON.parse(stored) : null
})
const login = async (email: string, _password: string): Promise<boolean> => {
// 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 false
const s: AuthSession = { user, token: 'mock-jwt-token-' + user.id }
setSession(s)
sessionStorage.setItem('hotelsync-session', JSON.stringify(s))
return true
}
const logout = () => {
setSession(null)
sessionStorage.removeItem('hotelsync-session')
}
return (
<AuthContext.Provider value={{ session, user: session?.user ?? null, login, logout }}>
{children}
</AuthContext.Provider>
)
}
export function useAuth() {
const ctx = useContext(AuthContext)
if (!ctx) throw new Error('useAuth must be used within AuthProvider')
return ctx
}