diff --git a/client-new/src/contexts/ProfileContext.tsx b/client-new/src/contexts/ProfileContext.tsx index 092d720..ff5a77a 100644 --- a/client-new/src/contexts/ProfileContext.tsx +++ b/client-new/src/contexts/ProfileContext.tsx @@ -140,12 +140,12 @@ export const ProfileProvider: React.FC = ({ const toggleOnboarding = useCallback(async (): Promise => { if (!profile) return; - try { + console.log('[profile context] toggle onboarding profile (prev)', profile) const profileRespnse = await updateOnboardingToComplete(profile.id); - setCompletedOnboarding(true) + setCompletedOnboarding(profileRespnse.completed_onboarding_response) await setItemAsync('profile', JSON.stringify(profileRespnse)); - await setItemAsync('completedOnboarding', JSON.stringify(true)); + await setItemAsync('completedOnboarding', JSON.stringify(profileRespnse?.completed_onboarding_response || false)) } catch (error) { console.error(`Error setting onboarding to complete in profile:`, error); // Handle error - show message or perform recovery action diff --git a/client-new/src/contexts/UserContext.tsx b/client-new/src/contexts/UserContext.tsx index 70bdbd3..98ba983 100644 --- a/client-new/src/contexts/UserContext.tsx +++ b/client-new/src/contexts/UserContext.tsx @@ -52,7 +52,7 @@ export const UserProvider: React.FC = ({ children }) => { fetchProfile(userData.data.id); setUser(userData.data); setFirebaseUser(user); - setCompletedOnboarding(profile.completed_onboarding_response); + setCompletedOnboarding(profile?.completed_onboarding_response || false); console.log('[user context] userData', completedOnboarding) // Uncomment to store user data setItemAsync('firebaseUser', JSON.stringify(user)); diff --git a/client-new/src/navigation/OnboardingStack.tsx b/client-new/src/navigation/OnboardingStack.tsx index e685691..68c495f 100644 --- a/client-new/src/navigation/OnboardingStack.tsx +++ b/client-new/src/navigation/OnboardingStack.tsx @@ -18,8 +18,9 @@ export default function OnboardingStack() { { const { page, setPage, onboardingState, onboardingFlow } = useOnboarding(); const { user } = useUser(); - const { profile, fetchProfile, completeOnboarding, toggleOnboarding } = useProfile(); + const { completeOnboarding, toggleOnboarding } = useProfile(); const [persona, setPersona] = useState(null); const requestOnboarding = convertNumericToString(onboardingState); diff --git a/client-new/src/services/ProfileService.ts b/client-new/src/services/ProfileService.ts index b01fea7..8441672 100644 --- a/client-new/src/services/ProfileService.ts +++ b/client-new/src/services/ProfileService.ts @@ -5,6 +5,7 @@ import { IProfile } from '../interfaces/IProfile'; import { API_BASE_URL } from '@/services/const'; export const getProfile = async (user_id: string) => { + console.log('[profile service] fetching profile', `${API_BASE_URL}/users/${user_id}/profile`) const response = await axios.get(`${API_BASE_URL}/users/${user_id}/profile`); return response.data as IProfile; }; @@ -37,6 +38,7 @@ export const insertOnboardingResponse = async ( export const updateOnboardingToComplete = async ( profile_id: number, ): Promise => { + console.log('[profile service] updating onboarding to complete', `${API_BASE_URL}/profiles/complete/${profile_id}`) const response = await axios.patch(`${API_BASE_URL}/profiles/complete/${profile_id}`); return response.data; } \ No newline at end of file