-
Notifications
You must be signed in to change notification settings - Fork 4k
Category field when creating an expense in the selfDM #72756
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
Changes from all commits
176dd66
49aaf64
61e6e98
f41b418
9bbcbaf
3fdeb30
b8e4702
8655eab
dfdcdae
dfbf5ee
ae5f19f
7d1e2d7
4d1a4df
4fc6dae
449560e
3480921
3cba7ea
e0198fe
a3155ab
52537c3
a57a5d4
f522bb6
00029e0
fd9dd84
425e9ac
8e4fb97
affddd5
31cd097
78d329d
30b765b
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 |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ import useOnboardingTaskInformation from '@hooks/useOnboardingTaskInformation'; | |
| import useOnyx from '@hooks/useOnyx'; | ||
| import useParticipantsInvoiceReport from '@hooks/useParticipantsInvoiceReport'; | ||
| import usePermissions from '@hooks/usePermissions'; | ||
| import usePolicyForMovingExpenses from '@hooks/usePolicyForMovingExpenses'; | ||
| import useTheme from '@hooks/useTheme'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import {completeTestDriveTask} from '@libs/actions/Task'; | ||
|
|
@@ -146,24 +147,17 @@ function IOURequestStepConfirmation({ | |
| category, | ||
| })), | ||
| ); | ||
|
|
||
| const realPolicyID = getIOURequestPolicyID(initialTransaction, reportReal); | ||
| const isUnreported = transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID; | ||
| const isCreatingTrackExpense = action === CONST.IOU.ACTION.CREATE && iouType === CONST.IOU.TYPE.TRACK; | ||
| const {policyForMovingExpenses, policyForMovingExpensesID} = usePolicyForMovingExpenses(); | ||
| const realPolicyID = isCreatingTrackExpense || isUnreported ? policyForMovingExpensesID : getIOURequestPolicyID(initialTransaction, reportReal); | ||
| const draftPolicyID = getIOURequestPolicyID(initialTransaction, reportDraft); | ||
| const [policyDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${draftPolicyID}`, {canBeMissing: true}); | ||
| const [policyReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${realPolicyID}`, {canBeMissing: true}); | ||
| const [policyCategoriesReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${realPolicyID}`, {canBeMissing: true}); | ||
| const [policyCategoriesDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES_DRAFT}${draftPolicyID}`, {canBeMissing: true}); | ||
| const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${realPolicyID}`, {canBeMissing: true}); | ||
| const [userLocation] = useOnyx(ONYXKEYS.USER_LOCATION, {canBeMissing: true}); | ||
| const [reportAttributesDerived] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {canBeMissing: true, selector: reportsSelector}); | ||
| const [recentlyUsedDestinations] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_DESTINATIONS}${realPolicyID}`, {canBeMissing: true}); | ||
| const [policyRecentlyUsedCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${realPolicyID}`, {canBeMissing: true}); | ||
|
|
||
| /* | ||
| * We want to use a report from the transaction if it exists | ||
| * Also if the report was submitted and delayed submission is on, then we should use an initial report | ||
| */ | ||
| const isUnreported = transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID; | ||
| const transactionReport = getReportOrDraftReport(transaction?.reportID); | ||
| const shouldUseTransactionReport = | ||
| transactionReport && !(isProcessingReport(transactionReport) && !policyReal?.harvesting?.enabled) && isReportOutstanding(transactionReport, policyReal?.id, undefined, false); | ||
|
|
@@ -176,9 +170,20 @@ function IOURequestStepConfirmation({ | |
| } | ||
| return reportReal ?? reportDraft; | ||
| }, [isUnreported, shouldUseTransactionReport, transactionReport, reportReal, reportDraft]); | ||
| const policy = policyReal ?? policyDraft; | ||
| const policyID = isUnreported ? policy?.id : getIOURequestPolicyID(transaction, report); | ||
|
|
||
| const policy = isCreatingTrackExpense || isUnreported ? policyForMovingExpenses : (policyReal ?? policyDraft); | ||
| const policyID = isCreatingTrackExpense || isUnreported ? policyForMovingExpensesID : getIOURequestPolicyID(transaction, report); | ||
| const isDraftPolicy = policy === policyDraft; | ||
|
|
||
| const [policyCategoriesReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${realPolicyID}`, {canBeMissing: true}); | ||
|
Member
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. Wouldn't it make sense to use the
Contributor
Author
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. @parasharrajat I also changed the realPolicyID to be policyForMovingExpensesID For now I just want to make it work not breaking anything and causing regressions 😄 When we have the feature complete and working I would love to work on some cleanup.
Contributor
Author
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. also for getting all the data we used realPolicyID, so let's leave this way (at least for now)
Member
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. Sounds good. |
||
| const [policyCategoriesDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES_DRAFT}${draftPolicyID}`, {canBeMissing: true}); | ||
| const [policyRecentlyUsedCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${realPolicyID}`, {canBeMissing: true}); | ||
| const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${realPolicyID}`, {canBeMissing: true}); | ||
|
|
||
| const [userLocation] = useOnyx(ONYXKEYS.USER_LOCATION, {canBeMissing: true}); | ||
| const [reportAttributesDerived] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {canBeMissing: true, selector: reportsSelector}); | ||
| const [recentlyUsedDestinations] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_DESTINATIONS}${realPolicyID}`, {canBeMissing: true}); | ||
|
|
||
| const policyCategories = policyCategoriesReal ?? policyCategoriesDraft; | ||
| const receiverParticipant: Participant | InvoiceReceiver | undefined = transaction?.participants?.find((participant) => participant?.accountID) ?? report?.invoiceReceiver; | ||
| const receiverAccountID = receiverParticipant && 'accountID' in receiverParticipant && receiverParticipant.accountID ? receiverParticipant.accountID : CONST.DEFAULT_NUMBER_ID; | ||
|
|
@@ -259,6 +264,10 @@ function IOURequestStepConfirmation({ | |
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| if (isCreatingTrackExpense && policyForMovingExpensesID !== undefined && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { | ||
| openDraftWorkspaceRequest(policyForMovingExpensesID); | ||
| } | ||
|
|
||
| const policyExpenseChat = participants?.find((participant) => participant.isPolicyExpenseChat); | ||
| if (policyExpenseChat?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { | ||
| openDraftWorkspaceRequest(policyExpenseChat.policyID); | ||
|
|
@@ -267,7 +276,7 @@ function IOURequestStepConfirmation({ | |
| if (senderPolicyParticipant?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { | ||
| openDraftWorkspaceRequest(senderPolicyParticipant.policyID); | ||
| } | ||
| }, [isOffline, participants, policy?.pendingAction]); | ||
| }, [isCreatingTrackExpense, isOffline, participants, policy?.pendingAction, policyForMovingExpensesID]); | ||
|
|
||
| const defaultBillable = !!policy?.defaultBillable; | ||
| useEffect(() => { | ||
|
|
@@ -317,7 +326,9 @@ function IOURequestStepConfirmation({ | |
| if (!item.category) { | ||
| return; | ||
| } | ||
| if (policyCategories?.[item.category] && !policyCategories[item.category].enabled) { | ||
|
|
||
| // Clear category field when the category doesn't exist for selected policy, or it's disabled | ||
| if (!policyCategories?.[item.category] || !policyCategories[item.category]?.enabled) { | ||
| setMoneyRequestCategory(item.transactionID, '', policy?.id); | ||
| } | ||
| }); | ||
|
|
||
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.
Can you please add an explanation comment here?
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.
I think it's readable enough - if we don't have any categories we go back, otherwise we choose categories