From 5788b000f56fc2e055a4a09ddd09b2609730cad2 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Thu, 12 Feb 2026 04:38:49 +0000 Subject: [PATCH] V1.1 --- frontend/src/pages/index.tsx | 21 ++++++++++----- frontend/src/pages/profile/opt-in.tsx | 37 +++++++++++++++++++-------- frontend/src/stores/authSlice.ts | 11 ++++++-- 3 files changed, 49 insertions(+), 20 deletions(-) diff --git a/frontend/src/pages/index.tsx b/frontend/src/pages/index.tsx index dd261ac..3823c84 100644 --- a/frontend/src/pages/index.tsx +++ b/frontend/src/pages/index.tsx @@ -1,4 +1,4 @@ -import React, { ReactElement } from 'react'; +import React, { ReactElement, useEffect } from 'react'; import Head from 'next/head'; import Link from 'next/link'; import { useRouter } from 'next/router'; @@ -6,13 +6,20 @@ import { useAppSelector, useAppDispatch } from '../stores/hooks'; import LayoutGuest from '../layouts/Guest'; import { getPageTitle } from '../config'; import BaseButton from '../components/BaseButton'; -import { logoutUser } from '../stores/authSlice'; +import { logoutUser, findMe } from '../stores/authSlice'; export default function Starter() { const router = useRouter(); const dispatch = useAppDispatch(); const { currentUser, token } = useAppSelector((state) => state.auth); + // Hydrate auth state if token exists but currentUser doesn't + useEffect(() => { + if (token && !currentUser) { + dispatch(findMe()); + } + }, [token, currentUser, dispatch]); + const handleLogout = () => { dispatch(logoutUser()); router.push('/login'); @@ -62,12 +69,12 @@ export default function Starter() {
- + className="px-16 py-4 text-xl font-bold text-white rounded-none bg-[#091EAA] hover:bg-[#0055AA] border-none shadow-xl transition-all inline-block" + > + Enter Executive Directory +
diff --git a/frontend/src/pages/profile/opt-in.tsx b/frontend/src/pages/profile/opt-in.tsx index 10752cf..cdecb50 100644 --- a/frontend/src/pages/profile/opt-in.tsx +++ b/frontend/src/pages/profile/opt-in.tsx @@ -35,18 +35,33 @@ export default function ProfileOptIn() { setLoading(true); try { - // Update member profile with consent - await axios.put(`/member_profiles/${memberProfile.id}`, { - data: { - directory_consent: true, - consented_at: new Date(), - profile_status: 'draft' // Initial status after consent - } - }); + if (memberProfile?.id) { + // Update existing member profile with consent + await axios.put(`/member_profiles/${memberProfile.id}`, { + id: memberProfile.id, + data: { + directory_consent: true, + consented_at: new Date(), + profile_status: 'draft' // Initial status after consent + } + }); + } else { + // Create new member profile with consent + await axios.post(`/member_profiles`, { + data: { + user: currentUser.id, + directory_consent: true, + consented_at: new Date(), + profile_status: 'draft' + } + }); + } await dispatch(findMe()); - toast.success('Consent recorded. Please complete your profile.'); - router.push('/member_profiles/member_profiles-form'); + toast.success('Consent recorded. Welcome to the Directory!'); + + // Redirect to the directory list + router.push('/member_profiles/member_profiles-list'); } catch (error) { console.error(error); toast.error('Failed to save consent. Please try again.'); @@ -96,7 +111,7 @@ export default function ProfileOptIn() {
{ + if (typeof window !== 'undefined') { + return localStorage.getItem('token') || ''; + } + return ''; +}; + const initialState: MainState = { /* User */ isFetching: false, errorMessage: '', currentUser: null, - token: '', + token: getInitialToken(), notify: { showNotification: false, textNotification: '', @@ -121,4 +128,4 @@ export const authSlice = createSlice({ // Action creators are generated for each case reducer function export const { logoutUser } = authSlice.actions; -export default authSlice.reducer; +export default authSlice.reducer; \ No newline at end of file