V1.1
This commit is contained in:
parent
0c08f4b813
commit
5788b000f5
@ -1,4 +1,4 @@
|
|||||||
import React, { ReactElement } from 'react';
|
import React, { ReactElement, useEffect } from 'react';
|
||||||
import Head from 'next/head';
|
import Head from 'next/head';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
@ -6,13 +6,20 @@ import { useAppSelector, useAppDispatch } from '../stores/hooks';
|
|||||||
import LayoutGuest from '../layouts/Guest';
|
import LayoutGuest from '../layouts/Guest';
|
||||||
import { getPageTitle } from '../config';
|
import { getPageTitle } from '../config';
|
||||||
import BaseButton from '../components/BaseButton';
|
import BaseButton from '../components/BaseButton';
|
||||||
import { logoutUser } from '../stores/authSlice';
|
import { logoutUser, findMe } from '../stores/authSlice';
|
||||||
|
|
||||||
export default function Starter() {
|
export default function Starter() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const { currentUser, token } = useAppSelector((state) => state.auth);
|
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 = () => {
|
const handleLogout = () => {
|
||||||
dispatch(logoutUser());
|
dispatch(logoutUser());
|
||||||
router.push('/login');
|
router.push('/login');
|
||||||
@ -62,12 +69,12 @@ export default function Starter() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col items-center space-y-6 pt-4">
|
<div className="flex flex-col items-center space-y-6 pt-4">
|
||||||
<BaseButton
|
<Link
|
||||||
href="/member_profiles/member_profiles-list"
|
href="/member_profiles/member_profiles-list"
|
||||||
label="Enter Executive Directory"
|
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"
|
||||||
color="info"
|
>
|
||||||
className="px-16 py-4 text-xl rounded-none bg-[#091EAA] hover:bg-[#0055AA] border-none shadow-xl transition-all"
|
Enter Executive Directory
|
||||||
/>
|
</Link>
|
||||||
|
|
||||||
<div className="flex flex-wrap justify-center gap-x-8 gap-y-4 pt-4 text-gray-500 font-medium uppercase tracking-widest text-xs">
|
<div className="flex flex-wrap justify-center gap-x-8 gap-y-4 pt-4 text-gray-500 font-medium uppercase tracking-widest text-xs">
|
||||||
<Link href="/profile" className="hover:text-[#091EAA] transition-colors">
|
<Link href="/profile" className="hover:text-[#091EAA] transition-colors">
|
||||||
|
|||||||
@ -35,18 +35,33 @@ export default function ProfileOptIn() {
|
|||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
// Update member profile with consent
|
if (memberProfile?.id) {
|
||||||
|
// Update existing member profile with consent
|
||||||
await axios.put(`/member_profiles/${memberProfile.id}`, {
|
await axios.put(`/member_profiles/${memberProfile.id}`, {
|
||||||
|
id: memberProfile.id,
|
||||||
data: {
|
data: {
|
||||||
directory_consent: true,
|
directory_consent: true,
|
||||||
consented_at: new Date(),
|
consented_at: new Date(),
|
||||||
profile_status: 'draft' // Initial status after consent
|
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());
|
await dispatch(findMe());
|
||||||
toast.success('Consent recorded. Please complete your profile.');
|
toast.success('Consent recorded. Welcome to the Directory!');
|
||||||
router.push('/member_profiles/member_profiles-form');
|
|
||||||
|
// Redirect to the directory list
|
||||||
|
router.push('/member_profiles/member_profiles-list');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
toast.error('Failed to save consent. Please try again.');
|
toast.error('Failed to save consent. Please try again.');
|
||||||
@ -96,7 +111,7 @@ export default function ProfileOptIn() {
|
|||||||
|
|
||||||
<div className="pt-8 flex justify-center">
|
<div className="pt-8 flex justify-center">
|
||||||
<BaseButton
|
<BaseButton
|
||||||
label={loading ? 'Processing...' : 'Proceed to Profile Completion'}
|
label={loading ? 'Processing...' : 'Proceed to Directory'}
|
||||||
color="info"
|
color="info"
|
||||||
className="px-12 py-3 bg-[#091EAA] hover:bg-[#0055AA] border-none rounded-none text-lg shadow-lg"
|
className="px-12 py-3 bg-[#091EAA] hover:bg-[#0055AA] border-none rounded-none text-lg shadow-lg"
|
||||||
onClick={handleConsent}
|
onClick={handleConsent}
|
||||||
|
|||||||
@ -10,12 +10,19 @@ interface MainState {
|
|||||||
token: string;
|
token: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getInitialToken = () => {
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
return localStorage.getItem('token') || '';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
|
||||||
const initialState: MainState = {
|
const initialState: MainState = {
|
||||||
/* User */
|
/* User */
|
||||||
isFetching: false,
|
isFetching: false,
|
||||||
errorMessage: '',
|
errorMessage: '',
|
||||||
currentUser: null,
|
currentUser: null,
|
||||||
token: '',
|
token: getInitialToken(),
|
||||||
notify: {
|
notify: {
|
||||||
showNotification: false,
|
showNotification: false,
|
||||||
textNotification: '',
|
textNotification: '',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user