Skip to content

Commit

Permalink
Merge pull request #931 from ONEARMY/899-slideshow-profile-image
Browse files Browse the repository at this point in the history
fix case for empty coverImage profile
  • Loading branch information
BenGamma authored Apr 1, 2020
2 parents fd08f61 + fc36bb2 commit f9bb8ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
20 changes: 15 additions & 5 deletions src/pages/Settings/SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,20 @@ export class UserSettings extends React.Component<IProps, IState> {
return ret
}
public onCoverImgChange(v: IConvertedFileMeta, i: number) {
// Use existing array of images if exist & not empty or use empty array
const isInitialValueEmpty =
!Array.isArray(this.state.initialFormValues.coverImages) ||
this.state.initialFormValues.coverImages.length === 0
const isCustomValueEmpty =
!Array.isArray(this.state.customFormValues.coverImages) ||
this.state.customFormValues.coverImages.length === 0

// Use empty array if no cover image yet - otherwise use existing cover
let coverImagesArray =
Array.isArray(this.state.initialFormValues.coverImages) &&
this.state.initialFormValues.coverImages.length
isInitialValueEmpty && isCustomValueEmpty
? []
: isCustomValueEmpty
? this.state.initialFormValues.coverImages
: []
: this.state.customFormValues.coverImages
// If value is null || undefined && coverImagesArray exist
// We want to remove the element from coverImagesArray at given index (delete image)
if (
Expand All @@ -131,7 +139,9 @@ export class UserSettings extends React.Component<IProps, IState> {
coverImagesArray = this.replaceAt(coverImagesArray, i, v)
} else {
// Or just push value at the end of array
coverImagesArray.push(v as any)
if (coverImagesArray) {
coverImagesArray.push(v as any)
}
}
}

Expand Down
8 changes: 0 additions & 8 deletions src/pages/Settings/content/formSections/UserInfos.section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,12 @@ export class UserInfosSection extends React.Component<IProps, IState> {
Cover Image *
</Text>
<Box height="100px" width="150px" m="10px" data-cy="cover-image">
{/* <Field
canDelete
hasText={false}
name={`${step}.images[0]`}
src={images[0]}
component={ImageInputField}
/> */}
<Field
canDelete
hasText={false}
id="cover_image-1"
data-cy="cover_image-1"
name="coverImages[0]"
validate={required}
src={
initialFormValues.coverImages
? initialFormValues.coverImages[0]
Expand Down

0 comments on commit f9bb8ad

Please sign in to comment.