|
1 | 1 | import type {FeedKeysWithAssignedCards} from '@selectors/Card'; |
2 | | -import {fromUnixTime, isBefore} from 'date-fns'; |
| 2 | +import {format, fromUnixTime, isBefore} from 'date-fns'; |
3 | 3 | import groupBy from 'lodash/groupBy'; |
4 | 4 | import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; |
5 | 5 | import type {TupleToUnion, ValueOf} from 'type-fest'; |
@@ -840,6 +840,22 @@ function getDefaultCardName(cardholder?: string) { |
840 | 840 | return `${cardholder}'s card`; |
841 | 841 | } |
842 | 842 |
|
| 843 | +/** |
| 844 | + * Gets the start date for a card assignment. |
| 845 | + * When not editing, always returns the current date. |
| 846 | + * When editing, returns the existing start date or current date as fallback. |
| 847 | + * |
| 848 | + * @param isEditing - Whether the card assignment is being edited |
| 849 | + * @param existingStartDate - The existing start date from previous assignment |
| 850 | + * @returns Formatted start date string in yyyy-MM-dd format |
| 851 | + */ |
| 852 | +function getCardAssignmentStartDate(isEditing: boolean | undefined, existingStartDate?: string): string { |
| 853 | + if (!isEditing) { |
| 854 | + return format(new Date(), CONST.DATE.FNS_FORMAT_STRING); |
| 855 | + } |
| 856 | + return existingStartDate ?? format(new Date(), CONST.DATE.FNS_FORMAT_STRING); |
| 857 | +} |
| 858 | + |
843 | 859 | function checkIfNewFeedConnected(prevFeedsData: CompanyFeeds, currentFeedsData: CompanyFeeds, plaidBank?: string) { |
844 | 860 | const prevFeeds = Object.keys(prevFeedsData); |
845 | 861 | const currentFeeds = Object.keys(currentFeedsData); |
@@ -1196,6 +1212,7 @@ export { |
1196 | 1212 | hasOnlyOneCardToAssign, |
1197 | 1213 | checkIfNewFeedConnected, |
1198 | 1214 | getDefaultCardName, |
| 1215 | + getCardAssignmentStartDate, |
1199 | 1216 | getDomainOrWorkspaceAccountID, |
1200 | 1217 | mergeCardListWithWorkspaceFeeds, |
1201 | 1218 | isCard, |
|
0 commit comments