Skip to content

Commit 755d56c

Browse files
committed
fix: removed all reference to radix components
1 parent c9f3ef5 commit 755d56c

File tree

12 files changed

+511
-381
lines changed

12 files changed

+511
-381
lines changed

src/App.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ import MockNotification from './features/auth/components/MockNotification';
1616

1717
// Hooks and Utilities
1818
import { useEntries } from './features/statements/hooks/useEntries';
19+
import { useAuth } from './features/auth/api/hooks';
1920
import { handleMagicLinkVerification } from './features/auth/authUtils';
2021

2122
// Outer Component: Responsible only for setting up the environment (the providers) for the rest of the app.
2223
const AppContent: React.FC = () => {
2324
const { data } = useEntries();
25+
const { state: authState } = useAuth();
2426

2527
// Check for magic link tokens on app load
2628
useEffect(() => {
@@ -30,6 +32,17 @@ const AppContent: React.FC = () => {
3032

3133
verifyToken();
3234
}, []);
35+
36+
// Force synchronization between auth state and entries state when component mounts
37+
useEffect(() => {
38+
if (authState.user && authState.isAuthenticated) {
39+
console.log('AppContent: Found authenticated user, dispatching event:', authState.user);
40+
// Dispatch event to ensure EntriesProvider gets the user data
41+
window.dispatchEvent(new CustomEvent('authStateChanged', {
42+
detail: { user: authState.user }
43+
}));
44+
}
45+
}, [authState.user, authState.isAuthenticated]);
3346

3447
return (
3548
// MainPage and Header receives the username from context.

src/components/modals/UserDataModal.tsx

Lines changed: 208 additions & 209 deletions
Large diffs are not rendered by default.

src/components/ui/confirmation-dialog.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,26 @@ export function ConfirmationDialog({
2323
description,
2424
singleButton = false,
2525
}: ConfirmationDialogProps) {
26+
// Don't render anything if not open
27+
if (!isOpen) {
28+
return null;
29+
}
30+
2631
return (
27-
<Dialog open={isOpen} onOpenChange={onClose}>
28-
{/* Pass headerTitle so the shared DialogContent renders the pink header */}
29-
<DialogContent headerTitle={title} className='sm:max-w-md p-0'>
30-
{/* Optionally hide the description for screen readers */}
31-
<DialogDescription className='sr-only'>{description}</DialogDescription>
32+
<div className="fixed inset-0 z-50 flex items-center justify-center overflow-hidden bg-black/50">
33+
<div className="bg-white max-w-md rounded-lg shadow-lg overflow-hidden">
34+
{/* Header */}
35+
<div className="bg-brand-pink p-3 flex items-center">
36+
<h2 className="text-lg font-bold text-white">{title}</h2>
37+
</div>
38+
39+
{/* Body */}
3240
<div className='bg-gray-50 p-4'>
3341
<p className='text-sm text-gray-800'>{description}</p>
3442
</div>
35-
<DialogFooter className='p-4 bg-gray-50 sm:rounded-b-lg'>
43+
44+
{/* Footer */}
45+
<div className='p-4 bg-gray-50 flex justify-end space-x-2'>
3646
{singleButton ? (
3747
<Button variant='default' onClick={onConfirm} className="inline-flex items-center">
3848
<span>OK</span>
@@ -47,8 +57,8 @@ export function ConfirmationDialog({
4757
</Button>
4858
</>
4959
)}
50-
</DialogFooter>
51-
</DialogContent>
52-
</Dialog>
60+
</div>
61+
</div>
62+
</div>
5363
);
5464
}

src/components/ui/radix-compatibility.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useState, useEffect } from 'react';
22

33
// Import our simple components
44
import {
@@ -41,7 +41,16 @@ interface DialogRootProps {
4141

4242
// Create a Dialog Root that has the same API as Radix's
4343
const Dialog: React.FC<DialogRootProps> = ({ children, open, onOpenChange }) => {
44-
const [isOpen, setIsOpen] = useState(open || false);
44+
// IMPORTANT: Initialize isOpen to false by default
45+
const [isOpen, setIsOpen] = useState(open === true ? true : false);
46+
47+
// Add useEffect to update internal state when open prop changes
48+
useEffect(() => {
49+
// Only update when the prop explicitly changes to true or false (not undefined)
50+
if (open === true || open === false) {
51+
setIsOpen(open);
52+
}
53+
}, [open]);
4554

4655
const handleOpenChange = (newOpen: boolean) => {
4756
setIsOpen(newOpen);

src/components/ui/simple-dialog.tsx

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,33 @@ const SimpleDialogDescription: React.FC<SimpleDialogDescriptionProps> = ({ child
103103
);
104104
};
105105

106+
// Context for communicating between Dialog and DialogTrigger
107+
export const SimpleDialogContext = React.createContext<{
108+
isOpen: boolean;
109+
onOpenChange: (open: boolean) => void;
110+
}>({
111+
isOpen: false,
112+
onOpenChange: () => {},
113+
});
114+
106115
const SimpleDialogTrigger: React.FC<SimpleDialogTriggerProps> = ({ children }) => {
107-
return <>{children}</>;
116+
// Get the dialog context to control the dialog's open state
117+
const { onOpenChange } = React.useContext(SimpleDialogContext);
118+
119+
// Create a clickable wrapper that opens the dialog
120+
const handleClick = (e: React.MouseEvent) => {
121+
e.preventDefault();
122+
console.log('SimpleDialogTrigger: Opening dialog');
123+
onOpenChange(true);
124+
};
125+
126+
// If asChild is true, we'd clone the child element and add an onClick handler
127+
// For simplicity, we'll just wrap the children in a div with an onClick
128+
return (
129+
<div onClick={handleClick} style={{ display: 'inline-block', cursor: 'pointer' }}>
130+
{children}
131+
</div>
132+
);
108133
};
109134

110135
const SimpleDialog: React.FC<SimpleDialogProps> = ({
@@ -127,12 +152,21 @@ const SimpleDialog: React.FC<SimpleDialogProps> = ({
127152
return () => window.removeEventListener('keydown', onKeyDown);
128153
}, [isOpen, onOpenChange]);
129154

130-
if (!isOpen) return null;
155+
console.log('SimpleDialog rendering with isOpen:', isOpen);
131156

157+
// Provide the dialog state to all children via context
132158
return (
133-
<div className={cn('', className)}>
134-
{children}
135-
</div>
159+
<SimpleDialogContext.Provider value={{ isOpen, onOpenChange }}>
160+
{isOpen ? (
161+
<div className={cn('fixed inset-0 z-50', className)}>
162+
<SimpleDialogOverlay />
163+
{children}
164+
</div>
165+
) : (
166+
// Even when dialog is closed, we need to render the trigger
167+
<>{children}</>
168+
)}
169+
</SimpleDialogContext.Provider>
136170
);
137171
};
138172

src/features/auth/AuthProvider.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,14 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
6161
const { user, error } = await getCurrentUser();
6262

6363
if (user) {
64+
console.log('AuthProvider: User found during checkAuthStatus', user);
6465
dispatch({ type: 'AUTH_SUCCESS', payload: user });
66+
67+
// Dispatch a custom event for EntriesProvider to listen to
68+
window.dispatchEvent(new CustomEvent('authStateChanged', {
69+
detail: { user }
70+
}));
71+
console.log('AuthProvider: Dispatched authStateChanged event with user:', user);
6572
} else {
6673
dispatch({ type: 'AUTH_FAILURE', payload: error || 'No user found' });
6774
}
@@ -126,6 +133,12 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
126133

127134
if (result.success && result.user) {
128135
dispatch({ type: 'AUTH_SUCCESS', payload: result.user });
136+
137+
// Dispatch event for EntriesProvider
138+
window.dispatchEvent(new CustomEvent('authStateChanged', {
139+
detail: { user: result.user }
140+
}));
141+
129142
return { success: true };
130143
} else {
131144
dispatch({

src/features/auth/api/mockAuthService.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,14 @@ export const mockUpdateUserProfile = async (
220220
// Update the user's profile
221221
if (data.username !== undefined) {
222222
mockUsers[userEmail].username = data.username;
223+
console.log(`MockAuth: Updated username for ${userEmail} to:`, data.username);
223224
}
224225

225226
// If this is the current user, update the current session
226227
if (currentSession.user && currentSession.user.id === userId) {
227228
currentSession.user = { ...mockUsers[userEmail] };
228229
localStorage.setItem('mockAuthSession', JSON.stringify(currentSession.user));
230+
console.log('MockAuth: Updated current session with new profile data:', currentSession.user);
229231
}
230232

231233
// Save updated users to localStorage

0 commit comments

Comments
 (0)