Full React + MUI + TypeScript SPA at frontend/: - API client with typed interfaces for all endpoints - AuthContext (session cookies, dev impersonation) - OrgContext (org list, active org switcher) - Money formatting (cents → display, satoshis → BCH) App shell: - Sidebar navigation with collapsible Ledgers and Financial sections - Top bar with org switcher, language selector (EN/SV/DE), user chip - Material UI theme with Inter font Live data pages (connected to real migrated production data): - Dashboard: YTD P&L cards, pending tasks, quick links - Balance Sheet: date picker, assets/debts tables with totals - Profit & Loss: year selector, income/costs breakdown, net result - Chart of Accounts: grouped by type with status chips - Crypto Treasury: total balance, address table with BCH amounts - Expense Claims: list with amounts, VAT, status chips Placeholder pages for: Inspect Ledgers, Budget vs Actual, Inbound/ Outbound Invoices, Payouts, End of Month, Org Settings, User Management Vite dev server proxies /api to ASP.NET Core backend on port 5222. Made-with: Cursor
58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
import { createContext, useContext, useState, useEffect, type ReactNode } from 'react'
|
|
import { api } from '../api/client'
|
|
|
|
interface AuthState {
|
|
userId: number
|
|
name: string
|
|
email: string
|
|
preferredCulture: string
|
|
lastOrgId: number
|
|
}
|
|
|
|
interface AuthContextType {
|
|
user: AuthState | null
|
|
loading: boolean
|
|
login: (email: string, password: string) => Promise<void>
|
|
logout: () => Promise<void>
|
|
devImpersonate: () => Promise<void>
|
|
}
|
|
|
|
const AuthContext = createContext<AuthContextType>(null!)
|
|
|
|
export function AuthProvider({ children }: { children: ReactNode }) {
|
|
const [user, setUser] = useState<AuthState | null>(null)
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
useEffect(() => {
|
|
api.auth.me()
|
|
.then(setUser)
|
|
.catch(() => setUser(null))
|
|
.finally(() => setLoading(false))
|
|
}, [])
|
|
|
|
const login = async (email: string, password: string) => {
|
|
await api.auth.login(email, password)
|
|
const me = await api.auth.me()
|
|
setUser(me)
|
|
}
|
|
|
|
const logout = async () => {
|
|
await api.auth.logout()
|
|
setUser(null)
|
|
}
|
|
|
|
const devImpersonate = async () => {
|
|
await api.dev.impersonate()
|
|
const me = await api.auth.me()
|
|
setUser(me)
|
|
}
|
|
|
|
return (
|
|
<AuthContext.Provider value={{ user, loading, login, logout, devImpersonate }}>
|
|
{children}
|
|
</AuthContext.Provider>
|
|
)
|
|
}
|
|
|
|
export const useAuth = () => useContext(AuthContext)
|