-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Feat: add a new category within the category list #86177
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
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
eca73c4
feature: add a new category within the category list
daledah feb7bdf
Merge branch 'main' into fix/85681
daledah af61ad1
Merge branch 'main' into fix/85681
daledah abd7805
Merge branch 'main' into fix/85681
daledah 623faa6
fix auto select created category
daledah 420e10c
Merge branch 'main' into fix/85681
daledah 6bee40a
fix comments and keyboard flicker
daledah eaae0b7
resolve conflict
daledah 9b492fe
fix auto select created category
daledah 8b352bb
resolve conflict
daledah c893136
fix ts
daledah a0d34f2
Merge branch 'main' into fix/85681
daledah c3a8fe1
resolve conflict
daledah 55338c1
fix the error appears below the category field for a while
daledah 2cb5b17
Merge branch 'main' into fix/85681
daledah ea19b9a
fix: blank page briefly appears after saving a new category
daledah 297f1cd
resolve conflict
daledah b508b6c
Merge branch 'main' into fix/85681
daledah cf9518b
Merge branch 'main' into fix/85681
daledah 4d8a2d3
create new component and fix the navigation bug
daledah d6e3b4e
fix lint
daledah 9b96a1a
fix ts
daledah bc53029
Merge branch 'main' into fix/85681
daledah bf805d4
fix comments
daledah 7dc939f
resolve conflict
daledah 9504eb4
fix lint
daledah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
214 changes: 214 additions & 0 deletions
214
src/pages/iou/request/step/IOURequestStepCategoryCreate.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,214 @@ | ||
| import React, {useCallback} from 'react'; | ||
| import type {FormOnyxValues} from '@components/Form/types'; | ||
| import {useSearchStateContext} from '@components/Search/SearchContext'; | ||
| import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useOnboardingTaskInformation from '@hooks/useOnboardingTaskInformation'; | ||
| import useOnyx from '@hooks/useOnyx'; | ||
| import usePermissions from '@hooks/usePermissions'; | ||
| import usePolicyForTransaction from '@hooks/usePolicyForTransaction'; | ||
| import useRestartOnReceiptFailure from '@hooks/useRestartOnReceiptFailure'; | ||
| import {getIOURequestPolicyID, setMoneyRequestCategory} from '@libs/actions/IOU'; | ||
| import {setDraftSplitTransaction} from '@libs/actions/IOU/Split'; | ||
| import {updateMoneyRequestCategory} from '@libs/actions/IOU/UpdateMoneyRequest'; | ||
| import {createPolicyCategory} from '@libs/actions/Policy/Category'; | ||
| import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import {hasTags} from '@libs/PolicyUtils'; | ||
| import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; | ||
| import CategoryForm from '@pages/workspace/categories/CategoryForm'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import type SCREENS from '@src/SCREENS'; | ||
| import StepScreenWrapper from './StepScreenWrapper'; | ||
| import type {WithFullTransactionOrNotFoundProps} from './withFullTransactionOrNotFound'; | ||
| import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; | ||
| import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound'; | ||
| import withWritableReportOrNotFound from './withWritableReportOrNotFound'; | ||
|
|
||
| type IOURequestStepCategoryCreateProps = WithWritableReportOrNotFoundProps<typeof SCREENS.MONEY_REQUEST.STEP_CATEGORY_CREATE> & | ||
| WithFullTransactionOrNotFoundProps<typeof SCREENS.MONEY_REQUEST.STEP_CATEGORY_CREATE>; | ||
|
|
||
| function IOURequestStepCategoryCreate({ | ||
| report: reportReal, | ||
| reportDraft, | ||
| route: { | ||
| params: {transactionID, action, iouType, reportID, backTo}, | ||
| }, | ||
| transaction, | ||
| }: IOURequestStepCategoryCreateProps) { | ||
| const {translate} = useLocalize(); | ||
| const currentUserPersonalDetails = useCurrentUserPersonalDetails(); | ||
| const {isBetaEnabled} = usePermissions(); | ||
| const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); | ||
| const {currentSearchHash} = useSearchStateContext(); | ||
|
|
||
| const isEditing = action === CONST.IOU.ACTION.EDIT; | ||
| const isEditingSplit = (iouType === CONST.IOU.TYPE.SPLIT || iouType === CONST.IOU.TYPE.SPLIT_EXPENSE) && isEditing; | ||
|
|
||
| const policyIdReal = getIOURequestPolicyID(transaction, reportReal); | ||
| const policyIdDraft = getIOURequestPolicyID(transaction, reportDraft); | ||
| const {policy} = usePolicyForTransaction({ | ||
| transaction, | ||
| reportPolicyID: policyIdReal ?? policyIdDraft, | ||
| action, | ||
| iouType, | ||
| isPerDiemRequest: false, | ||
| }); | ||
| const policyID = policy?.id; | ||
|
|
||
| const [splitDraftTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`); | ||
| const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`); | ||
| const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`); | ||
| const [policyRecentlyUsedCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${policyID}`); | ||
| const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(reportReal?.parentReportID ?? reportDraft?.parentReportID)}`); | ||
| const [parentReportNextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${getNonEmptyStringOnyxID(reportReal?.parentReportID ?? reportDraft?.parentReportID)}`); | ||
|
|
||
| const report = reportReal ?? reportDraft; | ||
|
|
||
| useRestartOnReceiptFailure(transaction, reportID, iouType, action); | ||
|
|
||
| const policyHasTags = hasTags(policyTags); | ||
|
|
||
| const { | ||
| taskReport: setupCategoryTaskReport, | ||
| taskParentReport: setupCategoryTaskParentReport, | ||
| isOnboardingTaskParentReportArchived: isSetupCategoryTaskParentReportArchived, | ||
| hasOutstandingChildTask, | ||
| parentReportAction, | ||
| } = useOnboardingTaskInformation(CONST.ONBOARDING_TASK_TYPE.SETUP_CATEGORIES); | ||
|
|
||
| const { | ||
| taskReport: setupCategoriesAndTagsTaskReport, | ||
| taskParentReport: setupCategoriesAndTagsTaskParentReport, | ||
| isOnboardingTaskParentReportArchived: isSetupCategoriesAndTagsTaskParentReportArchived, | ||
| hasOutstandingChildTask: setupCategoriesAndTagsHasOutstandingChildTask, | ||
| parentReportAction: setupCategoriesAndTagsParentReportAction, | ||
| } = useOnboardingTaskInformation(CONST.ONBOARDING_TASK_TYPE.SETUP_CATEGORIES_AND_TAGS); | ||
|
|
||
| const createCategory = useCallback( | ||
| (values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM>) => { | ||
| const categoryName = values.categoryName.trim(); | ||
|
|
||
| if (!policyID) { | ||
| return; | ||
| } | ||
|
|
||
| // 1. Create the category in the workspace (optimistic update, queued API call). | ||
| createPolicyCategory({ | ||
| policyID, | ||
| categoryName, | ||
| isSetupCategoriesTaskParentReportArchived: isSetupCategoryTaskParentReportArchived, | ||
| setupCategoryTaskReport, | ||
| setupCategoryTaskParentReport, | ||
| currentUserAccountID: currentUserPersonalDetails.accountID, | ||
| hasOutstandingChildTask, | ||
| parentReportAction, | ||
| setupCategoriesAndTagsTaskReport, | ||
| setupCategoriesAndTagsTaskParentReport, | ||
| isSetupCategoriesAndTagsTaskParentReportArchived, | ||
| setupCategoriesAndTagsHasOutstandingChildTask, | ||
| setupCategoriesAndTagsParentReportAction, | ||
| policyHasTags, | ||
| }); | ||
|
|
||
| // 2. Apply the newly created category to the transaction. | ||
| const policyCategoriesWithNewCategory = { | ||
| ...policyCategories, | ||
| [categoryName]: { | ||
| name: categoryName, | ||
| enabled: true, | ||
| errors: null, | ||
| pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| }, | ||
| }; | ||
|
|
||
| if (isEditingSplit && transaction) { | ||
| setDraftSplitTransaction(transaction.transactionID, splitDraftTransaction, {category: categoryName}, policy); | ||
| } else if (isEditing && report) { | ||
| updateMoneyRequestCategory({ | ||
| transactionID: transaction?.transactionID ?? transactionID, | ||
| transactionThreadReport: report, | ||
| parentReport, | ||
| parentReportNextStep, | ||
| category: categoryName, | ||
| policy, | ||
| policyTagList: policyTags, | ||
| policyCategories: policyCategoriesWithNewCategory, | ||
| policyRecentlyUsedCategories, | ||
| currentUserAccountIDParam: currentUserPersonalDetails.accountID, | ||
| currentUserEmailParam: currentUserPersonalDetails.login ?? '', | ||
| isASAPSubmitBetaEnabled, | ||
| hash: currentSearchHash, | ||
| }); | ||
| } else { | ||
| setMoneyRequestCategory(transactionID, categoryName, policy); | ||
| } | ||
|
|
||
| if (isEditing) { | ||
| Navigation.goBack(backTo); | ||
| } else { | ||
| Navigation.goBack(ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(action, iouType, transactionID, reportID)); | ||
| } | ||
| }, | ||
| [ | ||
| action, | ||
| backTo, | ||
| currentSearchHash, | ||
| currentUserPersonalDetails.accountID, | ||
| currentUserPersonalDetails.login, | ||
| hasOutstandingChildTask, | ||
| isASAPSubmitBetaEnabled, | ||
| isEditing, | ||
| isEditingSplit, | ||
| isSetupCategoriesAndTagsTaskParentReportArchived, | ||
| isSetupCategoryTaskParentReportArchived, | ||
| iouType, | ||
| parentReport, | ||
| parentReportAction, | ||
| parentReportNextStep, | ||
| policy, | ||
| policyCategories, | ||
| policyHasTags, | ||
| policyID, | ||
| policyRecentlyUsedCategories, | ||
| policyTags, | ||
| report, | ||
| reportID, | ||
| setupCategoriesAndTagsHasOutstandingChildTask, | ||
| setupCategoriesAndTagsParentReportAction, | ||
| setupCategoriesAndTagsTaskParentReport, | ||
| setupCategoriesAndTagsTaskReport, | ||
| setupCategoryTaskParentReport, | ||
| setupCategoryTaskReport, | ||
| splitDraftTransaction, | ||
| transaction, | ||
| transactionID, | ||
| ], | ||
| ); | ||
|
|
||
| return ( | ||
| <AccessOrNotFoundWrapper | ||
| accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]} | ||
| policyID={policyID} | ||
| featureName={CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED} | ||
| > | ||
| <StepScreenWrapper | ||
| headerTitle={translate('workspace.categories.addCategory')} | ||
| onBackButtonPress={() => Navigation.goBack()} | ||
| shouldShowWrapper | ||
| testID="IOURequestStepCategoryCreate" | ||
| > | ||
| <CategoryForm | ||
| onSubmit={createCategory} | ||
| policyCategories={policyCategories} | ||
| /> | ||
| </StepScreenWrapper> | ||
| </AccessOrNotFoundWrapper> | ||
| ); | ||
| } | ||
|
|
||
| const IOURequestStepCategoryCreateWithFullTransactionOrNotFound = withFullTransactionOrNotFound(IOURequestStepCategoryCreate); | ||
| const IOURequestStepCategoryCreateWithWritableReportOrNotFound = withWritableReportOrNotFound(IOURequestStepCategoryCreateWithFullTransactionOrNotFound); | ||
| export default IOURequestStepCategoryCreateWithWritableReportOrNotFound; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.