diff --git a/src/ROUTES.ts b/src/ROUTES.ts index bad346a8f0d0..cff3093a9493 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -2062,12 +2062,6 @@ const ROUTES = { // eslint-disable-next-line no-restricted-syntax -- Legacy route generation getRoute: (policyID: string, feed: string, backTo?: string) => getUrlWithBackToParam(`workspaces/${policyID}/company-cards/${feed}/assign-card`, backTo), }, - WORKSPACE_COMPANY_CARDS_TRANSACTION_START_DATE: { - route: 'workspaces/:policyID/company-cards/:feed/assign-card/transaction-start-date', - - // eslint-disable-next-line no-restricted-syntax -- Legacy route generation - getRoute: (policyID: string, feed: string, backTo?: string) => getUrlWithBackToParam(`workspaces/${policyID}/company-cards/${feed}/assign-card/transaction-start-date`, backTo), - }, WORKSPACE_COMPANY_CARD_DETAILS: { route: 'workspaces/:policyID/company-cards/:bank/:cardID', diff --git a/src/SCREENS.ts b/src/SCREENS.ts index cab8d814b911..1e85b43a3caf 100644 --- a/src/SCREENS.ts +++ b/src/SCREENS.ts @@ -556,7 +556,6 @@ const SCREENS = { PROFILE: 'Workspace_Overview', COMPANY_CARDS: 'Workspace_CompanyCards', COMPANY_CARDS_ASSIGN_CARD: 'Workspace_CompanyCards_AssignCard', - COMPANY_CARDS_TRANSACTION_START_DATE: 'Workspace_CompanyCards_TransactionStartDate', COMPANY_CARDS_SELECT_FEED: 'Workspace_CompanyCards_Select_Feed', COMPANY_CARDS_BANK_CONNECTION: 'Workspace_CompanyCards_BankConnection', COMPANY_CARDS_ADD_NEW: 'Workspace_CompanyCards_New', diff --git a/src/components/SelectionList/BaseSelectionList.tsx b/src/components/SelectionList/BaseSelectionList.tsx index d0c7fdc5ece6..6c015f3ffcb7 100644 --- a/src/components/SelectionList/BaseSelectionList.tsx +++ b/src/components/SelectionList/BaseSelectionList.tsx @@ -76,6 +76,7 @@ function BaseSelectionList({ shouldSingleExecuteRowSelect = false, shouldPreventDefaultFocusOnSelectRow = false, shouldShowTextInput = !!textInputOptions?.label, + shouldHighlightSelectedItem = true, }: SelectionListProps) { const styles = useThemeStyles(); const isFocused = useIsFocused(); @@ -324,6 +325,7 @@ function BaseSelectionList({ wrapperStyle={style?.listItemWrapperStyle} titleStyles={style?.listItemTitleStyles} singleExecution={singleExecution} + shouldHighlightSelectedItem={shouldHighlightSelectedItem} shouldSyncFocus={!isTextInputFocusedRef.current && hasKeyBeenPressed.current} /> ); diff --git a/src/components/SelectionList/ListItem/BaseListItem.tsx b/src/components/SelectionList/ListItem/BaseListItem.tsx index 256d9d701e40..dff7151d4175 100644 --- a/src/components/SelectionList/ListItem/BaseListItem.tsx +++ b/src/components/SelectionList/ListItem/BaseListItem.tsx @@ -41,6 +41,7 @@ function BaseListItem({ onLongPressRow, testID, shouldUseDefaultRightHandSideCheckmark = true, + shouldHighlightSelectedItem = true, }: BaseListItemProps) { const theme = useTheme(); const styles = useThemeStyles(); @@ -108,7 +109,9 @@ function BaseListItem({ id={keyForList ?? ''} style={[ pressableStyle, - isFocused && StyleUtils.getItemBackgroundColorStyle(!!item.isSelected, !!isFocused, !!item.isDisabled, theme.activeComponentBG, theme.hoverComponentBG), + isFocused && + shouldHighlightSelectedItem && + StyleUtils.getItemBackgroundColorStyle(!!item.isSelected, !!isFocused, !!item.isDisabled, theme.activeComponentBG, theme.hoverComponentBG), ]} onFocus={onFocus} onMouseLeave={handleMouseLeave} @@ -121,7 +124,9 @@ function BaseListItem({ accessibilityState={{selected: !!isFocused}} style={[ wrapperStyle, - isFocused && StyleUtils.getItemBackgroundColorStyle(!!item.isSelected, !!isFocused, !!item.isDisabled, theme.activeComponentBG, theme.hoverComponentBG), + isFocused && + shouldHighlightSelectedItem && + StyleUtils.getItemBackgroundColorStyle(!!item.isSelected, !!isFocused, !!item.isDisabled, theme.activeComponentBG, theme.hoverComponentBG), ]} > {typeof children === 'function' ? children(hovered) : children} diff --git a/src/components/SelectionList/ListItem/ListItemRenderer.tsx b/src/components/SelectionList/ListItem/ListItemRenderer.tsx index 3f9ed30427ff..45aa83229cf6 100644 --- a/src/components/SelectionList/ListItem/ListItemRenderer.tsx +++ b/src/components/SelectionList/ListItem/ListItemRenderer.tsx @@ -16,6 +16,7 @@ type ListItemRendererProps = Omit['singleExecution']; titleStyles?: StyleProp; titleContainerStyles?: StyleProp; + shouldHighlightSelectedItem: boolean; }; function ListItemRenderer({ @@ -45,6 +46,7 @@ function ListItemRenderer({ singleExecution, titleContainerStyles, shouldUseDefaultRightHandSideCheckmark, + shouldHighlightSelectedItem, }: ListItemRendererProps) { const handleOnCheckboxPress = () => { if (isTransactionGroupListItemType(item)) { @@ -95,6 +97,7 @@ function ListItemRenderer({ titleStyles={titleStyles} titleContainerStyles={titleContainerStyles} shouldUseDefaultRightHandSideCheckmark={shouldUseDefaultRightHandSideCheckmark} + shouldHighlightSelectedItem={shouldHighlightSelectedItem} /> {item.footerContent && item.footerContent} diff --git a/src/components/SelectionList/ListItem/RadioListItem.tsx b/src/components/SelectionList/ListItem/RadioListItem.tsx index 256c3b0a876f..91f443373062 100644 --- a/src/components/SelectionList/ListItem/RadioListItem.tsx +++ b/src/components/SelectionList/ListItem/RadioListItem.tsx @@ -23,6 +23,7 @@ function RadioListItem({ shouldSyncFocus, wrapperStyle, titleStyles, + shouldHighlightSelectedItem = true, }: RadioListItemProps) { const styles = useThemeStyles(); const fullTitle = isMultilineSupported ? item.text?.trimStart() : item.text; @@ -45,6 +46,7 @@ function RadioListItem({ onFocus={onFocus} shouldSyncFocus={shouldSyncFocus} pendingAction={item.pendingAction} + shouldHighlightSelectedItem={shouldHighlightSelectedItem} > <> {!!item.leftElement && item.leftElement} diff --git a/src/components/SelectionList/ListItem/SingleSelectListItem.tsx b/src/components/SelectionList/ListItem/SingleSelectListItem.tsx index 06706771ecb8..671a2a4a51ae 100644 --- a/src/components/SelectionList/ListItem/SingleSelectListItem.tsx +++ b/src/components/SelectionList/ListItem/SingleSelectListItem.tsx @@ -23,6 +23,7 @@ function SingleSelectListItem({ shouldSyncFocus, wrapperStyle, titleStyles, + shouldHighlightSelectedItem = true, }: SingleSelectListItemProps) { const styles = useThemeStyles(); @@ -56,6 +57,7 @@ function SingleSelectListItem({ shouldSyncFocus={shouldSyncFocus} wrapperStyle={[wrapperStyle, styles.optionRowCompact]} titleStyles={titleStyles} + shouldHighlightSelectedItem={shouldHighlightSelectedItem} /> ); } diff --git a/src/components/SelectionList/ListItem/types.ts b/src/components/SelectionList/ListItem/types.ts index b10e7a0fef15..53fc743f1425 100644 --- a/src/components/SelectionList/ListItem/types.ts +++ b/src/components/SelectionList/ListItem/types.ts @@ -233,6 +233,9 @@ type ListItemProps = CommonListItemProps & { /** Whether to show the default right hand side checkmark */ shouldUseDefaultRightHandSideCheckmark?: boolean; + + /** Whether to highlight the selected item */ + shouldHighlightSelectedItem?: boolean; }; type ValidListItem = @@ -263,6 +266,8 @@ type BaseListItemProps = CommonListItemProps & { shouldUseDefaultRightHandSideCheckmark?: boolean; /** Whether to show the right caret icon */ shouldShowRightCaret?: boolean; + /** Whether to highlight the selected item */ + shouldHighlightSelectedItem?: boolean; }; type RadioListItemProps = ListItemProps; diff --git a/src/components/SelectionList/types.ts b/src/components/SelectionList/types.ts index dd9ca1033ed3..7b6afe5a6c53 100644 --- a/src/components/SelectionList/types.ts +++ b/src/components/SelectionList/types.ts @@ -143,6 +143,9 @@ type SelectionListProps = { /** Whether to show the text input */ shouldShowTextInput?: boolean; + + /** Whether to highlight the selected item */ + shouldHighlightSelectedItem?: boolean; }; type TextInputOptions = { diff --git a/src/components/SelectionListWithSections/BaseListItem.tsx b/src/components/SelectionListWithSections/BaseListItem.tsx index 3c106b93e7fe..1a9a15e1ce54 100644 --- a/src/components/SelectionListWithSections/BaseListItem.tsx +++ b/src/components/SelectionListWithSections/BaseListItem.tsx @@ -43,6 +43,7 @@ function BaseListItem({ shouldUseDefaultRightHandSideCheckmark = true, forwardedFSClass, shouldShowRightCaret = false, + shouldHighlightSelectedItem = true, }: BaseListItemProps) { const theme = useTheme(); const styles = useThemeStyles(); @@ -110,7 +111,9 @@ function BaseListItem({ id={keyForList ?? ''} style={[ pressableStyle, - isFocused && StyleUtils.getItemBackgroundColorStyle(!!item.isSelected, !!isFocused, !!item.isDisabled, theme.activeComponentBG, theme.hoverComponentBG), + isFocused && + shouldHighlightSelectedItem && + StyleUtils.getItemBackgroundColorStyle(!!item.isSelected, !!isFocused, !!item.isDisabled, theme.activeComponentBG, theme.hoverComponentBG), ]} onFocus={onFocus} onMouseLeave={handleMouseLeave} @@ -123,7 +126,9 @@ function BaseListItem({ accessibilityState={{selected: !!isFocused}} style={[ wrapperStyle, - isFocused && StyleUtils.getItemBackgroundColorStyle(!!item.isSelected, !!isFocused, !!item.isDisabled, theme.activeComponentBG, theme.hoverComponentBG), + isFocused && + shouldHighlightSelectedItem && + StyleUtils.getItemBackgroundColorStyle(!!item.isSelected, !!isFocused, !!item.isDisabled, theme.activeComponentBG, theme.hoverComponentBG), ]} fsClass={forwardedFSClass} > diff --git a/src/components/SelectionListWithSections/BaseSelectionListItemRenderer.tsx b/src/components/SelectionListWithSections/BaseSelectionListItemRenderer.tsx index e61d61450a82..dd30c5fed2d9 100644 --- a/src/components/SelectionListWithSections/BaseSelectionListItemRenderer.tsx +++ b/src/components/SelectionListWithSections/BaseSelectionListItemRenderer.tsx @@ -58,6 +58,7 @@ function BaseSelectionListItemRenderer({ personalDetails, userBillingFundID, shouldShowRightCaret, + shouldHighlightSelectedItem = true, }: BaseSelectionListItemRendererProps) { const handleOnCheckboxPress = () => { if (isTransactionGroupListItemType(item)) { @@ -115,6 +116,7 @@ function BaseSelectionListItemRenderer({ userBillingFundID={userBillingFundID} index={index} shouldShowRightCaret={shouldShowRightCaret} + shouldHighlightSelectedItem={shouldHighlightSelectedItem} sectionIndex={sectionIndex} /> {item.footerContent && item.footerContent} diff --git a/src/components/SelectionListWithSections/BaseSelectionListWithSections.tsx b/src/components/SelectionListWithSections/BaseSelectionListWithSections.tsx index b68ac6c9f0e6..88d22cb0f450 100644 --- a/src/components/SelectionListWithSections/BaseSelectionListWithSections.tsx +++ b/src/components/SelectionListWithSections/BaseSelectionListWithSections.tsx @@ -142,6 +142,7 @@ function BaseSelectionListWithSections({ canShowProductTrainingTooltip, renderScrollComponent, shouldShowRightCaret, + shouldHighlightSelectedItem = true, ref, }: SelectionListProps) { const styles = useThemeStyles(); @@ -649,6 +650,7 @@ function BaseSelectionListWithSections({ isSelected: selected, ...item, }} + shouldHighlightSelectedItem={shouldHighlightSelectedItem} shouldUseDefaultRightHandSideCheckmark={shouldUseDefaultRightHandSideCheckmark} index={index} sectionIndex={section?.indexOffset} diff --git a/src/components/SelectionListWithSections/RadioListItem.tsx b/src/components/SelectionListWithSections/RadioListItem.tsx index 256c3b0a876f..91f443373062 100644 --- a/src/components/SelectionListWithSections/RadioListItem.tsx +++ b/src/components/SelectionListWithSections/RadioListItem.tsx @@ -23,6 +23,7 @@ function RadioListItem({ shouldSyncFocus, wrapperStyle, titleStyles, + shouldHighlightSelectedItem = true, }: RadioListItemProps) { const styles = useThemeStyles(); const fullTitle = isMultilineSupported ? item.text?.trimStart() : item.text; @@ -45,6 +46,7 @@ function RadioListItem({ onFocus={onFocus} shouldSyncFocus={shouldSyncFocus} pendingAction={item.pendingAction} + shouldHighlightSelectedItem={shouldHighlightSelectedItem} > <> {!!item.leftElement && item.leftElement} diff --git a/src/components/SelectionListWithSections/SingleSelectListItem.tsx b/src/components/SelectionListWithSections/SingleSelectListItem.tsx index ef199924a14e..56d023e28aa5 100644 --- a/src/components/SelectionListWithSections/SingleSelectListItem.tsx +++ b/src/components/SelectionListWithSections/SingleSelectListItem.tsx @@ -23,6 +23,7 @@ function SingleSelectListItem({ shouldSyncFocus, wrapperStyle, titleStyles, + shouldHighlightSelectedItem = true, }: SingleSelectListItemProps) { const styles = useThemeStyles(); const isSelected = item.isSelected; @@ -56,6 +57,7 @@ function SingleSelectListItem({ shouldSyncFocus={shouldSyncFocus} wrapperStyle={[wrapperStyle, styles.optionRowCompact]} titleStyles={titleStyles} + shouldHighlightSelectedItem={shouldHighlightSelectedItem} /> ); } diff --git a/src/components/SelectionListWithSections/types.ts b/src/components/SelectionListWithSections/types.ts index b45ee62a24ca..37bcf0ed0140 100644 --- a/src/components/SelectionListWithSections/types.ts +++ b/src/components/SelectionListWithSections/types.ts @@ -112,6 +112,9 @@ type CommonListItemProps = { /** Whether to show the right caret */ shouldShowRightCaret?: boolean; + + /** Whether to highlight the selected item */ + shouldHighlightSelectedItem?: boolean; } & TRightHandSideComponent; type ListItemFocusEventHandler = (event: NativeSyntheticEvent) => void; @@ -949,6 +952,9 @@ type SelectionListProps = Partial & { /** Whether to show the right caret icon */ shouldShowRightCaret?: boolean; + + /** Whether to highlight the selected item */ + shouldHighlightSelectedItem?: boolean; } & TRightHandSideComponent; type SelectionListHandle = { diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx index d2565562b587..f26571389b0f 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx @@ -683,8 +683,6 @@ const SettingsModalStackNavigator = createModalStackNavigator require('../../../../pages/workspace/companyCards/WorkspaceCompanyCardFeedSelectorPage').default, [SCREENS.WORKSPACE.COMPANY_CARDS_BANK_CONNECTION]: () => require('../../../../pages/workspace/companyCards/BankConnection').default, [SCREENS.WORKSPACE.COMPANY_CARDS_ADD_NEW]: () => require('../../../../pages/workspace/companyCards/addNew/AddNewCardPage').default, - [SCREENS.WORKSPACE.COMPANY_CARDS_TRANSACTION_START_DATE]: () => - require('../../../../pages/workspace/companyCards/assignCard/TransactionStartDateSelectorPage').default, [SCREENS.WORKSPACE.COMPANY_CARD_DETAILS]: () => require('../../../../pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage').default, [SCREENS.WORKSPACE.COMPANY_CARD_NAME]: () => require('../../../../pages/workspace/companyCards/WorkspaceCompanyCardEditCardNamePage').default, [SCREENS.WORKSPACE.COMPANY_CARD_EXPORT]: () => require('../../../../pages/workspace/companyCards/WorkspaceCompanyCardAccountSelectCardPage').default, diff --git a/src/libs/Navigation/linkingConfig/RELATIONS/WORKSPACE_TO_RHP.ts b/src/libs/Navigation/linkingConfig/RELATIONS/WORKSPACE_TO_RHP.ts index 5cea72f6439e..60cca8d846bc 100755 --- a/src/libs/Navigation/linkingConfig/RELATIONS/WORKSPACE_TO_RHP.ts +++ b/src/libs/Navigation/linkingConfig/RELATIONS/WORKSPACE_TO_RHP.ts @@ -240,7 +240,6 @@ const WORKSPACE_TO_RHP: Partial['config'] = { [SCREENS.WORKSPACE.COMPANY_CARDS_ASSIGN_CARD]: { path: ROUTES.WORKSPACE_COMPANY_CARDS_ASSIGN_CARD.route, }, - [SCREENS.WORKSPACE.COMPANY_CARDS_TRANSACTION_START_DATE]: { - path: ROUTES.WORKSPACE_COMPANY_CARDS_TRANSACTION_START_DATE.route, - }, [SCREENS.WORKSPACE.INVITE]: { path: ROUTES.WORKSPACE_INVITE.route, }, diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 60348b78e4ea..1ec30c43fe2f 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -2203,12 +2203,6 @@ type WorkspaceSplitNavigatorParamList = { // eslint-disable-next-line no-restricted-syntax -- `backTo` usages in this file are legacy. Do not add new `backTo` params to screens. See contributingGuides/NAVIGATION.md backTo?: Routes; }; - [SCREENS.WORKSPACE.COMPANY_CARDS_TRANSACTION_START_DATE]: { - policyID: string; - feed: string; - // eslint-disable-next-line no-restricted-syntax -- `backTo` usages in this file are legacy. Do not add new `backTo` params to screens. See contributingGuides/NAVIGATION.md - backTo?: Routes; - }; [SCREENS.WORKSPACE.PER_DIEM]: { policyID: string; }; diff --git a/src/pages/workspace/companyCards/assignCard/AssignCardFeedPage.tsx b/src/pages/workspace/companyCards/assignCard/AssignCardFeedPage.tsx index 6c3e0845a66a..2d0f4dabe373 100644 --- a/src/pages/workspace/companyCards/assignCard/AssignCardFeedPage.tsx +++ b/src/pages/workspace/companyCards/assignCard/AssignCardFeedPage.tsx @@ -82,13 +82,7 @@ function AssignCardFeedPage({route, policy}: AssignCardFeedPageProps) { /> ); case CONST.COMPANY_CARD.STEP.TRANSACTION_START_DATE: - return ( - - ); + return ; case CONST.COMPANY_CARD.STEP.CARD_NAME: return ; case CONST.COMPANY_CARD.STEP.CONFIRMATION: diff --git a/src/pages/workspace/companyCards/assignCard/TransactionStartDateSelectorPage.tsx b/src/pages/workspace/companyCards/assignCard/TransactionStartDateSelectorPage.tsx deleted file mode 100644 index e350b4cc9722..000000000000 --- a/src/pages/workspace/companyCards/assignCard/TransactionStartDateSelectorPage.tsx +++ /dev/null @@ -1,87 +0,0 @@ -import {format} from 'date-fns'; -import React from 'react'; -import DatePicker from '@components/DatePicker'; -import FormProvider from '@components/Form/FormProvider'; -import InputWrapper from '@components/Form/InputWrapper'; -import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; -import HeaderWithBackButton from '@components/HeaderWithBackButton'; -import ScreenWrapper from '@components/ScreenWrapper'; -import useLocalize from '@hooks/useLocalize'; -import useOnyx from '@hooks/useOnyx'; -import useThemeStyles from '@hooks/useThemeStyles'; -import {setTransactionStartDate} from '@libs/actions/CompanyCards'; -import Navigation from '@libs/Navigation/Navigation'; -import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; -import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types'; -import {getFieldRequiredErrors} from '@libs/ValidationUtils'; -import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; -import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; -import type SCREENS from '@src/SCREENS'; -import INPUT_IDS from '@src/types/form/AssignCardForm'; - -type TransactionStartDateSelectorModalProps = PlatformStackScreenProps; - -function TransactionStartDateSelectorPage({route}: TransactionStartDateSelectorModalProps) { - const styles = useThemeStyles(); - const {translate} = useLocalize(); - const [assignCard] = useOnyx(ONYXKEYS.ASSIGN_CARD); - const startDate = assignCard?.startDate ?? assignCard?.data?.startDate ?? format(new Date(), CONST.DATE.FNS_FORMAT_STRING); - const policyID = route.params.policyID; - - const validate = (values: FormOnyxValues): FormInputErrors => - getFieldRequiredErrors(values, [INPUT_IDS.START_DATE]); - - const goBack = () => { - Navigation.goBack(ROUTES.WORKSPACE_COMPANY_CARDS_ASSIGN_CARD.getRoute(policyID, route.params.feed, route.params.backTo)); - }; - - const submit = (values: FormOnyxValues) => { - setTransactionStartDate(values[INPUT_IDS.START_DATE]); - goBack(); - }; - - return ( - - - - - - - - - ); -} - -TransactionStartDateSelectorPage.displayName = 'TransactionStartDateSelectorPage'; - -export default TransactionStartDateSelectorPage; diff --git a/src/pages/workspace/companyCards/assignCard/TransactionStartDateStep.tsx b/src/pages/workspace/companyCards/assignCard/TransactionStartDateStep.tsx index d0117f07290c..ebba1db68bb6 100644 --- a/src/pages/workspace/companyCards/assignCard/TransactionStartDateStep.tsx +++ b/src/pages/workspace/companyCards/assignCard/TransactionStartDateStep.tsx @@ -2,59 +2,21 @@ import {format, subDays} from 'date-fns'; import React, {useMemo, useState} from 'react'; import {View} from 'react-native'; import Button from '@components/Button'; +import DatePicker from '@components/DatePicker'; import InteractiveStepWrapper from '@components/InteractiveStepWrapper'; -import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; import SelectionList from '@components/SelectionList'; -import RadioListItem from '@components/SelectionList/ListItem/RadioListItem'; +import SingleSelectListItem from '@components/SelectionListWithSections/SingleSelectListItem'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; import useThemeStyles from '@hooks/useThemeStyles'; -import Navigation from '@libs/Navigation/Navigation'; import {getPersonalDetailByEmail} from '@libs/PersonalDetailsUtils'; +import {isRequiredFulfilled} from '@libs/ValidationUtils'; import {setAssignCardStepAndData} from '@userActions/CompanyCards'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; -import type {Route} from '@src/ROUTES'; -import type {CompanyCardFeed} from '@src/types/onyx'; -type TransactionStartDateStepProps = { - policyID: string | undefined; - feed: CompanyCardFeed; - backTo?: Route; -}; - -type TransactionStartDateSelectionListFooterProps = TransactionStartDateStepProps & { - dateOptionSelected: string; - startDate: string; -}; - -function TransactionStartDateSelectionListFooter({dateOptionSelected, startDate, policyID, feed, backTo}: TransactionStartDateSelectionListFooterProps) { - const {translate} = useLocalize(); - - if (dateOptionSelected !== CONST.COMPANY_CARD.TRANSACTION_START_DATE_OPTIONS.CUSTOM) { - return null; - } - - const onPress = () => { - if (!policyID) { - return; - } - Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS_TRANSACTION_START_DATE.getRoute(policyID, feed, backTo)); - }; - - return ( - - ); -} - -function TransactionStartDateStep({policyID, feed, backTo}: TransactionStartDateStepProps) { +function TransactionStartDateStep() { const {translate} = useLocalize(); const styles = useThemeStyles(); @@ -63,8 +25,9 @@ function TransactionStartDateStep({policyID, feed, backTo}: TransactionStartDate const data = assignCard?.data; const assigneeDisplayName = getPersonalDetailByEmail(data?.email ?? '')?.displayName ?? ''; - const [dateOptionSelected, setDateOptionSelected] = useState(data?.dateOption ?? CONST.COMPANY_CARD.TRANSACTION_START_DATE_OPTIONS.FROM_BEGINNING); - const startDate = assignCard?.startDate ?? data?.startDate ?? format(new Date(), CONST.DATE.FNS_FORMAT_STRING); + const [dateOptionSelected, setDateOptionSelected] = useState(data?.dateOption ?? CONST.COMPANY_CARD.TRANSACTION_START_DATE_OPTIONS.CUSTOM); + const [errorText, setErrorText] = useState(''); + const [startDate, setStartDate] = useState(() => assignCard?.startDate ?? data?.startDate ?? format(new Date(), CONST.DATE.FNS_FORMAT_STRING)); const handleBackButtonPress = () => { if (isEditing) { @@ -78,10 +41,20 @@ function TransactionStartDateStep({policyID, feed, backTo}: TransactionStartDate }; const handleSelectDateOption = (dateOption: string) => { + setErrorText(''); setDateOptionSelected(dateOption); + if (dateOption === CONST.COMPANY_CARD.TRANSACTION_START_DATE_OPTIONS.FROM_BEGINNING) { + return; + } + setStartDate(format(new Date(), CONST.DATE.FNS_FORMAT_STRING)); }; const submit = () => { + if (dateOptionSelected === CONST.COMPANY_CARD.TRANSACTION_START_DATE_OPTIONS.CUSTOM && !isRequiredFulfilled(startDate)) { + setErrorText(translate('common.error.fieldRequired')); + return; + } + const date90DaysBack = format(subDays(new Date(), 90), CONST.DATE.FNS_FORMAT_STRING); setAssignCardStepAndData({ @@ -126,13 +99,14 @@ function TransactionStartDateStep({policyID, feed, backTo}: TransactionStartDate {translate('workspace.companyCards.startDateDescription')} handleSelectDateOption(value)} data={dateOptions} shouldSingleExecuteRowSelect initiallyFocusedItemKey={dateOptionSelected} shouldUpdateFocusedIndex addBottomSafeAreaPadding + shouldHighlightSelectedItem={false} footerContent={