Skip to content

Commit

Permalink
Merge pull request #41193 from Expensify/beaman-useCorrectAvatarUrlPo…
Browse files Browse the repository at this point in the history
…licyProp
  • Loading branch information
blimpich authored May 1, 2024
2 parents a86c04d + abe4e09 commit ae5f41a
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ function MoneyRequestConfirmationList({
key={translate('workspace.invoices.sendFrom')}
shouldShowRightIcon={!isReadOnly && canUpdateSenderWorkspace}
title={senderWorkspace?.name}
icon={senderWorkspace?.avatar ? senderWorkspace?.avatar : getDefaultWorkspaceAvatar(senderWorkspace?.name)}
icon={senderWorkspace?.avatarURL ? senderWorkspace?.avatarURL : getDefaultWorkspaceAvatar(senderWorkspace?.name)}
iconType={CONST.ICON_TYPE_WORKSPACE}
description={translate('workspace.common.workspace')}
label={translate('workspace.invoices.sendFrom')}
Expand Down
2 changes: 1 addition & 1 deletion src/components/WorkspaceSwitcherButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function WorkspaceSwitcherButton({policy}: WorkspaceSwitcherButtonProps) {
return {source: Expensicons.ExpensifyAppIcon, name: CONST.WORKSPACE_SWITCHER.NAME, type: CONST.ICON_TYPE_AVATAR};
}

const avatar = policy?.avatar ? policy.avatar : getDefaultWorkspaceAvatar(policy?.name);
const avatar = policy?.avatarURL ? policy.avatarURL : getDefaultWorkspaceAvatar(policy?.name);
return {
source: avatar,
name: policy?.name ?? '',
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useReportIDs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import useCurrentReportID from './useCurrentReportID';
import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails';

type ChatReportSelector = OnyxTypes.Report & {isUnreadWithMention: boolean};
type PolicySelector = Pick<OnyxTypes.Policy, 'type' | 'name' | 'avatar' | 'employeeList'>;
type PolicySelector = Pick<OnyxTypes.Policy, 'type' | 'name' | 'avatarURL' | 'employeeList'>;
type ReportActionsSelector = Array<Pick<OnyxTypes.ReportAction, 'reportActionID' | 'actionName' | 'errors' | 'message' | 'originalMessage'>>;

type ReportIDsContextProviderProps = {
Expand Down Expand Up @@ -97,7 +97,7 @@ const policySelector = (policy: OnyxEntry<OnyxTypes.Policy>): PolicySelector =>
(policy && {
type: policy.type,
name: policy.name,
avatar: policy.avatar,
avatarURL: policy.avatarURL,
employeeList: policy.employeeList,
}) as PolicySelector;

Expand Down
6 changes: 3 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,7 @@ function getDefaultWorkspaceAvatarTestID(workspaceName: string): string {

function getWorkspaceAvatar(report: OnyxEntry<Report>): UserUtils.AvatarSource {
const workspaceName = getPolicyName(report, false, allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]);
const avatar = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]?.avatar ?? '';
const avatar = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]?.avatarURL ?? '';
return !isEmpty(avatar) ? avatar : getDefaultWorkspaceAvatar(workspaceName);
}

Expand Down Expand Up @@ -1733,8 +1733,8 @@ function getIconsForParticipants(participants: number[], personalDetails: OnyxCo
*/
function getWorkspaceIcon(report: OnyxEntry<Report>, policy: OnyxEntry<Policy> = null): Icon {
const workspaceName = getPolicyName(report, false, policy);
const policyExpenseChatAvatarSource = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]?.avatar
? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]?.avatar
const policyExpenseChatAvatarSource = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]?.avatarURL
? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]?.avatarURL
: getDefaultWorkspaceAvatar(workspaceName);

const workspaceIcon: Icon = {
Expand Down
26 changes: 13 additions & 13 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ function deleteWorkspace(policyID: string, policyName: string) {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
avatar: '',
avatarURL: '',
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
errors: null,
},
Expand Down Expand Up @@ -1511,13 +1511,13 @@ function updateWorkspaceAvatar(policyID: string, file: File) {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
avatar: file.uri,
avatarURL: file.uri,
originalFileName: file.name,
errorFields: {
avatar: null,
avatarURL: null,
},
pendingFields: {
avatar: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
avatarURL: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
},
Expand All @@ -1528,7 +1528,7 @@ function updateWorkspaceAvatar(policyID: string, file: File) {
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
pendingFields: {
avatar: null,
avatarURL: null,
},
},
},
Expand All @@ -1538,7 +1538,7 @@ function updateWorkspaceAvatar(policyID: string, file: File) {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
avatar: allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]?.avatar,
avatarURL: allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]?.avatarURL,
},
},
];
Expand All @@ -1561,12 +1561,12 @@ function deleteWorkspaceAvatar(policyID: string) {
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
pendingFields: {
avatar: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
avatarURL: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
errorFields: {
avatar: null,
avatarURL: null,
},
avatar: '',
avatarURL: '',
},
},
];
Expand All @@ -1576,7 +1576,7 @@ function deleteWorkspaceAvatar(policyID: string) {
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
pendingFields: {
avatar: null,
avatarURL: null,
},
},
},
Expand All @@ -1587,7 +1587,7 @@ function deleteWorkspaceAvatar(policyID: string) {
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
errorFields: {
avatar: ErrorUtils.getMicroSecondOnyxError('avatarWithImagePicker.deleteWorkspaceError'),
avatarURL: ErrorUtils.getMicroSecondOnyxError('avatarWithImagePicker.deleteWorkspaceError'),
},
},
},
Expand All @@ -1604,10 +1604,10 @@ function deleteWorkspaceAvatar(policyID: string) {
function clearAvatarErrors(policyID: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {
errorFields: {
avatar: null,
avatarURL: null,
},
pendingFields: {
avatar: null,
avatarURL: null,
},
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/WorkspaceSwitcherPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function WorkspaceSwitcherPage() {
brickRoadIndicator: getIndicatorTypeForPolicy(policy?.id),
icons: [
{
source: policy?.avatar ? policy.avatar : ReportUtils.getDefaultWorkspaceAvatar(policy?.name),
source: policy?.avatarURL ? policy.avatarURL : ReportUtils.getDefaultWorkspaceAvatar(policy?.name),
fallbackIcon: Expensicons.FallbackWorkspaceAvatar,
name: policy?.name,
type: CONST.ICON_TYPE_WORKSPACE,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionItemCreated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default withOnyx<ReportActionItemCreatedProps, ReportActionItemCreatedOny
ReportActionItemCreated,
(prevProps, nextProps) =>
prevProps.policy?.name === nextProps.policy?.name &&
prevProps.policy?.avatar === nextProps.policy?.avatar &&
prevProps.policy?.avatarURL === nextProps.policy?.avatarURL &&
prevProps.report?.stateNum === nextProps.report?.stateNum &&
prevProps.report?.statusNum === nextProps.report?.statusNum &&
prevProps.report?.lastReadTime === nextProps.report?.lastReadTime &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const useIsFocused = () => {
return isFocused || (topmostCentralPane?.name === SCREENS.SEARCH.CENTRAL_PANE && isSmallScreenWidth);
};

type PolicySelector = Pick<OnyxTypes.Policy, 'type' | 'role' | 'isPolicyExpenseChatEnabled' | 'pendingAction' | 'avatar' | 'name' | 'id'>;
type PolicySelector = Pick<OnyxTypes.Policy, 'type' | 'role' | 'isPolicyExpenseChatEnabled' | 'pendingAction' | 'avatarURL' | 'name' | 'id'>;

type FloatingActionButtonAndPopoverOnyxProps = {
/** The list of policies the user has access to. */
Expand Down Expand Up @@ -91,7 +91,7 @@ const policySelector = (policy: OnyxEntry<OnyxTypes.Policy>): PolicySelector =>
id: policy.id,
isPolicyExpenseChatEnabled: policy.isPolicyExpenseChatEnabled,
pendingAction: policy.pendingAction,
avatar: policy.avatar,
avatarURL: policy.avatarURL,
name: policy.name,
}) as PolicySelector;

Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepSendFrom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function IOURequestStepSendFrom({route, transaction, allPolicies}: IOURequestSte
keyForList: policy.id,
icons: [
{
source: policy?.avatar ? policy.avatar : ReportUtils.getDefaultWorkspaceAvatar(policy.name),
source: policy?.avatarURL ? policy.avatarURL : ReportUtils.getDefaultWorkspaceAvatar(policy.name),
fallbackIcon: Expensicons.FallbackWorkspaceAvatar,
name: policy.name,
type: CONST.ICON_TYPE_WORKSPACE,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type WorkspaceAvatarOnyxProps = {
type WorkspaceAvatarProps = WorkspaceAvatarOnyxProps & StackScreenProps<AuthScreensParamList, typeof SCREENS.WORKSPACE_AVATAR>;

function WorkspaceAvatar({policy, isLoadingApp = true}: WorkspaceAvatarProps) {
const avatarURL = policy?.avatar ?? '' ? policy?.avatar ?? '' : ReportUtils.getDefaultWorkspaceAvatar(policy?.name ?? '');
const avatarURL = policy?.avatarURL ?? '' ? policy?.avatarURL ?? '' : ReportUtils.getDefaultWorkspaceAvatar(policy?.name ?? '');

return (
<AttachmentModal
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/WorkspaceInitialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc

const hasMembersError = PolicyUtils.hasEmployeeListError(policy);
const hasPolicyCategoryError = PolicyUtils.hasPolicyCategoriesError(policyCategories);
const hasGeneralSettingsError = !isEmptyObject(policy?.errorFields?.generalSettings ?? {}) || !isEmptyObject(policy?.errorFields?.avatar ?? {});
const hasGeneralSettingsError = !isEmptyObject(policy?.errorFields?.generalSettings ?? {}) || !isEmptyObject(policy?.errorFields?.avatarURL ?? {});
const shouldShowProtectedItems = PolicyUtils.isPolicyAdmin(policy);
const isPaidGroupPolicy = PolicyUtils.isPaidGroupPolicy(policy);
const isFreeGroupPolicy = PolicyUtils.isFreeGroupPolicy(policy);
Expand Down Expand Up @@ -310,7 +310,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc
return {source: Expensicons.ExpensifyAppIcon, name: CONST.WORKSPACE_SWITCHER.NAME, type: CONST.ICON_TYPE_AVATAR};
}

const avatar = policy?.avatar ? policy.avatar : getDefaultWorkspaceAvatar(policy?.name);
const avatar = policy?.avatarURL ? policy.avatarURL : getDefaultWorkspaceAvatar(policy?.name);
return {
source: avatar,
name: policy?.name ?? '',
Expand Down
16 changes: 8 additions & 8 deletions src/pages/workspace/WorkspaceProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ function WorkspaceProfilePage({policy, currencyList = {}, route}: WorkSpaceProfi
containerStyles={styles.avatarXLarge}
imageStyles={[styles.avatarXLarge, styles.alignSelfCenter]}
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- nullish coalescing cannot be used if left side can be empty string
source={policy?.avatar || ReportUtils.getDefaultWorkspaceAvatar(policyName)}
source={policy?.avatarURL || ReportUtils.getDefaultWorkspaceAvatar(policyName)}
fallbackIcon={Expensicons.FallbackWorkspaceAvatar}
size={CONST.AVATAR_SIZE.XLARGE}
name={policyName}
accountID={policy?.id ?? ''}
type={CONST.ICON_TYPE_WORKSPACE}
/>
),
[policy?.avatar, policy?.id, policyName, styles.alignSelfCenter, styles.avatarXLarge],
[policy?.avatarURL, policy?.id, policyName, styles.alignSelfCenter, styles.avatarXLarge],
);

const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
Expand Down Expand Up @@ -139,28 +139,28 @@ function WorkspaceProfilePage({policy, currencyList = {}, route}: WorkSpaceProfi
/>
<AvatarWithImagePicker
onViewPhotoPress={() => Navigation.navigate(ROUTES.WORKSPACE_AVATAR.getRoute(policy?.id ?? ''))}
source={policy?.avatar ?? ''}
source={policy?.avatarURL ?? ''}
size={CONST.AVATAR_SIZE.XLARGE}
avatarStyle={styles.avatarXLarge}
enablePreview
DefaultAvatar={DefaultAvatar}
type={CONST.ICON_TYPE_WORKSPACE}
fallbackIcon={Expensicons.FallbackWorkspaceAvatar}
style={[
policy?.errorFields?.avatar ?? isSmallScreenWidth ? styles.mb1 : styles.mb3,
policy?.errorFields?.avatarURL ?? isSmallScreenWidth ? styles.mb1 : styles.mb3,
isSmallScreenWidth ? styles.mtn17 : styles.mtn20,
styles.alignItemsStart,
styles.sectionMenuItemTopDescription,
]}
editIconStyle={styles.smallEditIconWorkspace}
isUsingDefaultAvatar={!policy?.avatar ?? null}
isUsingDefaultAvatar={!policy?.avatarURL ?? false}
onImageSelected={(file) => Policy.updateWorkspaceAvatar(policy?.id ?? '', file as File)}
onImageRemoved={() => Policy.deleteWorkspaceAvatar(policy?.id ?? '')}
editorMaskImage={Expensicons.ImageCropSquareMask}
pendingAction={policy?.pendingFields?.avatar}
errors={policy?.errorFields?.avatar}
pendingAction={policy?.pendingFields?.avatarURL}
errors={policy?.errorFields?.avatarURL}
onErrorClose={() => Policy.clearAvatarErrors(policy?.id ?? '')}
previewSource={UserUtils.getFullSizeAvatar(policy?.avatar ?? '')}
previewSource={UserUtils.getFullSizeAvatar(policy?.avatarURL ?? '')}
headerTitle={translate('workspace.common.workspaceAvatar')}
originalFileName={policy?.originalFileName}
disabled={readOnly}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceProfileSharePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function WorkspaceProfileSharePage({policy}: WithPolicyProps) {
ref={qrCodeRef}
url={url}
title={policyName}
logo={(policy?.avatar ? policy.avatar : expensifyLogo) as ImageSourcePropType}
logo={(policy?.avatarURL ? policy.avatarURL : expensifyLogo) as ImageSourcePropType}
logoRatio={CONST.QR.DEFAULT_LOGO_SIZE_RATIO}
logoMarginRatio={CONST.QR.DEFAULT_LOGO_MARGIN_RATIO}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/WorkspacesListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ function WorkspacesListPage({policies, reimbursementAccount, reports, session}:
}
return {
title: policy.name,
icon: policy.avatar ? policy.avatar : ReportUtils.getDefaultWorkspaceAvatar(policy.name),
icon: policy.avatarURL ? policy.avatarURL : ReportUtils.getDefaultWorkspaceAvatar(policy.name),
action: () => Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policy.id)),
brickRoadIndicator: reimbursementAccountBrickRoadIndicator ?? PolicyUtils.getPolicyBrickRoadIndicatorStatus(policy),
pendingAction: policy.pendingAction,
Expand All @@ -346,7 +346,7 @@ function WorkspacesListPage({policies, reimbursementAccount, reports, session}:
dismissWorkspaceError(policy.id, policy.pendingAction);
},
disabled: policy.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
iconType: policy.avatar ? CONST.ICON_TYPE_AVATAR : CONST.ICON_TYPE_ICON,
iconType: policy.avatarURL ? CONST.ICON_TYPE_AVATAR : CONST.ICON_TYPE_ICON,
iconFill: theme.textLight,
fallbackIcon: Expensicons.FallbackWorkspaceAvatar,
policyID: policy.id,
Expand Down
1 change: 0 additions & 1 deletion src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback<
address?: CompanyAddress;

/** The URL for the policy avatar */
avatar?: string;
avatarURL?: string;

/** Error objects keyed by field name containing errors keyed by microtime */
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/LHNTestUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function getFakePolicy(id = '1', name = 'Workspace-Test-001'): Policy {
type: 'free',
owner: '[email protected]',
outputCurrency: 'BRL',
avatar: '',
avatarURL: '',
employeeList: {},
isPolicyExpenseChatEnabled: true,
lastModified: '1697323926777105',
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/collections/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function createRandomPolicy(index: number): Policy {
role: rand(Object.values(CONST.POLICY.ROLE)),
owner: randEmail(),
ownerAccountID: index,
avatar: randAvatar(),
avatarURL: randAvatar(),
isFromFullPolicy: randBoolean(),
lastModified: randPastDate().toISOString(),
pendingAction: rand(Object.values(CONST.RED_BRICK_ROAD_PENDING_ACTION)),
Expand Down

0 comments on commit ae5f41a

Please sign in to comment.