Skip to content

Commit

Permalink
Merge pull request #14979 from fedirjh/Fix-14961
Browse files Browse the repository at this point in the history
[Refactor] Remove deprecated PersonalDetails.setPersonalDetails
  • Loading branch information
puneetlath authored Feb 20, 2023
2 parents adbe5f7 + b8c2bf2 commit 401cbca
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 60 deletions.
3 changes: 0 additions & 3 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ export default {
emailAddress: 'Email address',
setMyTimezoneAutomatically: 'Set my timezone automatically',
timezone: 'Timezone',
growlMessageOnSave: 'Your profile was successfully saved',
invalidFileMessage: 'Invalid file. Please try a different image.',
avatarUploadFailureMessage: 'An error occurred uploading the avatar, please try again.',
online: 'Online',
Expand Down Expand Up @@ -600,8 +599,6 @@ export default {
},
personalDetails: {
error: {
firstNameLength: `First name cannot be longer than ${CONST.DISPLAY_NAME.MAX_LENGTH} characters`,
lastNameLength: `Last name cannot be longer than ${CONST.DISPLAY_NAME.MAX_LENGTH} characters`,
containsReservedWord: 'First name cannot contain the words Expensify or Concierge',
hasInvalidCharacter: 'Name cannot contain a comma or semicolon',
},
Expand Down
3 changes: 0 additions & 3 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ export default {
emailAddress: 'Dirección de email',
setMyTimezoneAutomatically: 'Configura mi zona horaria automáticamente',
timezone: 'Zona horaria',
growlMessageOnSave: 'Tu perfil se ha guardado correctamente',
invalidFileMessage: 'Archivo inválido. Pruebe con una imagen diferente.',
avatarUploadFailureMessage: 'No se pudo subir el avatar. Por favor, inténtalo de nuevo.',
online: 'En línea',
Expand Down Expand Up @@ -600,8 +599,6 @@ export default {
},
personalDetails: {
error: {
firstNameLength: `El nombre no puede tener más de ${CONST.DISPLAY_NAME.MAX_LENGTH} caracteres`,
lastNameLength: `El apellido no puede tener más de ${CONST.DISPLAY_NAME.MAX_LENGTH} caracteres`,
containsReservedWord: 'El nombre no puede contener las palabras Expensify o Concierge',
hasInvalidCharacter: 'El nombre no puede contener una coma o un punto y coma',
},
Expand Down
7 changes: 4 additions & 3 deletions src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,22 @@ Onyx.connect({
},
});

let timezone;
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS,
callback: (val) => {
if (!val) {
if (!val || timezone) {
return;
}

const timezone = lodashGet(val, [currentUserEmail, 'timezone'], {});
timezone = lodashGet(val, [currentUserEmail, 'timezone'], {});
const currentTimezone = moment.tz.guess(true);

// If the current timezone is different than the user's timezone, and their timezone is set to automatic
// then update their timezone.
if (_.isObject(timezone) && timezone.automatic && timezone.selected !== currentTimezone) {
timezone.selected = currentTimezone;
PersonalDetails.setPersonalDetails({timezone});
PersonalDetails.updateAutomaticTimezone(timezone);
}
},
});
Expand Down
51 changes: 0 additions & 51 deletions src/libs/actions/PersonalDetails.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import lodashGet from 'lodash/get';
import lodashMerge from 'lodash/merge';
import Onyx from 'react-native-onyx';
import Str from 'expensify-common/lib/str';
import ONYXKEYS from '../../ONYXKEYS';
import CONST from '../../CONST';
import * as API from '../API';
import * as DeprecatedAPI from '../deprecatedAPI';
import NameValuePair from './NameValuePair';
import * as ReportUtils from '../ReportUtils';
import Growl from '../Growl';
import * as Localize from '../Localize';
import Navigation from '../Navigation/Navigation';
import ROUTES from '../../ROUTES';

Expand Down Expand Up @@ -86,51 +81,6 @@ function extractFirstAndLastNameFromAvailableDetails({
};
}

/**
* Merges partial details object into the local store.
*
* @param {Object} details
* @private
*/
function mergeLocalPersonalDetails(details) {
// We are merging the partial details provided to this method with the existing details we have for the user so
// that we don't overwrite any values that may exist in storage.
const mergedDetails = lodashMerge(personalDetails[currentUserEmail], details);

// displayName is a generated field so we'll use the firstName and lastName + login to update it.
mergedDetails.displayName = getDisplayName(currentUserEmail, mergedDetails);

Onyx.merge(ONYXKEYS.PERSONAL_DETAILS, {[currentUserEmail]: mergedDetails});
}

/**
* Sets the personal details object for the current user
*
* @param {Object} details
* @param {boolean} shouldGrowl
*/
function setPersonalDetails(details, shouldGrowl) {
DeprecatedAPI.PersonalDetails_Update({details: JSON.stringify(details)})
.then((response) => {
if (response.jsonCode === 200) {
if (details.timezone) {
NameValuePair.set(CONST.NVP.TIMEZONE, details.timezone);
}
mergeLocalPersonalDetails(details);

if (shouldGrowl) {
Growl.show(Localize.translateLocal('profilePage.growlMessageOnSave'), CONST.GROWL.SUCCESS, 3000);
}
} else if (response.jsonCode === 400) {
Growl.error(Localize.translateLocal('personalDetails.error.firstNameLength'), 3000);
} else if (response.jsonCode === 401) {
Growl.error(Localize.translateLocal('personalDetails.error.lastNameLength'), 3000);
} else {
console.debug('Error while setting personal details', response);
}
});
}

/**
* @param {String} pronouns
*/
Expand Down Expand Up @@ -402,7 +352,6 @@ function clearAvatarErrors() {

export {
getDisplayName,
setPersonalDetails,
updateAvatar,
deleteAvatar,
openIOUModalPage,
Expand Down

0 comments on commit 401cbca

Please sign in to comment.