From e4ff7b1c008afac833f845f7b43f0d111d8c25d9 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Fri, 19 Jan 2024 05:05:32 -0600 Subject: [PATCH 1/3] fix: check if the activePolicyID is a public workspace --- src/pages/workspace/WorkspaceNewRoomPage.js | 38 ++++++++++++++------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/pages/workspace/WorkspaceNewRoomPage.js b/src/pages/workspace/WorkspaceNewRoomPage.js index 35fab36e5d41..979aaaf23144 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.js +++ b/src/pages/workspace/WorkspaceNewRoomPage.js @@ -100,10 +100,25 @@ function WorkspaceNewRoomPage(props) { const {isOffline} = useNetwork(); const {isSmallScreenWidth} = useWindowDimensions(); const [visibility, setVisibility] = useState(CONST.REPORT.VISIBILITY.RESTRICTED); - const [policyID, setPolicyID] = useState(props.activePolicyID); const [writeCapability, setWriteCapability] = useState(CONST.REPORT.WRITE_CAPABILITIES.ALL); const wasLoading = usePrevious(props.formState.isLoading); const visibilityDescription = useMemo(() => translate(`newRoomPage.${visibility}Description`), [translate, visibility]); + + const workspaceOptions = useMemo( + () => + _.map(PolicyUtils.getActivePolicies(props.policies), (policy) => ({ + label: policy.name, + key: policy.id, + value: policy.id, + })), + [props.policies], + ); + const [policyID, setPolicyID] = useState(() => { + if (_.some(workspaceOptions, option => option.value === props.activePolicyID)) { + return props.activePolicyID; + } + return ''; + }); const isPolicyAdmin = useMemo(() => { if (!policyID) { return false; @@ -144,10 +159,17 @@ function WorkspaceNewRoomPage(props) { useEffect(() => { if (policyID) { + if (_.some(workspaceOptions, opt => opt.value === policyID)) { + setPolicyID(''); + } return; } - setPolicyID(props.activePolicyID); - }, [props.activePolicyID, policyID]); + if (_.some(workspaceOptions, opt => opt.value === props.activePolicyID)) { + setPolicyID(props.activePolicyID); + } else { + setPolicyID(''); + } + }, [props.activePolicyID, policyID, workspaceOptions]); useEffect(() => { if (!(((wasLoading && !props.formState.isLoading) || (isOffline && props.formState.isLoading)) && _.isEmpty(props.formState.errorFields))) { @@ -196,15 +218,7 @@ function WorkspaceNewRoomPage(props) { [props.reports], ); - const workspaceOptions = useMemo( - () => - _.map(PolicyUtils.getActivePolicies(props.policies), (policy) => ({ - label: policy.name, - key: policy.id, - value: policy.id, - })), - [props.policies], - ); + const writeCapabilityOptions = useMemo( () => From 30a44a800d261d2e9e976adf3f13b3fc4abfe854 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Fri, 19 Jan 2024 05:06:26 -0600 Subject: [PATCH 2/3] fix: prettier --- src/pages/workspace/WorkspaceNewRoomPage.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/pages/workspace/WorkspaceNewRoomPage.js b/src/pages/workspace/WorkspaceNewRoomPage.js index 979aaaf23144..aaaa71219c2a 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.js +++ b/src/pages/workspace/WorkspaceNewRoomPage.js @@ -114,7 +114,7 @@ function WorkspaceNewRoomPage(props) { [props.policies], ); const [policyID, setPolicyID] = useState(() => { - if (_.some(workspaceOptions, option => option.value === props.activePolicyID)) { + if (_.some(workspaceOptions, (option) => option.value === props.activePolicyID)) { return props.activePolicyID; } return ''; @@ -159,12 +159,12 @@ function WorkspaceNewRoomPage(props) { useEffect(() => { if (policyID) { - if (_.some(workspaceOptions, opt => opt.value === policyID)) { + if (_.some(workspaceOptions, (opt) => opt.value === policyID)) { setPolicyID(''); } return; } - if (_.some(workspaceOptions, opt => opt.value === props.activePolicyID)) { + if (_.some(workspaceOptions, (opt) => opt.value === props.activePolicyID)) { setPolicyID(props.activePolicyID); } else { setPolicyID(''); @@ -218,8 +218,6 @@ function WorkspaceNewRoomPage(props) { [props.reports], ); - - const writeCapabilityOptions = useMemo( () => _.map(CONST.REPORT.WRITE_CAPABILITIES, (value) => ({ From b6151febb49e7e7c131a15242dd85c6121c938fb Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Thu, 25 Jan 2024 16:00:15 -0600 Subject: [PATCH 3/3] fix: reset policyID when doesn't exist --- src/pages/workspace/WorkspaceNewRoomPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/WorkspaceNewRoomPage.js b/src/pages/workspace/WorkspaceNewRoomPage.js index aaaa71219c2a..b616b519ff32 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.js +++ b/src/pages/workspace/WorkspaceNewRoomPage.js @@ -159,7 +159,7 @@ function WorkspaceNewRoomPage(props) { useEffect(() => { if (policyID) { - if (_.some(workspaceOptions, (opt) => opt.value === policyID)) { + if (!_.some(workspaceOptions, (opt) => opt.value === policyID)) { setPolicyID(''); } return;