Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The user can not save the information on 'Edit Profile' page after clicking on the 'Home page' #2937

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

ArtemHolikov
Copy link
Contributor

@ArtemHolikov ArtemHolikov commented Dec 5, 2024

Was result:
If user has unsaved changes and redirected to another page, he could do this without any information about unsaved changes.

Actual result:
If user has unsaved changes and want to go to another page, modal window appears about unsaved changes with propose to update or leave without changes.

image

Space2Study.-.Google.Chrome.2024-12-05.13-55-23.mp4

@ArtemHolikov ArtemHolikov added bug Something isn't working Frontend part my-profile labels Dec 5, 2024
@ArtemHolikov ArtemHolikov self-assigned this Dec 5, 2024
Copy link

sonarqubecloud bot commented Dec 5, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
58.7% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Comment on lines +140 to +156
if (hasChanged) {
const changes: Partial<EditProfileState> = {
...changedCurrent
}

if (!hasChanges(changedInitial.videoLink, changedCurrent.videoLink)) {
delete changes.videoLink
}

if (hasPhotoChanged) {
changes.photo = changedCurrent.photo
}

return changes
} else {
return {}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to replace this block with if-not approach. You will not have an exta else here.

@@ -103,6 +104,63 @@ const EditProfile = () => {
}
}, [loading, profileState, initialEditProfileState])

const changedProfileFields = useMemo<Partial<EditProfileState>>(() => {
if (!initialEditProfileState || !profileState) return {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend you to not return {} for non-changed profile fields. It's not obvious actualy.
Return null if profile fields are not changed, it will simplify logic for isProfileChanged variable calculation. You will have just const isProfileChanged = Boolean(changedProfileFields) without useMemo

@@ -213,7 +271,41 @@ const EditProfile = () => {
if (hash) {
navigate(`${authRoutes.myProfile.path}#complete`)
}
}
}, [profileState, changedFields])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix linter errors here. This function can have unexpectable behaviour because of missing dependencies
image

const changedProfileFields = useMemo<Partial<EditProfileState>>(() => {
if (!initialEditProfileState || !profileState) return {}

const changedInitial = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename it, please.

Suggested change
const changedInitial = {
const initialProfileInformation = {

videoLink: initialEditProfileState.videoLink
}

const changedCurrent = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const changedCurrent = {
const changedProfileInformation = {

videoLink: profileState.videoLink
}

const hasPhotoChanged = hasPhotoChanges(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const hasPhotoChanged = hasPhotoChanges(
const isPhotoChanged = hasPhotoChanges(

changedCurrent.photo
)

const hasChanged =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const hasChanged =
const isProfileInformationChanged =

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Frontend part my-profile
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants