-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Use new api command AddWorkspaceRoom #10863
Changes from all commits
8d51541
f8bf291
29e5449
126095f
7795cac
ae97e15
e9fe6cf
e0080da
fc3f25a
0285d03
6aee812
893fb26
1ac43d0
59d991a
a565376
2fe7dce
3e48e25
5384829
70bc06e
9bf1106
a1157f9
edf0158
ab70b5c
f540685
d16b08d
6237de8
d8b1efd
14ab87c
e5fb0d7
44d4667
877b45a
bb6527d
ee989bf
2c175af
f54314f
3a9fd3c
6066771
41dc249
069a4c8
b6f4319
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -593,16 +593,18 @@ function fetchAllReports( | |
* @param {String} ownerEmail | ||
* @param {Boolean} isOwnPolicyExpenseChat | ||
* @param {String} oldPolicyName | ||
* @param {String} visibility | ||
* @returns {Object} | ||
*/ | ||
function buildOptimisticChatReport( | ||
participantList, | ||
reportName = 'Chat Report', | ||
chatType = '', | ||
policyID = '_FAKE_', | ||
ownerEmail = '__FAKE__', | ||
policyID = CONST.POLICY.OWNER_EMAIL_FAKE, | ||
ownerEmail = CONST.REPORT.OWNER_EMAIL_FAKE, | ||
isOwnPolicyExpenseChat = false, | ||
oldPolicyName = '', | ||
visibility = undefined, | ||
) { | ||
return { | ||
chatType, | ||
|
@@ -616,7 +618,7 @@ function buildOptimisticChatReport( | |
lastMessageTimestamp: 0, | ||
lastVisitedTimestamp: 0, | ||
maxSequenceNumber: 0, | ||
notificationPreference: '', | ||
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.DAILY, | ||
oldPolicyName, | ||
ownerEmail, | ||
participants: participantList, | ||
|
@@ -625,7 +627,7 @@ function buildOptimisticChatReport( | |
reportName, | ||
stateNum: 0, | ||
statusNum: 0, | ||
visibility: undefined, | ||
visibility, | ||
}; | ||
} | ||
|
||
|
@@ -639,7 +641,6 @@ function buildOptimisticCreatedReportAction(ownerEmail) { | |
0: { | ||
actionName: CONST.REPORT.ACTIONS.TYPE.CREATED, | ||
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
actorEmail: currentUserEmail, | ||
actorAccountID: currentUserAccountID, | ||
message: [ | ||
{ | ||
|
@@ -1449,6 +1450,91 @@ function createPolicyRoom(policyID, reportName, visibility) { | |
.finally(() => Onyx.set(ONYXKEYS.IS_LOADING_CREATE_POLICY_ROOM, false)); | ||
} | ||
|
||
/** | ||
* Add a policy report (workspace room) optimistically and navigate to it. | ||
* | ||
* @param {Object} policy | ||
* @param {String} reportName | ||
* @param {String} visibility | ||
*/ | ||
function addPolicyReport(policy, reportName, visibility) { | ||
// The participants include the current user (admin) and the employees. Participants must not be empty. | ||
const participants = [currentUserEmail, ...policy.employeeList]; | ||
const policyReport = buildOptimisticChatReport( | ||
participants, | ||
reportName, | ||
CONST.REPORT.CHAT_TYPE.POLICY_ROOM, | ||
policy.id, | ||
CONST.REPORT.OWNER_EMAIL_FAKE, | ||
false, | ||
'', | ||
visibility, | ||
); | ||
|
||
// Onyx.set is used on the optimistic data so that it is present before navigating to the workspace room. With Onyx.merge the workspace room reportID is not present when | ||
// storeCurrentlyViewedReport is called on the ReportScreen, so fetchChatReportsByIDs is called which is unnecessary since the optimistic data will be stored in Onyx. | ||
// If there was an error creating the room, then fetchChatReportsByIDs throws an error and the user is navigated away from the report instead of showing the RBR error message. | ||
// Therefore, Onyx.set is used instead of Onyx.merge. | ||
const optimisticData = [ | ||
{ | ||
onyxMethod: CONST.ONYX.METHOD.SET, | ||
key: `${ONYXKEYS.COLLECTION.REPORT}${policyReport.reportID}`, | ||
value: { | ||
pendingFields: { | ||
addWorkspaceRoom: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
}, | ||
...policyReport, | ||
}, | ||
}, | ||
{ | ||
onyxMethod: CONST.ONYX.METHOD.SET, | ||
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${policyReport.reportID}`, | ||
value: buildOptimisticCreatedReportAction(policyReport.ownerEmail), | ||
}, | ||
]; | ||
const successData = [ | ||
{ | ||
onyxMethod: CONST.ONYX.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.REPORT}${policyReport.reportID}`, | ||
value: { | ||
pendingFields: { | ||
addWorkspaceRoom: null, | ||
}, | ||
}, | ||
}, | ||
{ | ||
onyxMethod: CONST.ONYX.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${policyReport.reportID}`, | ||
value: { | ||
0: { | ||
pendingAction: null, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
API.write( | ||
'AddWorkspaceRoom', | ||
{ | ||
policyID: policyReport.policyID, | ||
reportName, | ||
visibility, | ||
reportID: policyReport.reportID, | ||
}, | ||
{optimisticData, successData}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coming from #20502 - it would have been best to add a |
||
); | ||
Navigation.navigate(ROUTES.getReportRoute(policyReport.reportID)); | ||
} | ||
|
||
/** | ||
* @param {Number} reportID The reportID of the policy report (workspace room) | ||
*/ | ||
function navigateToConciergeChatAndDeletePolicyReport(reportID) { | ||
navigateToConciergeChat(); | ||
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, null); | ||
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, null); | ||
} | ||
|
||
/** | ||
* @param {Object} policyRoomReport | ||
* @param {Number} policyRoomReport.reportID | ||
|
@@ -1659,6 +1745,8 @@ export { | |
handleInaccessibleReport, | ||
setReportWithDraft, | ||
createPolicyRoom, | ||
addPolicyReport, | ||
navigateToConciergeChatAndDeletePolicyReport, | ||
setIsComposerFullSize, | ||
markCommentAsUnread, | ||
readNewestAction, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import React from 'react'; | ||
import {Pressable, View} from 'react-native'; | ||
import lodashGet from 'lodash/get'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import PropTypes from 'prop-types'; | ||
import ONYXKEYS from '../../../ONYXKEYS'; | ||
|
@@ -8,10 +9,15 @@ import ReportWelcomeText from '../../../components/ReportWelcomeText'; | |
import participantPropTypes from '../../../components/participantPropTypes'; | ||
import * as ReportUtils from '../../../libs/ReportUtils'; | ||
import styles from '../../../styles/styles'; | ||
import OfflineWithFeedback from '../../../components/OfflineWithFeedback'; | ||
import * as Report from '../../../libs/actions/Report'; | ||
|
||
const propTypes = { | ||
/** The report currently being looked at */ | ||
report: PropTypes.shape({ | ||
/** The id of the report */ | ||
reportID: PropTypes.number, | ||
|
||
/** Avatars corresponding to a chat */ | ||
icons: PropTypes.arrayOf(PropTypes.string), | ||
|
||
|
@@ -38,24 +44,31 @@ const ReportActionItemCreated = (props) => { | |
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(props.report); | ||
const icons = ReportUtils.getIcons(props.report, props.personalDetails, props.policies); | ||
return ( | ||
<View | ||
accessibilityLabel="Chat welcome message" | ||
style={[ | ||
styles.chatContent, | ||
styles.pb8, | ||
styles.p5, | ||
]} | ||
<OfflineWithFeedback | ||
pendingAction={lodashGet(props.report, 'pendingFields.addWorkspaceRoom')} | ||
errors={lodashGet(props.report, 'errorFields.addWorkspaceRoom')} | ||
errorRowStyles={styles.addWorkspaceRoomErrorRow} | ||
onClose={() => Report.navigateToConciergeChatAndDeletePolicyReport(props.report.reportID)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any chance report could be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There might still be something to be careful of here though.
While this is true, it does not guarantee that a report is returned. It could read the report from Onyx, find nothing there, then pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah, good point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, but just calling it "safe" really isn't a good place to leave this. You should mark the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right, yes. My bad. I will create a follow up PR for that. |
||
> | ||
<View style={[styles.justifyContentCenter, styles.alignItemsCenter, styles.flex1]}> | ||
<Pressable onPress={() => ReportUtils.navigateToDetailsPage(props.report)}> | ||
<RoomHeaderAvatars | ||
icons={icons} | ||
shouldShowLargeAvatars={isPolicyExpenseChat} | ||
/> | ||
</Pressable> | ||
<ReportWelcomeText report={props.report} /> | ||
<View | ||
accessibilityLabel="Chat welcome message" | ||
style={[ | ||
styles.chatContent, | ||
styles.pb8, | ||
styles.p5, | ||
]} | ||
> | ||
<View style={[styles.justifyContentCenter, styles.alignItemsCenter, styles.flex1]}> | ||
<Pressable onPress={() => ReportUtils.navigateToDetailsPage(props.report)}> | ||
<RoomHeaderAvatars | ||
icons={icons} | ||
shouldShowLargeAvatars={isPolicyExpenseChat} | ||
/> | ||
</Pressable> | ||
<ReportWelcomeText report={props.report} /> | ||
</View> | ||
</View> | ||
</View> | ||
</OfflineWithFeedback> | ||
); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB: this is definitely a complex and difficult to understand condition, I wonder if there are any ways to simplify it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's pretty ugly. It would help to break it out into several descriptive boolean variables. I think @tgolen might be cleaning that up with his LHN cleanup issues? I'm going to leave it as is for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this logic has actually been moved here in main
App/src/libs/SidebarUtils.js
Lines 125 to 134 in 7fbe704
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, let me take a try at cleaning up this logic 👍 I created a GH for it here: https://github.com/Expensify/Expensify/issues/229633