Skip to content

Commit

Permalink
Merge pull request #34796 from s-alves10/fix/issue-34647
Browse files Browse the repository at this point in the history
  • Loading branch information
roryabraham authored Jan 27, 2024
2 parents 7abf42b + b6151fe commit 9dbc389
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions src/pages/workspace/WorkspaceNewRoomPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))) {
Expand Down Expand Up @@ -196,16 +218,6 @@ 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(
() =>
_.map(CONST.REPORT.WRITE_CAPABILITIES, (value) => ({
Expand Down

0 comments on commit 9dbc389

Please sign in to comment.