diff --git a/src/languages/en.js b/src/languages/en.js index 48057765ce67..9ab1bcd0edd4 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -121,6 +121,7 @@ export default { enterManually: 'Enter it manually', message: 'Message ', leaveRoom: 'Leave room', + leaveThread: 'Leave thread', you: 'You', youAfterPreposition: 'you', your: 'your', diff --git a/src/languages/es.js b/src/languages/es.js index 43ccdfcdf2db..23cd4654c003 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -120,6 +120,7 @@ export default { enterManually: 'Introducir manualmente', message: 'Chatear con ', leaveRoom: 'Salir de la sala de chat', + leaveThread: 'Salir del hilo', you: 'Tú', youAfterPreposition: 'ti', your: 'tu', diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index b01ab88749be..bc88a2214c98 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -473,15 +473,16 @@ function isThreadFirstChat(reportAction, reportID) { /** * Get either the policyName or domainName the chat is tied to * @param {Object} report - * @param {Object} parentReport * @returns {String} */ -function getChatRoomSubtitle(report, parentReport = null) { +function getChatRoomSubtitle(report) { if (isThread(report)) { if (!getChatType(report)) { return ''; } + const parentReport = lodashGet(allReports, [`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`]); + // If thread is not from a DM or group chat, the subtitle will follow the pattern 'Workspace Name • #roomName' const workspaceName = getPolicyName(report); let roomName = ''; @@ -1113,7 +1114,7 @@ function getReportName(report) { function navigateToDetailsPage(report) { const participants = lodashGet(report, 'participants', []); - if (isChatRoom(report) || isPolicyExpenseChat(report)) { + if (isChatRoom(report) || isPolicyExpenseChat(report) || isThread(report)) { Navigation.navigate(ROUTES.getReportDetailsRoute(report.reportID)); return; } diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index c8e15e929fa1..45e992be8889 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -260,10 +260,9 @@ function getOptionData(reportID) { result.tooltipText = ReportUtils.getReportParticipantsTitle(report.participants || []); result.hasOutstandingIOU = report.hasOutstandingIOU; result.parentReportID = report.parentReportID || null; - const parentReport = result.parentReportID ? chatReports[`${ONYXKEYS.COLLECTION.REPORT}${result.parentReportID}`] : null; const hasMultipleParticipants = participantPersonalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat; - const subtitle = ReportUtils.getChatRoomSubtitle(report, parentReport); + const subtitle = ReportUtils.getChatRoomSubtitle(report); const login = Str.removeSMSDomain(lodashGet(personalDetail, 'login', '')); const formattedLogin = Str.isSMSLogin(login) ? LocalePhoneNumber.formatPhoneNumber(login) : login; diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 27ed1c85e7a0..89e542320d02 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -14,7 +14,6 @@ import * as OptionsListUtils from '../OptionsListUtils'; import DateUtils from '../DateUtils'; import * as ReportUtils from '../ReportUtils'; import Log from '../Log'; -import * as Report from './Report'; import Permissions from '../Permissions'; const allPolicies = {}; @@ -1148,42 +1147,6 @@ function setWorkspaceInviteMembersDraft(policyID, memberEmails) { Onyx.set(`${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT}${policyID}`, memberEmails); } -/** - * - * @param {String} reportID - */ -function leaveRoom(reportID) { - API.write( - 'LeaveRoom', - { - reportID, - }, - { - optimisticData: [ - { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: { - stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, - statusNum: CONST.REPORT.STATUS.CLOSED, - }, - }, - ], - failureData: [ - { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: { - stateNum: CONST.REPORT.STATE_NUM.OPEN, - statusNum: CONST.REPORT.STATUS.OPEN, - }, - }, - ], - }, - ); - Report.navigateToConciergeChat(); -} - export { removeMembers, addMembersToWorkspace, @@ -1213,5 +1176,4 @@ export { removeWorkspace, setWorkspaceInviteMembersDraft, isPolicyOwner, - leaveRoom, }; diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 268a052d4a4e..fb7b123a813d 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1585,6 +1585,43 @@ function openReportFromDeepLink(url) { }); } +/** + * Leave a report by setting the state to submitted and closed + * + * @param {String} reportID + */ +function leaveRoom(reportID) { + API.write( + 'LeaveRoom', + { + reportID, + }, + { + optimisticData: [ + { + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: { + stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, + statusNum: CONST.REPORT.STATUS.CLOSED, + }, + }, + ], + failureData: [ + { + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: { + stateNum: CONST.REPORT.STATE_NUM.OPEN, + statusNum: CONST.REPORT.STATUS.OPEN, + }, + }, + ], + }, + ); + navigateToConciergeChat(); +} + export { addComment, addAttachment, @@ -1626,4 +1663,5 @@ export { toggleEmojiReaction, hasAccountIDReacted, shouldShowReportActionNotification, + leaveRoom, }; diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index 9ed7bfa86092..11badcede40b 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -15,7 +15,7 @@ import styles from '../styles/styles'; import DisplayNames from '../components/DisplayNames'; import * as OptionsListUtils from '../libs/OptionsListUtils'; import * as ReportUtils from '../libs/ReportUtils'; -import * as Policy from '../libs/actions/Policy'; +import * as Report from '../libs/actions/Report'; import participantPropTypes from '../components/participantPropTypes'; import * as Expensicons from '../components/Icon/Expensicons'; import ROUTES from '../ROUTES'; @@ -82,7 +82,7 @@ class ReportDetailsPage extends Component { }); } - if (ReportUtils.isPolicyExpenseChat(this.props.report) || ReportUtils.isChatRoom(this.props.report)) { + if (ReportUtils.isPolicyExpenseChat(this.props.report) || ReportUtils.isChatRoom(this.props.report) || ReportUtils.isThread(this.props.report)) { menuItems.push({ key: CONST.REPORT_DETAILS_MENU_ITEM.SETTINGS, translationKey: 'common.settings', @@ -94,12 +94,13 @@ class ReportDetailsPage extends Component { } const policy = this.props.policies[`${ONYXKEYS.COLLECTION.POLICY}${this.props.report.policyID}`]; - if (ReportUtils.isUserCreatedPolicyRoom(this.props.report) || ReportUtils.canLeaveRoom(this.props.report, !_.isEmpty(policy))) { + const isThread = ReportUtils.isThread(this.props.report); + if (ReportUtils.isUserCreatedPolicyRoom(this.props.report) || ReportUtils.canLeaveRoom(this.props.report, !_.isEmpty(policy)) || isThread) { menuItems.push({ key: CONST.REPORT_DETAILS_MENU_ITEM.LEAVE_ROOM, - translationKey: 'common.leaveRoom', + translationKey: isThread ? 'common.leaveThread' : 'common.leaveRoom', icon: Expensicons.Exit, - action: () => Policy.leaveRoom(this.props.report.reportID), + action: () => Report.leaveRoom(this.props.report.reportID), }); } @@ -109,6 +110,7 @@ class ReportDetailsPage extends Component { render() { const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(this.props.report); const isChatRoom = ReportUtils.isChatRoom(this.props.report); + const isThread = ReportUtils.isThread(this.props.report); const chatRoomSubtitle = ReportUtils.getChatRoomSubtitle(this.props.report); const participants = lodashGet(this.props.report, 'participants', []); const isMultipleParticipant = participants.length > 1; @@ -139,7 +141,7 @@ class ReportDetailsPage extends Component { tooltipEnabled numberOfLines={1} textStyles={[styles.textHeadline, styles.mb2, styles.textAlignCenter, styles.pre]} - shouldUseFullTitle={isChatRoom || isPolicyExpenseChat} + shouldUseFullTitle={isChatRoom || isPolicyExpenseChat || isThread} /> { {({safeAreaPaddingBottomStyle}) => ( policy && policy.id === this.props.report.policyID); - const shouldDisableRename = this.shouldDisableRename(linkedWorkspace); + const shouldDisableRename = this.shouldDisableRename(linkedWorkspace) || ReportUtils.isThread(this.props.report); return ( diff --git a/src/pages/ShareCodePage.js b/src/pages/ShareCodePage.js index 8fbfabe9f524..c67c42520767 100644 --- a/src/pages/ShareCodePage.js +++ b/src/pages/ShareCodePage.js @@ -37,6 +37,7 @@ class ShareCodePage extends React.Component { render() { const isReport = this.props.report != null && this.props.report.reportID != null; + const subtitle = ReportUtils.getChatRoomSubtitle(this.props.report); const url = isReport ? `${CONST.NEW_EXPENSIFY_URL}r/${this.props.report.reportID}` : `${CONST.NEW_EXPENSIFY_URL}details?login=${this.props.session.email}`; @@ -58,7 +59,7 @@ class ShareCodePage extends React.Component { ref={this.qrCodeRef} url={url} title={isReport ? this.props.report.reportName : this.props.currentUserPersonalDetails.displayName} - subtitle={isReport ? ReportUtils.getPolicyName(this.props.report) : this.props.session.email} + subtitle={isReport ? subtitle : this.props.session.email} logo={isReport ? roomAvatar : this.props.currentUserPersonalDetails.avatar} />