mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage
synced 2026-04-11 18:28:15 +00:00
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:
68
src/providers/auth-provider.tsx
Normal file
68
src/providers/auth-provider.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
52
src/providers/data-provider.tsx
Normal file
52
src/providers/data-provider.tsx
Normal file
@@ -0,0 +1,52 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { createContext, useContext, useState } from 'react';
|
||||
|
||||
import type { Lead, Campaign, Ad, LeadActivity, FollowUp, WhatsAppTemplate, Agent } from '@/types/entities';
|
||||
import { mockLeads, mockCampaigns, mockAds, mockFollowUps, mockLeadActivities, mockTemplates, mockAgents } from '@/mocks';
|
||||
|
||||
type DataContextType = {
|
||||
leads: Lead[];
|
||||
campaigns: Campaign[];
|
||||
ads: Ad[];
|
||||
followUps: FollowUp[];
|
||||
leadActivities: LeadActivity[];
|
||||
templates: WhatsAppTemplate[];
|
||||
agents: Agent[];
|
||||
updateLead: (id: string, updates: Partial<Lead>) => void;
|
||||
};
|
||||
|
||||
const DataContext = createContext<DataContextType | undefined>(undefined);
|
||||
|
||||
export const useData = (): DataContextType => {
|
||||
const context = useContext(DataContext);
|
||||
|
||||
if (context === undefined) {
|
||||
throw new Error('useData must be used within a DataProvider');
|
||||
}
|
||||
|
||||
return context;
|
||||
};
|
||||
|
||||
interface DataProviderProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export const DataProvider = ({ children }: DataProviderProps) => {
|
||||
const [leads, setLeads] = useState<Lead[]>(mockLeads);
|
||||
const [campaigns] = useState<Campaign[]>(mockCampaigns);
|
||||
const [ads] = useState<Ad[]>(mockAds);
|
||||
const [followUps] = useState<FollowUp[]>(mockFollowUps);
|
||||
const [leadActivities] = useState<LeadActivity[]>(mockLeadActivities);
|
||||
const [templates] = useState<WhatsAppTemplate[]>(mockTemplates);
|
||||
const [agents] = useState<Agent[]>(mockAgents);
|
||||
|
||||
const updateLead = (id: string, updates: Partial<Lead>) => {
|
||||
setLeads((prev) => prev.map((lead) => (lead.id === id ? { ...lead, ...updates } : lead)));
|
||||
};
|
||||
|
||||
return (
|
||||
<DataContext.Provider value={{ leads, campaigns, ads, followUps, leadActivities, templates, agents, updateLead }}>
|
||||
{children}
|
||||
</DataContext.Provider>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user