Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ function AuthScreens() {
const [isDelegatorFromOldDotIsReady, setIsDelegatorFromOldDotIsReady] = useState(false);

const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true});
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});
const [initialLastUpdateIDAppliedToClient] = useOnyx(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, {canBeMissing: true});
const [modal] = useOnyx(ONYXKEYS.MODAL, {canBeMissing: true});
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true});
Expand Down Expand Up @@ -251,7 +252,7 @@ function AuthScreens() {
App.reconnectApp(initialLastUpdateIDAppliedToClient);
}

App.setUpPoliciesAndNavigate(session);
App.setUpPoliciesAndNavigate(session, introSelected);

App.redirectThirdPartyDesktopSignIn();

Expand Down
8 changes: 5 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,7 @@ Onyx.connect({
return acc;
}

// eslint-disable-next-line @typescript-eslint/no-deprecated
InteractionManager.runAfterInteractions(() => {
handlePreexistingReport(report);
});
Expand Down Expand Up @@ -10475,9 +10476,9 @@ function getReportActionActorAccountID(
}
}

function createDraftWorkspaceAndNavigateToConfirmationScreen(transactionID: string, actionName: IOUAction): void {
function createDraftWorkspaceAndNavigateToConfirmationScreen(introSelected: OnyxEntry<IntroSelected>, transactionID: string, actionName: IOUAction): void {
const isCategorizing = actionName === CONST.IOU.ACTION.CATEGORIZE;
const {expenseChatReportID, policyID, policyName} = createDraftWorkspace(currentUserEmail);
const {expenseChatReportID, policyID, policyName} = createDraftWorkspace(introSelected, currentUserEmail);
setMoneyRequestParticipants(transactionID, [
{
selected: true,
Expand All @@ -10501,6 +10502,7 @@ function createDraftTransactionAndNavigateToParticipantSelector(
reportID: string | undefined,
actionName: IOUAction,
reportActionID: string | undefined,
introSelected: OnyxEntry<IntroSelected>,
isRestrictedToPreferredPolicy = false,
preferredPolicyID?: string,
): void {
Expand Down Expand Up @@ -10628,7 +10630,7 @@ function createDraftTransactionAndNavigateToParticipantSelector(
return;
}

return createDraftWorkspaceAndNavigateToConfirmationScreen(transactionID, actionName);
return createDraftWorkspaceAndNavigateToConfirmationScreen(introSelected, transactionID, actionName);
}

/**
Expand Down
63 changes: 38 additions & 25 deletions src/libs/actions/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,33 +445,40 @@ function endSignOnTransition() {
return resolveSignOnTransitionToFinishPromise();
}

type CreateWorkspaceWithPolicyDraftParams = {
introSelected: OnyxEntry<OnyxTypes.IntroSelected>;
policyOwnerEmail?: string;
policyName?: string;
transitionFromOldDot?: boolean;
makeMeAdmin?: boolean;
backTo?: string;
policyID?: string;
currency?: string;
file?: File;
routeToNavigateAfterCreate?: Route;
lastUsedPaymentMethod?: OnyxTypes.LastPaymentMethodType;
};

/**
* Create a new draft workspace and navigate to it
*
* @param [policyOwnerEmail] Optional, the email of the account to make the owner of the policy
* @param [policyName] Optional, custom policy name we will use for created workspace
* @param [transitionFromOldDot] Optional, if the user is transitioning from old dot
* @param [makeMeAdmin] Optional, leave the calling account as an admin on the policy
* @param [backTo] An optional return path. If provided, it will be URL-encoded and appended to the resulting URL.
* @param [policyID] Optional, Policy id.
* @param [currency] Optional, selected currency for the workspace
* @param [file], avatar file for workspace
* @param [routeToNavigateAfterCreate], Optional, route to navigate after creating a workspace
Comment thread
DylanDylann marked this conversation as resolved.
Resolved
*/
function createWorkspaceWithPolicyDraftAndNavigateToIt(
policyOwnerEmail = '',
policyName = '',
transitionFromOldDot = false,
makeMeAdmin = false,
backTo = '',
policyID = '',
currency?: string,
file?: File,
routeToNavigateAfterCreate?: Route,
lastUsedPaymentMethod?: OnyxTypes.LastPaymentMethodType,
) {
function createWorkspaceWithPolicyDraftAndNavigateToIt(params: CreateWorkspaceWithPolicyDraftParams) {
const {
introSelected,
policyOwnerEmail = '',
policyName = '',
transitionFromOldDot = false,
makeMeAdmin = false,
backTo = '',
policyID = '',
currency,
file,
routeToNavigateAfterCreate,
lastUsedPaymentMethod,
} = params;

const policyIDWithDefault = policyID || generatePolicyID();
createDraftInitialWorkspace(policyOwnerEmail, policyName, policyIDWithDefault, makeMeAdmin, currency, file);
createDraftInitialWorkspace(introSelected, policyOwnerEmail, policyName, policyIDWithDefault, makeMeAdmin, currency, file);
Navigation.isNavigationReady()
.then(() => {
if (transitionFromOldDot) {
Expand Down Expand Up @@ -531,7 +538,7 @@ function savePolicyDraftByNewWorkspace(
* When the exitTo route is 'workspace/new', we create a new
* workspace and navigate to it
*/
function setUpPoliciesAndNavigate(session: OnyxEntry<OnyxTypes.Session>) {
function setUpPoliciesAndNavigate(session: OnyxEntry<OnyxTypes.Session>, introSelected: OnyxEntry<OnyxTypes.IntroSelected>) {
const currentUrl = getCurrentUrl();
if (!session || !currentUrl?.includes('exitTo')) {
endSignOnTransition();
Expand All @@ -553,7 +560,13 @@ function setUpPoliciesAndNavigate(session: OnyxEntry<OnyxTypes.Session>) {

const shouldCreateFreePolicy = !isLoggingInAsNewUser && isTransitioning && exitTo === ROUTES.WORKSPACE_NEW;
if (shouldCreateFreePolicy) {
createWorkspaceWithPolicyDraftAndNavigateToIt(policyOwnerEmail, policyName, true, makeMeAdmin);
createWorkspaceWithPolicyDraftAndNavigateToIt({
introSelected,
policyOwnerEmail,
policyName,
transitionFromOldDot: true,
makeMeAdmin,
});
return;
}
if (!isLoggingInAsNewUser && exitTo) {
Expand Down
36 changes: 26 additions & 10 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ Onyx.connect({
callback: (value) => (activePolicyID = value),
});

let introSelected: OnyxEntry<IntroSelected>;
let deprecatedIntroSelected: OnyxEntry<IntroSelected>;
Onyx.connect({
key: ONYXKEYS.NVP_INTRO_SELECTED,
callback: (value) => (introSelected = value),
callback: (value) => (deprecatedIntroSelected = value),
});

/**
Expand Down Expand Up @@ -1945,7 +1945,15 @@ function buildOptimisticDistanceRateCustomUnits(reportCurrency?: string): Optimi
* @param [currency] Optional, selected currency for the workspace
* @param [file], avatar file for workspace
*/
function createDraftInitialWorkspace(policyOwnerEmail = '', policyName = '', policyID = generatePolicyID(), makeMeAdmin = false, currency = '', file?: File) {
function createDraftInitialWorkspace(
introSelected: OnyxEntry<IntroSelected>,
policyOwnerEmail = '',
policyName = '',
policyID = generatePolicyID(),
makeMeAdmin = false,
currency = '',
file?: File,
) {
const workspaceName = policyName || generateDefaultWorkspaceName(policyOwnerEmail);
const {customUnits, outputCurrency} = buildOptimisticDistanceRateCustomUnits(currency);
const shouldEnableWorkflowsByDefault =
Expand Down Expand Up @@ -2408,13 +2416,13 @@ function buildPolicyData(options: BuildPolicyDataOptions = {}) {
};

if (
introSelected !== undefined &&
(introSelected.choice === CONST.ONBOARDING_CHOICES.TEST_DRIVE_RECEIVER || !introSelected?.createWorkspace) &&
deprecatedIntroSelected !== undefined &&
(deprecatedIntroSelected.choice === CONST.ONBOARDING_CHOICES.TEST_DRIVE_RECEIVER || !deprecatedIntroSelected?.createWorkspace) &&
engagementChoice &&
shouldAddOnboardingTasks
) {
const {onboardingMessages} = getOnboardingMessages(true);
const onboardingData = ReportUtils.prepareOnboardingOnyxData(introSelected, engagementChoice, onboardingMessages[engagementChoice], adminsChatReportID, policyID);
const onboardingData = ReportUtils.prepareOnboardingOnyxData(deprecatedIntroSelected, engagementChoice, onboardingMessages[engagementChoice], adminsChatReportID, policyID);
if (!onboardingData) {
return {successData, optimisticData, failureData, params};
}
Expand All @@ -2429,13 +2437,13 @@ function buildPolicyData(options: BuildPolicyDataOptions = {}) {
}

// For test drive receivers, we want to complete the createWorkspace task in concierge, instead of #admin room
if (introSelected?.choice === CONST.ONBOARDING_CHOICES.TEST_DRIVE_RECEIVER && introSelected.createWorkspace) {
const createWorkspaceTaskReport = {reportID: introSelected.createWorkspace};
if (deprecatedIntroSelected?.choice === CONST.ONBOARDING_CHOICES.TEST_DRIVE_RECEIVER && deprecatedIntroSelected.createWorkspace) {
const createWorkspaceTaskReport = {reportID: deprecatedIntroSelected.createWorkspace};
const {
optimisticData: optimisticCreateWorkspaceTaskData,
successData: successCreateWorkspaceTaskData,
failureData: failureCreateWorkspaceTaskData,
} = buildTaskData(createWorkspaceTaskReport, introSelected.createWorkspace);
} = buildTaskData(createWorkspaceTaskReport, deprecatedIntroSelected.createWorkspace);

optimisticData.push(...optimisticCreateWorkspaceTaskData);
successData.push(...successCreateWorkspaceTaskData);
Expand Down Expand Up @@ -2486,7 +2494,15 @@ function createWorkspace(options: BuildPolicyDataOptions = {}): CreateWorkspaceP
* @param [policyName] custom policy name we will use for created workspace
* @param [policyID] custom policy id we will use for created workspace
*/
function createDraftWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName = '', policyID = generatePolicyID(), currency = '', file?: File): CreateWorkspaceParams {
function createDraftWorkspace(
introSelected: OnyxEntry<IntroSelected>,
policyOwnerEmail = '',
makeMeAdmin = false,
policyName = '',
policyID = generatePolicyID(),
currency = '',
file?: File,
): CreateWorkspaceParams {
const workspaceName = policyName || generateDefaultWorkspaceName(policyOwnerEmail);

const {customUnits, customUnitID, customUnitRateID, outputCurrency} = buildOptimisticDistanceRateCustomUnits(currency);
Expand Down
7 changes: 5 additions & 2 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, {canBeMissing: true});
const [isDebugModeEnabled = false] = useOnyx(ONYXKEYS.IS_DEBUG_MODE_ENABLED, {canBeMissing: true});
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: false});
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const [isLastMemberLeavingGroupModalVisible, setIsLastMemberLeavingGroupModalVisible] = useState(false);
const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false);
Expand Down Expand Up @@ -429,6 +430,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
actionReportID,
CONST.IOU.ACTION.SUBMIT,
actionableWhisperReportActionID,
introSelected,
isRestrictedToPreferredPolicy,
preferredPolicyID,
);
Expand All @@ -442,7 +444,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
isAnonymousAction: false,
shouldShowRightIcon: true,
action: () => {
createDraftTransactionAndNavigateToParticipantSelector(iouTransactionID, actionReportID, CONST.IOU.ACTION.CATEGORIZE, actionableWhisperReportActionID);
createDraftTransactionAndNavigateToParticipantSelector(iouTransactionID, actionReportID, CONST.IOU.ACTION.CATEGORIZE, actionableWhisperReportActionID, introSelected);
},
});
items.push({
Expand All @@ -452,7 +454,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
isAnonymousAction: false,
shouldShowRightIcon: true,
action: () => {
createDraftTransactionAndNavigateToParticipantSelector(iouTransactionID, actionReportID, CONST.IOU.ACTION.SHARE, actionableWhisperReportActionID);
createDraftTransactionAndNavigateToParticipantSelector(iouTransactionID, actionReportID, CONST.IOU.ACTION.SHARE, actionableWhisperReportActionID, introSelected);
},
});
}
Expand Down Expand Up @@ -571,6 +573,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
isSmallScreenWidth,
isRestrictedToPreferredPolicy,
preferredPolicyID,
introSelected,
]);

const displayNamesWithTooltips = useMemo(() => {
Expand Down
5 changes: 4 additions & 1 deletion src/pages/Travel/TravelUpgrade.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import type {WorkspaceConfirmationSubmitFunctionParams} from '@components/Worksp
import WorkspaceConfirmationForm from '@components/WorkspaceConfirmationForm';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import type {TravelNavigatorParamList} from '@libs/Navigation/types';
import UpgradeConfirmation from '@pages/workspace/upgrade/UpgradeConfirmation';
import UpgradeIntro from '@pages/workspace/upgrade/UpgradeIntro';
import CONST from '@src/CONST';
import {createDraftWorkspace, createWorkspace} from '@src/libs/actions/Policy/Policy';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';

type TravelUpgradeProps = StackScreenProps<TravelNavigatorParamList, typeof SCREENS.TRAVEL.UPGRADE>;
Expand All @@ -24,12 +26,13 @@ function TravelUpgrade({route}: TravelUpgradeProps) {
const feature = CONST.UPGRADE_FEATURE_INTRO_MAPPING.travel;
const {translate} = useLocalize();
const {isOffline} = useNetwork();
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});

const [isUpgraded, setIsUpgraded] = useState(false);
const [shouldShowConfirmation, setShouldShowConfirmation] = useState(false);

const onSubmit = (params: WorkspaceConfirmationSubmitFunctionParams) => {
createDraftWorkspace('', false, params.name, params.policyID, params.currency, params.avatarFile as File);
createDraftWorkspace(introSelected, '', false, params.name, params.policyID, params.currency, params.avatarFile as File);
setShouldShowConfirmation(false);
setIsUpgraded(true);
createWorkspace({
Expand Down
12 changes: 10 additions & 2 deletions src/pages/home/report/PureReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ type PureReportActionItemProps = {
/** All the data of the policy collection */
policies: OnyxCollection<OnyxTypes.Policy>;

/** Model of onboarding selected */
introSelected?: OnyxEntry<OnyxTypes.IntroSelected>;

/** Report for this action */
report: OnyxEntry<OnyxTypes.Report>;

Expand Down Expand Up @@ -324,6 +327,7 @@ type PureReportActionItemProps = {
reportID: string | undefined,
actionName: IOUAction,
reportActionID: string,
introSelected: OnyxEntry<OnyxTypes.IntroSelected>,
isRestrictedToPreferredPolicy?: boolean,
preferredPolicyID?: string,
) => void;
Expand Down Expand Up @@ -406,6 +410,7 @@ const isEmptyHTML = <T extends React.JSX.Element>({props: {html}}: T): boolean =
function PureReportActionItem({
allReports,
policies,
introSelected,
action,
report,
policy,
Expand Down Expand Up @@ -788,6 +793,7 @@ function PureReportActionItem({
reportActionReportID,
CONST.IOU.ACTION.SUBMIT,
action.reportActionID,
introSelected,
isRestrictedToPreferredPolicy,
preferredPolicyID,
);
Expand All @@ -801,14 +807,14 @@ function PureReportActionItem({
text: 'actionableMentionTrackExpense.categorize',
key: `${action.reportActionID}-actionableMentionTrackExpense-categorize`,
onPress: () => {
createDraftTransactionAndNavigateToParticipantSelector(transactionID, reportActionReportID, CONST.IOU.ACTION.CATEGORIZE, action.reportActionID);
createDraftTransactionAndNavigateToParticipantSelector(transactionID, reportActionReportID, CONST.IOU.ACTION.CATEGORIZE, action.reportActionID, introSelected);
},
},
{
text: 'actionableMentionTrackExpense.share',
key: `${action.reportActionID}-actionableMentionTrackExpense-share`,
onPress: () => {
createDraftTransactionAndNavigateToParticipantSelector(transactionID, reportActionReportID, CONST.IOU.ACTION.SHARE, action.reportActionID);
createDraftTransactionAndNavigateToParticipantSelector(transactionID, reportActionReportID, CONST.IOU.ACTION.SHARE, action.reportActionID, introSelected);
},
},
);
Expand Down Expand Up @@ -969,6 +975,7 @@ function PureReportActionItem({
formatPhoneNumber,
isOriginalReportArchived,
resolveActionableMentionWhisper,
introSelected,
]);

/**
Expand Down Expand Up @@ -1850,6 +1857,7 @@ export default memo(PureReportActionItem, (prevProps, nextProps) => {
prevProps.isUserValidated === nextProps.isUserValidated &&
prevProps.parentReport?.reportID === nextProps.parentReport?.reportID &&
deepEqual(prevProps.personalDetails, nextProps.personalDetails) &&
deepEqual(prevProps.introSelected, nextProps.introSelected) &&
deepEqual(prevProps.blockedFromConcierge, nextProps.blockedFromConcierge) &&
prevProps.originalReportID === nextProps.originalReportID &&
prevProps.isArchivedRoom === nextProps.isArchivedRoom &&
Expand Down
2 changes: 2 additions & 0 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function ReportActionItem({
const originalReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${originalReportID}`];
const isOriginalReportArchived = useReportIsArchived(originalReportID);
const [currentUserAccountID] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false, selector: accountIDSelector});
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});
const iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${getIOUReportIDFromReportActionPreview(action)}`];
const movedFromReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${getMovedReportID(action, CONST.REPORT.MOVE_TYPE.FROM)}`];
const movedToReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${getMovedReportID(action, CONST.REPORT.MOVE_TYPE.TO)}`];
Expand All @@ -115,6 +116,7 @@ function ReportActionItem({
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
allReports={allReports}
introSelected={introSelected}
policies={policies}
action={action}
report={report}
Expand Down
Loading