-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35830 from tienifr/fix/33992
Fix: Room visibility can’t be changed after a room is created
- Loading branch information
Showing
13 changed files
with
179 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type {RoomVisibility} from '@src/types/onyx/Report'; | ||
|
||
type UpdateRoomVisibilityParams = { | ||
reportID: string; | ||
visibility: RoomVisibility; | ||
}; | ||
|
||
export default UpdateRoomVisibilityParams; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import type {StackScreenProps} from '@react-navigation/stack'; | ||
import React, {useCallback, useMemo, useState} from 'react'; | ||
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; | ||
import ConfirmModal from '@components/ConfirmModal'; | ||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import SelectionList from '@components/SelectionList'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import type {ReportSettingsNavigatorParamList} from '@libs/Navigation/types'; | ||
import * as ReportUtils from '@libs/ReportUtils'; | ||
import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; | ||
import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; | ||
import * as ReportActions from '@userActions/Report'; | ||
import CONST from '@src/CONST'; | ||
import type SCREENS from '@src/SCREENS'; | ||
import type {RoomVisibility} from '@src/types/onyx/Report'; | ||
|
||
type VisibilityProps = WithReportOrNotFoundProps & StackScreenProps<ReportSettingsNavigatorParamList, typeof SCREENS.REPORT_SETTINGS.VISIBILITY>; | ||
|
||
function VisibilityPage({report}: VisibilityProps) { | ||
const [showConfirmModal, setShowConfirmModal] = useState(false); | ||
|
||
const shouldDisableVisibility = ReportUtils.isArchivedRoom(report); | ||
const {translate} = useLocalize(); | ||
|
||
const visibilityOptions = useMemo( | ||
() => | ||
Object.values(CONST.REPORT.VISIBILITY) | ||
.filter((visibilityOption) => visibilityOption !== CONST.REPORT.VISIBILITY.PUBLIC_ANNOUNCE) | ||
.map((visibilityOption) => ({ | ||
text: translate(`newRoomPage.visibilityOptions.${visibilityOption}`), | ||
value: visibilityOption, | ||
alternateText: translate(`newRoomPage.${visibilityOption}Description`), | ||
keyForList: visibilityOption, | ||
isSelected: visibilityOption === report?.visibility, | ||
})), | ||
[translate, report?.visibility], | ||
); | ||
|
||
const changeVisibility = useCallback( | ||
(newVisibility: RoomVisibility) => { | ||
if (!report) { | ||
return; | ||
} | ||
ReportActions.updateRoomVisibility(report.reportID, report.visibility, newVisibility, true, report); | ||
}, | ||
[report], | ||
); | ||
|
||
const hideModal = useCallback(() => { | ||
setShowConfirmModal(false); | ||
}, []); | ||
|
||
return ( | ||
<ScreenWrapper | ||
includeSafeAreaPaddingBottom={false} | ||
testID={VisibilityPage.displayName} | ||
> | ||
<FullPageNotFoundView shouldShow={shouldDisableVisibility}> | ||
<HeaderWithBackButton | ||
title={translate('newRoomPage.visibility')} | ||
onBackButtonPress={() => ReportUtils.goBackToDetailsPage(report)} | ||
/> | ||
<SelectionList | ||
Check failure on line 64 in src/pages/settings/Report/VisibilityPage.tsx GitHub Actions / typecheck / typecheck
|
||
shouldPreventDefaultFocusOnSelectRow | ||
sections={[{data: visibilityOptions}]} | ||
onSelectRow={(option) => { | ||
if (option.value === CONST.REPORT.VISIBILITY.PUBLIC) { | ||
setShowConfirmModal(true); | ||
return; | ||
} | ||
changeVisibility(option.value); | ||
}} | ||
initiallyFocusedOptionKey={visibilityOptions.find((visibility) => visibility.isSelected)?.keyForList} | ||
/> | ||
<ConfirmModal | ||
isVisible={showConfirmModal} | ||
onConfirm={() => { | ||
changeVisibility(CONST.REPORT.VISIBILITY.PUBLIC); | ||
hideModal(); | ||
}} | ||
onCancel={hideModal} | ||
title={translate('common.areYouSure')} | ||
prompt={translate('newRoomPage.publicDescription')} | ||
confirmText={translate('common.yes')} | ||
cancelText={translate('common.no')} | ||
danger | ||
/> | ||
</FullPageNotFoundView> | ||
</ScreenWrapper> | ||
); | ||
} | ||
|
||
VisibilityPage.displayName = 'VisibilityPage'; | ||
|
||
export default withReportOrNotFound()(VisibilityPage); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters