Skip to content
Merged
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
51 changes: 51 additions & 0 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _ from 'underscore';
import Onyx from 'react-native-onyx';
import lodashGet from 'lodash/get';
import {PUBLIC_DOMAINS} from 'expensify-common/lib/CONST';
import * as DeprecatedAPI from '../deprecatedAPI';
import * as API from '../API';
import ONYXKEYS from '../../ONYXKEYS';
Expand Down Expand Up @@ -751,6 +752,55 @@ function clearAddMemberError(policyID, memberEmail) {
});
}

/**
* @param {String} value
* @returns {String}
*/
function capitalizeFirstLetter(value) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not really feel like this function belongs here.. more importantly, this function already exists: https://github.com/Expensify/expensify-common/blob/main/lib/str.js#L327 -- please change the code to use that instead 🙇

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this updated?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR was created to remove the out of place method

return value.charAt(0).toUpperCase() + value.slice(1);
}

/**
* Generate a policy name based on an email and policy list.
* @returns {String}
*/
function generateDefaultWorkspaceName() {
const emailParts = sessionEmail.split('@');
let defaultWorkspaceName = '';
if (!emailParts || emailParts.length !== 2) {
return defaultWorkspaceName;
}
const username = emailParts[0];
const domain = emailParts[1];

if (_.includes(PUBLIC_DOMAINS, domain.toLowerCase())) {
defaultWorkspaceName = `${capitalizeFirstLetter(username)}'s Workspace`;
} else {
defaultWorkspaceName = `${capitalizeFirstLetter(domain.split('.')[0])}'s Workspace`;
}

if (`@${domain.toLowerCase()}` === CONST.SMS.DOMAIN) {
defaultWorkspaceName = 'My Group Workspace';
}

if (allPolicies.length === 0) {
return defaultWorkspaceName;
}

Comment thread
thienlnam marked this conversation as resolved.
Resolved
// Check if this name already exists in the policies
let suffix = 0;
_.forEach(allPolicies, (policy) => {
// Get the name of the policy
const {name} = policy;

if (name.toLowerCase().includes(defaultWorkspaceName.toLowerCase())) {
suffix += 1;
}
});

return suffix > 0 ? `${defaultWorkspaceName} ${suffix}` : defaultWorkspaceName;
}

/**
* Returns a client generated 16 character hexadecimal value for the policyID
* @returns {String}
Expand Down Expand Up @@ -779,6 +829,7 @@ export {
subscribeToPolicyEvents,
clearDeleteMemberError,
clearAddMemberError,
generateDefaultWorkspaceName,
updateGeneralSettings,
clearWorkspaceGeneralSettingsErrors,
deleteWorkspaceAvatar,
Expand Down