Repository navigation
[OldDot Rules Migration] Expense report rules #47468
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
marcaaron
merged 80 commits into
Expensify:main
from
software-mansion-labs:brtqkr/expense-reports-section
Sep 6, 2024
Merged
Changes from all commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
3081420
Add ExpenseReportRulesSection
WojtekBoman 3623d4a
menu setup
BrtqKr 3e622bf
replace items with ToggleSettingOptionRow
BrtqKr e99bf88
add custom report names section content wip
BrtqKr bff54c3
add translations
BrtqKr 94a0db2
setup rhp nav
BrtqKr b07708a
add bullet points, wire up form wip
BrtqKr 2e82822
wire up custom name form
BrtqKr 0d6aa6f
cleanup custom names, prevent from changing names wip
BrtqKr 4d15101
cleanup custom names
BrtqKr 66382f0
wire up prevent member created title
BrtqKr 6be513d
wire up prevent self approval
BrtqKr 2169b17
add remaining routes
BrtqKr 132ccbb
auto approve reports under amount page wip
BrtqKr 285cf5e
wire up auto approval
BrtqKr 5797fb1
add percentage form
BrtqKr 2e75abd
wire up auto approval audit rate
BrtqKr 45b46b4
wire up auto pay
BrtqKr 72c38a4
rule lock conditions wip
BrtqKr 6f59541
wire up enablePolicyAutoReimbursementLimit
BrtqKr daa7c9c
wire up enablePolicyAutoReimbursementLimit, validate wip
BrtqKr b188339
wire up enableAutoApprovalOptions
BrtqKr 36160d3
wire up auto approve reports under
BrtqKr 7e72524
wire up random report audit
BrtqKr 21549c6
wire up enable custom report names
BrtqKr 8c8f270
wire up custom report name
BrtqKr 269dedd
wire up custom report names
BrtqKr 34a5c4b
wire up prevent self approval
BrtqKr 9bc374a
add fallback subtitle, fix translations
BrtqKr b881703
add custom name validation
BrtqKr 215a252
add validation, fix amount form validation
BrtqKr b1df169
add fallbacks
BrtqKr b5c7486
add side effects
BrtqKr 0edff08
cleanup jsdoc
BrtqKr edc14fe
move actions to policy
BrtqKr 67e9e83
Merge remote-tracking branch 'origin/main' into brtqkr/expense-report…
BrtqKr b89de0a
fix audit rate command
BrtqKr 00b8175
add keys
BrtqKr 05f9529
cleanup
BrtqKr 34eb99a
review fixes
BrtqKr 2af9b37
fix translations
BrtqKr d23fb35
add jsdoc
BrtqKr 1f327fa
Merge remote-tracking branch 'origin/main' into brtqkr/expense-report…
BrtqKr 7b73789
fix command
BrtqKr db3f8c7
add pending fields
BrtqKr 4b044a0
Merge remote-tracking branch 'origin/main' into brtqkr/expense-report…
BrtqKr 1ef024a
fix types
BrtqKr ea72e31
review fixes
BrtqKr 6d06f5d
cleanup
BrtqKr 7b8a235
cleanup
BrtqKr 058773f
Merge remote-tracking branch 'origin/main' into brtqkr/expense-report…
BrtqKr 6bcb2e4
cleanup
BrtqKr 9fc1685
cleanup
BrtqKr 79c5ae6
cleanup
BrtqKr c48575b
add offline with feedback
BrtqKr a22d5fb
add fallback values
BrtqKr db46fb0
cleanup
BrtqKr b9eb9ae
lint fix
BrtqKr 721a0ec
Merge remote-tracking branch 'origin/main' into brtqkr/expense-report…
BrtqKr b229a26
remove wrapper
BrtqKr 816deeb
make pending fields more direct
BrtqKr 001041f
change permissions
BrtqKr 927461f
block access when unavailable
BrtqKr 8a46e91
cleanup
BrtqKr 6cd2540
remove tmp permissions
BrtqKr ed21e12
modify pending fields
BrtqKr 550939e
block api calls when the value is identical
BrtqKr 5d81f1b
add fallback
BrtqKr 1a008ba
add fallbacks
BrtqKr e7fdedf
move conditions higher
BrtqKr e921c73
policyID fallback changes, move conditon to utils function
BrtqKr 3f0b321
cleanup
BrtqKr ab1a8cb
cleanup
BrtqKr 020b1e3
reivew changes
BrtqKr c71279f
add conditional pending actions
BrtqKr efe9fe6
change error message
BrtqKr 2d55ee0
Merge remote-tracking branch 'origin/main' into brtqkr/expense-report…
BrtqKr 0ef8fb2
swap condition for workflow approvals unavailable
BrtqKr 3f55bd3
run prettier
BrtqKr 442d734
update translations
BrtqKr 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,11 +43,13 @@ type AmountFormProps = { | |
| /** Custom max amount length. It defaults to CONST.IOU.AMOUNT_MAX_LENGTH */ | ||
| amountMaxLength?: number; | ||
|
|
||
| /** Custom label for the TextInput */ | ||
| label?: string; | ||
|
|
||
| /** Whether the form should use a standard TextInput as a base */ | ||
| displayAsTextInput?: boolean; | ||
| } & Pick<TextInputWithCurrencySymbolProps, 'hideCurrencySymbol' | 'extraSymbol'> & | ||
| Pick<BaseTextInputProps, 'autoFocus'>; | ||
| Pick<BaseTextInputProps, 'autoFocus' | 'hasError'>; | ||
|
|
||
| /** | ||
| * Returns the new selection object based on the updated amount's length | ||
|
|
@@ -67,7 +69,6 @@ function AmountForm( | |
| currency = CONST.CURRENCY.USD, | ||
| extraDecimals = 0, | ||
| amountMaxLength, | ||
| errorText, | ||
| onInputChange, | ||
| onCurrencyButtonPress, | ||
| displayAsTextInput = false, | ||
|
|
@@ -296,11 +297,11 @@ function AmountForm( | |
| // eslint-disable-next-line react/jsx-props-no-spreading | ||
| {...rest} | ||
| /> | ||
| {!!errorText && ( | ||
| {!!rest.errorText && ( | ||
| <FormHelpMessage | ||
| style={[styles.pAbsolute, styles.b0, canUseTouchScreen ? styles.mb0 : styles.mb3, styles.ph5, styles.w100]} | ||
| isError | ||
| message={errorText} | ||
| message={rest.errorText} | ||
|
Comment on lines
-299
to
+304
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. this, on the other hand, was necessary, because the error handling was broken in general |
||
| /> | ||
| )} | ||
| </View> | ||
|
|
||
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,52 @@ | ||
| import type {ReactNode} from 'react'; | ||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import Text from './Text'; | ||
|
|
||
| type BulletListItem = string; | ||
|
|
||
| type BulletListProps = { | ||
| /** List of items for the list. Each item will be rendered as a sepearte point. */ | ||
| items: BulletListItem[]; | ||
|
|
||
| /** Header section of the list */ | ||
| header: string | ReactNode; | ||
| }; | ||
|
|
||
| function BulletList({items, header}: BulletListProps) { | ||
| const styles = useThemeStyles(); | ||
|
|
||
| const baseTextStyles = [styles.mutedNormalTextLabel]; | ||
|
|
||
| const renderBulletListHeader = () => { | ||
| if (typeof header === 'string') { | ||
| return <Text style={baseTextStyles}>{header}</Text>; | ||
| } | ||
| return header; | ||
| }; | ||
|
|
||
| const renderBulletPoint = (item: string) => { | ||
| return ( | ||
| <Text | ||
| style={baseTextStyles} | ||
| key={item} | ||
| > | ||
| <Text style={[styles.ph2, baseTextStyles]}>•</Text> | ||
| {item} | ||
| </Text> | ||
| ); | ||
| }; | ||
|
|
||
| return ( | ||
| <View style={[styles.w100, styles.mt2]}> | ||
| {renderBulletListHeader()} | ||
| <View>{items.map((item) => renderBulletPoint(item))}</View> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| BulletList.displayName = 'BulletList'; | ||
|
|
||
| export type {BulletListProps}; | ||
| export default BulletList; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import type {ForwardedRef} from 'react'; | ||
| import React, {forwardRef, useCallback, useMemo, useRef, useState} from 'react'; | ||
| import type {NativeSyntheticEvent, TextInputSelectionChangeEventData} from 'react-native'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import * as MoneyRequestUtils from '@libs/MoneyRequestUtils'; | ||
| import CONST from '@src/CONST'; | ||
| import TextInput from './TextInput'; | ||
| import type {BaseTextInputRef} from './TextInput/BaseTextInput/types'; | ||
|
|
||
| type PercentageFormProps = { | ||
| /** Amount supplied by the FormProvider */ | ||
| value?: string; | ||
|
|
||
| /** Error to display at the bottom of the component */ | ||
| errorText?: string; | ||
|
|
||
| /** Callback to update the amount in the FormProvider */ | ||
| onInputChange?: (value: string) => void; | ||
|
|
||
| /** Custom label for the TextInput */ | ||
| label?: string; | ||
|
marcaaron marked this conversation as resolved.
Resolved
|
||
| }; | ||
|
|
||
| /** | ||
| * Returns the new selection object based on the updated amount's length | ||
| */ | ||
| const getNewSelection = (oldSelection: {start: number; end: number}, prevLength: number, newLength: number) => { | ||
| const cursorPosition = oldSelection.end + (newLength - prevLength); | ||
| return {start: cursorPosition, end: cursorPosition}; | ||
| }; | ||
|
|
||
| function PercentageForm({value: amount, errorText, onInputChange, label, ...rest}: PercentageFormProps, forwardedRef: ForwardedRef<BaseTextInputRef>) { | ||
| const {toLocaleDigit, numberFormat} = useLocalize(); | ||
|
|
||
| const textInput = useRef<BaseTextInputRef | null>(null); | ||
|
|
||
| const currentAmount = useMemo(() => (typeof amount === 'string' ? amount : ''), [amount]); | ||
|
|
||
| const [selection, setSelection] = useState({ | ||
| start: currentAmount.length, | ||
| end: currentAmount.length, | ||
| }); | ||
|
|
||
| const forwardDeletePressedRef = useRef(false); | ||
|
|
||
| /** | ||
| * Sets the selection and the amount accordingly to the value passed to the input | ||
| * @param newAmount - Changed amount from user input | ||
| */ | ||
| const setNewAmount = useCallback( | ||
| (newAmount: string) => { | ||
| // Remove spaces from the newAmount value because Safari on iOS adds spaces when pasting a copied value | ||
| // More info: https://github.com/Expensify/App/issues/16974 | ||
| const newAmountWithoutSpaces = MoneyRequestUtils.stripSpacesFromAmount(newAmount); | ||
|
marcaaron marked this conversation as resolved.
Resolved
|
||
| // Use a shallow copy of selection to trigger setSelection | ||
| // More info: https://github.com/Expensify/App/issues/16385 | ||
| if (!MoneyRequestUtils.validatePercentage(newAmountWithoutSpaces)) { | ||
| setSelection((prevSelection) => ({...prevSelection})); | ||
| return; | ||
| } | ||
|
|
||
| const strippedAmount = MoneyRequestUtils.stripCommaFromAmount(newAmountWithoutSpaces); | ||
| const isForwardDelete = currentAmount.length > strippedAmount.length && forwardDeletePressedRef.current; | ||
| setSelection(getNewSelection(selection, isForwardDelete ? strippedAmount.length : currentAmount.length, strippedAmount.length)); | ||
| onInputChange?.(strippedAmount); | ||
| }, | ||
| [currentAmount, onInputChange, selection], | ||
| ); | ||
|
|
||
| const formattedAmount = MoneyRequestUtils.replaceAllDigits(currentAmount, toLocaleDigit); | ||
|
|
||
| return ( | ||
| <TextInput | ||
| label={label} | ||
| value={formattedAmount} | ||
| onChangeText={setNewAmount} | ||
| placeholder={numberFormat(0)} | ||
| ref={(ref: BaseTextInputRef) => { | ||
| if (typeof forwardedRef === 'function') { | ||
| forwardedRef(ref); | ||
| } else if (forwardedRef && 'current' in forwardedRef) { | ||
| // eslint-disable-next-line no-param-reassign | ||
| forwardedRef.current = ref; | ||
| } | ||
| textInput.current = ref; | ||
| }} | ||
| selection={selection} | ||
| onSelectionChange={(e: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => { | ||
| setSelection(e.nativeEvent.selection); | ||
| }} | ||
| suffixCharacter="%" | ||
| keyboardType={CONST.KEYBOARD_TYPE.DECIMAL_PAD} | ||
| // eslint-disable-next-line react/jsx-props-no-spreading | ||
| {...rest} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| PercentageForm.displayName = 'PercentageForm'; | ||
|
|
||
| export default forwardRef(PercentageForm); | ||
| export type {PercentageFormProps}; | ||
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.