feat: add auth and data providers with mock data hooks

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-16 14:34:23 +05:30
parent 15483c5542
commit dc68577477
5 changed files with 255 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
import type { ReactNode } from 'react';
import { createContext, useContext, useState } from 'react';
export type Role = 'executive' | 'admin';
type User = {
name: string;
initials: string;
role: Role;
email: string;
};
type AuthContextType = {
user: User;
setRole: (role: Role) => void;
isAdmin: boolean;
isAuthenticated: boolean;
login: () => void;
logout: () => void;
};
const USERS: Record<Role, User> = {
admin: {
name: 'Admin User',
initials: 'AU',
role: 'admin',
email: 'admin@ramaiah.com',
},
executive: {
name: 'Sanjay M.',
initials: 'SM',
role: 'executive',
email: 'sanjay@ramaiah.com',
},
};
const AuthContext = createContext<AuthContextType | undefined>(undefined);
export const useAuth = (): AuthContextType => {
const context = useContext(AuthContext);
if (context === undefined) {
throw new Error('useAuth must be used within an AuthProvider');
}
return context;
};
interface AuthProviderProps {
children: ReactNode;
}
export const AuthProvider = ({ children }: AuthProviderProps) => {
const [role, setRole] = useState<Role>('executive');
const [isAuthenticated, setIsAuthenticated] = useState(false);
const user = USERS[role];
const isAdmin = role === 'admin';
const login = () => setIsAuthenticated(true);
const logout = () => setIsAuthenticated(false);
return (
<AuthContext.Provider value={{ user, setRole, isAdmin, isAuthenticated, login, logout }}>
{children}
</AuthContext.Provider>
);
};