-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[OldDot Rules Migration] Category settings: Default categories #48391
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
eaa19a1
1874bff
9833de9
2646a9f
62bc63e
2fd739b
09cd340
4b9d455
645bb70
898ff98
5981f6e
7343191
41e6968
b7742e5
147fc69
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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| type SetWorkspaceDefaultSpendCategoryParams = { | ||
| policyID: string; | ||
| groupID: string; | ||
| category: string; | ||
| }; | ||
|
|
||
| export default SetWorkspaceDefaultSpendCategoryParams; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import React, {useState} from 'react'; | ||
| import BaseListItem from '@components/SelectionList/BaseListItem'; | ||
| import type {BaseListItemProps, ListItem} from '@components/SelectionList/types'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import blurActiveElement from '@libs/Accessibility/blurActiveElement'; | ||
| import CategorySelector from '@pages/workspace/distanceRates/CategorySelector'; | ||
| import * as Policy from '@userActions/Policy/Policy'; | ||
|
|
||
| function SpendCategorySelectorListItem<TItem extends ListItem>({item, onSelectRow, isFocused}: BaseListItemProps<TItem>) { | ||
| const styles = useThemeStyles(); | ||
| const [isCategoryPickerVisible, setIsCategoryPickerVisible] = useState(false); | ||
| const {policyID, groupID, categoryID} = item; | ||
|
|
||
| if (!policyID || !groupID) { | ||
| return; | ||
| } | ||
|
|
||
| const onSelect = (data: TItem) => { | ||
| setIsCategoryPickerVisible(true); | ||
| onSelectRow(data); | ||
| }; | ||
|
|
||
| const setNewCategory = (selectedCategory: ListItem) => { | ||
| if (!selectedCategory.text) { | ||
| return; | ||
| } | ||
| Policy.setWorkspaceDefaultSpendCategory(policyID, groupID, selectedCategory.text); | ||
| }; | ||
|
Comment on lines
+23
to
+28
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. When setting a new category we had to check that it's not the current selected one i.e. newCategory != currentCategory. This is because we have a case where if you go offline, delete the current category and select it again the following API calls will be queued:
And in the second API call we will be setting the spend category to a category that no longer exists which will causes an error. (Comnig from #49295) |
||
|
|
||
| return ( | ||
| <BaseListItem | ||
| item={item} | ||
| wrapperStyle={[isFocused && styles.sidebarLinkActive]} | ||
| pressableStyle={[styles.mt2]} | ||
| onSelectRow={onSelect} | ||
| isFocused={isFocused} | ||
| showTooltip | ||
| keyForList={item.keyForList} | ||
| > | ||
| <CategorySelector | ||
| wrapperStyle={[styles.ph5]} | ||
| focused={isFocused} | ||
| policyID={policyID} | ||
| label={groupID[0].toUpperCase() + groupID.slice(1)} | ||
| defaultValue={categoryID} | ||
| setNewCategory={setNewCategory} | ||
| isPickerVisible={isCategoryPickerVisible} | ||
| showPickerModal={() => setIsCategoryPickerVisible(true)} | ||
| hidePickerModal={() => { | ||
| setIsCategoryPickerVisible(false); | ||
| blurActiveElement(); | ||
| }} | ||
| shouldUseCustomScrollView | ||
| /> | ||
| </BaseListItem> | ||
| ); | ||
| } | ||
|
|
||
| SpendCategorySelectorListItem.displayName = 'SpendCategorySelectorListItem'; | ||
|
|
||
| export default SpendCategorySelectorListItem; | ||
Uh oh!
There was an error while loading. Please reload this page.