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

Feature : Improve display of error message on AvatarWithImagePicker #23754

Merged
merged 6 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 26 additions & 34 deletions src/components/AvatarWithImagePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import * as Expensicons from './Icon/Expensicons';
import styles from '../styles/styles';
import themeColors from '../styles/themes/default';
import AttachmentPicker from './AttachmentPicker';
import ConfirmModal from './ConfirmModal';
import AvatarCropModal from './AvatarCropModal/AvatarCropModal';
import OfflineWithFeedback from './OfflineWithFeedback';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
Expand All @@ -22,6 +21,7 @@ import stylePropTypes from '../styles/stylePropTypes';
import * as FileUtils from '../libs/fileDownload/FileUtils';
import getImageResolution from '../libs/fileDownload/getImageResolution';
import PressableWithoutFeedback from './Pressable/PressableWithoutFeedback';
import DotIndicatorMessage from './DotIndicatorMessage';

const propTypes = {
/** Avatar source to display */
Expand Down Expand Up @@ -103,16 +103,14 @@ class AvatarWithImagePicker extends React.Component {
constructor(props) {
super(props);
this.animation = new SpinningIndicatorAnimation();
this.hideErrorModal = this.hideErrorModal.bind(this);
this.showErrorModal = this.showErrorModal.bind(this);
this.setError = this.setError.bind(this);
this.isValidSize = this.isValidSize.bind(this);
this.showAvatarCropModal = this.showAvatarCropModal.bind(this);
this.hideAvatarCropModal = this.hideAvatarCropModal.bind(this);
this.state = {
isMenuVisible: false,
isErrorModalVisible: false,
errorModalPrompt: '',
errorModalTitle: '',
shoudShowValidationError: false,
validationError: '',
isAvatarCropModalOpen: false,
imageName: '',
imageUri: '',
Expand Down Expand Up @@ -141,15 +139,10 @@ class AvatarWithImagePicker extends React.Component {
}

/**
* @param {String} title
* @param {String} prompt
* @param {String} error
*/
showErrorModal(title, prompt) {
this.setState({isErrorModalVisible: true, errorModalTitle: title, errorModalPrompt: prompt});
}

hideErrorModal() {
this.setState({isErrorModalVisible: false});
setError(error) {
this.setState({shoudShowValidationError: true, validationError: error});
dhairyasenjaliya marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -196,24 +189,17 @@ class AvatarWithImagePicker extends React.Component {
*/
showAvatarCropModal(image) {
if (!this.isValidExtension(image)) {
this.showErrorModal(
this.props.translate('avatarWithImagePicker.imageUploadFailed'),
this.props.translate('avatarWithImagePicker.notAllowedExtension', {allowedExtensions: CONST.AVATAR_ALLOWED_EXTENSIONS}),
);
this.setError(this.props.translate('avatarWithImagePicker.notAllowedExtension', {allowedExtensions: CONST.AVATAR_ALLOWED_EXTENSIONS}));
return;
}
if (!this.isValidSize(image)) {
this.showErrorModal(
this.props.translate('avatarWithImagePicker.imageUploadFailed'),
this.props.translate('avatarWithImagePicker.sizeExceeded', {maxUploadSizeInMB: CONST.AVATAR_MAX_ATTACHMENT_SIZE / (1024 * 1024)}),
);
this.setError(this.props.translate('avatarWithImagePicker.sizeExceeded', {maxUploadSizeInMB: CONST.AVATAR_MAX_ATTACHMENT_SIZE / (1024 * 1024)}));
return;
}

this.isValidResolution(image).then((isValidResolution) => {
if (!isValidResolution) {
this.showErrorModal(
this.props.translate('avatarWithImagePicker.imageUploadFailed'),
this.setError(
this.props.translate('avatarWithImagePicker.resolutionConstraints', {
minHeightInPx: CONST.AVATAR_MIN_HEIGHT_PX,
minWidthInPx: CONST.AVATAR_MIN_WIDTH_PX,
Expand All @@ -226,6 +212,7 @@ class AvatarWithImagePicker extends React.Component {

this.setState({
isAvatarCropModalOpen: true,
shoudShowValidationError: false,
isMenuVisible: false,
imageUri: image.uri,
imageName: image.name,
Expand Down Expand Up @@ -263,7 +250,14 @@ class AvatarWithImagePicker extends React.Component {
icon: Expensicons.Trashcan,
text: this.props.translate('avatarWithImagePicker.removePhoto'),
onSelected: () => {
this.props.onImageRemoved();
this.setState(
{
shoudShowValidationError: false,
},
() => {
this.props.onImageRemoved();
dhairyasenjaliya marked this conversation as resolved.
Show resolved Hide resolved
},
);
},
});
}
Expand Down Expand Up @@ -333,15 +327,13 @@ class AvatarWithImagePicker extends React.Component {
</AttachmentPicker>
</View>
</PressableWithoutFeedback>
<ConfirmModal
title={this.state.errorModalTitle}
onConfirm={this.hideErrorModal}
onCancel={this.hideErrorModal}
isVisible={this.state.isErrorModalVisible}
prompt={this.state.errorModalPrompt}
confirmText={this.props.translate('common.close')}
shouldShowCancelButton={false}
/>
{this.state.shoudShowValidationError && (
<DotIndicatorMessage
style={[styles.mt6]}
messages={{0: this.state.validationError}}
type="error"
/>
)}
<AvatarCropModal
onClose={this.hideAvatarCropModal}
isVisible={this.state.isAvatarCropModalOpen}
Expand Down
1 change: 0 additions & 1 deletion src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,6 @@ export default {
uploadPhoto: 'Upload photo',
removePhoto: 'Remove photo',
editImage: 'Edit photo',
imageUploadFailed: 'Image upload failed',
deleteWorkspaceError: 'Sorry, there was an unexpected problem deleting your workspace avatar.',
sizeExceeded: ({maxUploadSizeInMB}) => `The selected image exceeds the maximum upload size of ${maxUploadSizeInMB}MB.`,
resolutionConstraints: ({minHeightInPx, minWidthInPx, maxHeightInPx, maxWidthInPx}) =>
Expand Down
1 change: 0 additions & 1 deletion src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ export default {
uploadPhoto: 'Subir foto',
removePhoto: 'Eliminar foto',
editImage: 'Editar foto',
imageUploadFailed: 'Error al cargar la imagen',
deleteWorkspaceError: 'Lo sentimos, hubo un problema eliminando el avatar de su espacio de trabajo.',
sizeExceeded: ({maxUploadSizeInMB}) => `La imagen supera el tamaño máximo de ${maxUploadSizeInMB}MB.`,
resolutionConstraints: ({minHeightInPx, minWidthInPx, maxHeightInPx, maxWidthInPx}) =>
Expand Down
1 change: 1 addition & 0 deletions src/pages/settings/Profile/ProfilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function ProfilePage(props) {
errors={lodashGet(props.currentUserPersonalDetails, 'errorFields.avatar', null)}
errorRowStyles={[styles.mt6]}
onErrorClose={PersonalDetails.clearAvatarErrors}
style={[styles.mh5]}
/>
<View style={[styles.mt4]}>
{_.map(profileSettingsOptions, (detail, index) => (
Expand Down
Loading