-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent profile updates without changes (#2849)
* fix videoLink type in edit profile slice * fix photo and videoLink edit processing by role * update editProfileSlice tests * fix sending videoLink as empty string to server * fix updating videoLink as empty string is not send to server * fix tests to include actual initial videoLink state * fix photo change on edit profile page * fix edit profile tests * add EditProfilePhoto type * fix avatarSrc in AccountIcon type check * fix sending unchnaged videoLink every time to server * fix removed photo display in account icon * add fetching user data from server on page unload to prevent showing not applied changes * add tests for EditProfile * extract utils and add tests * extract hasPhotoChanges util and add tests * improve has photo changes test to inlcude mocked functions * remove void for dispatch in debouncedUpdateProfileData
- Loading branch information
Showing
17 changed files
with
290 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const areAllValuesEmptyStrings = (obj: { | ||
[key: string]: string | ||
}): boolean => { | ||
return Object.values(obj).every( | ||
(value) => typeof value === 'string' && value === '' | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { EditProfilePhoto, UpdatedPhoto } from '~/types' | ||
import { isUpdatedPhoto } from '~/utils/is-updated-photo' | ||
import { areAllValuesEmptyStrings } from '~/utils/are-all-values-empty-strings' | ||
|
||
export const hasPhotoChanges = ( | ||
initialPhoto: EditProfilePhoto, | ||
currentPhoto: EditProfilePhoto | ||
): boolean => { | ||
if (initialPhoto !== '' && currentPhoto === '') { | ||
return true | ||
} | ||
|
||
if ( | ||
typeof initialPhoto === 'string' && | ||
isUpdatedPhoto(currentPhoto) && | ||
(currentPhoto as UpdatedPhoto).name !== initialPhoto | ||
) { | ||
return true | ||
} | ||
|
||
if ( | ||
initialPhoto === null && | ||
isUpdatedPhoto(currentPhoto) && | ||
areAllValuesEmptyStrings(currentPhoto as UpdatedPhoto) | ||
) { | ||
return true | ||
} | ||
|
||
if ( | ||
isUpdatedPhoto(initialPhoto) && | ||
isUpdatedPhoto(currentPhoto) && | ||
(initialPhoto as UpdatedPhoto).name !== (currentPhoto as UpdatedPhoto).name | ||
) { | ||
return true | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { EditProfilePhoto } from '~/types' | ||
|
||
export const isUpdatedPhoto = (photo: EditProfilePhoto): boolean => { | ||
return ( | ||
photo !== null && | ||
typeof photo === 'object' && | ||
'name' in photo && | ||
'src' in photo | ||
) | ||
} |
Oops, something went wrong.