-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[#16935] Workspace creation with Policy Draft info #29256
Changes from 3 commits
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 |
---|---|---|
|
@@ -909,6 +909,48 @@ function buildOptimisticCustomUnits() { | |
}; | ||
} | ||
|
||
/** | ||
* Optimistically creates a Policy Draft for a new workspace | ||
* | ||
* @param {String} [policyOwnerEmail] Optional, the email of the account to make the owner of the policy | ||
* @param {String} [policyName] Optional, custom policy name we will use for created workspace | ||
* @param {String} [policyID] Optional, custom policy id we will use for created workspace | ||
*/ | ||
function createDraftInitialWorkspace(policyOwnerEmail = '', policyName = '', policyID = generatePolicyID()) { | ||
gedu marked this conversation as resolved.
Show resolved
Hide resolved
gedu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const workspaceName = policyName || generateDefaultWorkspaceName(policyOwnerEmail); | ||
const {customUnits} = buildOptimisticCustomUnits(); | ||
|
||
const optimisticData = [ | ||
{ | ||
onyxMethod: Onyx.METHOD.SET, | ||
key: `${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyID}`, | ||
value: { | ||
id: policyID, | ||
type: CONST.POLICY.TYPE.FREE, | ||
name: workspaceName, | ||
role: CONST.POLICY.ROLE.ADMIN, | ||
owner: sessionEmail, | ||
isPolicyExpenseChatEnabled: true, | ||
outputCurrency: lodashGet(allPersonalDetails, [sessionAccountID, 'localCurrencyCode'], CONST.CURRENCY.USD), | ||
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
customUnits, | ||
}, | ||
}, | ||
{ | ||
onyxMethod: Onyx.METHOD.SET, | ||
key: `${ONYXKEYS.COLLECTION.POLICY_MEMBERS_DRAFTS}${policyID}`, | ||
value: { | ||
[sessionAccountID]: { | ||
role: CONST.POLICY.ROLE.ADMIN, | ||
errors: {}, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
Onyx.update(optimisticData); | ||
} | ||
|
||
/** | ||
* Optimistically creates a new workspace and default workspace chats | ||
* | ||
|
@@ -957,6 +999,16 @@ function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName | |
}, | ||
{ | ||
optimisticData: [ | ||
{ | ||
onyxMethod: Onyx.METHOD.SET, | ||
key: `${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyID}`, | ||
value: null, | ||
}, | ||
{ | ||
onyxMethod: Onyx.METHOD.SET, | ||
key: `${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${policyID}`, | ||
value: 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 think updates are done in order. It seems safer to clear the draft policy at last. |
||
{ | ||
onyxMethod: Onyx.METHOD.SET, | ||
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, | ||
|
@@ -1131,6 +1183,7 @@ function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName | |
], | ||
}, | ||
); | ||
|
||
return adminsChatReportID; | ||
} | ||
|
||
|
@@ -1259,4 +1312,5 @@ export { | |
clearErrors, | ||
openDraftWorkspaceRequest, | ||
buildOptimisticPolicyRecentlyUsedCategories, | ||
createDraftInitialWorkspace, | ||
}; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,6 +11,7 @@ import Tooltip from '../../components/Tooltip'; | |||||
import Text from '../../components/Text'; | ||||||
import ConfirmModal from '../../components/ConfirmModal'; | ||||||
import * as Expensicons from '../../components/Icon/Expensicons'; | ||||||
import * as App from '../../libs/actions/App'; | ||||||
import ScreenWrapper from '../../components/ScreenWrapper'; | ||||||
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize'; | ||||||
import MenuItem from '../../components/MenuItem'; | ||||||
|
@@ -31,6 +32,7 @@ import * as ReimbursementAccountProps from '../ReimbursementAccount/reimbursemen | |||||
import * as ReportUtils from '../../libs/ReportUtils'; | ||||||
import withWindowDimensions from '../../components/withWindowDimensions'; | ||||||
import PressableWithoutFeedback from '../../components/Pressable/PressableWithoutFeedback'; | ||||||
import useWindowDimensions from '../../hooks/useWindowDimensions'; | ||||||
|
||||||
const propTypes = { | ||||||
...policyPropTypes, | ||||||
|
@@ -65,9 +67,10 @@ function dismissError(policyID) { | |||||
} | ||||||
|
||||||
function WorkspaceInitialPage(props) { | ||||||
const policy = props.policy; | ||||||
const policy = props.policyDraft && props.policyDraft.id ? props.policyDraft : props.policy; | ||||||
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); | ||||||
const [isCurrencyModalOpen, setIsCurrencyModalOpen] = useState(false); | ||||||
const {isSmallScreenWidth} = useWindowDimensions(); | ||||||
const hasPolicyCreationError = Boolean(policy.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD && policy.errors); | ||||||
|
||||||
/** | ||||||
|
@@ -81,6 +84,17 @@ function WorkspaceInitialPage(props) { | |||||
Navigation.goBack(ROUTES.SETTINGS_WORKSPACES); | ||||||
}, [props.reports, policy]); | ||||||
|
||||||
useEffect(() => { | ||||||
const policyDraftId = lodashGet(props.policyDraft, 'id', null); | ||||||
if (!policyDraftId) { | ||||||
return; | ||||||
} | ||||||
|
||||||
App.savePolicyDraftByNewWorkspace(props.policyDraft.id, props.policyDraft.name, '', false, '', !isSmallScreenWidth); | ||||||
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.
Suggested change
|
||||||
// I only care when the component renders the first time | ||||||
gedu marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||||||
}, []); | ||||||
|
||||||
useEffect(() => { | ||||||
if (!isCurrencyModalOpen || policy.outputCurrency !== CONST.CURRENCY.USD) { | ||||||
return; | ||||||
|
@@ -189,8 +203,8 @@ function WorkspaceInitialPage(props) { | |||||
{({safeAreaPaddingBottomStyle}) => ( | ||||||
<FullPageNotFoundView | ||||||
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)} | ||||||
shouldShow={_.isEmpty(props.policy) || !PolicyUtils.isPolicyAdmin(props.policy) || PolicyUtils.isPendingDeletePolicy(props.policy)} | ||||||
subtitleKey={_.isEmpty(props.policy) ? undefined : 'workspace.common.notAuthorized'} | ||||||
shouldShow={_.isEmpty(policy) || !PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPendingDeletePolicy(policy)} | ||||||
subtitleKey={_.isEmpty(policy) ? undefined : 'workspace.common.notAuthorized'} | ||||||
> | ||||||
<HeaderWithBackButton | ||||||
title={props.translate('workspace.common.workspace')} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ import * as App from '../../libs/actions/App'; | |
import useLocalize from '../../hooks/useLocalize'; | ||
import useNetwork from '../../hooks/useNetwork'; | ||
import usePermissions from '../../hooks/usePermissions'; | ||
import useWindowDimensions from '../../hooks/useWindowDimensions'; | ||
import IllustratedHeaderPageLayout from '../../components/IllustratedHeaderPageLayout'; | ||
import SCREENS from '../../SCREENS'; | ||
import * as LottieAnimations from '../../components/LottieAnimations'; | ||
|
@@ -112,7 +111,6 @@ function WorkspacesListPage({policies, allPolicyMembers, reimbursementAccount, u | |
const {translate} = useLocalize(); | ||
const {isOffline} = useNetwork(); | ||
const {canUseWallet} = usePermissions(); | ||
const {isSmallScreenWidth} = useWindowDimensions(); | ||
|
||
/** | ||
* @param {Boolean} isPaymentItem whether the item being rendered is the payments menu item | ||
|
@@ -194,7 +192,7 @@ function WorkspacesListPage({policies, allPolicyMembers, reimbursementAccount, u | |
accessibilityLabel={translate('workspace.new.newWorkspace')} | ||
success | ||
text={translate('workspace.new.newWorkspace')} | ||
onPress={() => App.createWorkspaceAndNavigateToIt('', false, '', false, !isSmallScreenWidth)} | ||
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. @gedu Shouldn't we update all instances of 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. Good point, I think we do not need this in the other flows either. |
||
onPress={() => App.createWorkspaceWithPolicyDraftAndNavigateToIt()} | ||
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 can't just do
because the |
||
/> | ||
} | ||
> | ||
|
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.