From 8fd388b3aaa9ce01d0fb19cb628b8f24a64bd6af Mon Sep 17 00:00:00 2001 From: Jayesh Mangwani Date: Tue, 6 Jun 2023 16:17:20 +0530 Subject: [PATCH] feat: extracted camera icon from OfflineWithFeedback --- src/components/AvatarWithImagePicker.js | 58 ++++++++++++++------ src/pages/settings/Profile/ProfilePage.js | 24 ++++---- src/pages/workspace/WorkspaceSettingsPage.js | 55 +++++++++---------- 3 files changed, 78 insertions(+), 59 deletions(-) diff --git a/src/components/AvatarWithImagePicker.js b/src/components/AvatarWithImagePicker.js index 1ce12b6033ae..d4ae8efd2277 100644 --- a/src/components/AvatarWithImagePicker.js +++ b/src/components/AvatarWithImagePicker.js @@ -12,6 +12,7 @@ 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'; import variables from '../styles/variables'; import CONST from '../CONST'; @@ -63,6 +64,19 @@ const propTypes = { /** Image crop vector mask */ editorMaskImage: PropTypes.func, + /** Additional style object for the error row */ + errorRowStyles: stylePropTypes, + + /** A function to run when the X button next to the error is clicked */ + onErrorClose: PropTypes.func, + + /** The type of action that's pending */ + pendingAction: PropTypes.oneOf(['add', 'update', 'delete']), + + /** The errors to display */ + // eslint-disable-next-line react/forbid-prop-types + errors: PropTypes.object, + ...withLocalizePropTypes, }; @@ -78,6 +92,10 @@ const defaultProps = { fallbackIcon: Expensicons.FallbackAvatar, type: CONST.ICON_TYPE_AVATAR, editorMaskImage: undefined, + errorRowStyles: [], + onErrorClose: () => {}, + pendingAction: null, + errors: null, }; class AvatarWithImagePicker extends React.Component { @@ -258,22 +276,30 @@ class AvatarWithImagePicker extends React.Component { this.setState({isMenuVisible: true})}> - - - {this.props.source ? ( - - ) : ( - - )} - - + + + + {this.props.source ? ( + + ) : ( + + )} + + + + {({openPicker}) => ( <> diff --git a/src/pages/settings/Profile/ProfilePage.js b/src/pages/settings/Profile/ProfilePage.js index d58cb4ceec3d..5df2856ee529 100755 --- a/src/pages/settings/Profile/ProfilePage.js +++ b/src/pages/settings/Profile/ProfilePage.js @@ -9,7 +9,6 @@ import AvatarWithImagePicker from '../../../components/AvatarWithImagePicker'; import HeaderWithCloseButton from '../../../components/HeaderWithCloseButton'; import MenuItem from '../../../components/MenuItem'; import MenuItemWithTopDescription from '../../../components/MenuItemWithTopDescription'; -import OfflineWithFeedback from '../../../components/OfflineWithFeedback'; import ScreenWrapper from '../../../components/ScreenWrapper'; import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from '../../../components/withCurrentUserPersonalDetails'; import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize'; @@ -90,22 +89,19 @@ const ProfilePage = (props) => { onCloseButtonPress={() => Navigation.dismissModal(true)} /> - - - + onErrorClose={PersonalDetails.clearAvatarErrors} + /> {_.map(profileSettingsOptions, (detail, index) => ( - ( + + )} + type={CONST.ICON_TYPE_WORKSPACE} + fallbackIcon={Expensicons.FallbackWorkspaceAvatar} + style={[styles.mb3]} + anchorPosition={styles.createMenuPositionProfile(props.windowWidth)} + anchorAlignment={{horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.CENTER, vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP}} + isUsingDefaultAvatar={!lodashGet(props.policy, 'avatar', null)} + onImageSelected={(file) => Policy.updateWorkspaceAvatar(lodashGet(props.policy, 'id', ''), file)} + onImageRemoved={() => Policy.deleteWorkspaceAvatar(lodashGet(props.policy, 'id', ''))} + editorMaskImage={Expensicons.ImageCropSquareMask} pendingAction={lodashGet(props.policy, 'pendingFields.avatar', null)} errors={lodashGet(props.policy, 'errorFields.avatar', null)} - onClose={() => Policy.clearAvatarErrors(props.policy.id)} - > - ( - - )} - type={CONST.ICON_TYPE_WORKSPACE} - fallbackIcon={Expensicons.FallbackWorkspaceAvatar} - style={[styles.mb3]} - anchorPosition={styles.createMenuPositionProfile(props.windowWidth)} - anchorAlignment={{horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.CENTER, vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP}} - isUsingDefaultAvatar={!lodashGet(props.policy, 'avatar', null)} - onImageSelected={(file) => Policy.updateWorkspaceAvatar(lodashGet(props.policy, 'id', ''), file)} - onImageRemoved={() => Policy.deleteWorkspaceAvatar(lodashGet(props.policy, 'id', ''))} - editorMaskImage={Expensicons.ImageCropSquareMask} - /> - + onErrorClose={() => Policy.clearAvatarErrors(props.policy.id)} + />