diff --git a/src/CONST.ts b/src/CONST.ts index 873e1ca3b358..f61936ed02ca 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -579,6 +579,21 @@ const CONST = { REPORT: 'report', PERSONAL_DETAIL: 'personalDetail', }, + + QUICK_ACTIONS: { + REQUEST_MANUAL: 'requestManual', + REQUEST_SCAN: 'requestScan', + REQUEST_DISTANCE: 'requestDistance', + SPLIT_MANUAL: 'splitManual', + SPLIT_SCAN: 'splitScan', + SPLIT_DISTANCE: 'splitDistance', + TRACK_MANUAL: 'trackManual', + TRACK_SCAN: 'trackScan', + TRACK_DISTANCE: 'trackDistance', + ASSIGN_TASK: 'assignTask', + SEND_MONEY: 'sendMoney', + }, + RECEIPT: { ICON_SIZE: 164, PERMISSION_GRANTED: 'granted', diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index e14a880fcfa6..b6e460423638 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -131,6 +131,9 @@ const ONYXKEYS = { /** The NVP with the last distance rate used per policy */ NVP_LAST_SELECTED_DISTANCE_RATES: 'lastSelectedDistanceRates', + /** The NVP with the last action taken (for the Quick Action Button) */ + NVP_QUICK_ACTION_GLOBAL_CREATE: 'nvp_quickActionGlobalCreate', + /** Does this user have push notifications enabled for this device? */ PUSH_NOTIFICATIONS_ENABLED: 'pushNotificationsEnabled', @@ -599,6 +602,7 @@ type OnyxValuesMapping = { [ONYXKEYS.LOGS]: Record; [ONYXKEYS.SHOULD_STORE_LOGS]: boolean; [ONYXKEYS.CACHED_PDF_PATHS]: Record; + [ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE]: OnyxTypes.QuickAction; }; type OnyxValues = OnyxValuesMapping & OnyxCollectionValuesMapping & OnyxFormValuesMapping & OnyxFormDraftValuesMapping; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 868bfc28d781..91a74c593926 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -231,6 +231,14 @@ Onyx.connect({ }, }); +let quickAction: OnyxEntry = {}; +Onyx.connect({ + key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, + callback: (value) => { + quickAction = value; + }, +}); + /** * Initialize money request info * @param reportID to attach the transaction to @@ -457,11 +465,16 @@ function buildOnyxDataForMoneyRequest( policyTagList?: OnyxEntry, policyCategories?: OnyxEntry, optimisticNextStep?: OnyxTypes.ReportNextStep | null, + isOneOnOneSplit = false, ): [OnyxUpdate[], OnyxUpdate[], OnyxUpdate[]] { const isScanRequest = TransactionUtils.isScanRequest(transaction); const outstandingChildRequest = getOutstandingChildRequest(policy ?? {}, iouReport); const clearedPendingFields = Object.fromEntries(Object.keys(transaction.pendingFields ?? {}).map((key) => [key, null])); const optimisticData: OnyxUpdate[] = []; + let newQuickAction: ValueOf = isScanRequest ? CONST.QUICK_ACTIONS.REQUEST_SCAN : CONST.QUICK_ACTIONS.REQUEST_MANUAL; + if (TransactionUtils.isDistanceRequest(transaction)) { + newQuickAction = CONST.QUICK_ACTIONS.REQUEST_DISTANCE; + } if (chatReport) { optimisticData.push({ @@ -551,6 +564,18 @@ function buildOnyxDataForMoneyRequest( }, ); + if (!isOneOnOneSplit) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.SET, + key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, + value: { + action: newQuickAction, + reportID: chatReport?.reportID, + isFirstQuickAction: isEmptyObject(quickAction), + }, + }); + } + if (optimisticPolicyRecentlyUsedCategories.length) { optimisticData.push({ onyxMethod: Onyx.METHOD.SET, @@ -1649,6 +1674,7 @@ function createSplitsAndOnyxData( tag: string, existingSplitChatReportID = '', billable = false, + iouRequestType: IOURequestType = CONST.IOU.REQUEST_TYPE.MANUAL, ): SplitsAndOnyxData { const currentUserEmailForIOUSplit = PhoneNumber.addSMSDomainIfPhoneNumber(currentUserLogin); const participantAccountIDs = participants.map((participant) => Number(participant.accountID)); @@ -1712,6 +1738,15 @@ function createSplitsAndOnyxData( key: `${ONYXKEYS.COLLECTION.REPORT}${splitChatReport.reportID}`, value: splitChatReport, }, + { + onyxMethod: Onyx.METHOD.SET, + key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, + value: { + action: iouRequestType === CONST.IOU.REQUEST_TYPE.DISTANCE ? CONST.QUICK_ACTIONS.SPLIT_DISTANCE : CONST.QUICK_ACTIONS.SPLIT_MANUAL, + reportID: splitChatReport.reportID, + isFirstQuickAction: isEmptyObject(quickAction), + }, + }, existingSplitChatReport ? { onyxMethod: Onyx.METHOD.MERGE, @@ -1943,6 +1978,11 @@ function createSplitsAndOnyxData( optimisticTransactionThread, optimisticCreatedActionForTransactionThread, shouldCreateNewOneOnOneIOUReport, + null, + null, + null, + null, + true, ); const individualSplit = { @@ -2001,6 +2041,7 @@ function splitBill( tag: string, existingSplitChatReportID = '', billable = false, + iouRequestType: IOURequestType = CONST.IOU.REQUEST_TYPE.MANUAL, ) { const currentCreated = DateUtils.enrichMoneyRequestTimestamp(created); const {splitData, splits, onyxData} = createSplitsAndOnyxData( @@ -2016,6 +2057,7 @@ function splitBill( tag, existingSplitChatReportID, billable, + iouRequestType, ); const parameters: SplitBillParams = { @@ -2057,9 +2099,24 @@ function splitBillAndOpenReport( category: string, tag: string, billable: boolean, + iouRequestType: IOURequestType = CONST.IOU.REQUEST_TYPE.MANUAL, ) { const currentCreated = DateUtils.enrichMoneyRequestTimestamp(created); - const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, merchant, currentCreated, category, tag); + const {splitData, splits, onyxData} = createSplitsAndOnyxData( + participants, + currentUserLogin, + currentUserAccountID, + amount, + comment, + currency, + merchant, + currentCreated, + category, + tag, + '', + billable, + iouRequestType, + ); const parameters: SplitBillParams = { reportID: splitData.chatReportID, @@ -2167,6 +2224,15 @@ function startSplitBill( key: `${ONYXKEYS.COLLECTION.REPORT}${splitChatReport.reportID}`, value: splitChatReport, }, + { + onyxMethod: Onyx.METHOD.SET, + key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, + value: { + action: CONST.QUICK_ACTIONS.SPLIT_SCAN, + reportID: splitChatReport.reportID, + isFirstQuickAction: isEmptyObject(quickAction), + }, + }, existingSplitChatReport ? { onyxMethod: Onyx.METHOD.MERGE, @@ -2542,6 +2608,11 @@ function completeSplitBill(chatReportID: string, reportAction: OnyxTypes.ReportA optimisticTransactionThread, optimisticCreatedActionForTransactionThread, shouldCreateNewOneOnOneIOUReport, + null, + null, + null, + null, + true, ); splits.push({ @@ -3274,6 +3345,15 @@ function getSendMoneyParams( lastVisibleActionCreated: reportPreviewAction.created, }, }; + const optimisticQuickActionData: OnyxUpdate = { + onyxMethod: Onyx.METHOD.SET, + key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, + value: { + action: CONST.QUICK_ACTIONS.SEND_MONEY, + reportID: chatReport.reportID, + isFirstQuickAction: isEmptyObject(quickAction), + }, + }; const optimisticIOUReportData: OnyxUpdate = { onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticIOUReport.reportID}`, @@ -3440,6 +3520,7 @@ function getSendMoneyParams( const optimisticData: OnyxUpdate[] = [ optimisticChatReportData, + optimisticQuickActionData, optimisticIOUReportData, optimisticChatReportActionsData, optimisticIOUReportActionsData, diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index 491a75f9c643..681ed0ec383f 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -59,6 +59,14 @@ Onyx.connect({ callback: (value) => (allPersonalDetails = value), }); +let quickAction: OnyxEntry = {}; +Onyx.connect({ + key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, + callback: (value) => { + quickAction = value; + }, +}); + const allReportActions: OnyxCollection = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, @@ -227,6 +235,18 @@ function createTaskAndNavigate( }, ); + // FOR QUICK ACTION NVP + optimisticData.push({ + onyxMethod: Onyx.METHOD.SET, + key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, + value: { + action: CONST.QUICK_ACTIONS.ASSIGN_TASK, + reportID: parentReportID, + isFirstQuickAction: isEmptyObject(quickAction), + targetAccountID: assigneeAccountID, + }, + }); + // If needed, update optimistic data for parent report action of the parent report. const optimisticParentReportData = ReportUtils.getOptimisticDataForParentReportAction(parentReportID, currentTime, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); if (!isEmptyObject(optimisticParentReportData)) { diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.js b/src/pages/iou/request/step/IOURequestStepConfirmation.js index 0a6a4cc610a9..2c869354d96f 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.js +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.js @@ -295,6 +295,7 @@ function IOURequestStepConfirmation({ transaction.tag, report.reportID, transaction.billable, + transaction.iouRequestType, ); return; } @@ -313,6 +314,7 @@ function IOURequestStepConfirmation({ transaction.category, transaction.tag, transaction.billable, + transaction.iouRequestType, ); return; } diff --git a/src/types/onyx/QuickAction.ts b/src/types/onyx/QuickAction.ts new file mode 100644 index 000000000000..6cf1af929a5c --- /dev/null +++ b/src/types/onyx/QuickAction.ts @@ -0,0 +1,18 @@ +import type {ValueOf} from 'type-fest'; +import type CONST from '@src/CONST'; + +type QuickAction = { + /** The action to take */ + action?: ValueOf; + + /** ID of the report */ + reportID?: string; + + /** ID of the target account for task actions */ + targetAccountID?: number; + + /** True if it is the first quick action we store for this user */ + isFirstQuickAction?: boolean; +}; + +export default QuickAction; diff --git a/src/types/onyx/index.ts b/src/types/onyx/index.ts index e3118538258e..7d129d8e2cd9 100644 --- a/src/types/onyx/index.ts +++ b/src/types/onyx/index.ts @@ -43,6 +43,7 @@ import type {PolicyTag, PolicyTagList, PolicyTags} from './PolicyTag'; import type PreferredTheme from './PreferredTheme'; import type PriorityMode from './PriorityMode'; import type PrivatePersonalDetails from './PrivatePersonalDetails'; +import type QuickAction from './QuickAction'; import type RecentlyUsedCategories from './RecentlyUsedCategories'; import type RecentlyUsedReportFields from './RecentlyUsedReportFields'; import type RecentlyUsedTags from './RecentlyUsedTags'; @@ -119,6 +120,7 @@ export type { PreferredTheme, PriorityMode, PrivatePersonalDetails, + QuickAction, RecentWaypoint, RecentlyUsedCategories, RecentlyUsedTags,