Skip to content

Commit

Permalink
Merge pull request Expensify#53048 from Krishna2323/krishna2323/issue…
Browse files Browse the repository at this point in the history
…/52373

feat: There is no way to identify the primary workspace, making it appear essentially random.
  • Loading branch information
grgia authored Jan 3, 2025
2 parents 165a9ba + b5031a8 commit d60500a
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2562,6 +2562,8 @@ const translations = {
other: (count: number) => `${count} selected`,
}),
settlementFrequency: 'Settlement frequency',
setAsDefault: 'Set as default workspace',
defaultNote: `Receipts sent to ${CONST.EMAIL.RECEIPTS} will appear in this workspace.`,
deleteConfirmation: 'Are you sure you want to delete this workspace?',
deleteWithCardsConfirmation: 'Are you sure you want to delete this workspace? This will remove all card feeds and assigned cards.',
unavailable: 'Unavailable workspace',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2585,6 +2585,8 @@ const translations = {
other: (count: number) => `${count} seleccionados`,
}),
settlementFrequency: 'Frecuencia de liquidación',
setAsDefault: 'Establecer como espacio de trabajo predeterminado',
defaultNote: `Los recibos enviados a ${CONST.EMAIL.RECEIPTS} aparecerán en este espacio de trabajo.`,
deleteConfirmation: '¿Estás seguro de que quieres eliminar este espacio de trabajo?',
deleteWithCardsConfirmation: '¿Estás seguro de que quieres eliminar este espacio de trabajo? Se eliminarán todos los datos de las tarjetas y las tarjetas asignadas.',
unavailable: 'Espacio de trabajo no disponible',
Expand Down
2 changes: 1 addition & 1 deletion src/libs/API/parameters/SetNameValuePairParams.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type SetNameValuePairParams = {
name: string;
value: boolean;
value: boolean | string;
};

export default SetNameValuePairParams;
33 changes: 33 additions & 0 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import type {
OpenWorkspaceInvitePageParams,
OpenWorkspaceParams,
RequestExpensifyCardLimitIncreaseParams,
SetNameValuePairParams,
SetPolicyAutomaticApprovalLimitParams,
SetPolicyAutomaticApprovalRateParams,
SetPolicyAutoReimbursementLimitParams,
Expand Down Expand Up @@ -824,6 +825,37 @@ function leaveWorkspace(policyID?: string) {
API.write(WRITE_COMMANDS.LEAVE_POLICY, params, {optimisticData, successData, failureData});
}

function updateDefaultPolicy(newPolicyID?: string, oldPolicyID?: string) {
if (!newPolicyID) {
return;
}
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
value: newPolicyID,
},
];

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
value: oldPolicyID,
},
];

const parameters: SetNameValuePairParams = {
name: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
value: newPolicyID,
};

API.write(WRITE_COMMANDS.SET_NAME_VALUE_PAIR, parameters, {
optimisticData,
failureData,
});
}

function addBillingCardAndRequestPolicyOwnerChange(
policyID: string,
cardData: {
Expand Down Expand Up @@ -4797,6 +4829,7 @@ export {
verifySetupIntentAndRequestPolicyOwnerChange,
updateInvoiceCompanyName,
updateInvoiceCompanyWebsite,
updateDefaultPolicy,
getAssignedSupportData,
downgradeToTeam,
};
Expand Down
12 changes: 12 additions & 0 deletions src/pages/workspace/WorkspacesListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ function WorkspacesListPage() {
const [reimbursementAccount] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT);
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
const [session] = useOnyx(ONYXKEYS.SESSION);
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP);
const shouldShowLoadingIndicator = isLoadingApp && !isOffline;

Expand Down Expand Up @@ -170,6 +171,7 @@ function WorkspacesListPage() {
({item, index}: GetMenuItem) => {
const isAdmin = PolicyUtils.isPolicyAdmin(item as unknown as PolicyType, session?.email);
const isOwner = item.ownerAccountID === session?.accountID;
const isDefault = activePolicyID === item.policyID;
// Menu options to navigate to the chat report of #admins and #announce room.
// For navigation, the chat report ids may be unavailable due to the missing chat reports in Onyx.
// In such cases, let us use the available chat report ids from the policy.
Expand Down Expand Up @@ -222,6 +224,14 @@ function WorkspacesListPage() {
});
}

if (!isDefault && !item?.isJoinRequestPending) {
threeDotsMenuItems.push({
icon: Expensicons.Star,
text: translate('workspace.common.setAsDefault'),
onSelected: () => Policy.updateDefaultPolicy(item.policyID, activePolicyID),
});
}

return (
<OfflineWithFeedback
key={`${item.title}_${index}`}
Expand Down Expand Up @@ -252,6 +262,7 @@ function WorkspacesListPage() {
brickRoadIndicator={item.brickRoadIndicator}
shouldDisableThreeDotsMenu={item.disabled}
style={[item.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE ? styles.offlineFeedback.deleted : {}]}
isDefault={isDefault}
/>
)}
</PressableWithoutFeedback>
Expand All @@ -268,6 +279,7 @@ function WorkspacesListPage() {
styles.offlineFeedback.deleted,
session?.accountID,
session?.email,
activePolicyID,
isSupportalAction,
],
);
Expand Down
19 changes: 19 additions & 0 deletions src/pages/workspace/WorkspacesListRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as Illustrations from '@components/Icon/Illustrations';
import type {PopoverMenuItem} from '@components/PopoverMenu';
import Text from '@components/Text';
import ThreeDotsMenu from '@components/ThreeDotsMenu';
import Tooltip from '@components/Tooltip';
import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails';
import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalDetails';
import WorkspacesListRowDisplayName from '@components/WorkspacesListRowDisplayName';
Expand Down Expand Up @@ -65,6 +66,9 @@ type WorkspacesListRowProps = WithCurrentUserPersonalDetailsProps & {

/** ID of the policy */
policyID?: string;

/** is policy defualt */
isDefault?: boolean;
};

type BrickRoadIndicatorIconProps = {
Expand Down Expand Up @@ -108,6 +112,7 @@ function WorkspacesListRow({
shouldDisableThreeDotsMenu,
isJoinRequestPending,
policyID,
isDefault,
}: WorkspacesListRowProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
Expand Down Expand Up @@ -140,6 +145,20 @@ function WorkspacesListRow({
/>
</View>
)}
{!!isDefault && (
<Tooltip
maxWidth={variables.w184}
text={translate('workspace.common.defaultNote')}
>
<View style={[styles.flexRow, styles.gap2, styles.alignItemsCenter, styles.justifyContentEnd]}>
<Badge
text={translate('common.default')}
textStyles={styles.textStrong}
badgeStyles={[styles.alignSelfCenter, styles.badgeBordered, styles.badgeSuccess]}
/>
</View>
</Tooltip>
)}
{!isJoinRequestPending && (
<View style={[styles.flexRow, styles.ml2, styles.gap1]}>
<View style={[styles.flexRow, styles.gap2, styles.alignItemsCenter, isNarrow && styles.workspaceListRBR]}>
Expand Down

0 comments on commit d60500a

Please sign in to comment.