-
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 UpdatePolicyRoomName api command #10237
Changes from 35 commits
162ef4e
0e38b5a
303a0a3
f265e7e
124f8f5
15fbbf8
e657bd8
2fd2a55
7bdd021
1847e5a
f4a7b45
f952838
a77f503
b7ad9f8
5070cbd
20fdbdb
b388315
292c524
b493390
837f5db
45fa867
2a0683e
3693e27
1bfae69
acb83ab
d33ef6a
e4cbb45
2eea06a
2a3c71f
924afb9
e0497af
04cd7b4
06dd5d8
eddd6ce
106ad15
4c150ff
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 |
---|---|---|
|
@@ -43,6 +43,9 @@ const propTypes = { | |
/** ID of the policy */ | ||
id: PropTypes.string, | ||
}).isRequired, | ||
|
||
/** A ref forwarded to the TextInput */ | ||
forwardedRef: PropTypes.func, | ||
}; | ||
|
||
const defaultProps = { | ||
|
@@ -51,6 +54,7 @@ const defaultProps = { | |
disabled: false, | ||
errorText: '', | ||
...fullPolicyDefaultProps, | ||
forwardedRef: () => {}, | ||
}; | ||
|
||
class RoomNameInput extends Component { | ||
|
@@ -91,6 +95,7 @@ class RoomNameInput extends Component { | |
render() { | ||
return ( | ||
<TextInput | ||
ref={this.props.forwardedRef} | ||
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. I added a ref so the input value can be cleared from the parent. |
||
disabled={this.props.disabled} | ||
label={this.props.translate('newRoomPage.roomName')} | ||
prefixCharacter={CONST.POLICY.ROOM_PREFIX} | ||
|
@@ -118,4 +123,7 @@ export default compose( | |
key: ONYXKEYS.COLLECTION.POLICY, | ||
}, | ||
}), | ||
)(RoomNameInput); | ||
)(React.forwardRef((props, ref) => ( | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
<RoomNameInput {...props} forwardedRef={ref} /> | ||
))); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,9 +67,8 @@ const propTypes = { | |
/** A fallback avatar icon to display when there is an error on loading avatar from remote URL. */ | ||
fallbackIcon: PropTypes.func, | ||
|
||
/** If we need to show a brick road indicator or not. For now only value allowed is `error`, | ||
* but we will add `success` later for manual requests */ | ||
brickRoadIndicator: PropTypes.oneOf(['error']), | ||
/** The type of brick road indicator to show. */ | ||
brickRoadIndicator: PropTypes.oneOf([CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR, '']), | ||
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. The empty string is the empty value so that functions that get the brick road indicator property can always return a string. |
||
}; | ||
|
||
export default propTypes; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1377,30 +1377,66 @@ function createPolicyRoom(policyID, reportName, visibility) { | |
} | ||
|
||
/** | ||
* Renames a user created Policy Room. | ||
* @param {String} reportID | ||
* @param {String} reportName | ||
* @param {Object} policyRoomReport | ||
neil-marcellini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @param {Number} policyRoomReport.reportID | ||
* @param {String} policyRoomReport.reportName | ||
* @param {String} policyRoomName The updated name for the policy room | ||
*/ | ||
function renameReport(reportID, reportName) { | ||
Onyx.set(ONYXKEYS.IS_LOADING_RENAME_POLICY_ROOM, true); | ||
DeprecatedAPI.RenameReport({reportID, reportName}) | ||
.then((response) => { | ||
if (response.jsonCode === CONST.JSON_CODE.UNABLE_TO_RETRY) { | ||
Growl.error(Localize.translateLocal('newRoomPage.growlMessageOnRenameError')); | ||
return; | ||
} | ||
function updatePolicyRoomName(policyRoomReport, policyRoomName) { | ||
const reportID = policyRoomReport.reportID; | ||
const previousName = policyRoomReport.reportName; | ||
const optimisticData = [ | ||
{ | ||
onyxMethod: CONST.ONYX.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, | ||
value: { | ||
reportName: policyRoomName, | ||
pendingFields: { | ||
reportName: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, | ||
}, | ||
errorFields: { | ||
reportName: null, | ||
}, | ||
}, | ||
}, | ||
]; | ||
const successData = [ | ||
{ | ||
|
||
if (response.jsonCode !== CONST.JSON_CODE.SUCCESS) { | ||
Growl.error(response.message); | ||
return; | ||
} | ||
onyxMethod: CONST.ONYX.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, | ||
value: { | ||
pendingFields: { | ||
reportName: null, | ||
}, | ||
neil-marcellini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}, | ||
]; | ||
const failureData = [ | ||
{ | ||
|
||
Growl.success(Localize.translateLocal('newRoomPage.policyRoomRenamed')); | ||
onyxMethod: CONST.ONYX.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, | ||
value: { | ||
reportName: previousName, | ||
}, | ||
}, | ||
]; | ||
API.write('UpdatePolicyRoomName', {reportID, policyRoomName}, {optimisticData, successData, failureData}); | ||
} | ||
|
||
// Update the report name so that the LHN and header display the updated name | ||
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {reportName}); | ||
}) | ||
.finally(() => Onyx.set(ONYXKEYS.IS_LOADING_RENAME_POLICY_ROOM, false)); | ||
/** | ||
* @param {Number} reportID The reportID of the policy room. | ||
*/ | ||
function clearPolicyRoomNameErrors(reportID) { | ||
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, { | ||
errorFields: { | ||
reportName: null, | ||
}, | ||
pendingFields: { | ||
reportName: null, | ||
}, | ||
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. I'm gonna guess that we are setting 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. Yep, that's exactly it. |
||
}); | ||
} | ||
|
||
/** | ||
|
@@ -1547,12 +1583,13 @@ export { | |
setReportWithDraft, | ||
fetchInitialActions, | ||
createPolicyRoom, | ||
renameReport, | ||
setIsComposerFullSize, | ||
markCommentAsUnread, | ||
readNewestAction, | ||
readOldestAction, | ||
openReport, | ||
openPaymentDetailsPage, | ||
createOptimisticReport, | ||
updatePolicyRoomName, | ||
clearPolicyRoomNameErrors, | ||
}; |
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.
Treat this as a boolean in case it's an empty string.