Skip to content

Commit

Permalink
whatever
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Jan 31, 2025
1 parent 096d1b5 commit d530bb0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 73 deletions.
114 changes: 44 additions & 70 deletions src/components/form/UpdateAccountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ const UpdateAccountForm: FC<UpdateAccountFormProps> = ({ authUser }) => {

const initialValues = authUser.student
? {
id: authUser.id,
password: "",
password_repeat: "",
current_password: "",
}
id: authUser.id,
password: "",
password_repeat: "",
current_password: "",
}
: {
id: authUser.id,
password: "",
password_repeat: "",
current_password: "",
first_name: authUser.first_name,
last_name: authUser.last_name,
email: authUser.email,
}
id: authUser.id,
password: "",
password_repeat: "",
current_password: "",
first_name: authUser.first_name,
last_name: authUser.last_name,
email: authUser.email,
}

return (
<>
Expand Down Expand Up @@ -104,77 +104,51 @@ const UpdateAccountForm: FC<UpdateAccountFormProps> = ({ authUser }) => {
]

if (isEmailDirty || isPasswordDirty) {
let loginPath = generatePath(paths.login.indy._)
let loginPath = "paths.login.indy._"

if (authUser.student) {
loginPath = generatePath(paths.login.student._)
loginPath = "paths.login.student._"
} else if (authUser.teacher) {
loginPath = generatePath(paths.login.teacher._)
loginPath = "paths.login.teacher._"
}

if (isEmailDirty) {
void logout(null)
.unwrap()
.then(() => {
void logout(null)
.unwrap()
.then(() => {
if (isEmailDirty) {
messages.push(
"Your email will be changed once you have verified it, until then you can still log in with your old email.",
)
navigate(loginPath, {
state: {
notifications: messages.map(message => ({
props: { children: message },
})),
},
})
})
// TODO: Check what happens here - is the field still updated?
.catch(() => {
navigate(".", {
replace: true,
state: {
notifications: [
{
props: {
error: true,
children: "Failed to log you out.",
},
},
],
},
})
})
}
if (isPasswordDirty) {
void logout(null)
.unwrap()
.then(() => {
}
if (isPasswordDirty) {
messages.push(
"Going forward, please log in using your new password.",
)
navigate(loginPath, {
state: {
notifications: messages.map(message => ({
props: { children: message },
})),
},
})
}
navigate(loginPath, {
state: {
notifications: messages.map(message => ({
props: { children: message },
})),
},
})
.catch(() => {
navigate(".", {
replace: true,
state: {
notifications: [
{
props: {
error: true,
children: "Failed to log you out.",
},
})
// TODO: Check what happens here - is the field still updated?
.catch(() => {
navigate(".", {
replace: true,
state: {
notifications: [
{
props: {
error: true,
children: "Failed to log you out.",
},
],
},
})
},
],
},
})
}
})
} else {
navigate(".", {
state: {
Expand Down
5 changes: 2 additions & 3 deletions src/pages/studentAccount/StudentAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { type SessionMetadata } from "codeforlife/hooks"
import { Typography } from "@mui/material"
import { handleResultState } from "codeforlife/utils/api"

import * as forms from "../../components/form"
import { paths } from "../../routes"
import { useRetrieveUserQuery } from "../../api/user"

Expand All @@ -22,7 +21,7 @@ const _StudentAccount: FC<SessionMetadata> = ({ user_type, user_id }) =>
bgcolor={user_type === "student" ? "tertiary" : "secondary"}
/>
<page.Section>
<forms.UpdateAccountForm authUser={authUser} />
<UpdateAccountForm authUser={authUser} />
</page.Section>
{user_type === "indy" && (
<>
Expand All @@ -35,7 +34,7 @@ const _StudentAccount: FC<SessionMetadata> = ({ user_type, user_id }) =>
<LinkButton to={paths.indy.dashboard.joinClass._}>Join</LinkButton>
</page.Section>
<page.Section>
<forms.DeleteAccountForm authUser={authUser} />
<DeleteAccountForm authUser={authUser} />
</page.Section>
</>
)}
Expand Down

0 comments on commit d530bb0

Please sign in to comment.