Skip to content

Commit eb1691a

Browse files
committed
Fix
1 parent 88a56cf commit eb1691a

File tree

3 files changed

+18
-33
lines changed

3 files changed

+18
-33
lines changed

frontend/app/signup/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ const styles = StyleSheet.create({
150150
flex: 1,
151151
backgroundColor: Colors.light.transparent,
152152
paddingHorizontal: 50,
153-
paddingTop: '20%',
153+
paddingTop: '35%',
154154
paddingBottom: 25,
155155
justifyContent: 'flex-start',
156156
},
@@ -159,8 +159,8 @@ const styles = StyleSheet.create({
159159
marginBottom: -20,
160160
},
161161
logo: {
162-
width: 225,
163-
height: 225,
162+
width: 260,
163+
height: 160,
164164
},
165165
header: {
166166
marginBottom: 24,

frontend/context/AuthContext.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,10 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
9393
}, []);
9494

9595
const fetchUserEntity = useCallback(async () => {
96-
if (!user?.entityId) return;
97-
98-
// only fetch volunteer for now
96+
// Fetch the current user's volunteer entity if it exists
9997
const volunteerResponse = await volunteerService.getSelf();
10098
setVolunteer(volunteerResponse);
101-
}, [user?.entityId]); // Keep this dependency
99+
}, []); // No need to depend on user.entityId
102100

103101
const signOut = useCallback(async () => {
104102
await userService.logout();
@@ -159,7 +157,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
159157
if (user?.entityId && !volunteer && token) {
160158
fetchUserEntity();
161159
}
162-
}, [user?.entityId, volunteer, token]);
160+
}, [user?.entityId, volunteer, token, fetchUserEntity]);
163161

164162
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
165163
}

frontend/hooks/useProfile.ts

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { useState, useEffect } from 'react';
22
import { Alert } from 'react-native';
3-
import { useAuth } from '@/context/AuthContext';
43
import { profileService } from '@/services/profileService';
54
import { ProfileData } from '@/types/api/profile';
65
import { Event } from '@/types/api/event';
76
import { Volunteer } from '@/types/api/volunteer';
87
import { useCurrentVolunteer } from '@/hooks/useCurrentVolunteer';
9-
import { useUpcomingEvents } from '@/hooks/useUpcomingEvents';
108

119
// TODO: abstract to backend asw
1210
function calculateTotalHours(completedEvents: Event[]): number {
@@ -20,49 +18,44 @@ function calculateTotalHours(completedEvents: Event[]): number {
2018
}
2119

2220
export function useProfile() {
23-
const { user } = useAuth();
2421
const {
2522
data: qVolunteer,
2623
isLoading: volunteerLoading,
2724
refetch: refetchVolunteer,
2825
} = useCurrentVolunteer();
29-
const { data: qUpcomingEvents, refetch: refetchUpcomingEvents } =
30-
useUpcomingEvents(user?.entityId);
3126
const [loading, setLoading] = useState(true);
3227
const [refreshing, setRefreshing] = useState(false);
3328
const [volunteer, setVolunteer] = useState<Volunteer | null>(null);
3429
const [upcomingEvents, setUpcomingEvents] = useState<Event[]>([]);
3530
const [profileData, setProfileData] = useState<ProfileData | null>(null);
3631

3732
const loadProfileData = async (isRefresh = false) => {
38-
if (!user?.entityId) {
39-
setLoading(false);
40-
return;
41-
}
4233
try {
4334
if (isRefresh) {
4435
setRefreshing(true);
4536
} else {
4637
setLoading(true);
4738
}
48-
// Ensure we have latest volunteer and upcoming events (React Query)
49-
const [vResult, uResult, pastEventsData] = await Promise.all([
50-
refetchVolunteer(),
51-
refetchUpcomingEvents(),
52-
profileService.getPastEvents(user.entityId),
53-
]);
39+
// Ensure we have latest volunteer
40+
const vResult = await refetchVolunteer();
5441

55-
const v = vResult.data ?? qVolunteer ?? null;
42+
const v: Volunteer | null = vResult.data ?? qVolunteer ?? null;
5643
setVolunteer(v);
57-
const upcoming = uResult.data ?? qUpcomingEvents ?? [];
58-
setUpcomingEvents(upcoming);
5944

6045
if (!v) {
46+
setUpcomingEvents([]);
6147
setProfileData(null);
6248
return;
6349
}
6450

65-
const levelProgress = await profileService.getLevelProgress();
51+
// Fetch upcoming and past events using the resolved volunteer id
52+
const [upcoming, pastEventsData, levelProgress] = await Promise.all([
53+
profileService.getUpcomingEvents(v.id),
54+
profileService.getPastEvents(v.id),
55+
profileService.getLevelProgress(),
56+
]);
57+
58+
setUpcomingEvents(upcoming);
6659
const totalHours = calculateTotalHours(pastEventsData);
6760

6861
const stats = {
@@ -92,22 +85,16 @@ export function useProfile() {
9285

9386
useEffect(() => {
9487
// When user or volunteer changes, rebuild profile
95-
if (!user?.entityId) {
96-
setLoading(false);
97-
return;
98-
}
9988
// If volunteer query is still loading, wait
10089
if (volunteerLoading) return;
10190
// Build with current data (events will be fetched)
10291
loadProfileData(false);
10392
// eslint-disable-next-line react-hooks/exhaustive-deps
10493
}, [
105-
user?.entityId,
10694
qVolunteer?.id,
10795
qVolunteer?.firstName,
10896
qVolunteer?.lastName,
10997
qVolunteer?.experience,
110-
qUpcomingEvents?.length,
11198
]);
11299

113100
return {

0 commit comments

Comments
 (0)