From 5f8e0766e3f1d3ab98e1fa1a6a81a78217abeb81 Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Fri, 3 Feb 2023 14:35:13 -0800 Subject: [PATCH 01/23] Use hash of policy name to determine color combo, use new default workspace avatars --- src/components/Icon/index.js | 23 ++++++++-- src/libs/ReportUtils.js | 22 ++++++++++ src/pages/workspace/WorkspaceInitialPage.js | 9 +++- src/pages/workspace/WorkspaceSettingsPage.js | 9 +++- src/styles/StyleUtils.js | 44 +++++++++++++++++++- src/styles/styles.js | 5 +++ 6 files changed, 105 insertions(+), 7 deletions(-) diff --git a/src/components/Icon/index.js b/src/components/Icon/index.js index e2017cc5b923..d335a52a58f7 100644 --- a/src/components/Icon/index.js +++ b/src/components/Icon/index.js @@ -28,6 +28,12 @@ const propTypes = { /** Is SVG avatar icon */ isSVGAvatar: PropTypes.bool, + + /** Is workspace icon */ + isWorkspaceAvatar: PropTypes.bool, + + // eslint-disable-next-line react/forbid-prop-types + workspaceColorStyle: PropTypes.object, }; const defaultProps = { @@ -37,6 +43,8 @@ const defaultProps = { small: false, inline: false, isSVGAvatar: false, + isWorkspaceAvatar: false, + workspaceColorStyle: {}, }; // We must use a class component to create an animatable component with the Animated API @@ -46,7 +54,7 @@ class Icon extends PureComponent { const width = this.props.small ? variables.iconSizeSmall : this.props.width; const height = this.props.small ? variables.iconSizeSmall : this.props.height; const iconStyles = [StyleUtils.getWidthAndHeightStyle(width, height), IconWrapperStyles, styles.pAbsolute, - StyleUtils.getAvatarSVGBorder(this.props.isSVGAvatar)]; + StyleUtils.getAvatarSVGBorder(this.props.isSVGAvatar, this.props.isWorkspaceAvatar), this.props.workspaceColorStyle]; if (this.props.inline) { return ( @@ -58,7 +66,7 @@ class Icon extends PureComponent { @@ -66,11 +74,18 @@ class Icon extends PureComponent { } return ( - + ); diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 51a28759d45c..fa6d2bcf8c97 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -16,6 +16,7 @@ import * as NumberFormatUtils from './NumberFormatUtils'; import Permissions from './Permissions'; import DateUtils from './DateUtils'; import * as defaultAvatars from '../components/Icon/DefaultAvatars'; +import * as defaultWorkspaceAvatars from '../components/Icon/WorkspaceDefaultAvatars'; let sessionEmail; Onyx.connect({ @@ -453,6 +454,25 @@ function getDefaultAvatar(login = '') { return defaultAvatars[`Avatar${loginHashBucket}`]; } +/** + * Helper method to return the default avatar associated with the given login + * @param {String} [workspaceName] + * @returns {String} + */ +function getDefaultWorkspaceAvatar(workspaceName) { + if (!workspaceName) { + return Expensicons.FallbackWorkspaceAvatar; + } + + // Remove all chars not A-Z or 0-9 including underscore + const alphaNumeric = workspaceName.replace(/[^0-9a-z]/gi, '').toUpperCase(); + const firstChar = alphaNumeric[0]; + // eslint-disable-next-line no-console + console.log('first character: ', firstChar, defaultWorkspaceAvatars[`Workspace${firstChar}`]); + + return !firstChar ? Expensicons.FallbackWorkspaceAvatar : defaultWorkspaceAvatars[`Workspace${firstChar}`]; +} + /** * Helper method to return old dot default avatar associated with login * @@ -1425,4 +1445,6 @@ export { getOldDotDefaultAvatar, getNewMarkerReportActionID, canSeeDefaultRoom, + hashLogin, + getDefaultWorkspaceAvatar, }; diff --git a/src/pages/workspace/WorkspaceInitialPage.js b/src/pages/workspace/WorkspaceInitialPage.js index fd57e35f3257..a1f25fa2e829 100644 --- a/src/pages/workspace/WorkspaceInitialPage.js +++ b/src/pages/workspace/WorkspaceInitialPage.js @@ -28,6 +28,8 @@ import CONST from '../../CONST'; import * as ReimbursementAccount from '../../libs/actions/ReimbursementAccount'; import ONYXKEYS from '../../ONYXKEYS'; import OfflineWithFeedback from '../../components/OfflineWithFeedback'; +import * as StyleUtils from '../../styles/StyleUtils'; +import * as ReportUtils from '../../libs/ReportUtils'; const propTypes = { ...policyPropTypes, @@ -96,6 +98,9 @@ class WorkspaceInitialPage extends React.Component { render() { const policy = this.props.policy; + // eslint-disable-next-line no-console + console.log('POLICY: ', this.props.policy, lodashGet(this.props.policy, 'name', '')); + const policyName = lodashGet(this.props.policy, 'name', ''); const hasMembersError = PolicyUtils.hasPolicyMemberError(this.props.policyMemberList); const hasGeneralSettingsError = !_.isEmpty(lodashGet(this.props.policy, 'errorFields.generalSettings', {})) || !_.isEmpty(lodashGet(this.props.policy, 'errorFields.avatar', {})); @@ -202,10 +207,12 @@ class WorkspaceInitialPage extends React.Component { ) : ( )} diff --git a/src/pages/workspace/WorkspaceSettingsPage.js b/src/pages/workspace/WorkspaceSettingsPage.js index 7d609aabec9b..f2e2623eaa59 100644 --- a/src/pages/workspace/WorkspaceSettingsPage.js +++ b/src/pages/workspace/WorkspaceSettingsPage.js @@ -21,6 +21,8 @@ import withPolicy, {policyPropTypes, policyDefaultProps} from './withPolicy'; import {withNetwork} from '../../components/OnyxProvider'; import OfflineWithFeedback from '../../components/OfflineWithFeedback'; import Form from '../../components/Form'; +import * as StyleUtils from '../../styles/StyleUtils'; +import * as ReportUtils from '../../libs/ReportUtils'; const propTypes = { ...policyPropTypes, @@ -77,6 +79,9 @@ class WorkspaceSettingsPage extends React.Component { } render() { + // eslint-disable-next-line no-console + console.log('POLICY: ', this.props.policy, lodashGet(this.props.policy, 'name', '')); + const policyName = lodashGet(this.props.policy, 'name', ''); return ( ( )} fallbackIcon={Expensicons.FallbackWorkspaceAvatar} diff --git a/src/styles/StyleUtils.js b/src/styles/StyleUtils.js index 04a5339fdecc..efbbb766a097 100644 --- a/src/styles/StyleUtils.js +++ b/src/styles/StyleUtils.js @@ -6,6 +6,7 @@ import variables from './variables'; import colors from './colors'; import positioning from './utilities/positioning'; import styles from './styles'; +import * as ReportUtils from '../libs/ReportUtils'; /** * Return the style size from an avatar size constant @@ -49,15 +50,55 @@ function getAvatarStyle(size) { * Return the border style if avatar is SVG * * @param {Boolean} isSVG + * @param {Boolean} isWorkspace * @returns {Object} */ -function getAvatarSVGBorder(isSVG) { +function getAvatarSVGBorder(isSVG, isWorkspace = false) { + if (isWorkspace) { + return styles.squareAvatarBorder; + } if (!isSVG) { return {}; } return styles.svgAvatarBorder; } +/** + * Helper method to return old dot default avatar associated with login + * + * @param {String} [workspaceName] + * @returns {Object} + */ +function getDefaultWorspaceAvatarColor(workspaceName) { + const colorOptions = [ + ['#8DC8FF', '#003C73'], + ['#0185FF', '#002140'], + ['#003C73', '#8DC8FF'], + ['#8EECC4', '#085239'], + ['#03D47C', '#002E22'], + ['#085239', '#8EECC4'], + ['#FFED8F', '#722B03'], + ['#FED607', '#401102'], + ['#722B03', '#FFED8F'], + ['#FFC68C', '#780505'], + ['#FF7101', '#400000'], + ['#780505', '#FF7101'], + ['#FBCCFF', '#712A76'], + ['#F68DFE', '#49225B'], + ['#712A76', '#FBCCFF'], + ['#CCF7FF', '#28736D'], + ['#50EEF6', '#134038'], + ['#28736D', '#CCF7FF'], + ]; + + const colorHash = ReportUtils.hashLogin(workspaceName, colorOptions.length); + + // eslint-disable-next-line no-console + console.log('HASH RESULTS', colorHash, {backgroundColor: colorOptions[colorHash][0], fill: colorOptions[colorHash][1]}); + + return {backgroundColor: colorOptions[colorHash][0], fill: colorOptions[colorHash][1]}; +} + /** * Takes safe area insets and returns padding to use for a View * @@ -773,4 +814,5 @@ export { getReportWelcomeBackgroundImageStyle, getReportWelcomeBackgroundImageViewStyle, getReportWelcomeContainerStyle, + getDefaultWorspaceAvatarColor, }; diff --git a/src/styles/styles.js b/src/styles/styles.js index 65d97d416a0f..80e687d78b7c 100644 --- a/src/styles/styles.js +++ b/src/styles/styles.js @@ -2031,6 +2031,11 @@ const styles = { overflow: 'hidden', }, + squareAvatarBorder: { + borderRadius: 20, + overflow: 'hidden', + }, + displayName: { fontSize: variables.fontSizeLarge, fontFamily: fontFamily.EXP_NEUE_BOLD, From 27c7ed75225c0073a6da82cdf9624191953e9881 Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Fri, 3 Feb 2023 14:36:08 -0800 Subject: [PATCH 02/23] Add new workspace SVGs / import them --- .../avatars/workspace/default-avatar_0.svg | 14 ++++ .../avatars/workspace/default-avatar_1.svg | 14 ++++ .../avatars/workspace/default-avatar_2.svg | 16 ++++ .../avatars/workspace/default-avatar_3.svg | 15 ++++ .../avatars/workspace/default-avatar_4.svg | 14 ++++ .../avatars/workspace/default-avatar_5.svg | 15 ++++ .../avatars/workspace/default-avatar_6.svg | 15 ++++ .../avatars/workspace/default-avatar_7.svg | 14 ++++ .../avatars/workspace/default-avatar_8.svg | 15 ++++ .../avatars/workspace/default-avatar_9.svg | 15 ++++ .../avatars/workspace/default-avatar_a.svg | 16 ++++ .../avatars/workspace/default-avatar_b.svg | 16 ++++ .../avatars/workspace/default-avatar_c.svg | 14 ++++ .../avatars/workspace/default-avatar_d.svg | 15 ++++ .../avatars/workspace/default-avatar_e.svg | 16 ++++ .../avatars/workspace/default-avatar_f.svg | 15 ++++ .../avatars/workspace/default-avatar_g.svg | 15 ++++ .../avatars/workspace/default-avatar_h.svg | 16 ++++ .../avatars/workspace/default-avatar_i.svg | 13 ++++ .../avatars/workspace/default-avatar_j.svg | 13 ++++ .../avatars/workspace/default-avatar_k.svg | 16 ++++ .../avatars/workspace/default-avatar_l.svg | 14 ++++ .../avatars/workspace/default-avatar_m.svg | 16 ++++ .../avatars/workspace/default-avatar_n.svg | 15 ++++ .../avatars/workspace/default-avatar_o.svg | 13 ++++ .../avatars/workspace/default-avatar_p.svg | 15 ++++ .../avatars/workspace/default-avatar_q.svg | 14 ++++ .../avatars/workspace/default-avatar_r.svg | 18 +++++ .../avatars/workspace/default-avatar_s.svg | 16 ++++ .../avatars/workspace/default-avatar_t.svg | 15 ++++ .../avatars/workspace/default-avatar_u.svg | 17 +++++ .../avatars/workspace/default-avatar_v.svg | 17 +++++ .../avatars/workspace/default-avatar_w.svg | 20 +++++ .../avatars/workspace/default-avatar_x.svg | 20 +++++ .../avatars/workspace/default-avatar_y.svg | 18 +++++ .../avatars/workspace/default-avatar_z.svg | 18 +++++ .../Icon/WorkspaceDefaultAvatars.js | 75 +++++++++++++++++++ 37 files changed, 633 insertions(+) create mode 100644 assets/images/avatars/workspace/default-avatar_0.svg create mode 100644 assets/images/avatars/workspace/default-avatar_1.svg create mode 100644 assets/images/avatars/workspace/default-avatar_2.svg create mode 100644 assets/images/avatars/workspace/default-avatar_3.svg create mode 100644 assets/images/avatars/workspace/default-avatar_4.svg create mode 100644 assets/images/avatars/workspace/default-avatar_5.svg create mode 100644 assets/images/avatars/workspace/default-avatar_6.svg create mode 100644 assets/images/avatars/workspace/default-avatar_7.svg create mode 100644 assets/images/avatars/workspace/default-avatar_8.svg create mode 100644 assets/images/avatars/workspace/default-avatar_9.svg create mode 100644 assets/images/avatars/workspace/default-avatar_a.svg create mode 100644 assets/images/avatars/workspace/default-avatar_b.svg create mode 100644 assets/images/avatars/workspace/default-avatar_c.svg create mode 100644 assets/images/avatars/workspace/default-avatar_d.svg create mode 100644 assets/images/avatars/workspace/default-avatar_e.svg create mode 100644 assets/images/avatars/workspace/default-avatar_f.svg create mode 100644 assets/images/avatars/workspace/default-avatar_g.svg create mode 100644 assets/images/avatars/workspace/default-avatar_h.svg create mode 100644 assets/images/avatars/workspace/default-avatar_i.svg create mode 100644 assets/images/avatars/workspace/default-avatar_j.svg create mode 100644 assets/images/avatars/workspace/default-avatar_k.svg create mode 100644 assets/images/avatars/workspace/default-avatar_l.svg create mode 100644 assets/images/avatars/workspace/default-avatar_m.svg create mode 100644 assets/images/avatars/workspace/default-avatar_n.svg create mode 100644 assets/images/avatars/workspace/default-avatar_o.svg create mode 100644 assets/images/avatars/workspace/default-avatar_p.svg create mode 100644 assets/images/avatars/workspace/default-avatar_q.svg create mode 100644 assets/images/avatars/workspace/default-avatar_r.svg create mode 100644 assets/images/avatars/workspace/default-avatar_s.svg create mode 100644 assets/images/avatars/workspace/default-avatar_t.svg create mode 100644 assets/images/avatars/workspace/default-avatar_u.svg create mode 100644 assets/images/avatars/workspace/default-avatar_v.svg create mode 100644 assets/images/avatars/workspace/default-avatar_w.svg create mode 100644 assets/images/avatars/workspace/default-avatar_x.svg create mode 100644 assets/images/avatars/workspace/default-avatar_y.svg create mode 100644 assets/images/avatars/workspace/default-avatar_z.svg create mode 100644 src/components/Icon/WorkspaceDefaultAvatars.js diff --git a/assets/images/avatars/workspace/default-avatar_0.svg b/assets/images/avatars/workspace/default-avatar_0.svg new file mode 100644 index 000000000000..c942281517f4 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_0.svg @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_1.svg b/assets/images/avatars/workspace/default-avatar_1.svg new file mode 100644 index 000000000000..e6b0c71b53d4 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_1.svg @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_2.svg b/assets/images/avatars/workspace/default-avatar_2.svg new file mode 100644 index 000000000000..c7d469d662ba --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_2.svg @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_3.svg b/assets/images/avatars/workspace/default-avatar_3.svg new file mode 100644 index 000000000000..04c5d6d99372 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_3.svg @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_4.svg b/assets/images/avatars/workspace/default-avatar_4.svg new file mode 100644 index 000000000000..e547481faefd --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_4.svg @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_5.svg b/assets/images/avatars/workspace/default-avatar_5.svg new file mode 100644 index 000000000000..6b8c654ee784 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_5.svg @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_6.svg b/assets/images/avatars/workspace/default-avatar_6.svg new file mode 100644 index 000000000000..c8f155995263 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_6.svg @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_7.svg b/assets/images/avatars/workspace/default-avatar_7.svg new file mode 100644 index 000000000000..714725c62f2f --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_7.svg @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_8.svg b/assets/images/avatars/workspace/default-avatar_8.svg new file mode 100644 index 000000000000..edca9a464610 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_8.svg @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_9.svg b/assets/images/avatars/workspace/default-avatar_9.svg new file mode 100644 index 000000000000..0cc78a5dae7e --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_9.svg @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_a.svg b/assets/images/avatars/workspace/default-avatar_a.svg new file mode 100644 index 000000000000..5ea6d7a1dd0e --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_a.svg @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_b.svg b/assets/images/avatars/workspace/default-avatar_b.svg new file mode 100644 index 000000000000..dfdef9451455 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_b.svg @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_c.svg b/assets/images/avatars/workspace/default-avatar_c.svg new file mode 100644 index 000000000000..d09cd384d458 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_c.svg @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_d.svg b/assets/images/avatars/workspace/default-avatar_d.svg new file mode 100644 index 000000000000..2d8fb68adf58 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_d.svg @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_e.svg b/assets/images/avatars/workspace/default-avatar_e.svg new file mode 100644 index 000000000000..a21981f244c5 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_e.svg @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_f.svg b/assets/images/avatars/workspace/default-avatar_f.svg new file mode 100644 index 000000000000..2f1323e2c7f9 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_f.svg @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_g.svg b/assets/images/avatars/workspace/default-avatar_g.svg new file mode 100644 index 000000000000..51ff96cdfb7b --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_g.svg @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_h.svg b/assets/images/avatars/workspace/default-avatar_h.svg new file mode 100644 index 000000000000..ddabaa42d06b --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_h.svg @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_i.svg b/assets/images/avatars/workspace/default-avatar_i.svg new file mode 100644 index 000000000000..e9bc60254e2e --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_i.svg @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_j.svg b/assets/images/avatars/workspace/default-avatar_j.svg new file mode 100644 index 000000000000..9daf382ca8ef --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_j.svg @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_k.svg b/assets/images/avatars/workspace/default-avatar_k.svg new file mode 100644 index 000000000000..6018a9912f2c --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_k.svg @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_l.svg b/assets/images/avatars/workspace/default-avatar_l.svg new file mode 100644 index 000000000000..4fd4e62ff93a --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_l.svg @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_m.svg b/assets/images/avatars/workspace/default-avatar_m.svg new file mode 100644 index 000000000000..e2eea24f1af9 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_m.svg @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_n.svg b/assets/images/avatars/workspace/default-avatar_n.svg new file mode 100644 index 000000000000..d1f036614c08 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_n.svg @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_o.svg b/assets/images/avatars/workspace/default-avatar_o.svg new file mode 100644 index 000000000000..5f2c8e89fc89 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_o.svg @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_p.svg b/assets/images/avatars/workspace/default-avatar_p.svg new file mode 100644 index 000000000000..4729bbc0afb9 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_p.svg @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_q.svg b/assets/images/avatars/workspace/default-avatar_q.svg new file mode 100644 index 000000000000..ebdd318460e9 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_q.svg @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_r.svg b/assets/images/avatars/workspace/default-avatar_r.svg new file mode 100644 index 000000000000..015869a190ad --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_r.svg @@ -0,0 +1,18 @@ + + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_s.svg b/assets/images/avatars/workspace/default-avatar_s.svg new file mode 100644 index 000000000000..334af3a15636 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_s.svg @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_t.svg b/assets/images/avatars/workspace/default-avatar_t.svg new file mode 100644 index 000000000000..9ab5962f9ba1 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_t.svg @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_u.svg b/assets/images/avatars/workspace/default-avatar_u.svg new file mode 100644 index 000000000000..04daa1bd4b04 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_u.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_v.svg b/assets/images/avatars/workspace/default-avatar_v.svg new file mode 100644 index 000000000000..a94242b787e0 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_v.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_w.svg b/assets/images/avatars/workspace/default-avatar_w.svg new file mode 100644 index 000000000000..a0756f443422 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_w.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_x.svg b/assets/images/avatars/workspace/default-avatar_x.svg new file mode 100644 index 000000000000..516da8c1b563 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_x.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_y.svg b/assets/images/avatars/workspace/default-avatar_y.svg new file mode 100644 index 000000000000..435d0d79bc79 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_y.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + diff --git a/assets/images/avatars/workspace/default-avatar_z.svg b/assets/images/avatars/workspace/default-avatar_z.svg new file mode 100644 index 000000000000..48bb76f4a72a --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_z.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + diff --git a/src/components/Icon/WorkspaceDefaultAvatars.js b/src/components/Icon/WorkspaceDefaultAvatars.js new file mode 100644 index 000000000000..acf751b4075c --- /dev/null +++ b/src/components/Icon/WorkspaceDefaultAvatars.js @@ -0,0 +1,75 @@ +import Workspace0 from '../../../assets/images/avatars/workspace/default-avatar_0.svg'; +import Workspace1 from '../../../assets/images/avatars/workspace/default-avatar_1.svg'; +import Workspace2 from '../../../assets/images/avatars/workspace/default-avatar_2.svg'; +import Workspace3 from '../../../assets/images/avatars/workspace/default-avatar_3.svg'; +import Workspace4 from '../../../assets/images/avatars/workspace/default-avatar_4.svg'; +import Workspace5 from '../../../assets/images/avatars/workspace/default-avatar_5.svg'; +import Workspace6 from '../../../assets/images/avatars/workspace/default-avatar_6.svg'; +import Workspace7 from '../../../assets/images/avatars/workspace/default-avatar_7.svg'; +import Workspace8 from '../../../assets/images/avatars/workspace/default-avatar_8.svg'; +import Workspace9 from '../../../assets/images/avatars/workspace/default-avatar_9.svg'; +import WorkspaceA from '../../../assets/images/avatars/workspace/default-avatar_a.svg'; +import WorkspaceB from '../../../assets/images/avatars/workspace/default-avatar_b.svg'; +import WorkspaceC from '../../../assets/images/avatars/workspace/default-avatar_c.svg'; +import WorkspaceD from '../../../assets/images/avatars/workspace/default-avatar_d.svg'; +import WorkspaceE from '../../../assets/images/avatars/workspace/default-avatar_e.svg'; +import WorkspaceF from '../../../assets/images/avatars/workspace/default-avatar_f.svg'; +import WorkspaceG from '../../../assets/images/avatars/workspace/default-avatar_g.svg'; +import WorkspaceH from '../../../assets/images/avatars/workspace/default-avatar_h.svg'; +import WorkspaceI from '../../../assets/images/avatars/workspace/default-avatar_i.svg'; +import WorkspaceJ from '../../../assets/images/avatars/workspace/default-avatar_j.svg'; +import WorkspaceK from '../../../assets/images/avatars/workspace/default-avatar_k.svg'; +import WorkspaceL from '../../../assets/images/avatars/workspace/default-avatar_l.svg'; +import WorkspaceM from '../../../assets/images/avatars/workspace/default-avatar_m.svg'; +import WorkspaceN from '../../../assets/images/avatars/workspace/default-avatar_n.svg'; +import WorkspaceO from '../../../assets/images/avatars/workspace/default-avatar_o.svg'; +import WorkspaceP from '../../../assets/images/avatars/workspace/default-avatar_p.svg'; +import WorkspaceQ from '../../../assets/images/avatars/workspace/default-avatar_q.svg'; +import WorkspaceR from '../../../assets/images/avatars/workspace/default-avatar_r.svg'; +import WorkspaceS from '../../../assets/images/avatars/workspace/default-avatar_s.svg'; +import WorkspaceT from '../../../assets/images/avatars/workspace/default-avatar_t.svg'; +import WorkspaceU from '../../../assets/images/avatars/workspace/default-avatar_u.svg'; +import WorkspaceV from '../../../assets/images/avatars/workspace/default-avatar_v.svg'; +import WorkspaceW from '../../../assets/images/avatars/workspace/default-avatar_w.svg'; +import WorkspaceX from '../../../assets/images/avatars/workspace/default-avatar_x.svg'; +import WorkspaceY from '../../../assets/images/avatars/workspace/default-avatar_y.svg'; +import WorkspaceZ from '../../../assets/images/avatars/workspace/default-avatar_z.svg'; + +export { + Workspace0, + Workspace1, + Workspace2, + Workspace3, + Workspace4, + Workspace5, + Workspace6, + Workspace7, + Workspace8, + Workspace9, + WorkspaceA, + WorkspaceB, + WorkspaceC, + WorkspaceD, + WorkspaceE, + WorkspaceF, + WorkspaceG, + WorkspaceH, + WorkspaceI, + WorkspaceJ, + WorkspaceK, + WorkspaceL, + WorkspaceM, + WorkspaceN, + WorkspaceO, + WorkspaceP, + WorkspaceQ, + WorkspaceR, + WorkspaceS, + WorkspaceT, + WorkspaceU, + WorkspaceV, + WorkspaceW, + WorkspaceX, + WorkspaceY, + WorkspaceZ, +}; From 8107cad90f3b1e3994dcae8cad9d91561ce15859 Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Sat, 4 Feb 2023 09:30:20 -0800 Subject: [PATCH 03/23] Fix range for color options --- src/styles/StyleUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/styles/StyleUtils.js b/src/styles/StyleUtils.js index efbbb766a097..5efcb7f09df4 100644 --- a/src/styles/StyleUtils.js +++ b/src/styles/StyleUtils.js @@ -91,7 +91,7 @@ function getDefaultWorspaceAvatarColor(workspaceName) { ['#28736D', '#CCF7FF'], ]; - const colorHash = ReportUtils.hashLogin(workspaceName, colorOptions.length); + const colorHash = ReportUtils.hashLogin(workspaceName, colorOptions.length - 1); // eslint-disable-next-line no-console console.log('HASH RESULTS', colorHash, {backgroundColor: colorOptions[colorHash][0], fill: colorOptions[colorHash][1]}); From 0a96372622d2a2338844fb4fedcbd20dc8c8af27 Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Sat, 18 Feb 2023 14:26:00 -0800 Subject: [PATCH 04/23] Restructure icons shape in order to handle workspace avatars everywhere --- src/CONST.js | 2 + src/components/Avatar.js | 19 +++++- src/components/AvatarWithImagePicker.js | 5 ++ src/components/IOUConfirmationList.js | 6 +- src/components/Icon/index.js | 17 ++--- src/components/MenuItem.js | 17 +++++ src/components/MultipleAvatars.js | 22 +++++-- src/components/ReportActionItem/IOUPreview.js | 12 +++- src/components/RoomHeaderAvatars.js | 25 +++++--- src/components/SubscriptAvatar.js | 26 ++++++-- src/components/menuItemPropTypes.js | 8 ++- src/components/optionPropTypes.js | 6 +- src/libs/OptionsListUtils.js | 12 +++- src/libs/ReportUtils.js | 62 ++++++++++++++----- src/pages/ReportParticipantsPage.js | 7 ++- .../home/report/ReportActionItemCreated.js | 1 - src/pages/iou/IOUModal.js | 6 +- src/pages/iou/steps/IOUConfirmPage.js | 6 +- .../IOUParticipantsPage.js | 6 +- .../IOUParticipantsSplit.js | 6 +- src/pages/reportPropTypes.js | 6 +- src/pages/settings/InitialSettingsPage.js | 7 ++- src/pages/workspace/WorkspaceInitialPage.js | 35 +++-------- src/pages/workspace/WorkspaceMembersPage.js | 6 +- src/pages/workspace/WorkspaceSettingsPage.js | 21 +++---- src/pages/workspace/WorkspacesListPage.js | 5 +- src/stories/OptionRow.stories.js | 2 +- src/styles/StyleUtils.js | 48 ++++++++++---- src/styles/styles.js | 11 +++- src/styles/variables.js | 1 + 30 files changed, 297 insertions(+), 116 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index 12b2fdb1b8f7..48c07ab53da3 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -762,6 +762,8 @@ const CONST = { ICON_TYPE_ICON: 'icon', ICON_TYPE_AVATAR: 'avatar', + ICON_TYPE_WORKSPACE: 'workspace', + AVATAR_SIZE: { LARGE: 'large', MEDIUM: 'medium', diff --git a/src/components/Avatar.js b/src/components/Avatar.js index 3aaddd895ea8..1a7f5f25c609 100644 --- a/src/components/Avatar.js +++ b/src/components/Avatar.js @@ -34,6 +34,12 @@ const propTypes = { /** A fallback avatar icon to display when there is an error on loading avatar from remote URL. */ fallbackIcon: PropTypes.func, + /** Denotes whether it is an avatar or a workspace avatar */ + type: PropTypes.oneOf([CONST.ICON_TYPE_AVATAR, CONST.ICON_TYPE_WORKSPACE]), + + /** Owner of the avatar, typically a login email or workspace name */ + name: PropTypes.string, + /** Props to detect online status */ network: networkPropTypes.isRequired, }; @@ -45,6 +51,8 @@ const defaultProps = { size: CONST.AVATAR_SIZE.DEFAULT, fill: themeColors.icon, fallbackIcon: Expensicons.FallbackAvatar, + type: CONST.ICON_TYPE_AVATAR, + name: '', }; class Avatar extends PureComponent { @@ -68,9 +76,13 @@ class Avatar extends PureComponent { return null; } + const isWorkspace = this.props.type === CONST.ICON_TYPE_WORKSPACE; + const iconSize = StyleUtils.getAvatarSize(this.props.size); + const imageStyle = [ StyleUtils.getAvatarStyle(this.props.size), ...this.props.imageStyles, + StyleUtils.getAvatarBorderRadius(iconSize, this.props.type), ]; const iconStyle = [ @@ -78,7 +90,6 @@ class Avatar extends PureComponent { styles.bgTransparent, ...this.props.imageStyles, ]; - const iconSize = StyleUtils.getAvatarSize(this.props.size); return ( @@ -90,7 +101,11 @@ class Avatar extends PureComponent { height={iconSize} width={iconSize} fill={this.state.imageError ? themeColors.offline : this.props.fill} - isSVGAvatar + isWorkspaceAvatar + additionalStyles={[ + StyleUtils.getAvatarSVGBorder(this.props.type, iconSize), + isWorkspace ? StyleUtils.getDefaultWorspaceAvatarColor(this.props.name) : {}, + ]} /> ) diff --git a/src/components/AvatarWithImagePicker.js b/src/components/AvatarWithImagePicker.js index a2fa0f41da28..159e7019a8ec 100644 --- a/src/components/AvatarWithImagePicker.js +++ b/src/components/AvatarWithImagePicker.js @@ -57,6 +57,9 @@ const propTypes = { /** A fallback avatar icon to display when there is an error on loading avatar from remote URL. */ fallbackIcon: PropTypes.func, + /** A fallback avatar icon to display when there is an error on loading avatar from remote URL. */ + type: PropTypes.string, + ...withLocalizePropTypes, }; @@ -70,6 +73,7 @@ const defaultProps = { isUploading: false, size: CONST.AVATAR_SIZE.DEFAULT, fallbackIcon: Expensicons.FallbackAvatar, + type: CONST.ICON_TYPE_AVATAR, }; class AvatarWithImagePicker extends React.Component { @@ -258,6 +262,7 @@ class AvatarWithImagePicker extends React.Component { source={this.props.source} fallbackIcon={this.props.fallbackIcon} size={this.props.size} + type={this.props.type} /> ) : ( diff --git a/src/components/IOUConfirmationList.js b/src/components/IOUConfirmationList.js index 53baab7d64fa..9f00b086fb78 100755 --- a/src/components/IOUConfirmationList.js +++ b/src/components/IOUConfirmationList.js @@ -44,7 +44,11 @@ const propTypes = { login: PropTypes.string.isRequired, alternateText: PropTypes.string, hasDraftComment: PropTypes.bool, - icons: PropTypes.arrayOf(PropTypes.string), + icons: PropTypes.arrayOf(PropTypes.shape({ + source: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), + type: PropTypes.string, + name: PropTypes.string, + })), searchText: PropTypes.string, text: PropTypes.string, keyForList: PropTypes.string, diff --git a/src/components/Icon/index.js b/src/components/Icon/index.js index d335a52a58f7..73e059caa7db 100644 --- a/src/components/Icon/index.js +++ b/src/components/Icon/index.js @@ -26,14 +26,11 @@ const propTypes = { /** Is inline icon */ inline: PropTypes.bool, - /** Is SVG avatar icon */ - isSVGAvatar: PropTypes.bool, - /** Is workspace icon */ isWorkspaceAvatar: PropTypes.bool, // eslint-disable-next-line react/forbid-prop-types - workspaceColorStyle: PropTypes.object, + additionalStyles: PropTypes.arrayOf(PropTypes.object), }; const defaultProps = { @@ -42,9 +39,8 @@ const defaultProps = { fill: themeColors.icon, small: false, inline: false, - isSVGAvatar: false, isWorkspaceAvatar: false, - workspaceColorStyle: {}, + additionalStyles: [], }; // We must use a class component to create an animatable component with the Animated API @@ -54,7 +50,8 @@ class Icon extends PureComponent { const width = this.props.small ? variables.iconSizeSmall : this.props.width; const height = this.props.small ? variables.iconSizeSmall : this.props.height; const iconStyles = [StyleUtils.getWidthAndHeightStyle(width, height), IconWrapperStyles, styles.pAbsolute, - StyleUtils.getAvatarSVGBorder(this.props.isSVGAvatar, this.props.isWorkspaceAvatar), this.props.workspaceColorStyle]; + ...this.props.additionalStyles, + ]; if (this.props.inline) { return ( @@ -76,11 +73,7 @@ class Icon extends PureComponent { return ( { /> )} + {(props.icon && props.iconType === CONST.ICON_TYPE_WORKSPACE) && ( + + + + )} {(props.icon && props.iconType === CONST.ICON_TYPE_AVATAR) && ( { @@ -91,9 +97,11 @@ const MultipleAvatars = (props) => { style={[styles.horizontalStackedAvatar, StyleUtils.getHorizontalStackedAvatarBorderStyle(props.isHovered, props.isPressed), horizontalStyles[index]]} > )) @@ -124,11 +132,13 @@ const MultipleAvatars = (props) => { {/* View is necessary for tooltip to show for multiple avatars in LHN */} @@ -139,11 +149,13 @@ const MultipleAvatars = (props) => { diff --git a/src/components/ReportActionItem/IOUPreview.js b/src/components/ReportActionItem/IOUPreview.js index 35105f13a9ad..5bced4225915 100644 --- a/src/components/ReportActionItem/IOUPreview.js +++ b/src/components/ReportActionItem/IOUPreview.js @@ -136,8 +136,16 @@ const IOUPreview = (props) => { const managerName = ReportUtils.getDisplayNameForParticipant(managerEmail, true); const ownerName = ReportUtils.getDisplayNameForParticipant(ownerEmail, true); - const managerAvatar = ReportUtils.getAvatar(lodashGet(props.personalDetails, [managerEmail, 'avatar']), managerEmail); - const ownerAvatar = ReportUtils.getAvatar(lodashGet(props.personalDetails, [ownerEmail, 'avatar']), ownerEmail); + const managerAvatar = { + source: ReportUtils.getAvatar(lodashGet(props.personalDetails, [managerEmail, 'avatar']), managerEmail), + type: CONST.ICON_TYPE_AVATAR, + name: managerEmail, + }; + const ownerAvatar = { + source: ReportUtils.getAvatar(lodashGet(props.personalDetails, [ownerEmail, 'avatar']), ownerEmail), + type: CONST.ICON_TYPE_AVATAR, + name: ownerEmail, + }; const cachedTotal = props.iouReport.total && props.iouReport.currency ? props.numberFormat( Math.abs(props.iouReport.total) / 100, diff --git a/src/components/RoomHeaderAvatars.js b/src/components/RoomHeaderAvatars.js index 0c91b421dcaf..e36352f42ae4 100644 --- a/src/components/RoomHeaderAvatars.js +++ b/src/components/RoomHeaderAvatars.js @@ -10,8 +10,11 @@ import themeColors from '../styles/themes/default'; import * as StyleUtils from '../styles/StyleUtils'; const propTypes = { - /** Array of avatar URLs or icons */ - icons: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.func])), + icons: PropTypes.arrayOf(PropTypes.shape({ + source: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), + type: PropTypes.string, + name: PropTypes.string, + })), }; const defaultProps = { @@ -26,10 +29,12 @@ const RoomHeaderAvatars = (props) => { if (props.icons.length === 1) { return ( ); } @@ -45,13 +50,18 @@ const RoomHeaderAvatars = (props) => { return ( - {_.map(iconsToDisplay, (val, index) => ( - + {_.map(iconsToDisplay, (icon, index) => ( + {index === CONST.REPORT.MAX_PREVIEW_AVATARS - 1 && props.icons.length - CONST.REPORT.MAX_PREVIEW_AVATARS !== 0 && ( <> @@ -60,6 +70,7 @@ const RoomHeaderAvatars = (props) => { styles.roomHeaderAvatarSize, styles.roomHeaderAvatar, ...iconStyle, + StyleUtils.getAvatarBorderRadius(CONST.AVATAR_SIZE.LARGE_BORDERED, icon.type), styles.roomHeaderAvatarOverlay, ]} /> diff --git a/src/components/SubscriptAvatar.js b/src/components/SubscriptAvatar.js index 4261d9e26678..d90b869b5c89 100644 --- a/src/components/SubscriptAvatar.js +++ b/src/components/SubscriptAvatar.js @@ -11,10 +11,18 @@ import * as StyleUtils from '../styles/StyleUtils'; const propTypes = { /** Avatar URL or icon */ - mainAvatar: PropTypes.oneOfType([PropTypes.string, PropTypes.func]).isRequired, + mainAvatar: PropTypes.shape({ + source: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), + type: PropTypes.string, + name: PropTypes.string, + }), /** Subscript avatar URL or icon */ - secondaryAvatar: PropTypes.oneOfType([PropTypes.string, PropTypes.func]).isRequired, + secondaryAvatar: PropTypes.shape({ + source: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), + type: PropTypes.string, + name: PropTypes.string, + }), /** Tooltip for the main avatar */ mainTooltip: PropTypes.string, @@ -34,25 +42,33 @@ const defaultProps = { secondaryTooltip: '', size: CONST.AVATAR_SIZE.DEFAULT, backgroundColor: themeColors.componentBG, + mainAvatar: {}, + secondaryAvatar: {}, }; const SubscriptAvatar = props => ( diff --git a/src/components/menuItemPropTypes.js b/src/components/menuItemPropTypes.js index 949d1ca26f1a..665b535ad871 100644 --- a/src/components/menuItemPropTypes.js +++ b/src/components/menuItemPropTypes.js @@ -68,7 +68,7 @@ const propTypes = { subtitle: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), /** Flag to choose between avatar image or an icon */ - iconType: PropTypes.oneOf([CONST.ICON_TYPE_AVATAR, CONST.ICON_TYPE_ICON]), + iconType: PropTypes.oneOf([CONST.ICON_TYPE_AVATAR, CONST.ICON_TYPE_ICON, CONST.ICON_TYPE_WORKSPACE]), /** Whether the menu item should be interactive at all */ interactive: PropTypes.bool, @@ -77,7 +77,11 @@ const propTypes = { fallbackIcon: PropTypes.func, /** Avatars to show on the right of the menu item */ - floatRightAvatars: PropTypes.arrayOf(PropTypes.string), + floatRightAvatars: PropTypes.arrayOf(PropTypes.shape({ + source: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), + type: PropTypes.string, + name: PropTypes.string, + })), /** The type of brick road indicator to show. */ brickRoadIndicator: PropTypes.oneOf([CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR, CONST.BRICK_ROAD_INDICATOR_STATUS.INFO, '']), diff --git a/src/components/optionPropTypes.js b/src/components/optionPropTypes.js index 0cd38a206cdd..10b2f79e775c 100644 --- a/src/components/optionPropTypes.js +++ b/src/components/optionPropTypes.js @@ -13,7 +13,11 @@ export default PropTypes.shape({ alternateText: PropTypes.string, // Array of URLs or icons - icons: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.func])), + icons: PropTypes.arrayOf(PropTypes.shape({ + source: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), + type: PropTypes.string, + name: PropTypes.string, + })), // Login (only present when there is a single participant) login: PropTypes.string, diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 0f8c3828a543..1f2833357bd9 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -593,7 +593,11 @@ function getOptions(reports, personalDetails, { }); // If user doesn't exist, use a default avatar - userToInvite.icons = [ReportUtils.getAvatar('', login)]; + userToInvite.icons = [{ + source: ReportUtils.getAvatar('', login), + name: login, + type: CONST.ICON_TYPE_AVATAR, + }]; } // If we are prioritizing 1:1 chats in search, do it only once we started searching @@ -663,7 +667,11 @@ function getIOUConfirmationOptionsFromMyPersonalDetail(myPersonalDetail, amountT return { text: myPersonalDetail.displayName, alternateText: myPersonalDetail.login, - icons: [ReportUtils.getAvatar(myPersonalDetail.avatar, myPersonalDetail.login)], + icons: [{ + source: ReportUtils.getAvatar(myPersonalDetail.avatar, myPersonalDetail.login), + name: myPersonalDetail.login, + type: CONST.ICON_TYPE_AVATAR, + }], descriptiveText: amountText, login: myPersonalDetail.login, }; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index a40ba64feeb4..d06a05b6e4c5 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -479,8 +479,6 @@ function getDefaultWorkspaceAvatar(workspaceName) { // Remove all chars not A-Z or 0-9 including underscore const alphaNumeric = workspaceName.replace(/[^0-9a-z]/gi, '').toUpperCase(); const firstChar = alphaNumeric[0]; - // eslint-disable-next-line no-console - console.log('first character: ', firstChar, defaultWorkspaceAvatars[`Workspace${firstChar}`]); return !firstChar ? Expensicons.FallbackWorkspaceAvatar : defaultWorkspaceAvatars[`Workspace${firstChar}`]; } @@ -562,42 +560,72 @@ function getFullSizeAvatar(avatarURL, login) { * @returns {Array<*>} */ function getIcons(report, personalDetails, policies, defaultIcon = null) { + let source = ''; + let type = CONST.ICON_TYPE_AVATAR; + let name = ''; + if (_.isEmpty(report)) { - return [defaultIcon || Expensicons.FallbackAvatar]; + source = defaultIcon || Expensicons.FallbackAvatar; + return [{source, type, name}]; } if (isConciergeChatReport(report)) { - return [CONST.CONCIERGE_ICON_URL]; + source = CONST.CONCIERGE_ICON_URL; + return [{source, type, name}]; } if (isArchivedRoom(report)) { - return [Expensicons.DeletedRoomAvatar]; + source = Expensicons.DeletedRoomAvatar; + return [{source, type, name}]; } if (isDomainRoom(report)) { - return [Expensicons.DomainRoomAvatar]; + source = Expensicons.DomainRoomAvatar; + return [{source, type, name}]; } if (isAdminRoom(report)) { - return [Expensicons.AdminRoomAvatar]; + source = Expensicons.AdminRoomAvatar; + return [{source, type, name}]; } if (isAnnounceRoom(report)) { - return [Expensicons.AnnounceRoomAvatar]; + source = Expensicons.AnnounceRoomAvatar; + return [{source, type, name}]; } if (isChatRoom(report)) { - return [Expensicons.ActiveRoomAvatar]; + source = Expensicons.ActiveRoomAvatar; + return [{source, type, name}]; } if (isPolicyExpenseChat(report)) { + const workspaceName = lodashGet(policies, [ + `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, 'name', + ]); + const policyExpenseChatAvatarSource = lodashGet(policies, [ `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, 'avatar', - ]) || Expensicons.Workspace; + ]) || getDefaultWorkspaceAvatar(workspaceName); // Return the workspace avatar if the user is the owner of the policy expense chat if (report.isOwnPolicyExpenseChat) { - return [policyExpenseChatAvatarSource]; + source = policyExpenseChatAvatarSource; + type = CONST.ICON_TYPE_WORKSPACE; + name = workspaceName; + return [{source, type, name}]; } + const adminIcon = { + source: getAvatar(lodashGet(personalDetails, [report.ownerEmail, 'avatar']), report.ownerEmail), + name: report.ownerEmail, + type: CONST.ICON_TYPE_AVATAR, + }; + + const workspaceIcon = { + source: policyExpenseChatAvatarSource, + type: CONST.ICON_TYPE_WORKSPACE, + name: workspaceName, + }; + // If the user is an admin, return avatar source of the other participant of the report // (their workspace chat) and the avatar source of the workspace return [ - getAvatar(lodashGet(personalDetails, [report.ownerEmail, 'avatar']), report.ownerEmail), - policyExpenseChatAvatarSource, + adminIcon, + workspaceIcon, ]; } @@ -606,7 +634,6 @@ function getIcons(report, personalDetails, policies, defaultIcon = null) { for (let i = 0; i < participants.length; i++) { const login = participants[i]; - const avatarSource = getAvatar(lodashGet(personalDetails, [login, 'avatar'], ''), login); participantDetails.push([ login, @@ -621,7 +648,12 @@ function getIcons(report, personalDetails, policies, defaultIcon = null) { // Now that things are sorted, gather only the avatars (third element in the array) and return those const avatars = []; for (let i = 0; i < sortedParticipantDetails.length; i++) { - avatars.push(sortedParticipantDetails[i][2]); + const userIcon = { + source: sortedParticipantDetails[i][2], + type: CONST.ICON_TYPE_AVATAR, + name: sortedParticipantDetails[i][0], + }; + avatars.push(userIcon); } return avatars; diff --git a/src/pages/ReportParticipantsPage.js b/src/pages/ReportParticipantsPage.js index 07c4d62b448a..9f21d9a7826d 100755 --- a/src/pages/ReportParticipantsPage.js +++ b/src/pages/ReportParticipantsPage.js @@ -21,6 +21,7 @@ import * as ReportUtils from '../libs/ReportUtils'; import reportPropTypes from './reportPropTypes'; import withReportOrNavigateHome from './home/report/withReportOrNavigateHome'; import FullPageNotFoundView from '../components/BlockingViews/FullPageNotFoundView'; +import CONST from '../CONST'; const propTypes = { /* Onyx Props */ @@ -59,7 +60,11 @@ const getAllParticipants = (report, personalDetails) => { return ({ alternateText: userLogin, displayName: userPersonalDetail.displayName, - icons: [ReportUtils.getAvatar(userPersonalDetail.avatar, login)], + icons: [{ + source: ReportUtils.getAvatar(userPersonalDetail.avatar, login), + name: login, + type: CONST.ICON_TYPE_AVATAR, + }], keyForList: userLogin, login, text: userPersonalDetail.displayName, diff --git a/src/pages/home/report/ReportActionItemCreated.js b/src/pages/home/report/ReportActionItemCreated.js index be958eb4bb03..28b0d9cb0a94 100644 --- a/src/pages/home/report/ReportActionItemCreated.js +++ b/src/pages/home/report/ReportActionItemCreated.js @@ -43,7 +43,6 @@ const defaultProps = { const ReportActionItemCreated = (props) => { const icons = ReportUtils.getIcons(props.report, props.personalDetails, props.policies); - return ( PolicyUtils.shouldShowPolicy(policy, this.props.network.isOffline)) .sortBy(policy => policy.name) - .pluck('avatar') + .map(policy => ({ + source: policy.avatar || ReportUtils.getDefaultWorkspaceAvatar(policy.name), + name: policy.name, + type: CONST.ICON_TYPE_WORKSPACE, + })) .value(); + const policyBrickRoadIndicator = _.chain(this.props.policies) .filter(policy => policy && policy.type === CONST.POLICY.TYPE.FREE && policy.role === CONST.POLICY.ROLE.ADMIN) .find(policy => PolicyUtils.hasPolicyError(policy) || PolicyUtils.getPolicyBrickRoadIndicatorStatus(policy, this.props.policyMembers)) diff --git a/src/pages/workspace/WorkspaceInitialPage.js b/src/pages/workspace/WorkspaceInitialPage.js index 678391b02150..7bb72057732f 100644 --- a/src/pages/workspace/WorkspaceInitialPage.js +++ b/src/pages/workspace/WorkspaceInitialPage.js @@ -10,12 +10,10 @@ import styles from '../../styles/styles'; import Tooltip from '../../components/Tooltip'; import Text from '../../components/Text'; import ConfirmModal from '../../components/ConfirmModal'; -import Icon from '../../components/Icon'; import * as Expensicons from '../../components/Icon/Expensicons'; import ScreenWrapper from '../../components/ScreenWrapper'; import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize'; import MenuItem from '../../components/MenuItem'; -import themedefault from '../../styles/themes/default'; import HeaderWithCloseButton from '../../components/HeaderWithCloseButton'; import compose from '../../libs/compose'; import Avatar from '../../components/Avatar'; @@ -28,7 +26,6 @@ import CONST from '../../CONST'; import * as ReimbursementAccount from '../../libs/actions/ReimbursementAccount'; import ONYXKEYS from '../../ONYXKEYS'; import OfflineWithFeedback from '../../components/OfflineWithFeedback'; -import * as StyleUtils from '../../styles/StyleUtils'; import * as ReportUtils from '../../libs/ReportUtils'; const propTypes = { @@ -98,8 +95,6 @@ class WorkspaceInitialPage extends React.Component { render() { const policy = this.props.policy; - // eslint-disable-next-line no-console - console.log('POLICY: ', this.props.policy, lodashGet(this.props.policy, 'name', '')); const policyName = lodashGet(this.props.policy, 'name', ''); const hasMembersError = PolicyUtils.hasPolicyMemberError(this.props.policyMemberList); const hasGeneralSettingsError = !_.isEmpty(lodashGet(this.props.policy, 'errorFields.generalSettings', {})) @@ -197,26 +192,16 @@ class WorkspaceInitialPage extends React.Component { style={[styles.pRelative, styles.avatarLarge]} onPress={this.openEditor} > - {this.props.policy.avatar - ? ( - - ) - : ( - - )} + {!_.isEmpty(this.props.policy.name) && ( diff --git a/src/pages/workspace/WorkspaceSettingsPage.js b/src/pages/workspace/WorkspaceSettingsPage.js index 56d04a54624e..e2eb3730155f 100644 --- a/src/pages/workspace/WorkspaceSettingsPage.js +++ b/src/pages/workspace/WorkspaceSettingsPage.js @@ -9,10 +9,8 @@ import styles from '../../styles/styles'; import Text from '../../components/Text'; import compose from '../../libs/compose'; import * as Policy from '../../libs/actions/Policy'; -import Icon from '../../components/Icon'; import * as Expensicons from '../../components/Icon/Expensicons'; import AvatarWithImagePicker from '../../components/AvatarWithImagePicker'; -import defaultTheme from '../../styles/themes/default'; import CONST from '../../CONST'; import Picker from '../../components/Picker'; import TextInput from '../../components/TextInput'; @@ -21,8 +19,8 @@ import withPolicy, {policyPropTypes, policyDefaultProps} from './withPolicy'; import {withNetwork} from '../../components/OnyxProvider'; import OfflineWithFeedback from '../../components/OfflineWithFeedback'; import Form from '../../components/Form'; -import * as StyleUtils from '../../styles/StyleUtils'; import * as ReportUtils from '../../libs/ReportUtils'; +import Avatar from '../../components/Avatar'; const propTypes = { ...policyPropTypes, @@ -79,8 +77,6 @@ class WorkspaceSettingsPage extends React.Component { } render() { - // eslint-disable-next-line no-console - console.log('POLICY: ', this.props.policy, lodashGet(this.props.policy, 'name', '')); const policyName = lodashGet(this.props.policy, 'name', ''); return ( ( - )} + type={CONST.ICON_TYPE_WORKSPACE} fallbackIcon={Expensicons.FallbackWorkspaceAvatar} style={[styles.mb3]} anchorPosition={{top: 172, right: 18}} diff --git a/src/pages/workspace/WorkspacesListPage.js b/src/pages/workspace/WorkspacesListPage.js index 5ef22eea7912..cbf604ae10f8 100755 --- a/src/pages/workspace/WorkspacesListPage.js +++ b/src/pages/workspace/WorkspacesListPage.js @@ -24,6 +24,7 @@ import Button from '../../components/Button'; import FixedFooter from '../../components/FixedFooter'; import BlockingView from '../../components/BlockingViews/BlockingView'; import {withNetwork} from '../../components/OnyxProvider'; +import * as ReportUtils from '../../libs/ReportUtils'; const propTypes = { /* Onyx Props */ @@ -119,7 +120,7 @@ class WorkspacesListPage extends Component { .filter(policy => PolicyUtils.shouldShowPolicy(policy, this.props.network.isOffline)) .map(policy => ({ title: policy.name, - icon: policy.avatar ? policy.avatar : Expensicons.Building, + icon: policy.avatar ? policy.avatar : ReportUtils.getDefaultWorkspaceAvatar(policy.name), iconType: policy.avatar ? CONST.ICON_TYPE_AVATAR : CONST.ICON_TYPE_ICON, action: () => Navigation.navigate(ROUTES.getWorkspaceInitialRoute(policy.id)), iconStyles: policy.avatar ? [] : [styles.popoverMenuIconEmphasized], @@ -157,7 +158,7 @@ class WorkspacesListPage extends Component { Date: Sat, 18 Feb 2023 14:48:21 -0800 Subject: [PATCH 05/23] Add default building for non A-Z/0-9 characters, clean up utils functions --- .../Icon/WorkspaceDefaultAvatars.js | 2 + src/libs/ReportUtils.js | 47 ++++++++++--------- src/styles/StyleUtils.js | 2 +- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/components/Icon/WorkspaceDefaultAvatars.js b/src/components/Icon/WorkspaceDefaultAvatars.js index acf751b4075c..0f5490b981bd 100644 --- a/src/components/Icon/WorkspaceDefaultAvatars.js +++ b/src/components/Icon/WorkspaceDefaultAvatars.js @@ -34,6 +34,7 @@ import WorkspaceW from '../../../assets/images/avatars/workspace/default-avatar_ import WorkspaceX from '../../../assets/images/avatars/workspace/default-avatar_x.svg'; import WorkspaceY from '../../../assets/images/avatars/workspace/default-avatar_y.svg'; import WorkspaceZ from '../../../assets/images/avatars/workspace/default-avatar_z.svg'; +import WorkspaceBuilding from '../../../assets/images/avatars/workspace/default-avatar_building.svg'; export { Workspace0, @@ -72,4 +73,5 @@ export { WorkspaceX, WorkspaceY, WorkspaceZ, + WorkspaceBuilding, }; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index d06a05b6e4c5..9010d9a291d5 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -478,9 +478,8 @@ function getDefaultWorkspaceAvatar(workspaceName) { // Remove all chars not A-Z or 0-9 including underscore const alphaNumeric = workspaceName.replace(/[^0-9a-z]/gi, '').toUpperCase(); - const firstChar = alphaNumeric[0]; - return !firstChar ? Expensicons.FallbackWorkspaceAvatar : defaultWorkspaceAvatars[`Workspace${firstChar}`]; + return !alphaNumeric ? defaultWorkspaceAvatars.WorkspaceBuilding : defaultWorkspaceAvatars[`Workspace${alphaNumeric[0]}`]; } /** @@ -560,37 +559,39 @@ function getFullSizeAvatar(avatarURL, login) { * @returns {Array<*>} */ function getIcons(report, personalDetails, policies, defaultIcon = null) { - let source = ''; - let type = CONST.ICON_TYPE_AVATAR; - let name = ''; + const result = { + source: '', + type: CONST.ICON_TYPE_AVATAR, + name: '', + }; if (_.isEmpty(report)) { - source = defaultIcon || Expensicons.FallbackAvatar; - return [{source, type, name}]; + result.source = defaultIcon || Expensicons.FallbackAvatar; + return [result]; } if (isConciergeChatReport(report)) { - source = CONST.CONCIERGE_ICON_URL; - return [{source, type, name}]; + result.source = CONST.CONCIERGE_ICON_URL; + return [result]; } if (isArchivedRoom(report)) { - source = Expensicons.DeletedRoomAvatar; - return [{source, type, name}]; + result.source = Expensicons.DeletedRoomAvatar; + return [result]; } if (isDomainRoom(report)) { - source = Expensicons.DomainRoomAvatar; - return [{source, type, name}]; + result.source = Expensicons.DomainRoomAvatar; + return [result]; } if (isAdminRoom(report)) { - source = Expensicons.AdminRoomAvatar; - return [{source, type, name}]; + result.source = Expensicons.AdminRoomAvatar; + return [result]; } if (isAnnounceRoom(report)) { - source = Expensicons.AnnounceRoomAvatar; - return [{source, type, name}]; + result.source = Expensicons.AnnounceRoomAvatar; + return [result]; } if (isChatRoom(report)) { - source = Expensicons.ActiveRoomAvatar; - return [{source, type, name}]; + result.source = Expensicons.ActiveRoomAvatar; + return [result]; } if (isPolicyExpenseChat(report)) { const workspaceName = lodashGet(policies, [ @@ -603,10 +604,10 @@ function getIcons(report, personalDetails, policies, defaultIcon = null) { // Return the workspace avatar if the user is the owner of the policy expense chat if (report.isOwnPolicyExpenseChat) { - source = policyExpenseChatAvatarSource; - type = CONST.ICON_TYPE_WORKSPACE; - name = workspaceName; - return [{source, type, name}]; + result.source = policyExpenseChatAvatarSource; + result.type = CONST.ICON_TYPE_WORKSPACE; + result.name = workspaceName; + return [result]; } const adminIcon = { diff --git a/src/styles/StyleUtils.js b/src/styles/StyleUtils.js index 04e800c6d73c..b135a65a0ef3 100644 --- a/src/styles/StyleUtils.js +++ b/src/styles/StyleUtils.js @@ -119,7 +119,7 @@ function getDefaultWorspaceAvatarColor(workspaceName) { ['#28736D', '#CCF7FF'], ]; - const colorHash = ReportUtils.hashLogin(workspaceName, colorOptions.length - 1); + const colorHash = ReportUtils.hashLogin(workspaceName.trim(), colorOptions.length - 1); return {backgroundColor: colorOptions[colorHash][0], fill: colorOptions[colorHash][1]}; } From d9143df5b9e6c1c1e7171defe59c59cc7cc15c3c Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Sat, 18 Feb 2023 15:15:50 -0800 Subject: [PATCH 06/23] Move proptypes into new file --- .../avatars/workspace/default-avatar_building.svg | 14 ++++++++++++++ src/components/Avatar.js | 2 +- src/components/AvatarWithImagePicker.js | 4 ++-- src/components/IOUConfirmationList.js | 7 ++----- src/components/Icon/index.js | 5 +++-- src/components/MultipleAvatars.js | 7 ++----- src/components/RoomHeaderAvatars.js | 7 ++----- src/components/SubscriptAvatar.js | 13 +++---------- src/components/avatarPropTypes.js | 8 ++++++++ src/components/optionPropTypes.js | 9 +++------ src/pages/iou/steps/IOUConfirmPage.js | 7 ++----- .../IOUParticipantsPage/IOUParticipantsPage.js | 7 ++----- .../IOUParticipantsPage/IOUParticipantsSplit.js | 7 ++----- src/pages/reportPropTypes.js | 7 ++----- 14 files changed, 48 insertions(+), 56 deletions(-) create mode 100644 assets/images/avatars/workspace/default-avatar_building.svg create mode 100644 src/components/avatarPropTypes.js diff --git a/assets/images/avatars/workspace/default-avatar_building.svg b/assets/images/avatars/workspace/default-avatar_building.svg new file mode 100644 index 000000000000..d249c47eed24 --- /dev/null +++ b/assets/images/avatars/workspace/default-avatar_building.svg @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/src/components/Avatar.js b/src/components/Avatar.js index 1a7f5f25c609..6c4c9c6fbbd1 100644 --- a/src/components/Avatar.js +++ b/src/components/Avatar.js @@ -101,7 +101,7 @@ class Avatar extends PureComponent { height={iconSize} width={iconSize} fill={this.state.imageError ? themeColors.offline : this.props.fill} - isWorkspaceAvatar + isWorkspaceAvatar={isWorkspace} additionalStyles={[ StyleUtils.getAvatarSVGBorder(this.props.type, iconSize), isWorkspace ? StyleUtils.getDefaultWorspaceAvatarColor(this.props.name) : {}, diff --git a/src/components/AvatarWithImagePicker.js b/src/components/AvatarWithImagePicker.js index 159e7019a8ec..6f33445ba146 100644 --- a/src/components/AvatarWithImagePicker.js +++ b/src/components/AvatarWithImagePicker.js @@ -57,8 +57,8 @@ const propTypes = { /** A fallback avatar icon to display when there is an error on loading avatar from remote URL. */ fallbackIcon: PropTypes.func, - /** A fallback avatar icon to display when there is an error on loading avatar from remote URL. */ - type: PropTypes.string, + /** Denotes whether it is an avatar or a workspace avatar */ + type: PropTypes.oneOf([CONST.ICON_TYPE_AVATAR, CONST.ICON_TYPE_WORKSPACE]), ...withLocalizePropTypes, }; diff --git a/src/components/IOUConfirmationList.js b/src/components/IOUConfirmationList.js index 9f00b086fb78..b6b834828e67 100755 --- a/src/components/IOUConfirmationList.js +++ b/src/components/IOUConfirmationList.js @@ -16,6 +16,7 @@ import SettlementButton from './SettlementButton'; import ROUTES from '../ROUTES'; import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes, withCurrentUserPersonalDetailsDefaultProps} from './withCurrentUserPersonalDetails'; import * as IOUUtils from '../libs/IOUUtils'; +import avatarPropTypes from './avatarPropTypes'; const propTypes = { /** Callback to inform parent modal of success */ @@ -44,11 +45,7 @@ const propTypes = { login: PropTypes.string.isRequired, alternateText: PropTypes.string, hasDraftComment: PropTypes.bool, - icons: PropTypes.arrayOf(PropTypes.shape({ - source: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), - type: PropTypes.string, - name: PropTypes.string, - })), + icons: PropTypes.arrayOf(avatarPropTypes), searchText: PropTypes.string, text: PropTypes.string, keyForList: PropTypes.string, diff --git a/src/components/Icon/index.js b/src/components/Icon/index.js index 73e059caa7db..7dc65d57f563 100644 --- a/src/components/Icon/index.js +++ b/src/components/Icon/index.js @@ -52,6 +52,7 @@ class Icon extends PureComponent { const iconStyles = [StyleUtils.getWidthAndHeightStyle(width, height), IconWrapperStyles, styles.pAbsolute, ...this.props.additionalStyles, ]; + const iconFill = this.props.isWorkspaceAvatar ? {} : this.props.fill; if (this.props.inline) { return ( @@ -63,7 +64,7 @@ class Icon extends PureComponent { @@ -78,7 +79,7 @@ class Icon extends PureComponent { ); diff --git a/src/components/MultipleAvatars.js b/src/components/MultipleAvatars.js index 897158e59f5f..e757f3855f8f 100644 --- a/src/components/MultipleAvatars.js +++ b/src/components/MultipleAvatars.js @@ -10,14 +10,11 @@ import themeColors from '../styles/themes/default'; import * as StyleUtils from '../styles/StyleUtils'; import CONST from '../CONST'; import variables from '../styles/variables'; +import avatarPropTypes from './avatarPropTypes'; const propTypes = { /** Array of avatar URLs or icons */ - icons: PropTypes.arrayOf(PropTypes.shape({ - source: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), - type: PropTypes.string, - name: PropTypes.string, - })), + icons: PropTypes.arrayOf(avatarPropTypes), /** Set the size of avatars */ size: PropTypes.oneOf(_.values(CONST.AVATAR_SIZE)), diff --git a/src/components/RoomHeaderAvatars.js b/src/components/RoomHeaderAvatars.js index e36352f42ae4..c1881f2e940f 100644 --- a/src/components/RoomHeaderAvatars.js +++ b/src/components/RoomHeaderAvatars.js @@ -8,13 +8,10 @@ import CONST from '../CONST'; import Avatar from './Avatar'; import themeColors from '../styles/themes/default'; import * as StyleUtils from '../styles/StyleUtils'; +import avatarPropTypes from './avatarPropTypes'; const propTypes = { - icons: PropTypes.arrayOf(PropTypes.shape({ - source: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), - type: PropTypes.string, - name: PropTypes.string, - })), + icons: PropTypes.arrayOf(avatarPropTypes), }; const defaultProps = { diff --git a/src/components/SubscriptAvatar.js b/src/components/SubscriptAvatar.js index d90b869b5c89..d7e8acbbf1dc 100644 --- a/src/components/SubscriptAvatar.js +++ b/src/components/SubscriptAvatar.js @@ -8,21 +8,14 @@ import themeColors from '../styles/themes/default'; import Avatar from './Avatar'; import CONST from '../CONST'; import * as StyleUtils from '../styles/StyleUtils'; +import avatarPropTypes from './avatarPropTypes'; const propTypes = { /** Avatar URL or icon */ - mainAvatar: PropTypes.shape({ - source: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), - type: PropTypes.string, - name: PropTypes.string, - }), + mainAvatar: avatarPropTypes, /** Subscript avatar URL or icon */ - secondaryAvatar: PropTypes.shape({ - source: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), - type: PropTypes.string, - name: PropTypes.string, - }), + secondaryAvatar: avatarPropTypes, /** Tooltip for the main avatar */ mainTooltip: PropTypes.string, diff --git a/src/components/avatarPropTypes.js b/src/components/avatarPropTypes.js new file mode 100644 index 000000000000..c068b481c596 --- /dev/null +++ b/src/components/avatarPropTypes.js @@ -0,0 +1,8 @@ +import PropTypes from 'prop-types'; +import CONST from '../CONST'; + +export default PropTypes.shape({ + source: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), + type: PropTypes.oneOf([CONST.ICON_TYPE_AVATAR, CONST.ICON_TYPE_WORKSPACE]), + name: PropTypes.string, +}); diff --git a/src/components/optionPropTypes.js b/src/components/optionPropTypes.js index 10b2f79e775c..7c89c9283156 100644 --- a/src/components/optionPropTypes.js +++ b/src/components/optionPropTypes.js @@ -1,6 +1,7 @@ import PropTypes from 'prop-types'; import CONST from '../CONST'; import participantPropTypes from './participantPropTypes'; +import avatarPropTypes from './avatarPropTypes'; export default PropTypes.shape({ // Text to display @@ -12,12 +13,8 @@ export default PropTypes.shape({ // Alternate text to display alternateText: PropTypes.string, - // Array of URLs or icons - icons: PropTypes.arrayOf(PropTypes.shape({ - source: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), - type: PropTypes.string, - name: PropTypes.string, - })), + // Array of icon information + icons: PropTypes.arrayOf(avatarPropTypes), // Login (only present when there is a single participant) login: PropTypes.string, diff --git a/src/pages/iou/steps/IOUConfirmPage.js b/src/pages/iou/steps/IOUConfirmPage.js index 871a99158427..ea321b0e0a9b 100644 --- a/src/pages/iou/steps/IOUConfirmPage.js +++ b/src/pages/iou/steps/IOUConfirmPage.js @@ -2,6 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import IOUConfirmationList from '../../../components/IOUConfirmationList'; import CONST from '../../../CONST'; +import avatarPropTypes from '../../../components/avatarPropTypes'; const propTypes = { /** Callback to inform parent modal of success */ @@ -27,11 +28,7 @@ const propTypes = { login: PropTypes.string.isRequired, alternateText: PropTypes.string, hasDraftComment: PropTypes.bool, - icons: PropTypes.arrayOf(PropTypes.shape({ - source: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), - type: PropTypes.string, - name: PropTypes.string, - })), + icons: PropTypes.arrayOf(avatarPropTypes), searchText: PropTypes.string, text: PropTypes.string, keyForList: PropTypes.string, diff --git a/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsPage.js b/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsPage.js index 4d91f37c0fc1..2d948552611e 100644 --- a/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsPage.js +++ b/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsPage.js @@ -7,6 +7,7 @@ import IOUParticipantsSplit from './IOUParticipantsSplit'; import IOUParticipantsRequest from './IOUParticipantsRequest'; import styles from '../../../../styles/styles'; import FullScreenLoadingIndicator from '../../../../components/FullscreenLoadingIndicator'; +import avatarPropTypes from '../../../../components/avatarPropTypes'; const propTypes = { /** Callback to inform parent modal of success */ @@ -23,11 +24,7 @@ const propTypes = { login: PropTypes.string.isRequired, alternateText: PropTypes.string, hasDraftComment: PropTypes.bool, - icons: PropTypes.arrayOf(PropTypes.shape({ - source: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), - type: PropTypes.string, - name: PropTypes.string, - })), + icons: PropTypes.arrayOf(avatarPropTypes), searchText: PropTypes.string, text: PropTypes.string, keyForList: PropTypes.string, diff --git a/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js b/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js index d87d1b652548..716aae99900c 100755 --- a/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js +++ b/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js @@ -13,6 +13,7 @@ import compose from '../../../../libs/compose'; import Text from '../../../../components/Text'; import personalDetailsPropType from '../../../personalDetailsPropType'; import reportPropTypes from '../../../reportPropTypes'; +import avatarPropTypes from '../../../../components/avatarPropTypes'; const propTypes = { /** Beta features list */ @@ -29,11 +30,7 @@ const propTypes = { login: PropTypes.string.isRequired, alternateText: PropTypes.string, hasDraftComment: PropTypes.bool, - icons: PropTypes.arrayOf(PropTypes.shape({ - source: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), - type: PropTypes.string, - name: PropTypes.string, - })), + icons: PropTypes.arrayOf(avatarPropTypes), searchText: PropTypes.string, text: PropTypes.string, keyForList: PropTypes.string, diff --git a/src/pages/reportPropTypes.js b/src/pages/reportPropTypes.js index 35276b5175ed..ef1e78576a5a 100644 --- a/src/pages/reportPropTypes.js +++ b/src/pages/reportPropTypes.js @@ -1,6 +1,7 @@ import _ from 'underscore'; import PropTypes from 'prop-types'; import CONST from '../CONST'; +import avatarPropTypes from '../components/avatarPropTypes'; export default PropTypes.shape({ @@ -11,11 +12,7 @@ export default PropTypes.shape({ hasOutstandingIOU: PropTypes.bool, /** List of icons for report participants */ - icons: PropTypes.arrayOf(PropTypes.shape({ - source: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), - type: PropTypes.string, - name: PropTypes.string, - })), + icons: PropTypes.arrayOf(avatarPropTypes), /** Are we loading more report actions? */ isLoadingMoreReportActions: PropTypes.bool, From 6f90cb339ceb185e306c91681ad9fcc42a2762a0 Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Sat, 18 Feb 2023 15:30:23 -0800 Subject: [PATCH 07/23] Use proptype for floatRightAvatars --- src/components/menuItemPropTypes.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/components/menuItemPropTypes.js b/src/components/menuItemPropTypes.js index 665b535ad871..9f3b40a55b43 100644 --- a/src/components/menuItemPropTypes.js +++ b/src/components/menuItemPropTypes.js @@ -1,6 +1,7 @@ import PropTypes from 'prop-types'; import CONST from '../CONST'; import stylePropTypes from '../styles/stylePropTypes'; +import avatarPropTypes from './avatarPropTypes'; const propTypes = { /** Text to be shown as badge near the right end. */ @@ -77,11 +78,7 @@ const propTypes = { fallbackIcon: PropTypes.func, /** Avatars to show on the right of the menu item */ - floatRightAvatars: PropTypes.arrayOf(PropTypes.shape({ - source: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), - type: PropTypes.string, - name: PropTypes.string, - })), + floatRightAvatars: PropTypes.arrayOf(avatarPropTypes), /** The type of brick road indicator to show. */ brickRoadIndicator: PropTypes.oneOf([CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR, CONST.BRICK_ROAD_INDICATOR_STATUS.INFO, '']), From e156deedf35f4b6f4bcbf65b07887d6f463c6887 Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Sat, 18 Feb 2023 15:51:52 -0800 Subject: [PATCH 08/23] Styling for settings page horizontal avatars --- src/components/Avatar.js | 2 +- src/components/MultipleAvatars.js | 4 +++- src/components/SubscriptAvatar.js | 2 +- src/styles/StyleUtils.js | 19 ++++++++++--------- src/styles/styles.js | 12 ------------ src/styles/variables.js | 1 + 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/components/Avatar.js b/src/components/Avatar.js index 6c4c9c6fbbd1..f6eb8512ffe4 100644 --- a/src/components/Avatar.js +++ b/src/components/Avatar.js @@ -103,7 +103,7 @@ class Avatar extends PureComponent { fill={this.state.imageError ? themeColors.offline : this.props.fill} isWorkspaceAvatar={isWorkspace} additionalStyles={[ - StyleUtils.getAvatarSVGBorder(this.props.type, iconSize), + StyleUtils.getAvatarBorderStyle(this.props.type, iconSize), isWorkspace ? StyleUtils.getDefaultWorspaceAvatarColor(this.props.name) : {}, ]} /> diff --git a/src/components/MultipleAvatars.js b/src/components/MultipleAvatars.js index e757f3855f8f..35bcd2d8c600 100644 --- a/src/components/MultipleAvatars.js +++ b/src/components/MultipleAvatars.js @@ -91,7 +91,8 @@ const MultipleAvatars = (props) => { _.map([...props.icons].splice(0, 4).reverse(), (icon, index) => ( { // Set overlay background color with RGBA value so that the text will not inherit opacity StyleUtils.getBackgroundColorWithOpacityStyle(themeColors.overlay, variables.overlayOpacity), styles.horizontalStackedAvatar4Overlay, + StyleUtils.getAvatarBorderRadius(StyleUtils.getAvatarSize(props.size), props.icons[3].type), ]} > diff --git a/src/components/SubscriptAvatar.js b/src/components/SubscriptAvatar.js index d7e8acbbf1dc..240a87ae6a75 100644 --- a/src/components/SubscriptAvatar.js +++ b/src/components/SubscriptAvatar.js @@ -52,7 +52,7 @@ const SubscriptAvatar = props => ( diff --git a/src/styles/StyleUtils.js b/src/styles/StyleUtils.js index b135a65a0ef3..4a7c0d979f8f 100644 --- a/src/styles/StyleUtils.js +++ b/src/styles/StyleUtils.js @@ -60,6 +60,10 @@ function getAvatarBorderRadius(size = 0, type) { borderRadius = variables.componentBorderRadiusSmall; return {borderRadius}; } + if (size <= variables.avatarSizeSmall) { + borderRadius = variables.componentBorderRadiusMedium; + return {borderRadius}; + } if (size <= variables.avatarSizeNormal) { borderRadius = variables.componentBorderRadiusNormal; return {borderRadius}; @@ -81,14 +85,11 @@ function getAvatarBorderRadius(size = 0, type) { * @param {Number} size * @returns {Object} */ -function getAvatarSVGBorder(type, size = 0) { - if (type === CONST.ICON_TYPE_WORKSPACE) { - return { - overflow: 'hidden', - ...getAvatarBorderRadius(size, type), - }; - } - return styles.svgAvatarBorder; +function getAvatarBorderStyle(type, size = 0) { + return { + overflow: 'hidden', + ...getAvatarBorderRadius(size, type), + }; } /** @@ -802,7 +803,7 @@ function getReportWelcomeContainerStyle(isSmallScreenWidth) { export { getAvatarSize, getAvatarStyle, - getAvatarSVGBorder, + getAvatarBorderStyle, getErrorPageContainerStyle, getSafeAreaPadding, getSafeAreaMargins, diff --git a/src/styles/styles.js b/src/styles/styles.js index c8c2f655b695..98ce727c0d30 100644 --- a/src/styles/styles.js +++ b/src/styles/styles.js @@ -1625,7 +1625,6 @@ const styles = { height: 28, width: 28, backgroundColor: themeColors.appBG, - borderRadius: 8, paddingTop: 2, alignItems: 'center', }, @@ -1792,7 +1791,6 @@ const styles = { width: 28, borderWidth: 2, borderStyle: 'solid', - borderRadius: 10, zIndex: 6, }, @@ -2063,16 +2061,6 @@ const styles = { overflow: 'hidden', }, - squareAvatarBorder: { - borderRadius: 8, - overflow: 'hidden', - }, - - squareAvatarBorderSubscript: { - borderRadius: 4, - overflow: 'hidden', - }, - displayName: { fontSize: variables.fontSizeLarge, fontFamily: fontFamily.EXP_NEUE_BOLD, diff --git a/src/styles/variables.js b/src/styles/variables.js index 485e7c29cd75..cf8b2daedf37 100644 --- a/src/styles/variables.js +++ b/src/styles/variables.js @@ -22,6 +22,7 @@ export default { componentSizeLarge: 52, componentBorderRadius: 8, componentBorderRadiusSmall: 4, + componentBorderRadiusMedium: 6, componentBorderRadiusNormal: 8, componentBorderRadiusLarge: 16, componentBorderRadiusCard: 12, From 542817845ee34a076e586c23c8001a680dfe297e Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Sat, 18 Feb 2023 16:07:21 -0800 Subject: [PATCH 09/23] refactor getAvatarBorderStyle --- src/components/Avatar.js | 4 ++-- src/components/MultipleAvatars.js | 4 ++-- src/components/SubscriptAvatar.js | 2 +- src/styles/StyleUtils.js | 38 ++++++++++++++----------------- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/components/Avatar.js b/src/components/Avatar.js index f6eb8512ffe4..3c4bbda4d880 100644 --- a/src/components/Avatar.js +++ b/src/components/Avatar.js @@ -82,7 +82,7 @@ class Avatar extends PureComponent { const imageStyle = [ StyleUtils.getAvatarStyle(this.props.size), ...this.props.imageStyles, - StyleUtils.getAvatarBorderRadius(iconSize, this.props.type), + StyleUtils.getAvatarBorderRadius(this.props.size, this.props.type), ]; const iconStyle = [ @@ -103,7 +103,7 @@ class Avatar extends PureComponent { fill={this.state.imageError ? themeColors.offline : this.props.fill} isWorkspaceAvatar={isWorkspace} additionalStyles={[ - StyleUtils.getAvatarBorderStyle(this.props.type, iconSize), + StyleUtils.getAvatarBorderStyle(this.props.size, this.props.type), isWorkspace ? StyleUtils.getDefaultWorspaceAvatarColor(this.props.name) : {}, ]} /> diff --git a/src/components/MultipleAvatars.js b/src/components/MultipleAvatars.js index 35bcd2d8c600..6e30a2579a25 100644 --- a/src/components/MultipleAvatars.js +++ b/src/components/MultipleAvatars.js @@ -92,7 +92,7 @@ const MultipleAvatars = (props) => { { // Set overlay background color with RGBA value so that the text will not inherit opacity StyleUtils.getBackgroundColorWithOpacityStyle(themeColors.overlay, variables.overlayOpacity), styles.horizontalStackedAvatar4Overlay, - StyleUtils.getAvatarBorderRadius(StyleUtils.getAvatarSize(props.size), props.icons[3].type), + StyleUtils.getAvatarBorderRadius(props.size, props.icons[3].type), ]} > diff --git a/src/components/SubscriptAvatar.js b/src/components/SubscriptAvatar.js index 240a87ae6a75..6da3e918fec4 100644 --- a/src/components/SubscriptAvatar.js +++ b/src/components/SubscriptAvatar.js @@ -52,7 +52,7 @@ const SubscriptAvatar = props => ( diff --git a/src/styles/StyleUtils.js b/src/styles/StyleUtils.js index 4a7c0d979f8f..7d30e85362db 100644 --- a/src/styles/StyleUtils.js +++ b/src/styles/StyleUtils.js @@ -49,30 +49,26 @@ function getAvatarStyle(size) { /** * Return the border style if avatar is SVG * -* @param {Number} size +* @param {String} size * @param {String} type * @returns {Object} */ -function getAvatarBorderRadius(size = 0, type) { +function getAvatarBorderRadius(size, type) { + const AVATAR_BORDERS = { + [CONST.AVATAR_SIZE.SMALL_SUBSCRIPT]: variables.componentBorderRadiusSmall, + [CONST.AVATAR_SIZE.MID_SUBSCRIPT]: variables.componentBorderRadiusSmall, + [CONST.AVATAR_SIZE.SUBSCRIPT]: variables.componentBorderRadiusSmall, + [CONST.AVATAR_SIZE.SMALLER]: variables.componentBorderRadiusMedium, + [CONST.AVATAR_SIZE.SMALL]: variables.componentBorderRadiusMedium, + [CONST.AVATAR_SIZE.DEFAULT]: variables.componentBorderRadiusNormal, + [CONST.AVATAR_SIZE.MEDIUM]: variables.componentBorderRadiusLarge, + [CONST.AVATAR_SIZE.LARGE]: variables.componentBorderRadiusLarge, + [CONST.AVATAR_SIZE.LARGE_BORDERED]: variables.componentBorderRadiusRounded, + }; + let borderRadius = variables.buttonBorderRadius; if (type === CONST.ICON_TYPE_WORKSPACE) { - if (size <= variables.avatarSizeSubscript) { - borderRadius = variables.componentBorderRadiusSmall; - return {borderRadius}; - } - if (size <= variables.avatarSizeSmall) { - borderRadius = variables.componentBorderRadiusMedium; - return {borderRadius}; - } - if (size <= variables.avatarSizeNormal) { - borderRadius = variables.componentBorderRadiusNormal; - return {borderRadius}; - } - if (size <= variables.avatarSizeLarge) { - borderRadius = variables.componentBorderRadiusLarge; - return {borderRadius}; - } - borderRadius = variables.componentBorderRadiusRounded; + borderRadius = AVATAR_BORDERS[size]; return {borderRadius}; } return {borderRadius}; @@ -81,11 +77,11 @@ function getAvatarBorderRadius(size = 0, type) { /** * Return the border style if avatar is SVG * + * @param {String} size * @param {String} type - * @param {Number} size * @returns {Object} */ -function getAvatarBorderStyle(type, size = 0) { +function getAvatarBorderStyle(size, type) { return { overflow: 'hidden', ...getAvatarBorderRadius(size, type), From 98233500e6f3782c57e37d194a9fb8393c9a7424 Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Sat, 18 Feb 2023 16:36:41 -0800 Subject: [PATCH 10/23] Removed isWorkspaceAvatar prop --- src/pages/workspace/WorkspaceInitialPage.js | 1 - src/pages/workspace/WorkspaceSettingsPage.js | 1 - 2 files changed, 2 deletions(-) diff --git a/src/pages/workspace/WorkspaceInitialPage.js b/src/pages/workspace/WorkspaceInitialPage.js index 7bb72057732f..d2dacbe2f45c 100644 --- a/src/pages/workspace/WorkspaceInitialPage.js +++ b/src/pages/workspace/WorkspaceInitialPage.js @@ -200,7 +200,6 @@ class WorkspaceInitialPage extends React.Component { size={CONST.AVATAR_SIZE.LARGE} name={policyName} type={CONST.ICON_TYPE_WORKSPACE} - isWorkspaceAvatar /> {!_.isEmpty(this.props.policy.name) && ( diff --git a/src/pages/workspace/WorkspaceSettingsPage.js b/src/pages/workspace/WorkspaceSettingsPage.js index e2eb3730155f..6f0e5c425123 100644 --- a/src/pages/workspace/WorkspaceSettingsPage.js +++ b/src/pages/workspace/WorkspaceSettingsPage.js @@ -112,7 +112,6 @@ class WorkspaceSettingsPage extends React.Component { size={CONST.AVATAR_SIZE.LARGE} name={policyName} type={CONST.ICON_TYPE_WORKSPACE} - isWorkspaceAvatar /> )} type={CONST.ICON_TYPE_WORKSPACE} From e54ca2aab78fe4000507299d06e50faa29bb6b4a Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Mon, 20 Feb 2023 10:35:39 -0800 Subject: [PATCH 11/23] Fix building SVG --- assets/images/avatars/workspace/default-avatar_building.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/images/avatars/workspace/default-avatar_building.svg b/assets/images/avatars/workspace/default-avatar_building.svg index d249c47eed24..69c0f0e73dc4 100644 --- a/assets/images/avatars/workspace/default-avatar_building.svg +++ b/assets/images/avatars/workspace/default-avatar_building.svg @@ -3,7 +3,7 @@ {_.isFunction(this.props.source) || this.state.imageError @@ -100,7 +102,7 @@ class Avatar extends PureComponent { src={this.state.imageError ? this.props.fallbackIcon : this.props.source} height={iconSize} width={iconSize} - fill={this.state.imageError ? themeColors.offline : this.props.fill} + fill={this.state.imageError ? themeColors.offline : iconFillColor} isWorkspaceAvatar={isWorkspace} additionalStyles={[ StyleUtils.getAvatarBorderStyle(this.props.size, this.props.type), diff --git a/src/components/Icon/index.js b/src/components/Icon/index.js index 7dc65d57f563..6535030e0fe0 100644 --- a/src/components/Icon/index.js +++ b/src/components/Icon/index.js @@ -52,7 +52,7 @@ class Icon extends PureComponent { const iconStyles = [StyleUtils.getWidthAndHeightStyle(width, height), IconWrapperStyles, styles.pAbsolute, ...this.props.additionalStyles, ]; - const iconFill = this.props.isWorkspaceAvatar ? {} : this.props.fill; + const iconFill = this.props.isWorkspaceAvatar ? this.props.fill : this.props.fill; if (this.props.inline) { return ( From 27f6d79b82a35c81f2ad20e6c651d9dc613765a4 Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Thu, 23 Feb 2023 17:55:28 -0800 Subject: [PATCH 13/23] Add support for accented characters --- src/libs/ReportUtils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 9010d9a291d5..a89f6768285b 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -477,7 +477,8 @@ function getDefaultWorkspaceAvatar(workspaceName) { } // Remove all chars not A-Z or 0-9 including underscore - const alphaNumeric = workspaceName.replace(/[^0-9a-z]/gi, '').toUpperCase(); + const withoutAccents = workspaceName.normalize('NFD').replace(/[\u0300-\u036f]/g, ''); + const alphaNumeric = withoutAccents.replace(/[^0-9a-z]/gi, '').toUpperCase(); return !alphaNumeric ? defaultWorkspaceAvatars.WorkspaceBuilding : defaultWorkspaceAvatars[`Workspace${alphaNumeric[0]}`]; } From 63aaa29dddb4473622e09306e870122170f7a7b0 Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Thu, 23 Feb 2023 18:40:22 -0800 Subject: [PATCH 14/23] Remove isWorkspaceAvatar from Icon props, fix key --- src/components/Avatar.js | 1 - src/components/Icon/index.js | 9 ++------- src/components/RoomHeaderAvatars.js | 2 +- src/styles/StyleUtils.js | 2 ++ 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/components/Avatar.js b/src/components/Avatar.js index 2cf17eb40a6f..b8a93d692048 100644 --- a/src/components/Avatar.js +++ b/src/components/Avatar.js @@ -103,7 +103,6 @@ class Avatar extends PureComponent { height={iconSize} width={iconSize} fill={this.state.imageError ? themeColors.offline : iconFillColor} - isWorkspaceAvatar={isWorkspace} additionalStyles={[ StyleUtils.getAvatarBorderStyle(this.props.size, this.props.type), isWorkspace ? StyleUtils.getDefaultWorspaceAvatarColor(this.props.name) : {}, diff --git a/src/components/Icon/index.js b/src/components/Icon/index.js index 6535030e0fe0..df5af6453003 100644 --- a/src/components/Icon/index.js +++ b/src/components/Icon/index.js @@ -26,9 +26,6 @@ const propTypes = { /** Is inline icon */ inline: PropTypes.bool, - /** Is workspace icon */ - isWorkspaceAvatar: PropTypes.bool, - // eslint-disable-next-line react/forbid-prop-types additionalStyles: PropTypes.arrayOf(PropTypes.object), }; @@ -39,7 +36,6 @@ const defaultProps = { fill: themeColors.icon, small: false, inline: false, - isWorkspaceAvatar: false, additionalStyles: [], }; @@ -52,7 +48,6 @@ class Icon extends PureComponent { const iconStyles = [StyleUtils.getWidthAndHeightStyle(width, height), IconWrapperStyles, styles.pAbsolute, ...this.props.additionalStyles, ]; - const iconFill = this.props.isWorkspaceAvatar ? this.props.fill : this.props.fill; if (this.props.inline) { return ( @@ -64,7 +59,7 @@ class Icon extends PureComponent { @@ -79,7 +74,7 @@ class Icon extends PureComponent { ); diff --git a/src/components/RoomHeaderAvatars.js b/src/components/RoomHeaderAvatars.js index c1881f2e940f..eb47af4f6338 100644 --- a/src/components/RoomHeaderAvatars.js +++ b/src/components/RoomHeaderAvatars.js @@ -48,7 +48,7 @@ const RoomHeaderAvatars = (props) => { {_.map(iconsToDisplay, (icon, index) => ( - + Date: Mon, 27 Feb 2023 14:40:12 -0800 Subject: [PATCH 15/23] Add colors used for avatars --- src/styles/StyleUtils.js | 36 ++++++++++++++++++------------------ src/styles/colors.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/src/styles/StyleUtils.js b/src/styles/StyleUtils.js index f22c8557e8e2..7d459d32e14a 100644 --- a/src/styles/StyleUtils.js +++ b/src/styles/StyleUtils.js @@ -98,24 +98,24 @@ function getAvatarBorderStyle(size, type) { */ function getDefaultWorspaceAvatarColor(workspaceName) { const colorOptions = [ - ['#8DC8FF', '#003C73'], - ['#0185FF', '#002140'], - ['#003C73', '#8DC8FF'], - ['#8EECC4', '#085239'], - ['#03D47C', '#002E22'], - ['#085239', '#8EECC4'], - ['#FFED8F', '#722B03'], - ['#FED607', '#401102'], - ['#722B03', '#FFED8F'], - ['#FFC68C', '#780505'], - ['#FF7101', '#400000'], - ['#780505', '#FF7101'], - ['#FBCCFF', '#712A76'], - ['#F68DFE', '#49225B'], - ['#712A76', '#FBCCFF'], - ['#CCF7FF', '#28736D'], - ['#50EEF6', '#134038'], - ['#28736D', '#CCF7FF'], + [colors.blue200, colors.blue700], + [colors.blue400, colors.blue800], + [colors.blue700, colors.blue200], + [colors.green200, colors.green700], + [colors.green400, colors.green800], + [colors.green700, colors.green200], + [colors.yellow200, colors.yellow700], + [colors.yellow400, colors.yellow800], + [colors.yellow700, colors.yellow200], + [colors.tangerine200, colors.tangerine700], + [colors.tangerine400, colors.tangerine800], + [colors.tangerine700, colors.tangerine400], + [colors.pink200, colors.pink700], + [colors.pink400, colors.pink800], + [colors.pink700, colors.pink200], + [colors.ice200, colors.ice700], + [colors.ice400, colors.ice800], + [colors.ice700, colors.ice200], ]; const colorHash = ReportUtils.hashLogin(workspaceName.trim(), colorOptions.length - 1); diff --git a/src/styles/colors.js b/src/styles/colors.js index 7af4003a67f6..6997d0cc3dc0 100644 --- a/src/styles/colors.js +++ b/src/styles/colors.js @@ -35,6 +35,37 @@ export default { greenDefaultButtonDisabled: '#8BA69E', midnight: '#002140', + // Brand Colors from Figma + blue200: '#8DC8FF', + blue400: '#0185FF', + blue700: '#003C73', + blue800: '#002140', + + green200: '#8EECC4', + green400: '#03D47C', + green700: '#085239', + green800: '#002E22', + + yellow200: '#FFED8F', + yellow400: '#FED607', + yellow700: '#722B03', + yellow800: '#401102', + + tangerine200: '#FFC68C', + tangerine400: '#FF7101', + tangerine700: '#780505', + tangerine800: '#400000', + + pink200: '#FBCCFF', + pink400: '#F68DFE', + pink700: '#712A76', + pink800: '#49225B', + + ice200: '#CCF7FF', + ice400: '#50EEF6', + ice700: '#28736D', + ice800: '#134038', + // DEPRECATED COLORS. Do not reference these colors. Will be deleted in color switch PR. gray1: '#FAFAFA', gray2: '#ECECEC', From aa6a9df7f696eb698b2828657a35baf2250787d1 Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Tue, 28 Feb 2023 14:52:08 -0800 Subject: [PATCH 16/23] Hash function should return a value from [0, range) --- src/libs/ReportUtils.js | 12 ++++++------ src/styles/StyleUtils.js | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 0da2965fc9d0..3c84bffd1f5a 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -428,13 +428,13 @@ function formatReportLastMessageText(lastMessageText) { } /** - * Hashes provided string and returns a value between [1, range] + * Hashes provided string and returns a value between [0, range) * @param {String} login * @param {Number} range * @returns {Number} */ function hashLogin(login, range) { - return (Math.abs(hashCode(login.toLowerCase())) % range) + 1; + return (Math.abs(hashCode(login.toLowerCase())) % range); } /** @@ -451,8 +451,8 @@ function getDefaultAvatar(login = '') { } // There are 24 possible default avatars, so we choose which one this user has based - // on a simple hash of their login - const loginHashBucket = hashLogin(login, CONST.DEFAULT_AVATAR_COUNT); + // on a simple hash of their login. Note that Avatar count starts at 1. + const loginHashBucket = hashLogin(login, CONST.DEFAULT_AVATAR_COUNT) + 1; return defaultAvatars[`Avatar${loginHashBucket}`]; } @@ -486,8 +486,8 @@ function getOldDotDefaultAvatar(login = '') { } // There are 8 possible old dot default avatars, so we choose which one this user has based - // on a simple hash of their login - const loginHashBucket = hashLogin(login, CONST.OLD_DEFAULT_AVATAR_COUNT); + // on a simple hash of their login. Note that Avatar count starts at 1. + const loginHashBucket = hashLogin(login, CONST.OLD_DEFAULT_AVATAR_COUNT) + 1; return `${CONST.CLOUDFRONT_URL}/images/avatars/avatar_${loginHashBucket}.png`; } diff --git a/src/styles/StyleUtils.js b/src/styles/StyleUtils.js index 7d459d32e14a..e5340f4f3bf8 100644 --- a/src/styles/StyleUtils.js +++ b/src/styles/StyleUtils.js @@ -118,7 +118,7 @@ function getDefaultWorspaceAvatarColor(workspaceName) { [colors.ice700, colors.ice200], ]; - const colorHash = ReportUtils.hashLogin(workspaceName.trim(), colorOptions.length - 1); + const colorHash = ReportUtils.hashLogin(workspaceName.trim(), colorOptions.length); return {backgroundColor: colorOptions[colorHash][0], fill: colorOptions[colorHash][1]}; } From 58e794c97058f3ef2476df37beb318fcea0306d9 Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Tue, 28 Feb 2023 15:29:00 -0800 Subject: [PATCH 17/23] Code clean up, update storybook --- src/components/MenuItem.js | 44 ++++------ src/libs/ReportUtils.js | 2 +- src/stories/SubscriptAvatar.stories.js | 11 +-- src/styles/StyleUtils.js | 106 ++++++++++++------------- 4 files changed, 75 insertions(+), 88 deletions(-) diff --git a/src/components/MenuItem.js b/src/components/MenuItem.js index 04b6fca58b19..2fef4910b688 100644 --- a/src/components/MenuItem.js +++ b/src/components/MenuItem.js @@ -17,6 +17,7 @@ import SelectCircle from './SelectCircle'; import colors from '../styles/colors'; import variables from '../styles/variables'; import MultipleAvatars from './MultipleAvatars'; +import * as defaultWorkspaceAvatars from './Icon/WorkspaceDefaultAvatars'; const propTypes = { ...menuItemPropTypes, @@ -88,13 +89,13 @@ const MenuItem = (props) => { {({hovered, pressed}) => ( <> - {(props.icon && props.iconType === CONST.ICON_TYPE_ICON) && ( - + + {(props.icon && props.iconType === CONST.ICON_TYPE_ICON) && ( { true, )} /> - - )} - {(props.icon && props.iconType === CONST.ICON_TYPE_WORKSPACE) && ( - + )} + {(props.icon && props.iconType === CONST.ICON_TYPE_WORKSPACE) && ( + { name={props.title} type={CONST.ICON_TYPE_WORKSPACE} /> - - )} - {(props.icon && props.iconType === CONST.ICON_TYPE_AVATAR) && ( - + )} + {(props.icon && props.iconType === CONST.ICON_TYPE_AVATAR) && ( - - )} + )} + {Boolean(props.description) && props.shouldShowDescriptionOnTop && ( { isPressed={pressed} icons={props.floatRightAvatars} size={props.viewMode === CONST.OPTION_MODE.COMPACT ? CONST.AVATAR_SIZE.SMALL : CONST.AVATAR_SIZE.DEFAULT} - fallbackIcon={Expensicons.Workspace} + fallbackIcon={defaultWorkspaceAvatars.WorkspaceBuilding} shouldStackHorizontally={props.shouldStackHorizontally} /> diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 3c84bffd1f5a..ce83074de773 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -464,7 +464,7 @@ function getDefaultAvatar(login = '') { */ function getDefaultWorkspaceAvatar(workspaceName) { if (!workspaceName) { - return Expensicons.FallbackWorkspaceAvatar; + return defaultWorkspaceAvatars.WorkspaceBuilding; } // Remove all chars not A-Z or 0-9 including underscore diff --git a/src/stories/SubscriptAvatar.stories.js b/src/stories/SubscriptAvatar.stories.js index 0a6e67a2fdef..d93f5c77e6b0 100644 --- a/src/stories/SubscriptAvatar.stories.js +++ b/src/stories/SubscriptAvatar.stories.js @@ -1,6 +1,7 @@ import React from 'react'; import SubscriptAvatar from '../components/SubscriptAvatar'; -import * as Expensicons from '../components/Icon/Expensicons'; +import * as defaultWorkspaceAvatars from '../components/Icon/WorkspaceDefaultAvatars'; +import * as defaultAvatars from '../components/Icon/DefaultAvatars'; import CONST from '../CONST'; /** @@ -12,8 +13,8 @@ export default { title: 'Components/SubscriptAvatar', component: SubscriptAvatar, args: { - mainAvatar: Expensicons.Profile, - secondaryAvatar: Expensicons.Workspace, + mainAvatar: {source: defaultAvatars.Avatar5, name: '', type: CONST.ICON_TYPE_AVATAR}, + secondaryAvatar: {source: defaultWorkspaceAvatars.WorkspaceE, name: '', type: CONST.ICON_TYPE_WORKSPACE}, size: CONST.AVATAR_SIZE.DEFAULT, }, argTypes: { @@ -32,8 +33,8 @@ const Default = Template.bind({}); const AvatarURLStory = Template.bind({}); AvatarURLStory.args = { - mainAvatar: `${CONST.CLOUDFRONT_URL}/images/avatars/avatar_1.png`, - secondaryAvatar: `${CONST.CLOUDFRONT_URL}/images/avatars/avatar_3.png`, + mainAvatar: {source: defaultAvatars.Avatar1, name: '', type: CONST.ICON_TYPE_AVATAR}, + secondaryAvatar: {source: defaultAvatars.Avatar3, name: '', type: CONST.ICON_TYPE_AVATAR}, }; export { diff --git a/src/styles/StyleUtils.js b/src/styles/StyleUtils.js index e5340f4f3bf8..158c2d7b892a 100644 --- a/src/styles/StyleUtils.js +++ b/src/styles/StyleUtils.js @@ -8,6 +8,51 @@ import positioning from './utilities/positioning'; import styles from './styles'; import * as ReportUtils from '../libs/ReportUtils'; +const workspaceColorOptions = [ + [colors.blue200, colors.blue700], + [colors.blue400, colors.blue800], + [colors.blue700, colors.blue200], + [colors.green200, colors.green700], + [colors.green400, colors.green800], + [colors.green700, colors.green200], + [colors.yellow200, colors.yellow700], + [colors.yellow400, colors.yellow800], + [colors.yellow700, colors.yellow200], + [colors.tangerine200, colors.tangerine700], + [colors.tangerine400, colors.tangerine800], + [colors.tangerine700, colors.tangerine400], + [colors.pink200, colors.pink700], + [colors.pink400, colors.pink800], + [colors.pink700, colors.pink200], + [colors.ice200, colors.ice700], + [colors.ice400, colors.ice800], + [colors.ice700, colors.ice200], +]; + +const avatarBorderSizes = { + [CONST.AVATAR_SIZE.SMALL_SUBSCRIPT]: variables.componentBorderRadiusSmall, + [CONST.AVATAR_SIZE.MID_SUBSCRIPT]: variables.componentBorderRadiusSmall, + [CONST.AVATAR_SIZE.SUBSCRIPT]: variables.componentBorderRadiusSmall, + [CONST.AVATAR_SIZE.SMALLER]: variables.componentBorderRadiusMedium, + [CONST.AVATAR_SIZE.SMALL]: variables.componentBorderRadiusMedium, + [CONST.AVATAR_SIZE.DEFAULT]: variables.componentBorderRadiusNormal, + [CONST.AVATAR_SIZE.MEDIUM]: variables.componentBorderRadiusLarge, + [CONST.AVATAR_SIZE.LARGE]: variables.componentBorderRadiusLarge, + [CONST.AVATAR_SIZE.LARGE_BORDERED]: variables.componentBorderRadiusRounded, +}; + +const avatarSizes = { + [CONST.AVATAR_SIZE.DEFAULT]: variables.avatarSizeNormal, + [CONST.AVATAR_SIZE.SMALL_SUBSCRIPT]: variables.avatarSizeSmallSubscript, + [CONST.AVATAR_SIZE.MID_SUBSCRIPT]: variables.avatarSizeMidSubscript, + [CONST.AVATAR_SIZE.SUBSCRIPT]: variables.avatarSizeSubscript, + [CONST.AVATAR_SIZE.SMALL]: variables.avatarSizeSmall, + [CONST.AVATAR_SIZE.SMALLER]: variables.avatarSizeSmaller, + [CONST.AVATAR_SIZE.LARGE]: variables.avatarSizeLarge, + [CONST.AVATAR_SIZE.MEDIUM]: variables.avatarSizeMedium, + [CONST.AVATAR_SIZE.LARGE_BORDERED]: variables.avatarSizeLargeBordered, +}; + /** * Return the style size from an avatar size constant * @@ -15,19 +60,7 @@ import * as ReportUtils from '../libs/ReportUtils'; * @returns {Number} */ function getAvatarSize(size) { - const AVATAR_SIZES = { - [CONST.AVATAR_SIZE.DEFAULT]: variables.avatarSizeNormal, - [CONST.AVATAR_SIZE.SMALL_SUBSCRIPT]: variables.avatarSizeSmallSubscript, - [CONST.AVATAR_SIZE.MID_SUBSCRIPT]: variables.avatarSizeMidSubscript, - [CONST.AVATAR_SIZE.SUBSCRIPT]: variables.avatarSizeSubscript, - [CONST.AVATAR_SIZE.SMALL]: variables.avatarSizeSmall, - [CONST.AVATAR_SIZE.SMALLER]: variables.avatarSizeSmaller, - [CONST.AVATAR_SIZE.LARGE]: variables.avatarSizeLarge, - [CONST.AVATAR_SIZE.MEDIUM]: variables.avatarSizeMedium, - [CONST.AVATAR_SIZE.LARGE_BORDERED]: variables.avatarSizeLargeBordered, - }; - - return AVATAR_SIZES[size]; + return avatarSizes[size]; } /** @@ -54,26 +87,12 @@ function getAvatarStyle(size) { * @returns {Object} */ function getAvatarBorderRadius(size, type) { - const AVATAR_BORDERS = { - [CONST.AVATAR_SIZE.SMALL_SUBSCRIPT]: variables.componentBorderRadiusSmall, - [CONST.AVATAR_SIZE.MID_SUBSCRIPT]: variables.componentBorderRadiusSmall, - [CONST.AVATAR_SIZE.SUBSCRIPT]: variables.componentBorderRadiusSmall, - [CONST.AVATAR_SIZE.SMALLER]: variables.componentBorderRadiusMedium, - [CONST.AVATAR_SIZE.SMALL]: variables.componentBorderRadiusMedium, - [CONST.AVATAR_SIZE.DEFAULT]: variables.componentBorderRadiusNormal, - [CONST.AVATAR_SIZE.MEDIUM]: variables.componentBorderRadiusLarge, - [CONST.AVATAR_SIZE.LARGE]: variables.componentBorderRadiusLarge, - [CONST.AVATAR_SIZE.LARGE_BORDERED]: variables.componentBorderRadiusRounded, - }; - - // Default to rounded border - let borderRadius = variables.buttonBorderRadius; - if (type === CONST.ICON_TYPE_WORKSPACE) { - borderRadius = AVATAR_BORDERS[size]; - return {borderRadius}; + return {borderRadius: avatarBorderSizes[size]}; } - return {borderRadius}; + + // Default to rounded border + return {borderRadius: variables.buttonBorderRadius}; } /** @@ -97,30 +116,9 @@ function getAvatarBorderStyle(size, type) { * @returns {Object} */ function getDefaultWorspaceAvatarColor(workspaceName) { - const colorOptions = [ - [colors.blue200, colors.blue700], - [colors.blue400, colors.blue800], - [colors.blue700, colors.blue200], - [colors.green200, colors.green700], - [colors.green400, colors.green800], - [colors.green700, colors.green200], - [colors.yellow200, colors.yellow700], - [colors.yellow400, colors.yellow800], - [colors.yellow700, colors.yellow200], - [colors.tangerine200, colors.tangerine700], - [colors.tangerine400, colors.tangerine800], - [colors.tangerine700, colors.tangerine400], - [colors.pink200, colors.pink700], - [colors.pink400, colors.pink800], - [colors.pink700, colors.pink200], - [colors.ice200, colors.ice700], - [colors.ice400, colors.ice800], - [colors.ice700, colors.ice200], - ]; - - const colorHash = ReportUtils.hashLogin(workspaceName.trim(), colorOptions.length); + const colorHash = ReportUtils.hashLogin(workspaceName.trim(), workspaceColorOptions.length); - return {backgroundColor: colorOptions[colorHash][0], fill: colorOptions[colorHash][1]}; + return {backgroundColor: workspaceColorOptions[colorHash][0], fill: workspaceColorOptions[colorHash][1]}; } /** From 32c23f8d3bffad966a8ff967b65e5e9de61e5475 Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Tue, 28 Feb 2023 15:36:45 -0800 Subject: [PATCH 18/23] Fix workspace icon for image errors --- assets/images/avatars/fallback-avatar.svg | 2 +- src/components/Avatar.js | 5 ++++- src/components/Icon/index.js | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/assets/images/avatars/fallback-avatar.svg b/assets/images/avatars/fallback-avatar.svg index f509ba03b1a5..9cf85c555d6d 100644 --- a/assets/images/avatars/fallback-avatar.svg +++ b/assets/images/avatars/fallback-avatar.svg @@ -3,7 +3,7 @@ diff --git a/src/components/Avatar.js b/src/components/Avatar.js index b8a93d692048..b24e8f955158 100644 --- a/src/components/Avatar.js +++ b/src/components/Avatar.js @@ -13,6 +13,7 @@ import Image from './Image'; import {withNetwork} from './OnyxProvider'; import networkPropTypes from './networkPropTypes'; import styles from '../styles/styles'; +import * as ReportUtils from '../libs/ReportUtils'; const propTypes = { /** Source for the avatar. Can be a URL or an icon. */ @@ -92,6 +93,7 @@ class Avatar extends PureComponent { ]; const iconFillColor = isWorkspace ? StyleUtils.getDefaultWorspaceAvatarColor(this.props.name).fill : this.props.fill; + const fallbackAvatar = isWorkspace ? ReportUtils.getDefaultWorkspaceAvatar(this.props.name) : this.props.fallbackIcon; return ( @@ -99,13 +101,14 @@ class Avatar extends PureComponent { ? ( diff --git a/src/components/Icon/index.js b/src/components/Icon/index.js index df5af6453003..b6f25f01c7d7 100644 --- a/src/components/Icon/index.js +++ b/src/components/Icon/index.js @@ -17,7 +17,10 @@ const propTypes = { /** The height of the icon. */ height: PropTypes.number, - /** The fill color for the icon. Can be hex, rgb, rgba, or valid react-native named color such as 'red' or 'blue' */ + /** + * The fill color for the icon. Can be hex, rgb, rgba, or valid react-native named color such as 'red' or 'blue'. + * If the icon is a default workspace avatar, this fill color will be overwritten by styles passed in additionalStyles. + */ fill: PropTypes.string, /** Is small icon */ From 01b40f5362c8a774fbf24f6760cf9354c7743292 Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Wed, 1 Mar 2023 16:16:20 -0800 Subject: [PATCH 19/23] Use green700 for fallback avatars --- assets/images/avatars/fallback-avatar.svg | 2 +- src/components/Avatar.js | 2 +- src/styles/themes/default.js | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/assets/images/avatars/fallback-avatar.svg b/assets/images/avatars/fallback-avatar.svg index 9cf85c555d6d..0d71e0fbc210 100644 --- a/assets/images/avatars/fallback-avatar.svg +++ b/assets/images/avatars/fallback-avatar.svg @@ -3,7 +3,7 @@ diff --git a/src/components/Avatar.js b/src/components/Avatar.js index b24e8f955158..491dbc7081ef 100644 --- a/src/components/Avatar.js +++ b/src/components/Avatar.js @@ -108,7 +108,7 @@ class Avatar extends PureComponent { additionalStyles={[ StyleUtils.getAvatarBorderStyle(this.props.size, this.props.type), isWorkspace ? StyleUtils.getDefaultWorspaceAvatarColor(this.props.name) : {}, - this.state.imageError ? StyleUtils.getBackgroundColorStyle(themeColors.buttonDefaultBG) : {}, + this.state.imageError ? StyleUtils.getBackgroundColorStyle(themeColors.green700) : {}, ]} /> diff --git a/src/styles/themes/default.js b/src/styles/themes/default.js index 618859ea6813..9508ecec9842 100644 --- a/src/styles/themes/default.js +++ b/src/styles/themes/default.js @@ -60,6 +60,9 @@ const darkTheme = { checkBox: colors.green, pickerOptionsTextColor: colors.white, imageCropBackgroundColor: colors.greenIcons, + + // Brand color keys + green700: colors.green700, }; const oldTheme = { From d30fd5eaa483eae422a9b330ee6bfa4af88e8813 Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Thu, 2 Mar 2023 14:54:03 -0800 Subject: [PATCH 20/23] Add comments, clean up MenuItem, fix fallback bug with workspace invites --- src/components/Avatar.js | 9 ++- src/components/Icon/index.js | 5 +- src/components/MenuItem.js | 72 +++++++++++---------- src/libs/ReportUtils.js | 3 +- src/pages/workspace/WorkspaceMembersPage.js | 2 +- 5 files changed, 47 insertions(+), 44 deletions(-) diff --git a/src/components/Avatar.js b/src/components/Avatar.js index 491dbc7081ef..3253dec284d1 100644 --- a/src/components/Avatar.js +++ b/src/components/Avatar.js @@ -29,10 +29,15 @@ const propTypes = { /** Set the size of Avatar */ size: PropTypes.oneOf(_.values(CONST.AVATAR_SIZE)), - /** The fill color for the icon. Can be hex, rgb, rgba, or valid react-native named color such as 'red' or 'blue' */ + /** + * The fill color for the icon. Can be hex, rgb, rgba, or valid react-native named color such as 'red' or 'blue' + * If the avatar is type === workspace, this fill color will be ignored and decided based on the name prop. + */ fill: PropTypes.string, - /** A fallback avatar icon to display when there is an error on loading avatar from remote URL. */ + /** A fallback avatar icon to display when there is an error on loading avatar from remote URL. + * If the avatar is type === workspace, this fallback icon will be ignored and decided based on the name prop. + */ fallbackIcon: PropTypes.func, /** Denotes whether it is an avatar or a workspace avatar */ diff --git a/src/components/Icon/index.js b/src/components/Icon/index.js index b6f25f01c7d7..c65030afc407 100644 --- a/src/components/Icon/index.js +++ b/src/components/Icon/index.js @@ -17,10 +17,7 @@ const propTypes = { /** The height of the icon. */ height: PropTypes.number, - /** - * The fill color for the icon. Can be hex, rgb, rgba, or valid react-native named color such as 'red' or 'blue'. - * If the icon is a default workspace avatar, this fill color will be overwritten by styles passed in additionalStyles. - */ + /** The fill color for the icon. Can be hex, rgb, rgba, or valid react-native named color such as 'red' or 'blue'. */ fill: PropTypes.string, /** Is small icon */ diff --git a/src/components/MenuItem.js b/src/components/MenuItem.js index 2fef4910b688..587a5769ec6a 100644 --- a/src/components/MenuItem.js +++ b/src/components/MenuItem.js @@ -89,42 +89,44 @@ const MenuItem = (props) => { {({hovered, pressed}) => ( <> - - {(props.icon && props.iconType === CONST.ICON_TYPE_ICON) && ( - - )} - {(props.icon && props.iconType === CONST.ICON_TYPE_WORKSPACE) && ( + {props.icon && ( + + {(props.iconType === CONST.ICON_TYPE_ICON) && ( + + )} + {(props.iconType === CONST.ICON_TYPE_WORKSPACE) && ( - - )} - {(props.icon && props.iconType === CONST.ICON_TYPE_AVATAR) && ( - - )} - + + )} + {(props.iconType === CONST.ICON_TYPE_AVATAR) && ( + + )} + + )} {Boolean(props.description) && props.shouldShowDescriptionOnTop && ( Date: Thu, 2 Mar 2023 16:06:28 -0800 Subject: [PATCH 21/23] use ICON_TYPE_ICON from CONST --- src/components/MenuItem.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MenuItem.js b/src/components/MenuItem.js index 587a5769ec6a..33563bb029be 100644 --- a/src/components/MenuItem.js +++ b/src/components/MenuItem.js @@ -43,7 +43,7 @@ const defaultProps = { disabled: false, isSelected: false, subtitle: undefined, - iconType: 'icon', + iconType: CONST.ICON_TYPE_ICON, onPress: () => {}, interactive: true, fallbackIcon: Expensicons.FallbackAvatar, From 9f9c47f511b3c27d64e9e0514a6df0dddb46dd7c Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Thu, 2 Mar 2023 16:31:00 -0800 Subject: [PATCH 22/23] update workspaceColorOptions to use objects, update outdated comments --- src/styles/StyleUtils.js | 42 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/styles/StyleUtils.js b/src/styles/StyleUtils.js index 158c2d7b892a..3f968fec7c54 100644 --- a/src/styles/StyleUtils.js +++ b/src/styles/StyleUtils.js @@ -9,24 +9,24 @@ import styles from './styles'; import * as ReportUtils from '../libs/ReportUtils'; const workspaceColorOptions = [ - [colors.blue200, colors.blue700], - [colors.blue400, colors.blue800], - [colors.blue700, colors.blue200], - [colors.green200, colors.green700], - [colors.green400, colors.green800], - [colors.green700, colors.green200], - [colors.yellow200, colors.yellow700], - [colors.yellow400, colors.yellow800], - [colors.yellow700, colors.yellow200], - [colors.tangerine200, colors.tangerine700], - [colors.tangerine400, colors.tangerine800], - [colors.tangerine700, colors.tangerine400], - [colors.pink200, colors.pink700], - [colors.pink400, colors.pink800], - [colors.pink700, colors.pink200], - [colors.ice200, colors.ice700], - [colors.ice400, colors.ice800], - [colors.ice700, colors.ice200], + {backgroundColor: colors.blue200, fill: colors.blue700}, + {backgroundColor: colors.blue400, fill: colors.blue800}, + {backgroundColor: colors.blue700, fill: colors.blue200}, + {backgroundColor: colors.green200, fill: colors.green700}, + {backgroundColor: colors.green400, fill: colors.green800}, + {backgroundColor: colors.green700, fill: colors.green200}, + {backgroundColor: colors.yellow200, fill: colors.yellow700}, + {backgroundColor: colors.yellow400, fill: colors.yellow800}, + {backgroundColor: colors.yellow700, fill: colors.yellow200}, + {backgroundColor: colors.tangerine200, fill: colors.tangerine700}, + {backgroundColor: colors.tangerine400, fill: colors.tangerine800}, + {backgroundColor: colors.tangerine700, fill: colors.tangerine400}, + {backgroundColor: colors.pink200, fill: colors.pink700}, + {backgroundColor: colors.pink400, fill: colors.pink800}, + {backgroundColor: colors.pink700, fill: colors.pink200}, + {backgroundColor: colors.ice200, fill: colors.ice700}, + {backgroundColor: colors.ice400, fill: colors.ice800}, + {backgroundColor: colors.ice700, fill: colors.ice200}, ]; const avatarBorderSizes = { @@ -80,7 +80,7 @@ function getAvatarStyle(size) { } /** -* Return the border style if avatar is SVG +* Return the border radius for an avatar * * @param {String} size * @param {String} type @@ -96,7 +96,7 @@ function getAvatarBorderRadius(size, type) { } /** - * Return the border style if avatar is SVG + * Return the border style for an avatar * * @param {String} size * @param {String} type @@ -118,7 +118,7 @@ function getAvatarBorderStyle(size, type) { function getDefaultWorspaceAvatarColor(workspaceName) { const colorHash = ReportUtils.hashLogin(workspaceName.trim(), workspaceColorOptions.length); - return {backgroundColor: workspaceColorOptions[colorHash][0], fill: workspaceColorOptions[colorHash][1]}; + return workspaceColorOptions[colorHash]; } /** From b48c2f098aa9e50c392c6ea1569e7c4049ed1c5b Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Thu, 2 Mar 2023 16:44:47 -0800 Subject: [PATCH 23/23] rename color to fallbackIconColor --- src/components/Avatar.js | 2 +- src/styles/themes/default.js | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/Avatar.js b/src/components/Avatar.js index 3253dec284d1..ed05a78d18c4 100644 --- a/src/components/Avatar.js +++ b/src/components/Avatar.js @@ -113,7 +113,7 @@ class Avatar extends PureComponent { additionalStyles={[ StyleUtils.getAvatarBorderStyle(this.props.size, this.props.type), isWorkspace ? StyleUtils.getDefaultWorspaceAvatarColor(this.props.name) : {}, - this.state.imageError ? StyleUtils.getBackgroundColorStyle(themeColors.green700) : {}, + this.state.imageError ? StyleUtils.getBackgroundColorStyle(themeColors.fallbackIconColor) : {}, ]} /> diff --git a/src/styles/themes/default.js b/src/styles/themes/default.js index 9508ecec9842..722c0c8cb722 100644 --- a/src/styles/themes/default.js +++ b/src/styles/themes/default.js @@ -60,9 +60,7 @@ const darkTheme = { checkBox: colors.green, pickerOptionsTextColor: colors.white, imageCropBackgroundColor: colors.greenIcons, - - // Brand color keys - green700: colors.green700, + fallbackIconColor: colors.green700, }; const oldTheme = {