-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48171 from software-mansion-labs/rules/category-r…
…ules [OldDot Rules Migration] Category Rules
- Loading branch information
Showing
35 changed files
with
1,875 additions
and
107 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,115 @@ | ||
import React, {useMemo} from 'react'; | ||
import type {SectionListData} from 'react-native'; | ||
import useDebouncedState from '@hooks/useDebouncedState'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import usePolicy from '@hooks/usePolicy'; | ||
import useScreenWrapperTranstionStatus from '@hooks/useScreenWrapperTransitionStatus'; | ||
import * as DeviceCapabilities from '@libs/DeviceCapabilities'; | ||
import * as OptionsListUtils from '@libs/OptionsListUtils'; | ||
import * as PolicyUtils from '@libs/PolicyUtils'; | ||
import CONST from '@src/CONST'; | ||
import type {Icon} from '@src/types/onyx/OnyxCommon'; | ||
import Badge from './Badge'; | ||
import {FallbackAvatar} from './Icon/Expensicons'; | ||
import {usePersonalDetails} from './OnyxProvider'; | ||
import SelectionList from './SelectionList'; | ||
import InviteMemberListItem from './SelectionList/InviteMemberListItem'; | ||
import type {Section} from './SelectionList/types'; | ||
|
||
type SelectionListApprover = { | ||
text: string; | ||
alternateText: string; | ||
keyForList: string; | ||
isSelected: boolean; | ||
login: string; | ||
rightElement?: React.ReactNode; | ||
icons: Icon[]; | ||
}; | ||
type ApproverSection = SectionListData<SelectionListApprover, Section<SelectionListApprover>>; | ||
|
||
type WorkspaceMembersSelectionListProps = { | ||
policyID: string; | ||
selectedApprover: string; | ||
setApprover: (email: string) => void; | ||
}; | ||
|
||
function WorkspaceMembersSelectionList({policyID, selectedApprover, setApprover}: WorkspaceMembersSelectionListProps) { | ||
const {translate} = useLocalize(); | ||
const {didScreenTransitionEnd} = useScreenWrapperTranstionStatus(); | ||
const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState(''); | ||
const personalDetails = usePersonalDetails(); | ||
const policy = usePolicy(policyID); | ||
|
||
const sections: ApproverSection[] = useMemo(() => { | ||
const approvers: SelectionListApprover[] = []; | ||
|
||
if (policy?.employeeList) { | ||
const availableApprovers = Object.values(policy.employeeList) | ||
.map((employee): SelectionListApprover | null => { | ||
const isAdmin = employee?.role === CONST.REPORT.ROLE.ADMIN; | ||
const email = employee.email; | ||
|
||
if (!email) { | ||
return null; | ||
} | ||
|
||
const policyMemberEmailsToAccountIDs = PolicyUtils.getMemberAccountIDsForWorkspace(policy?.employeeList); | ||
const accountID = Number(policyMemberEmailsToAccountIDs[email] ?? ''); | ||
const {avatar, displayName = email} = personalDetails?.[accountID] ?? {}; | ||
|
||
return { | ||
text: displayName, | ||
alternateText: email, | ||
keyForList: email, | ||
isSelected: selectedApprover === email, | ||
login: email, | ||
icons: [{source: avatar ?? FallbackAvatar, type: CONST.ICON_TYPE_AVATAR, name: displayName, id: accountID}], | ||
rightElement: isAdmin ? <Badge text={translate('common.admin')} /> : undefined, | ||
}; | ||
}) | ||
.filter((approver): approver is SelectionListApprover => !!approver); | ||
|
||
approvers.push(...availableApprovers); | ||
} | ||
|
||
const filteredApprovers = | ||
debouncedSearchTerm !== '' | ||
? approvers.filter((option) => { | ||
const searchValue = OptionsListUtils.getSearchValueForPhoneOrEmail(debouncedSearchTerm); | ||
const isPartOfSearchTerm = !!option.text?.toLowerCase().includes(searchValue) || !!option.login?.toLowerCase().includes(searchValue); | ||
return isPartOfSearchTerm; | ||
}) | ||
: approvers; | ||
|
||
return [ | ||
{ | ||
title: undefined, | ||
data: OptionsListUtils.sortAlphabetically(filteredApprovers, 'text'), | ||
shouldShow: true, | ||
}, | ||
]; | ||
}, [debouncedSearchTerm, personalDetails, policy?.employeeList, selectedApprover, translate]); | ||
|
||
const handleOnSelectRow = (approver: SelectionListApprover) => { | ||
setApprover(approver.login); | ||
}; | ||
|
||
const headerMessage = useMemo(() => (searchTerm && !sections[0].data.length ? translate('common.noResultsFound') : ''), [searchTerm, sections, translate]); | ||
|
||
return ( | ||
<SelectionList | ||
sections={sections} | ||
ListItem={InviteMemberListItem} | ||
textInputLabel={translate('selectionList.nameEmailOrPhoneNumber')} | ||
textInputValue={searchTerm} | ||
onChangeText={setSearchTerm} | ||
headerMessage={headerMessage} | ||
onSelectRow={handleOnSelectRow} | ||
showScrollIndicator | ||
showLoadingPlaceholder={!didScreenTransitionEnd} | ||
shouldPreventDefaultFocusOnSelectRow={!DeviceCapabilities.canUseTouchScreen()} | ||
/> | ||
); | ||
} | ||
|
||
export default WorkspaceMembersSelectionList; |
This file contains 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 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
6 changes: 6 additions & 0 deletions
6
src/libs/API/parameters/RemovePolicyCategoryReceiptsRequiredParams.ts
This file contains 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,6 @@ | ||
type RemovePolicyCategoryReceiptsRequiredParams = { | ||
policyID: string; | ||
categoryName: string; | ||
}; | ||
|
||
export default RemovePolicyCategoryReceiptsRequiredParams; |
This file contains 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,7 @@ | ||
type SetPolicyCategoryApproverParams = { | ||
policyID: string; | ||
categoryName: string; | ||
approver: string; | ||
}; | ||
|
||
export default SetPolicyCategoryApproverParams; |
7 changes: 7 additions & 0 deletions
7
src/libs/API/parameters/SetPolicyCategoryDescriptionRequiredParams.ts
This file contains 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,7 @@ | ||
type SetPolicyCategoryDescriptionRequiredParams = { | ||
policyID: string; | ||
categoryName: string; | ||
areCommentsRequired: boolean; | ||
}; | ||
|
||
export default SetPolicyCategoryDescriptionRequiredParams; |
10 changes: 10 additions & 0 deletions
10
src/libs/API/parameters/SetPolicyCategoryMaxAmountParams.ts
This file contains 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,10 @@ | ||
import type {PolicyCategoryExpenseLimitType} from '@src/types/onyx/PolicyCategory'; | ||
|
||
type SetPolicyCategoryMaxAmountParams = { | ||
policyID: string; | ||
categoryName: string; | ||
maxExpenseAmount: number | null; | ||
expenseLimitType: PolicyCategoryExpenseLimitType; | ||
}; | ||
|
||
export default SetPolicyCategoryMaxAmountParams; |
7 changes: 7 additions & 0 deletions
7
src/libs/API/parameters/SetPolicyCategoryReceiptsRequiredParams.ts
This file contains 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,7 @@ | ||
type SetPolicyCategoryReceiptsRequiredParams = { | ||
policyID: string; | ||
categoryName: string; | ||
maxExpenseAmountNoReceipt: number; | ||
}; | ||
|
||
export default SetPolicyCategoryReceiptsRequiredParams; |
This file contains 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,7 @@ | ||
type SetPolicyCategoryTaxParams = { | ||
policyID: string; | ||
categoryName: string; | ||
taxID: string; | ||
}; | ||
|
||
export default SetPolicyCategoryTaxParams; |
7 changes: 7 additions & 0 deletions
7
src/libs/API/parameters/SetWorkspaceCategoryDescriptionHintParams.ts
This file contains 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,7 @@ | ||
type SetWorkspaceCategoryDescriptionHintParams = { | ||
policyID: string; | ||
categoryName: string; | ||
commentHint: string; | ||
}; | ||
|
||
export default SetWorkspaceCategoryDescriptionHintParams; |
This file contains 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 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
Oops, something went wrong.