diff --git a/src/CONST.js b/src/CONST.js index 42580b06b157..b449636dfd57 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -213,6 +213,7 @@ const CONST = { TYPE: { IOU: 'IOU', ADDCOMMENT: 'ADDCOMMENT', + RENAMED: 'RENAMED', }, }, ERROR: { diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js index 2e77064d3f87..573a8997a072 100755 --- a/src/ONYXKEYS.js +++ b/src/ONYXKEYS.js @@ -166,6 +166,9 @@ export default { // Are we loading the create policy room command IS_LOADING_CREATE_POLICY_ROOM: 'isLoadingCratePolicyRoom', + // Are we loading the rename policy room command + IS_LOADING_RENAME_POLICY_ROOM: 'isLoadingRenamePolicyRoom', + // Is Keyboard shortcuts modal open? IS_SHORTCUTS_MODAL_OPEN: 'isShortcutsModalOpen', diff --git a/src/components/ReportActionItem/RenameAction.js b/src/components/ReportActionItem/RenameAction.js new file mode 100644 index 000000000000..4b83ba66a610 --- /dev/null +++ b/src/components/ReportActionItem/RenameAction.js @@ -0,0 +1,34 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import lodashGet from 'lodash/get'; +import Text from '../Text'; +import styles from '../../styles/styles'; +import reportActionPropTypes from '../../pages/home/report/reportActionPropTypes'; +import withLocalize, {withLocalizePropTypes} from '../withLocalize'; + +const propTypes = { + /** All the data of the action */ + action: PropTypes.shape(reportActionPropTypes).isRequired, + + ...withLocalizePropTypes, +}; + +const RenameAction = (props) => { + const displayName = lodashGet(props.action, ['message', 0, 'text']); + const oldName = lodashGet(props.action, 'originalMessage.oldName', ''); + const newName = lodashGet(props.action, 'originalMessage.newName', ''); + + return ( + + + {displayName} + + {props.translate('newRoomPage.renamedRoomAction', {oldName, newName})} + + ); +}; + +RenameAction.propTypes = propTypes; +RenameAction.displayName = 'RenameAction'; + +export default withLocalize(RenameAction); diff --git a/src/languages/en.js b/src/languages/en.js index 7dcabe783343..85e591c08a31 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -884,11 +884,14 @@ export default { restrictedDescription: 'People in your workspace are able to find this room using Search', privateDescription: 'Only people invited to this room are able to find it', createRoom: 'Create Room', + policyRoomRenamed: 'Policy room renamed!', roomAlreadyExistsError: 'A room with this name already exists', roomNameReservedError: 'This name is reserved and cannot be used', + renamedRoomAction: ({oldName, newName}) => ` renamed this room from ${oldName} to ${newName}`, social: 'social', selectAWorkspace: 'Select a workspace', growlMessageOnError: 'Unable to create policy room, please check your connection and try again.', + growlMessageOnRenameError: 'Unable to rename policy room, please check your connection and try again.', visibilityOptions: { restricted: 'Restricted', private: 'Private', diff --git a/src/languages/es.js b/src/languages/es.js index 4082944d33a0..976b83df40f4 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -886,11 +886,14 @@ export default { restrictedDescription: 'Sólo las personas en tu espacio de trabajo pueden encontrar esta sala a través de "Buscar"', privateDescription: 'Sólo las personas que están invitadas a esta sala pueden encontrarla', createRoom: 'Crea una sala de chat', + policyRoomRenamed: '¡Espacio de trabajo renombrado!', roomAlreadyExistsError: 'Ya existe una sala con este nombre', roomNameReservedError: 'Este nombre está reservado y no puede usarse', + renamedRoomAction: ({oldName, newName}) => ` cambió el nombre de la sala de ${oldName} a ${newName}`, social: 'social', selectAWorkspace: 'Seleccionar un espacio de trabajo', growlMessageOnError: 'No ha sido posible crear el espacio de trabajo, por favor comprueba tu conexión e inténtalo de nuevo.', + growlMessageOnRenameError: 'No ha sido posible cambiar el nomdre del espacio de trabajo, por favor comprueba tu conexión e inténtalo de nuevo.', visibilityOptions: { restricted: 'Restringida', private: 'Privada', diff --git a/src/libs/API.js b/src/libs/API.js index 1279bb289d01..fd3581706ec5 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -1168,6 +1168,19 @@ function CreatePolicyRoom(parameters) { return Network.post(commandName, parameters); } +/** + * Renames a user-created policy room + * @param {Object} parameters + * @param {String} parameters.reportID + * @param {String} parameters.reportName + * @return {Promise} + */ +function RenameReport(parameters) { + const commandName = 'RenameReport'; + requireParameters(['reportID', 'reportName'], parameters, commandName); + return Network.post(commandName, parameters); +} + /** * Transfer Wallet balance and takes either the bankAccoundID or fundID * @param {Object} parameters @@ -1195,6 +1208,7 @@ export { CreateChatReport, CreateLogin, CreatePolicyRoom, + RenameReport, DeleteFund, DeleteLogin, DeleteBankAccount, diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 6555425f3e50..d1086ebfcb7e 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -584,7 +584,10 @@ function updateReportWithNewAction( setLocalLastRead(reportID, newMaxSequenceNumber); } - const messageText = lodashGet(reportAction, ['message', 0, 'text'], ''); + let messageText = lodashGet(reportAction, ['message', 0, 'text'], ''); + if (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.RENAMED) { + messageText = lodashGet(reportAction, 'originalMessage.html', ''); + } // Always merge the reportID into Onyx // If the report doesn't exist in Onyx yet, then all the rest of the data will be filled out @@ -1531,6 +1534,30 @@ function createPolicyRoom(policyID, reportName, visibility) { .finally(() => Onyx.set(ONYXKEYS.IS_LOADING_CREATE_POLICY_ROOM, false)); } +/** + * Renames a user created Policy Room. + * @param {String} reportID + * @param {String} reportName + */ +function renameReport(reportID, reportName) { + Onyx.set(ONYXKEYS.IS_LOADING_RENAME_POLICY_ROOM, true); + API.RenameReport({reportID, reportName}) + .then((response) => { + if (response.jsonCode !== 200) { + Growl.error(response.message); + return; + } + Growl.success(Localize.translateLocal('newRoomPage.policyRoomRenamed')); + + // Update the report name so that the LHN and header display the updated name + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {reportName}); + }) + .catch(() => { + Growl.error(Localize.translateLocal('newRoomPage.growlMessageOnRenameError')); + }) + .finally(() => Onyx.set(ONYXKEYS.IS_LOADING_RENAME_POLICY_ROOM, false)); +} + export { fetchAllReports, fetchActions, @@ -1560,5 +1587,6 @@ export { setReportWithDraft, fetchActionsWithLoadingState, createPolicyRoom, + renameReport, getLastReadSequenceNumber, }; diff --git a/src/pages/ReportSettingsPage.js b/src/pages/ReportSettingsPage.js index 1543d8686d1c..ac3e914988ca 100644 --- a/src/pages/ReportSettingsPage.js +++ b/src/pages/ReportSettingsPage.js @@ -89,7 +89,7 @@ class ReportSettingsPage extends Component { } render() { - const shouldDisableRename = ReportUtils.isDefaultRoom(this.props.report) || ReportUtils.isArchivedRoom(this.props.report); + const shouldDisableRename = ReportUtils.isDefaultRoom(this.props.report) || ReportUtils.isArchivedRoom(this.props.report) || this.props.isLoadingRenamePolicyRoom; const linkedWorkspace = _.find(this.props.policies, policy => policy.id === this.props.report.policyID); return ( @@ -141,10 +141,8 @@ class ReportSettingsPage extends Component {