Skip to content

Commit

Permalink
[C-3612] Update FinishProfilePage to preserve changes if the user goe…
Browse files Browse the repository at this point in the history
…s back to the handle page (#7163)
  • Loading branch information
Kyle-Shanks authored Jan 11, 2024
1 parent f4a9b9d commit 219762e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
25 changes: 21 additions & 4 deletions packages/web/src/pages/sign-up-page/components/AccountHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type AccountHeaderProps = {
size?: 'small' | 'large'
formDisplayName?: string
formProfileImage?: ImageFieldValue
onProfileImageChange?: (value: ImageFieldValue) => void
onCoverPhotoChange?: (value: ImageFieldValue) => void
}

const ProfileImageAvatar = ({
Expand Down Expand Up @@ -73,8 +75,15 @@ const ProfileImageAvatar = ({
}

export const AccountHeader = (props: AccountHeaderProps) => {
const { backButtonText, mode, formDisplayName, formProfileImage, size } =
props
const {
backButtonText,
mode,
formDisplayName,
formProfileImage,
onProfileImageChange,
onCoverPhotoChange,
size
} = props
const { value: profileImage } = useSelector(getProfileImageField) ?? {}
const { value: storedDisplayName } = useSelector(getNameField)
const { value: handle } = useSelector(getHandleField)
Expand Down Expand Up @@ -110,7 +119,11 @@ export const AccountHeader = (props: AccountHeaderProps) => {
) : null}
<Box h={isSmallSize ? 96 : 168} css={{ overflow: 'hidden' }} w='100%'>
{isEditing ? (
<ImageField name='coverPhoto' imageResizeOptions={{ square: false }}>
<ImageField
onChange={onCoverPhotoChange}
name='coverPhoto'
imageResizeOptions={{ square: false }}
>
{(uploadedImage) => (
<CoverPhotoBanner
coverPhotoUrl={uploadedImage?.url}
Expand Down Expand Up @@ -144,7 +157,11 @@ export const AccountHeader = (props: AccountHeaderProps) => {
gap={isSmallSize ? 's' : 'xl'}
>
{isEditing ? (
<ImageField name='profileImage' css={{ flex: 0 }}>
<ImageField
onChange={onProfileImageChange}
name='profileImage'
css={{ flex: 0 }}
>
{(uploadedImage) => (
<ProfileImageAvatar
imageUrl={uploadedImage?.url ?? profileImage?.url}
Expand Down
24 changes: 24 additions & 0 deletions packages/web/src/pages/sign-up-page/pages/FinishProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,27 @@ export const FinishProfilePage = () => {
displayName: savedDisplayName || ''
}

const setCoverPhoto = useCallback(
(value: ImageFieldValue) => {
dispatch(setField('coverPhoto', { value }))
},
[dispatch]
)

const setProfileImage = useCallback(
(value: ImageFieldValue) => {
dispatch(setField('profileImage', { value }))
},
[dispatch]
)

const setDisplayName = useCallback(
(value: string) => {
dispatch(setValueField('name', value))
},
[dispatch]
)

const handleSubmit = useCallback(
({ coverPhoto, profileImage, displayName }: FinishProfileValues) => {
dispatch(setValueField('name', displayName))
Expand Down Expand Up @@ -133,6 +154,8 @@ export const FinishProfilePage = () => {
mode='editing'
formDisplayName={values.displayName}
formProfileImage={values.profileImage}
onProfileImageChange={setProfileImage}
onCoverPhotoChange={setCoverPhoto}
/>
<ImageUploadErrorText />
<HarmonyTextField
Expand All @@ -142,6 +165,7 @@ export const FinishProfilePage = () => {
placeholder={messages.inputPlaceholder}
required
maxLength={32}
onChange={(e) => setDisplayName(e.currentTarget.value)}
css={(theme) => ({
padding: theme.spacing.l
})}
Expand Down

0 comments on commit 219762e

Please sign in to comment.