Skip to content

Commit 451c7a8

Browse files
committed
keep the redir behavior outside of the component
1 parent 4ed1321 commit 451c7a8

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/ui/pages/profile/ManageProfile.page.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import { AuthGuard } from '@ui/components/AuthGuard';
44
import { useApi } from '@ui/util/api';
55
import { UserProfileData, UserProfileDataBase } from '@common/types/msGraphApi';
66
import { ManageProfileComponent } from './ManageProfileComponent';
7-
import { useSearchParams } from 'react-router-dom';
7+
import { useNavigate, useSearchParams } from 'react-router-dom';
8+
import { useAuth } from '@ui/components/AuthContext';
89

910
export const ManageProfilePage: React.FC = () => {
1011
const api = useApi('msGraphApi');
12+
const { setLoginStatus } = useAuth();
13+
const navigate = useNavigate();
1114
const [searchParams] = useSearchParams();
1215
const returnTo = searchParams.get('returnTo') || undefined;
1316
const firstTime = searchParams.get('firstTime') === 'true' || false;
@@ -33,7 +36,14 @@ export const ManageProfilePage: React.FC = () => {
3336
}
3437
data.otherMails = newOtherEmails;
3538
delete data.discordUsername;
36-
return (await api.patch('/v1.0/me', data)).data;
39+
const response = await api.patch('/v1.0/me', data);
40+
if (response.status < 299 && firstTime) {
41+
setLoginStatus(true);
42+
}
43+
if (returnTo) {
44+
return navigate(returnTo);
45+
}
46+
return response.data;
3747
};
3848

3949
return (
@@ -44,7 +54,6 @@ export const ManageProfilePage: React.FC = () => {
4454
getProfile={getProfile}
4555
setProfile={setProfile}
4656
firstTime={firstTime}
47-
returnTo={returnTo}
4857
/>
4958
</Container>
5059
</AuthGuard>

src/ui/pages/profile/ManageProfileComponent.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
import React, { useEffect, useState } from 'react';
22
import { TextInput, Button, Group, Box, LoadingOverlay, Alert } from '@mantine/core';
33
import { UserProfileData } from '@common/types/msGraphApi';
4-
import { useAuth } from '@ui/components/AuthContext';
54
import { notifications } from '@mantine/notifications';
65
import { useNavigate } from 'react-router-dom';
7-
import { IconMoodSmileBeam, IconQuestionMark } from '@tabler/icons-react';
6+
import { IconMoodSmileBeam } from '@tabler/icons-react';
87

98
interface ManageProfileComponentProps {
109
getProfile: () => Promise<UserProfileData>;
1110
setProfile: (data: UserProfileData) => Promise<any>;
1211
firstTime: boolean;
13-
returnTo?: string;
1412
}
1513

1614
export const ManageProfileComponent: React.FC<ManageProfileComponentProps> = ({
1715
getProfile,
1816
setProfile,
1917
firstTime,
20-
returnTo,
2118
}) => {
22-
const { userData, setLoginStatus } = useAuth();
2319
const navigate = useNavigate();
2420
const [userProfile, setUserProfile] = useState<undefined | null | UserProfileData>(undefined);
2521
const [loading, setLoading] = useState(false);
@@ -53,10 +49,6 @@ export const ManageProfileComponent: React.FC<ManageProfileComponentProps> = ({
5349
title: 'Profile updated successfully',
5450
message: 'Changes may take some time to reflect.',
5551
});
56-
setLoginStatus(true);
57-
if (returnTo) {
58-
return navigate(returnTo);
59-
}
6052
await fetchProfile();
6153
} catch (e) {
6254
console.error(e);
@@ -97,7 +89,7 @@ export const ManageProfileComponent: React.FC<ManageProfileComponentProps> = ({
9789
onChange={(e) =>
9890
setUserProfile((prev) => prev && { ...prev, displayName: e.target.value })
9991
}
100-
placeholder={userData?.name}
92+
placeholder={userProfile?.displayName}
10193
required
10294
/>
10395
<TextInput
@@ -120,8 +112,9 @@ export const ManageProfileComponent: React.FC<ManageProfileComponentProps> = ({
120112
label="Email"
121113
value={userProfile?.mail || ''}
122114
onChange={(e) => setUserProfile((prev) => prev && { ...prev, mail: e.target.value })}
123-
placeholder={userData?.email}
115+
placeholder={userProfile?.mail}
124116
required
117+
disabled
125118
/>
126119

127120
<TextInput

0 commit comments

Comments
 (0)