Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,8 @@ const ONYXKEYS = {
EDIT_EXPENSIFY_CARD_NAME_DRAFT_FORM: 'editExpensifyCardNameDraft',
EDIT_EXPENSIFY_CARD_LIMIT_FORM: 'editExpensifyCardLimit',
EDIT_EXPENSIFY_CARD_LIMIT_DRAFT_FORM: 'editExpensifyCardLimitDraft',
EDIT_EXPENSIFY_CARD_LIMIT_TYPE_FORM: 'editExpensifyCardLimitType',
EDIT_EXPENSIFY_CARD_LIMIT_TYPE_DRAFT_FORM: 'editExpensifyCardLimitTypeDraft',
SAGE_INTACCT_CREDENTIALS_FORM: 'sageIntacctCredentialsForm',
SAGE_INTACCT_CREDENTIALS_FORM_DRAFT: 'sageIntacctCredentialsFormDraft',
NETSUITE_CUSTOM_FIELD_FORM: 'netSuiteCustomFieldForm',
Expand Down Expand Up @@ -1105,6 +1107,7 @@ type OnyxFormValuesMapping = {
[ONYXKEYS.FORMS.ASSIGN_CARD_FORM]: FormTypes.AssignCardForm;
[ONYXKEYS.FORMS.EDIT_EXPENSIFY_CARD_NAME_FORM]: FormTypes.EditExpensifyCardNameForm;
[ONYXKEYS.FORMS.EDIT_EXPENSIFY_CARD_LIMIT_FORM]: FormTypes.EditExpensifyCardLimitForm;
[ONYXKEYS.FORMS.EDIT_EXPENSIFY_CARD_LIMIT_TYPE_FORM]: FormTypes.EditExpensifyCardLimitTypeForm;
[ONYXKEYS.FORMS.SAGE_INTACCT_CREDENTIALS_FORM]: FormTypes.SageIntactCredentialsForm;
[ONYXKEYS.FORMS.NETSUITE_CUSTOM_FIELD_FORM]: FormTypes.NetSuiteCustomFieldForm;
[ONYXKEYS.FORMS.NETSUITE_CUSTOM_LIST_ADD_FORM]: FormTypes.NetSuiteCustomFieldForm;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
type UpdateExpensifyCardLimitTypeParams = {
cardID: number;
limitType: string;
validFrom?: string;
validThru?: string;
clearValidityDates?: boolean;
};

export default UpdateExpensifyCardLimitTypeParams;
4 changes: 2 additions & 2 deletions src/libs/CardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function getDefaultExpensifyCardLimitType(policy?: OnyxEntry<Policy>): ValueOf<t
return areApprovalsConfigured ? CONST.EXPENSIFY_CARD.LIMIT_TYPES.SMART : CONST.EXPENSIFY_CARD.LIMIT_TYPES.MONTHLY;
}

function getTranslationKeyForLimitType(limitType: ValueOf<typeof CONST.EXPENSIFY_CARD.LIMIT_TYPES> | undefined): TranslationPaths | '' {
function getTranslationKeyForLimitType(limitType: ValueOf<typeof CONST.EXPENSIFY_CARD.LIMIT_TYPES> | undefined): TranslationPaths {
switch (limitType) {
case CONST.EXPENSIFY_CARD.LIMIT_TYPES.SMART:
return 'workspace.card.issueNewCard.smartLimit';
Expand All @@ -302,7 +302,7 @@ function getTranslationKeyForLimitType(limitType: ValueOf<typeof CONST.EXPENSIFY
case CONST.EXPENSIFY_CARD.LIMIT_TYPES.SINGLE_USE:
return 'workspace.card.issueNewCard.singleUse';
default:
return '';
return 'workspace.card.issueNewCard.smartLimit';
Comment thread
nkdengineer marked this conversation as resolved.
Resolved
}
}

Expand Down
35 changes: 31 additions & 4 deletions src/libs/DateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -920,23 +920,49 @@ const formatInTimeZoneWithFallback: typeof formatInTimeZone = (date, timeZone, f
}
};

/**
* Converts a UTC datetime string to a date string (yyyy-MM-dd) in the target timezone.
* @param utcDateTime - Datetime string in UTC format (yyyy-MM-dd HH:mm:ss or yyyy-MM-dd HH:mm:ss.SSS)
* @param timeZone - Target timezone to display the date in
* @returns Date string in yyyy-MM-dd format, or empty string if invalid
*/
function formatUTCDateTimeToDateInTimezone(utcDateTime: string, timeZone: SelectedTimezone | undefined, formatStr = CONST.DATE.FNS_FORMAT_STRING): string {
if (!utcDateTime || !timeZone) {
return '';
}
try {
const date = toDate(utcDateTime, {timeZone: 'UTC'});
return formatInTimeZoneWithFallback(date, timeZone, formatStr);
} catch (error) {
Log.warn('[DateUtils] Failed to format UTC datetime to timezone', {utcDateTime, timeZone, error});
return '';
}
Comment thread
nkdengineer marked this conversation as resolved.
Resolved
}

/**
* Backend expects datetime format without milliseconds in some cases (yyyy-MM-dd HH:mm:ss)
*/
function formatDBTimeWithoutMilliseconds(timestamp: number): string {
return getDBTime(timestamp).replace(/\.\d{3}$/, '');
}

/**
* Convert a date to UTC by taking midnight (00:00:00) in the user's local timezone and expressing it as a UTC timestamp
*/

const normalizeDateToStartOfDay = (fromDate: string, timeZone: SelectedTimezone): string => {
const normalizeDateToStartOfDay = (fromDate: string, timeZone: SelectedTimezone | undefined): string => {
const localDate = parse(fromDate, CONST.DATE.FNS_FORMAT_STRING, new Date());
const midnightLocal = startOfDay(localDate);
return getDBTime(fromZonedTime(midnightLocal, timeZone).valueOf());
return formatDBTimeWithoutMilliseconds(fromZonedTime(midnightLocal, timeZone ?? 'UTC').valueOf());
};

/**
* Convert a date to UTC by taking end of day (23:59:59) in the user's local timezone and expressing it as a UTC timestamp
*/
const normalizeDateToEndOfDay = (thruDate: string, timeZone: SelectedTimezone): string => {
const normalizeDateToEndOfDay = (thruDate: string, timeZone: SelectedTimezone | undefined): string => {
const localDate = parse(thruDate, CONST.DATE.FNS_FORMAT_STRING, new Date());
const endOfDayLocal = endOfDay(localDate);
return getDBTime(fromZonedTime(endOfDayLocal, timeZone).valueOf());
return formatDBTimeWithoutMilliseconds(fromZonedTime(endOfDayLocal, timeZone ?? 'UTC').valueOf());
};

/**
Expand Down Expand Up @@ -1083,6 +1109,7 @@ const DateUtils = {
getFormattedDateRangeForPerDiem,
getFormattedSplitDateRange,
formatInTimeZoneWithFallback,
formatUTCDateTimeToDateInTimezone,
normalizeDateToStartOfDay,
normalizeDateToEndOfDay,
getMonthDateRange,
Expand Down
39 changes: 33 additions & 6 deletions src/libs/actions/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,16 @@ function updateExpensifyCardTitle(workspaceAccountID: number, cardID: number, ne
API.write(WRITE_COMMANDS.UPDATE_EXPENSIFY_CARD_TITLE, parameters, {optimisticData, successData, failureData});
}

function updateExpensifyCardLimitType(workspaceAccountID: number, cardID: number, newLimitType: CardLimitType, oldLimitType?: CardLimitType) {
function updateExpensifyCardLimitType(
workspaceAccountID: number,
cardID: number,
newLimitType: CardLimitType,
timeZone: SelectedTimezone | undefined,
oldCardNameValuePairs?: Card['nameValuePairs'],
validFrom?: string,
validThru?: string,
shouldClearValidityDates?: boolean,
) {
const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST>> = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -921,7 +930,13 @@ function updateExpensifyCardLimitType(workspaceAccountID: number, cardID: number
[cardID]: {
nameValuePairs: {
limitType: newLimitType,
pendingFields: {limitType: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE},
pendingFields: {
limitType: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
validFrom: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
validThru: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
validFrom: shouldClearValidityDates ? null : validFrom,
validThru: shouldClearValidityDates ? null : validThru,
Comment on lines +938 to +939

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During the optimistic update for issue, raw date strings (yyyy-MM-dd) are written directly to the card's validity properties. Because the detail page reads these fields expecting UTC datetimes, it reinterprets the bare date string as midnight UTC. For users located in timezones behind UTC, this causes the displayed date to shift backward by one calendar day until the backend response returns the correctly normalized data, resulting in a temporary visual flicker (#99336)

},
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
pendingFields: {availableSpend: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE},
Expand All @@ -940,7 +955,7 @@ function updateExpensifyCardLimitType(workspaceAccountID: number, cardID: number
[cardID]: {
isLoading: false,
nameValuePairs: {
pendingFields: {limitType: null},
pendingFields: {limitType: null, validFrom: null, validThru: null},
},
pendingAction: null,
pendingFields: {availableSpend: null},
Expand All @@ -956,8 +971,10 @@ function updateExpensifyCardLimitType(workspaceAccountID: number, cardID: number
value: {
[cardID]: {
nameValuePairs: {
limitType: oldLimitType,
pendingFields: {limitType: null},
limitType: oldCardNameValuePairs?.limitType,
validFrom: oldCardNameValuePairs?.validFrom,
validThru: oldCardNameValuePairs?.validThru,
pendingFields: {limitType: null, validFrom: null, validThru: null},
},
pendingFields: {availableSpend: null},
pendingAction: null,
Expand All @@ -971,6 +988,9 @@ function updateExpensifyCardLimitType(workspaceAccountID: number, cardID: number
const parameters: UpdateExpensifyCardLimitTypeParams = {
cardID,
limitType: newLimitType,
validFrom: validFrom ? DateUtils.normalizeDateToStartOfDay(validFrom, timeZone) : undefined,
Comment thread
nkdengineer marked this conversation as resolved.
Resolved
validThru: validThru ? DateUtils.normalizeDateToEndOfDay(validThru, timeZone) : undefined,
clearValidityDates: shouldClearValidityDates,
};

API.write(WRITE_COMMANDS.UPDATE_EXPENSIFY_CARD_LIMIT_TYPE, parameters, {optimisticData, successData, failureData});
Expand Down Expand Up @@ -1174,7 +1194,14 @@ function configureExpensifyCardsForPolicy(policyID: string, workspaceAccountID:
});
}

function issueExpensifyCard(domainAccountID: number, policyID: string | undefined, feedCountry: string, validateCode: string, timeZone: SelectedTimezone, data?: IssueNewCardData) {
function issueExpensifyCard(
domainAccountID: number,
policyID: string | undefined,
feedCountry: string,
validateCode: string,
timeZone: SelectedTimezone | undefined,
data?: IssueNewCardData,
) {
if (!data) {
return;
}
Expand Down
12 changes: 11 additions & 1 deletion src/pages/workspace/expensifyCard/WorkspaceCardListHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function WorkspaceCardListHeader({cardSettings}: WorkspaceCardListHeaderProps) {
</Text>
</View>
{!shouldUseNarrowLayout && (
<View style={[styles.flexRow, styles.gap2, styles.flex1, styles.alignItemsCenter, styles.justifyContentStart]}>
<View style={[styles.flexRow, styles.gap2, styles.flex2, styles.alignItemsCenter, styles.justifyContentStart]}>
<Text
numberOfLines={1}
style={[styles.textMicroSupporting, styles.lh16]}
Expand All @@ -52,6 +52,16 @@ function WorkspaceCardListHeader({cardSettings}: WorkspaceCardListHeaderProps) {
</Text>
</View>
)}
{!shouldUseNarrowLayout && (
<View style={[styles.flexRow, styles.gap2, styles.flex2, styles.alignItemsCenter, styles.justifyContentStart]}>
<Text
numberOfLines={1}
style={[styles.textMicroSupporting, styles.lh16]}
>
{translate('workspace.card.issueNewCard.limitType')}
</Text>
</View>
)}
<View
style={[
styles.flexRow,
Expand Down
19 changes: 17 additions & 2 deletions src/pages/workspace/expensifyCard/WorkspaceCardListRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {getTranslationKeyForLimitType} from '@libs/CardUtils';
import {convertToShortDisplayString} from '@libs/CurrencyUtils';
import {getDisplayNameOrDefault} from '@libs/PersonalDetailsUtils';
import CONST from '@src/CONST';
import type {PersonalDetails} from '@src/types/onyx';
import type {CardLimitType} from '@src/types/onyx/Card';

type WorkspacesListRowProps = {
/** The last four digits of the card */
Expand All @@ -34,9 +36,12 @@ type WorkspacesListRowProps = {

/** Whether the list item is hovered */
isHovered?: boolean;

/** Card limit type */
limitType: CardLimitType | undefined;
};

function WorkspaceCardListRow({limit, cardholder, lastFourPAN, name, currency, isVirtual, isHovered}: WorkspacesListRowProps) {
function WorkspaceCardListRow({limit, cardholder, lastFourPAN, name, currency, isVirtual, isHovered, limitType}: WorkspacesListRowProps) {
const icons = useMemoizedLazyExpensifyIcons(['ArrowRight', 'FallbackAvatar']);
const {shouldUseNarrowLayout} = useResponsiveLayout();
const styles = useThemeStyles();
Expand Down Expand Up @@ -69,7 +74,7 @@ function WorkspaceCardListRow({limit, cardholder, lastFourPAN, name, currency, i
</View>
</View>
{!shouldUseNarrowLayout && (
<View style={[styles.flexRow, styles.gap2, styles.flex1, styles.alignItemsCenter, styles.justifyContentStart]}>
<View style={[styles.flexRow, styles.gap2, styles.flex2, styles.alignItemsCenter, styles.justifyContentStart]}>
Comment thread
nkdengineer marked this conversation as resolved.
Resolved
<Text
numberOfLines={1}
style={[styles.textNormalThemeText, styles.lh16]}
Expand All @@ -78,6 +83,16 @@ function WorkspaceCardListRow({limit, cardholder, lastFourPAN, name, currency, i
</Text>
</View>
)}
{!shouldUseNarrowLayout && (
<View style={[styles.flexRow, styles.gap2, styles.flex2, styles.alignItemsCenter, styles.justifyContentStart]}>
<Text
numberOfLines={1}
style={[styles.textNormalThemeText, styles.lh16]}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB but setting line height of 16 px caused g to be cut-off. We fixed this in #82320

>
{translate(getTranslationKeyForLimitType(limitType))}
</Text>
</View>
)}
<View
style={[
styles.flexRow,
Expand Down
Loading
Loading