Skip to content

Commit

Permalink
Merge pull request #34160 from esh-g/active-policy-room-default
Browse files Browse the repository at this point in the history
  • Loading branch information
roryabraham authored Jan 14, 2024
2 parents fd45dea + c6a3e40 commit a2864a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/ValuePicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function ValuePicker({value, label, items, placeholder, errorText, onInputChange
hidePickerModal();
};

const descStyle = value.length === 0 ? StyleUtils.getFontSizeStyle(variables.fontSizeLabel) : null;
const descStyle = !value || value.length === 0 ? StyleUtils.getFontSizeStyle(variables.fontSizeLabel) : null;
const selectedItem = _.find(items, {value});
const selectedLabel = selectedItem ? selectedItem.label : '';

Expand Down
19 changes: 18 additions & 1 deletion src/pages/workspace/WorkspaceNewRoomPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ const propTypes = {
/** accountID of current user */
accountID: PropTypes.number,
}),

/** policyID for main workspace */
activePolicyID: PropTypes.string,
};
const defaultProps = {
reports: {},
Expand All @@ -88,6 +91,7 @@ const defaultProps = {
session: {
accountID: 0,
},
activePolicyID: null,
};

function WorkspaceNewRoomPage(props) {
Expand All @@ -96,7 +100,7 @@ function WorkspaceNewRoomPage(props) {
const {isOffline} = useNetwork();
const {isSmallScreenWidth} = useWindowDimensions();
const [visibility, setVisibility] = useState(CONST.REPORT.VISIBILITY.RESTRICTED);
const [policyID, setPolicyID] = useState(null);
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]);
Expand Down Expand Up @@ -138,6 +142,13 @@ function WorkspaceNewRoomPage(props) {
Report.clearNewRoomFormError();
}, []);

useEffect(() => {
if (policyID) {
return;
}
setPolicyID(props.activePolicyID);
}, [props.activePolicyID, policyID]);

useEffect(() => {
if (!(((wasLoading && !props.formState.isLoading) || (isOffline && props.formState.isLoading)) && _.isEmpty(props.formState.errorFields))) {
return;
Expand Down Expand Up @@ -296,6 +307,7 @@ function WorkspaceNewRoomPage(props) {
inputID="policyID"
label={translate('workspace.common.workspace')}
items={workspaceOptions}
value={policyID}
onValueChange={setPolicyID}
/>
</View>
Expand Down Expand Up @@ -354,5 +366,10 @@ export default compose(
session: {
key: ONYXKEYS.SESSION,
},
activePolicyID: {
key: ONYXKEYS.ACCOUNT,
selector: (account) => (account && account.activePolicyID) || null,
initialValue: null,
},
}),
)(WorkspaceNewRoomPage);

0 comments on commit a2864a0

Please sign in to comment.