-
Notifications
You must be signed in to change notification settings - Fork 3k
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 #37967 from software-mansion-labs/wave8/CreatingNe…
…wTaxes [Simplified Collect][Taxes] Creating new taxes
- Loading branch information
Showing
41 changed files
with
746 additions
and
26 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
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,64 @@ | ||
import React, {useState} from 'react'; | ||
import {View} from 'react-native'; | ||
import AmountForm from '@components/AmountForm'; | ||
import Button from '@components/Button'; | ||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
import Modal from '@components/Modal'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import ScrollView from '@components/ScrollView'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import CONST from '@src/CONST'; | ||
import type {AmountSelectorModalProps} from './types'; | ||
|
||
function AmountSelectorModal({value, description = '', onValueSelected, isVisible, onClose, ...rest}: AmountSelectorModalProps) { | ||
const {translate} = useLocalize(); | ||
const styles = useThemeStyles(); | ||
|
||
const [currentValue, setValue] = useState(value); | ||
|
||
return ( | ||
<Modal | ||
type={CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED} | ||
isVisible={isVisible} | ||
onClose={onClose} | ||
onModalHide={onClose} | ||
hideModalContentWhileAnimating | ||
useNativeDriver | ||
> | ||
<ScreenWrapper | ||
includePaddingTop={false} | ||
includeSafeAreaPaddingBottom={false} | ||
testID={AmountSelectorModal.displayName} | ||
shouldEnableMaxHeight | ||
> | ||
<HeaderWithBackButton | ||
title={description} | ||
onBackButtonPress={onClose} | ||
/> | ||
<ScrollView contentContainerStyle={[styles.flex1, styles.mh5, styles.mb5]}> | ||
<View style={styles.flex1}> | ||
<AmountForm | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...rest} | ||
autoFocus | ||
value={currentValue} | ||
onInputChange={setValue} | ||
/> | ||
</View> | ||
<Button | ||
success | ||
large | ||
pressOnEnter | ||
text={translate('common.save')} | ||
onPress={() => onValueSelected?.(currentValue ?? '')} | ||
/> | ||
</ScrollView> | ||
</ScreenWrapper> | ||
</Modal> | ||
); | ||
} | ||
|
||
AmountSelectorModal.displayName = 'AmountSelectorModal'; | ||
|
||
export default AmountSelectorModal; |
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,65 @@ | ||
import React, {forwardRef, useState} from 'react'; | ||
import type {ForwardedRef} from 'react'; | ||
import {View} from 'react-native'; | ||
import FormHelpMessage from '@components/FormHelpMessage'; | ||
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; | ||
import useStyleUtils from '@hooks/useStyleUtils'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import variables from '@styles/variables'; | ||
import callOrReturn from '@src/types/utils/callOrReturn'; | ||
import AmountSelectorModal from './AmountSelectorModal'; | ||
import type {AmountPickerProps} from './types'; | ||
|
||
function AmountPicker({value, description, title, errorText = '', onInputChange, furtherDetails, rightLabel, ...rest}: AmountPickerProps, forwardedRef: ForwardedRef<View>) { | ||
const styles = useThemeStyles(); | ||
const StyleUtils = useStyleUtils(); | ||
const [isPickerVisible, setIsPickerVisible] = useState(false); | ||
|
||
const showPickerModal = () => { | ||
setIsPickerVisible(true); | ||
}; | ||
|
||
const hidePickerModal = () => { | ||
setIsPickerVisible(false); | ||
}; | ||
|
||
const updateInput = (updatedValue: string) => { | ||
if (updatedValue !== value) { | ||
onInputChange?.(updatedValue); | ||
} | ||
hidePickerModal(); | ||
}; | ||
|
||
const descStyle = !value || value.length === 0 ? StyleUtils.getFontSizeStyle(variables.fontSizeLabel) : null; | ||
|
||
return ( | ||
<View> | ||
<MenuItemWithTopDescription | ||
ref={forwardedRef} | ||
shouldShowRightIcon | ||
title={callOrReturn(title, value)} | ||
descriptionTextStyle={descStyle} | ||
description={description} | ||
onPress={showPickerModal} | ||
furtherDetails={furtherDetails} | ||
rightLabel={rightLabel} | ||
/> | ||
<View style={styles.ml5}> | ||
<FormHelpMessage message={errorText} /> | ||
</View> | ||
<AmountSelectorModal | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...rest} | ||
value={value} | ||
isVisible={isPickerVisible} | ||
description={description} | ||
onClose={hidePickerModal} | ||
onValueSelected={updateInput} | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
AmountPicker.displayName = 'AmountPicker'; | ||
|
||
export default forwardRef(AmountPicker); |
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,40 @@ | ||
import type {AmountFormProps} from '@components/AmountForm'; | ||
import type {MenuItemBaseProps} from '@components/MenuItem'; | ||
import type {MaybePhraseKey} from '@libs/Localize'; | ||
|
||
type AmountSelectorModalProps = { | ||
/** Whether the modal is visible */ | ||
isVisible: boolean; | ||
|
||
/** Current value */ | ||
value?: string; | ||
|
||
/** Function to call when the user selects a item */ | ||
onValueSelected?: (value: string) => void; | ||
|
||
/** Function to call when the user closes the modal */ | ||
onClose: () => void; | ||
} & Pick<MenuItemBaseProps, 'description'>; | ||
|
||
type AmountPickerProps = { | ||
/** Item to display */ | ||
value?: string; | ||
|
||
/** A placeholder value to display */ | ||
title?: string | ((value?: string) => string); | ||
|
||
/** Form Error description */ | ||
errorText?: MaybePhraseKey; | ||
|
||
/** Callback to call when the input changes */ | ||
onInputChange?: (value: string | undefined) => void; | ||
|
||
/** Text to display under the main menu item */ | ||
furtherDetails?: string; | ||
|
||
/** Whether to show the tooltip text */ | ||
shouldShowTooltips?: boolean; | ||
} & Pick<MenuItemBaseProps, 'rightLabel' | 'description'> & | ||
AmountFormProps; | ||
|
||
export type {AmountSelectorModalProps, AmountPickerProps}; |
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
Oops, something went wrong.