Skip to content

Commit 3459429

Browse files
authored
fix: #5795 (#5837)
1 parent 529ade4 commit 3459429

File tree

1 file changed

+12
-2
lines changed
  • src/shared/components/Settings/Profile/BasicInfo/ImageInput

1 file changed

+12
-2
lines changed

src/shared/components/Settings/Profile/BasicInfo/ImageInput/index.jsx

+12-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default class ImageInput extends React.Component {
2525
this.state = {
2626
newBasicInfo: {},
2727
isImageOversize: false,
28+
isImageFile: true,
2829
};
2930
}
3031

@@ -72,6 +73,13 @@ export default class ImageInput extends React.Component {
7273
if (file === undefined) {
7374
return;
7475
}
76+
const allowedTypes = ['image/png', 'image/jpg', 'image/jpeg'];
77+
if (!allowedTypes.includes(file.type)) {
78+
this.setState({
79+
isImageFile: false,
80+
});
81+
return;
82+
}
7583
if (file.size > 2 * 1024 * 1024) {
7684
// If file size is greater than 2 MB, show error message
7785
this.setState({
@@ -81,6 +89,7 @@ export default class ImageInput extends React.Component {
8189
}
8290
this.setState({
8391
isImageOversize: false,
92+
isImageFile: true,
8493
});
8594
uploadPhotoInit();
8695
loadImage.parseMetaData(file, (data) => {
@@ -126,7 +135,7 @@ export default class ImageInput extends React.Component {
126135
deletingPhoto,
127136
} = profileState;
128137

129-
const { newBasicInfo, isImageOversize } = this.state;
138+
const { newBasicInfo, isImageOversize, isImageFile } = this.state;
130139

131140
return (
132141
<div styleName="image">
@@ -157,7 +166,8 @@ export default class ImageInput extends React.Component {
157166
<input type="file" name="image" accept="image/*" onChange={this.onUploadPhoto} id="change-image-input" className="hidden" />
158167
</div>
159168
</div>
160-
{isImageOversize && <div styleName="error-message">Please select an image smaller than 2MB</div>}
169+
{!isImageFile && <div styleName="error-message">Please select jpg, jpeg or png image files only</div>}
170+
{isImageFile && isImageOversize && <div styleName="error-message">Please select an image smaller than 2MB</div>}
161171
</div>
162172
);
163173
}

0 commit comments

Comments
 (0)