Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix: Unable to select members after adding them to the workspace" #37802

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"react-native-linear-gradient": "^2.8.1",
"react-native-localize": "^2.2.6",
"react-native-modal": "^13.0.0",
"react-native-onyx": "2.0.10",
"react-native-onyx": "2.0.7",
"react-native-pager-view": "6.2.2",
"react-native-pdf": "6.7.3",
"react-native-performance": "^5.1.0",
Expand Down
14 changes: 14 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4549,6 +4549,19 @@ function getReportOfflinePendingActionAndErrors(report: OnyxEntry<Report>): Repo
return {reportPendingAction, reportErrors};
}

function getPolicyExpenseChatReportIDByOwner(policyOwner: string): string | null {
const policyWithOwner = Object.values(allPolicies ?? {}).find((policy) => policy?.owner === policyOwner);
if (!policyWithOwner) {
return null;
}

const expenseChat = Object.values(allReports ?? {}).find((report) => isPolicyExpenseChat(report) && report?.policyID === policyWithOwner.id);
if (!expenseChat) {
return null;
}
return expenseChat.reportID;
}

/**
* Check if the report can create the request with type is iouType
*/
Expand Down Expand Up @@ -5232,6 +5245,7 @@ export {
isDM,
isSelfDM,
getPolicy,
getPolicyExpenseChatReportIDByOwner,
getWorkspaceChats,
shouldDisableRename,
hasSingleParticipant,
Expand Down
23 changes: 2 additions & 21 deletions src/libs/actions/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import playSoundExcludingMobile from '@libs/Sound/playSoundExcludingMobile';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {BlockedFromConcierge, FrequentlyUsedEmoji, Policy} from '@src/types/onyx';
import type {BlockedFromConcierge, FrequentlyUsedEmoji} from '@src/types/onyx';
import type Login from '@src/types/onyx/Login';
import type {OnyxServerUpdate} from '@src/types/onyx/OnyxUpdatesFromServer';
import type OnyxPersonalDetails from '@src/types/onyx/PersonalDetails';
Expand Down Expand Up @@ -775,7 +775,7 @@ function generateStatementPDF(period: string) {
/**
* Sets a contact method / secondary login as the user's "Default" contact method.
*/
function setContactMethodAsDefault(newDefaultContactMethod: string, policies: OnyxCollection<Pick<Policy, 'id' | 'ownerAccountID' | 'owner'>>) {
function setContactMethodAsDefault(newDefaultContactMethod: string) {
const oldDefaultContactMethod = currentEmail;
const optimisticData: OnyxUpdate[] = [
{
Expand Down Expand Up @@ -868,25 +868,6 @@ function setContactMethodAsDefault(newDefaultContactMethod: string, policies: On
},
];

Object.values(policies ?? {}).forEach((policy) => {
if (policy?.ownerAccountID !== currentUserAccountID) {
return;
}
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policy.id}`,
value: {
owner: newDefaultContactMethod,
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policy.id}`,
value: {
owner: policy.owner,
},
});
});
const parameters: SetContactMethodAsDefaultParams = {
partnerUserID: newDefaultContactMethod,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {LoginList, Policy, SecurityGroup, Session as TSession} from '@src/types/onyx';
import type {LoginList, SecurityGroup, Session as TSession} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import ValidateCodeForm from './ValidateCodeForm';
import type {ValidateCodeFormHandle} from './ValidateCodeForm/BaseValidateCodeForm';
Expand All @@ -48,14 +48,11 @@ type ContactMethodDetailsPageOnyxProps = {

/** Indicated whether the report data is loading */
isLoadingReportData: OnyxEntry<boolean>;

/** The list of this user's policies */
policies: OnyxCollection<Pick<Policy, 'id' | 'ownerAccountID' | 'owner'>>;
};

type ContactMethodDetailsPageProps = ContactMethodDetailsPageOnyxProps & StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.PROFILE.CONTACT_METHOD_DETAILS>;

function ContactMethodDetailsPage({loginList, session, myDomainSecurityGroups, securityGroups, isLoadingReportData = true, route, policies}: ContactMethodDetailsPageProps) {
function ContactMethodDetailsPage({loginList, session, myDomainSecurityGroups, securityGroups, isLoadingReportData = true, route}: ContactMethodDetailsPageProps) {
const {formatPhoneNumber, translate} = useLocalize();
const theme = useTheme();
const themeStyles = useThemeStyles();
Expand Down Expand Up @@ -91,8 +88,8 @@ function ContactMethodDetailsPage({loginList, session, myDomainSecurityGroups, s
* Attempt to set this contact method as user's "Default contact method"
*/
const setAsDefault = useCallback(() => {
User.setContactMethodAsDefault(contactMethod, policies);
}, [contactMethod, policies]);
User.setContactMethodAsDefault(contactMethod);
}, [contactMethod]);

/**
* Checks if the user is allowed to change their default contact method. This should only be allowed if:
Expand Down Expand Up @@ -305,12 +302,4 @@ export default withOnyx<ContactMethodDetailsPageProps, ContactMethodDetailsPageO
isLoadingReportData: {
key: `${ONYXKEYS.IS_LOADING_REPORT_DATA}`,
},
policies: {
key: ONYXKEYS.COLLECTION.POLICY,
selector: (data) => ({
id: data?.id ?? '',
ownerAccountID: data?.ownerAccountID,
owner: data?.owner ?? '',
}),
},
})(ContactMethodDetailsPage);
5 changes: 3 additions & 2 deletions src/pages/workspace/WorkspaceMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ function WorkspaceMembersPage({policyMembers, personalDetails, route, policy, se
*/
const validateSelection = useCallback(() => {
const newErrors: Errors = {};
const ownerAccountID = PersonalDetailsUtils.getAccountIDsByLogins(policy?.owner ? [policy.owner] : [])[0];
selectedEmployees.forEach((member) => {
if (member !== policy?.ownerAccountID && member !== session?.accountID) {
if (member !== ownerAccountID && member !== session?.accountID) {
return;
}
newErrors[member] = translate('workspace.people.error.cannotRemove');
Expand Down Expand Up @@ -325,7 +326,7 @@ function WorkspaceMembersPage({policyMembers, personalDetails, route, policy, se
isSelected,
isDisabled:
accountID === session?.accountID ||
accountID === policy?.ownerAccountID ||
details.login === policy?.owner ||
policyMember.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE ||
!isEmptyObject(policyMember.errors),
text: formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(details)),
Expand Down
Loading