-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Feat: [BYOC] - Make Transaction start date editable after card assignment
#78489
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
carlosmiceli
merged 2 commits into
Expensify:main
from
ikevin127:ikevin127-byoc-editTransactionStartDate
Jan 1, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
7 changes: 7 additions & 0 deletions
7
src/libs/API/parameters/UpdateCardTransactionStartDateParams.ts
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,7 @@ | ||
| type UpdateCardTransactionStartDateParams = { | ||
| authToken?: string | null; | ||
| cardID: number; | ||
| startDate: string; | ||
| }; | ||
|
|
||
| export default UpdateCardTransactionStartDateParams; |
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
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
162 changes: 162 additions & 0 deletions
162
src/pages/workspace/companyCards/WorkspaceCompanyCardEditTransactionStartDatePage.tsx
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,162 @@ | ||
| import {format, parseISO, subDays} from 'date-fns'; | ||
| import React, {useState} from 'react'; | ||
| import {View} from 'react-native'; | ||
| import type {ValueOf} from 'type-fest'; | ||
| import Button from '@components/Button'; | ||
| import DatePicker from '@components/DatePicker'; | ||
| import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
| import ScreenWrapper from '@components/ScreenWrapper'; | ||
| import SelectionList from '@components/SelectionList'; | ||
| import SingleSelectListItem from '@components/SelectionListWithSections/SingleSelectListItem'; | ||
| import Text from '@components/Text'; | ||
| import useCardFeeds from '@hooks/useCardFeeds'; | ||
| import useCardsList from '@hooks/useCardsList'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import usePolicy from '@hooks/usePolicy'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import {getCompanyCardFeed, getCompanyFeeds, getDomainOrWorkspaceAccountID} from '@libs/CardUtils'; | ||
| import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; | ||
| import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; | ||
| import {isRequiredFulfilled} from '@libs/ValidationUtils'; | ||
| import Navigation from '@navigation/Navigation'; | ||
| import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; | ||
| import {updateCardTransactionStartDate} from '@userActions/CompanyCards'; | ||
| import CONST from '@src/CONST'; | ||
| import type SCREENS from '@src/SCREENS'; | ||
| import type {CompanyCardFeedWithDomainID} from '@src/types/onyx'; | ||
|
|
||
| type DateOption = ValueOf<typeof CONST.COMPANY_CARD.TRANSACTION_START_DATE_OPTIONS>; | ||
| type WorkspaceCompanyCardEditTransactionStartDatePageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.COMPANY_CARD_EDIT_TRANSACTION_START_DATE>; | ||
|
|
||
| function WorkspaceCompanyCardEditTransactionStartDatePage({route}: WorkspaceCompanyCardEditTransactionStartDatePageProps) { | ||
| const {policyID, cardID} = route.params; | ||
| const feedName = decodeURIComponent(route.params.feed) as CompanyCardFeedWithDomainID; | ||
| const bank = getCompanyCardFeed(feedName); | ||
|
|
||
| const {translate} = useLocalize(); | ||
| const styles = useThemeStyles(); | ||
| const policy = usePolicy(policyID); | ||
| const workspaceAccountID = policy?.workspaceAccountID ?? CONST.DEFAULT_NUMBER_ID; | ||
|
|
||
| const [cardFeeds] = useCardFeeds(policyID); | ||
| const companyFeeds = getCompanyFeeds(cardFeeds); | ||
| const domainOrWorkspaceAccountID = getDomainOrWorkspaceAccountID(workspaceAccountID, companyFeeds[feedName]); | ||
|
|
||
| const [allBankCards] = useCardsList(feedName); | ||
| const card = allBankCards?.[cardID]; | ||
| const currentStartDate = card?.scrapeMinDate; | ||
|
|
||
| const [dateOptionSelected, setDateOptionSelected] = useState<DateOption>(CONST.COMPANY_CARD.TRANSACTION_START_DATE_OPTIONS.CUSTOM); | ||
|
|
||
| const [startDate, setStartDate] = useState(() => { | ||
| if (currentStartDate) { | ||
| return format(parseISO(currentStartDate), CONST.DATE.FNS_FORMAT_STRING); | ||
| } | ||
| return format(new Date(), CONST.DATE.FNS_FORMAT_STRING); | ||
| }); | ||
|
|
||
| const [errorText, setErrorText] = useState(''); | ||
|
|
||
|
ikevin127 marked this conversation as resolved.
|
||
| const handleSelectDateOption = (dateOption: DateOption) => { | ||
| setErrorText(''); | ||
| setDateOptionSelected(dateOption); | ||
| if (dateOption === CONST.COMPANY_CARD.TRANSACTION_START_DATE_OPTIONS.FROM_BEGINNING) { | ||
| return; | ||
| } | ||
| // Reset to current date when switching to custom | ||
| if (!currentStartDate) { | ||
| setStartDate(format(new Date(), CONST.DATE.FNS_FORMAT_STRING)); | ||
| } | ||
| }; | ||
|
|
||
|
ikevin127 marked this conversation as resolved.
|
||
| 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); | ||
| const newStartDate = dateOptionSelected === CONST.COMPANY_CARD.TRANSACTION_START_DATE_OPTIONS.FROM_BEGINNING ? date90DaysBack : startDate; | ||
|
|
||
| updateCardTransactionStartDate(domainOrWorkspaceAccountID, cardID, newStartDate, bank, currentStartDate); | ||
| Navigation.goBack(); | ||
| }; | ||
|
|
||
|
ikevin127 marked this conversation as resolved.
|
||
| const dateOptions = [ | ||
| { | ||
| value: CONST.COMPANY_CARD.TRANSACTION_START_DATE_OPTIONS.FROM_BEGINNING, | ||
| text: translate('workspace.companyCards.fromTheBeginning'), | ||
| keyForList: CONST.COMPANY_CARD.TRANSACTION_START_DATE_OPTIONS.FROM_BEGINNING, | ||
| isSelected: dateOptionSelected === CONST.COMPANY_CARD.TRANSACTION_START_DATE_OPTIONS.FROM_BEGINNING, | ||
| }, | ||
| { | ||
| value: CONST.COMPANY_CARD.TRANSACTION_START_DATE_OPTIONS.CUSTOM, | ||
| text: translate('workspace.companyCards.customStartDate'), | ||
| keyForList: CONST.COMPANY_CARD.TRANSACTION_START_DATE_OPTIONS.CUSTOM, | ||
| isSelected: dateOptionSelected === CONST.COMPANY_CARD.TRANSACTION_START_DATE_OPTIONS.CUSTOM, | ||
| }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <AccessOrNotFoundWrapper | ||
| policyID={policyID} | ||
| featureName={CONST.POLICY.MORE_FEATURES.ARE_COMPANY_CARDS_ENABLED} | ||
| > | ||
| <ScreenWrapper | ||
| testID="WorkspaceCompanyCardEditTransactionStartDatePage" | ||
| enableEdgeToEdgeBottomSafeAreaPadding | ||
| > | ||
| <HeaderWithBackButton | ||
| title={translate('workspace.moreFeatures.companyCards.transactionStartDate')} | ||
| onBackButtonPress={Navigation.goBack} | ||
| /> | ||
| <Text style={[styles.textSupporting, styles.ph5, styles.mv3]}>{translate('workspace.companyCards.startDateDescription')}</Text> | ||
| <View style={styles.flex1}> | ||
| <SelectionList | ||
| ListItem={SingleSelectListItem} | ||
|
ikevin127 marked this conversation as resolved.
|
||
| onSelectRow={({value}) => handleSelectDateOption(value)} | ||
| data={dateOptions} | ||
| shouldSingleExecuteRowSelect | ||
| initiallyFocusedItemKey={dateOptionSelected} | ||
| shouldUpdateFocusedIndex | ||
| addBottomSafeAreaPadding | ||
| shouldHighlightSelectedItem={false} | ||
| footerContent={ | ||
| <Button | ||
| success | ||
| large | ||
| pressOnEnter | ||
| text={translate('common.save')} | ||
| onPress={submit} | ||
| /> | ||
| } | ||
| listFooterContent={ | ||
| dateOptionSelected === CONST.COMPANY_CARD.TRANSACTION_START_DATE_OPTIONS.CUSTOM ? ( | ||
| <View style={[styles.ph5]}> | ||
| <DatePicker | ||
| inputID="" | ||
| value={startDate} | ||
|
ikevin127 marked this conversation as resolved.
|
||
| label={translate('iou.startDate')} | ||
| onInputChange={(value) => { | ||
| if (!isRequiredFulfilled(value)) { | ||
| setErrorText(translate('common.error.fieldRequired')); | ||
| } else { | ||
| setErrorText(''); | ||
| } | ||
| setStartDate(value); | ||
| }} | ||
| minDate={CONST.CALENDAR_PICKER.MIN_DATE} | ||
| maxDate={new Date()} | ||
| errorText={errorText} | ||
| /> | ||
| </View> | ||
| ) : null | ||
| } | ||
| /> | ||
| </View> | ||
| </ScreenWrapper> | ||
| </AccessOrNotFoundWrapper> | ||
| ); | ||
| } | ||
|
|
||
| export default WorkspaceCompanyCardEditTransactionStartDatePage; | ||
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.