Skip to content

Commit

Permalink
Merge pull request #302 from hotosm/fix/role-update-my-info
Browse files Browse the repository at this point in the history
Fix: Complete profile as a new role
  • Loading branch information
nrjadkry authored Oct 21, 2024
2 parents 28fcf43 + 105512d commit fb4c29a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
11 changes: 7 additions & 4 deletions src/frontend/src/components/GoogleAuth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ function GoogleAuth() {
credentials: 'include',
headers: { 'access-token': token.access_token },
});
const userDetails = await response2.json();

const userDetails = await response2.json();
// stringify the response and set it to local storage
const userDetailsString = JSON.stringify(userDetails);
localStorage.setItem('userprofile', userDetailsString);
setUserProfileDetails(userDetails);

// navigate according the user
if (userDetails?.has_user_profile) {
// navigate according the user profile completion
if (
userDetails?.has_user_profile &&
userDetails?.role?.includes(signedInAs)
) {
navigate('/projects');
} else {
navigate('/complete-profile');
Expand All @@ -57,7 +60,7 @@ function GoogleAuth() {
setIsReadyToRedirect(true);
};
loginRedirect();
}, [location.search, navigate]);
}, [location.search, navigate, signedInAs]);

return (
<Flex className="naxatw-h-screen-nav naxatw-w-full naxatw-animate-pulse naxatw-items-center naxatw-justify-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const MapSection = ({ projectData }: { projectData: Record<string, any> }) => {
}
},
onError: (err: any) => {
toast.error(err.message);
toast.error(err?.response?.data?.detail || err?.message || '');
},
});

Expand All @@ -90,7 +90,7 @@ const MapSection = ({ projectData }: { projectData: Record<string, any> }) => {
toast.success('Task Unlocked Successfully');
},
onError: (err: any) => {
toast.error(err.message);
toast.error(err?.response?.data?.detail || err?.message || '');
},
});

Expand Down
12 changes: 3 additions & 9 deletions src/frontend/src/components/common/UserProfile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,17 @@ import { useNavigate } from 'react-router-dom';
import UserAvatar from '@Components/common/UserAvatar';
import { toast } from 'react-toastify';
import { getLocalStorageValue } from '@Utils/getLocalStorageValue';
import { useGetUserDetailsQuery } from '@Api/projects';

export default function UserProfile() {
const [toggle, setToggle] = useState(false);
const navigate = useNavigate();

const { data: userDetails, isFetching }: Record<string, any> =
useGetUserDetailsQuery();

const userProfile = getLocalStorageValue('userprofile');
const role = localStorage.getItem('signedInAs');

useEffect(() => {
if (!userDetails || userDetails?.role?.includes(role) || isFetching) return;
if (!userDetails?.has_user_profile || !userDetails?.role?.includes(role))
navigate('/complete-profile');
}, [userDetails, role, navigate, isFetching]);
if (!userProfile || userProfile?.role?.includes(role)) return;
navigate('/complete-profile');
}, [userProfile, role, navigate]);

const settingOptions = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,16 @@ export default function Login() {
const userDetails = await response2.json();
const userDetailsString = JSON.stringify(userDetails);
localStorage.setItem('userprofile', userDetailsString);
navigate('/projects');

// navigate according the user profile completion
if (
userDetails?.has_user_profile &&
userDetails?.role?.includes(signedInAs)
) {
navigate('/projects');
} else {
navigate('/complete-profile');
}
},
onError: err => {
toast.error(err.response.data.detail);
Expand Down

0 comments on commit fb4c29a

Please sign in to comment.