diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index d9298817f6b7..35cf52a5ff99 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -234,7 +234,7 @@ function getOptionData({ result.isExpenseRequest = ReportUtils.isExpenseRequest(report); result.isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); result.shouldShowSubscript = ReportUtils.shouldReportShowSubscript(report); - result.pendingAction = report.pendingFields ? report.pendingFields.addWorkspaceRoom || report.pendingFields.createChat : undefined; + result.pendingAction = report.pendingFields?.addWorkspaceRoom ?? report.pendingFields?.createChat; result.brickRoadIndicator = hasErrors || hasViolations ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''; result.ownerAccountID = report.ownerAccountID; result.managerID = report.managerID; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 37308c73e724..ca43d92bde83 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -50,7 +50,7 @@ import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import type * as OnyxTypes from '@src/types/onyx'; import type {Participant, Split} from '@src/types/onyx/IOU'; -import type {ErrorFields, Errors, PendingFields} from '@src/types/onyx/OnyxCommon'; +import type {ErrorFields, Errors} from '@src/types/onyx/OnyxCommon'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; import type ReportAction from '@src/types/onyx/ReportAction'; import type {OnyxData} from '@src/types/onyx/Request'; @@ -302,7 +302,7 @@ function setMoneyRequestMerchant(transactionID: string, merchant: string, isDraf Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {merchant}); } -function setMoneyRequestPendingFields(transactionID: string, pendingFields: PendingFields) { +function setMoneyRequestPendingFields(transactionID: string, pendingFields: OnyxTypes.Transaction['pendingFields']) { Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {pendingFields}); } diff --git a/src/types/onyx/BankAccount.ts b/src/types/onyx/BankAccount.ts index b9d541b72f2e..d0f80708842c 100644 --- a/src/types/onyx/BankAccount.ts +++ b/src/types/onyx/BankAccount.ts @@ -11,7 +11,7 @@ type AdditionalData = { country?: string; }; -type BankAccount = { +type BankAccount = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** The bank account type */ accountType?: typeof CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT; @@ -40,10 +40,7 @@ type BankAccount = { /** Any additional error message to show */ errors?: OnyxCommon.Errors; - - /** Indicates the type of change made to the bank account that hasn't been synced with the server yet */ - pendingAction?: OnyxCommon.PendingAction; -}; +}>; type BankAccountList = Record; diff --git a/src/types/onyx/Fund.ts b/src/types/onyx/Fund.ts index 3073172a5eec..a3c0a95849d1 100644 --- a/src/types/onyx/Fund.ts +++ b/src/types/onyx/Fund.ts @@ -25,7 +25,7 @@ type AccountData = { bank?: BankName; }; -type Fund = { +type Fund = OnyxCommon.OnyxValueWithOfflineFeedback<{ accountData?: AccountData; accountType?: typeof CONST.PAYMENT_METHODS.DEBIT_CARD; description?: string; @@ -34,8 +34,7 @@ type Fund = { title?: string; isDefault?: boolean; errors?: OnyxCommon.Errors; - pendingAction?: OnyxCommon.PendingAction; -}; +}>; type FundList = Record; diff --git a/src/types/onyx/Login.ts b/src/types/onyx/Login.ts index 317c2b95c9b6..fec12da1b8e4 100644 --- a/src/types/onyx/Login.ts +++ b/src/types/onyx/Login.ts @@ -1,24 +1,24 @@ import type * as OnyxCommon from './OnyxCommon'; -type Login = { - /** Phone/Email associated with user */ - partnerUserID?: string; +type Login = OnyxCommon.OnyxValueWithOfflineFeedback< + { + /** Phone/Email associated with user */ + partnerUserID?: string; - /** Value of partner name */ - partnerName?: string; + /** Value of partner name */ + partnerName?: string; - /** Date login was validated, used to show info indicator status */ - validatedDate?: string; + /** Date login was validated, used to show info indicator status */ + validatedDate?: string; - /** Whether the user validation code was sent */ - validateCodeSent?: boolean; + /** Whether the user validation code was sent */ + validateCodeSent?: boolean; - /** Field-specific server side errors keyed by microtime */ - errorFields?: OnyxCommon.ErrorFields; - - /** Field-specific pending states for offline UI status */ - pendingFields?: OnyxCommon.PendingFields; -}; + /** Field-specific server side errors keyed by microtime */ + errorFields?: OnyxCommon.ErrorFields; + }, + 'defaultLogin' | 'validateLogin' | 'addedLogin' | 'deletedLogin' +>; type LoginList = Record; diff --git a/src/types/onyx/OnyxCommon.ts b/src/types/onyx/OnyxCommon.ts index 599f0dde66c2..1c5d46610286 100644 --- a/src/types/onyx/OnyxCommon.ts +++ b/src/types/onyx/OnyxCommon.ts @@ -3,9 +3,19 @@ import type {MaybePhraseKey} from '@libs/Localize'; import type {AvatarSource} from '@libs/UserUtils'; import type CONST from '@src/CONST'; -type PendingAction = ValueOf; +type PendingAction = ValueOf | null; -type PendingFields = Record; +type PendingFields = {[key in Exclude]?: PendingAction}; + +type OfflineFeedback = { + /** The type of action that's pending */ + pendingAction?: PendingAction; + + /** Field-specific pending states for offline updates */ + pendingFields?: PendingFields; +}; + +type OnyxValueWithOfflineFeedback = keyof TOnyx extends string ? TOnyx & OfflineFeedback : never; type ErrorFields = Record; @@ -33,4 +43,4 @@ type Icon = { fill?: string; }; -export type {Icon, PendingAction, PendingFields, ErrorFields, Errors, AvatarType}; +export type {Icon, PendingAction, ErrorFields, Errors, AvatarType, OnyxValueWithOfflineFeedback}; diff --git a/src/types/onyx/PersonalDetails.ts b/src/types/onyx/PersonalDetails.ts index 8d02d7cf26fc..42482f9104dc 100644 --- a/src/types/onyx/PersonalDetails.ts +++ b/src/types/onyx/PersonalDetails.ts @@ -23,7 +23,7 @@ type Status = { clearAfter: string; // ISO 8601 format; }; -type PersonalDetails = { +type PersonalDetails = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** ID of the current user from their personal details */ accountID: number; @@ -74,15 +74,12 @@ type PersonalDetails = { /** Field-specific server side errors keyed by microtime */ errorFields?: OnyxCommon.ErrorFields<'avatar'>; - /** Field-specific pending states for offline UI status */ - pendingFields?: OnyxCommon.PendingFields<'avatar' | 'originalFileName'>; - /** A fallback avatar icon to display when there is an error on loading avatar from remote URL. */ fallbackIcon?: string; /** Status of the current user from their personal details */ status?: Status; -}; +}>; type PersonalDetailsList = Record; diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index b79325611e9f..1662a76c02df 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -4,30 +4,28 @@ import type * as OnyxCommon from './OnyxCommon'; type Unit = 'mi' | 'km'; -type Rate = { +type Rate = OnyxCommon.OnyxValueWithOfflineFeedback<{ name?: string; rate?: number; currency?: string; customUnitRateID?: string; errors?: OnyxCommon.Errors; - pendingAction?: OnyxCommon.PendingAction; enabled?: boolean; -}; +}>; type Attributes = { unit: Unit; }; -type CustomUnit = { +type CustomUnit = OnyxCommon.OnyxValueWithOfflineFeedback<{ name: string; customUnitID: string; attributes: Attributes; rates: Record; defaultCategory?: string; enabled?: boolean; - pendingAction?: OnyxCommon.PendingAction; errors?: OnyxCommon.Errors; -}; +}>; type DisabledFields = { defaultBillable?: boolean; @@ -84,153 +82,150 @@ type Connection = { type AutoReportingOffset = number | ValueOf; -type Policy = { - /** The ID of the policy */ - id: string; - - /** The name of the policy */ - name: string; - - /** The current user's role in the policy */ - role: ValueOf; +type Policy = OnyxCommon.OnyxValueWithOfflineFeedback< + { + /** The ID of the policy */ + id: string; - /** The policy type */ - type: ValueOf; + /** The name of the policy */ + name: string; - /** The email of the policy owner */ - owner: string; + /** The current user's role in the policy */ + role: ValueOf; - /** The accountID of the policy owner */ - ownerAccountID?: number; + /** The policy type */ + type: ValueOf; - /** The output currency for the policy */ - outputCurrency: string; + /** The email of the policy owner */ + owner: string; - /** The URL for the policy avatar */ - avatar?: string; + /** The accountID of the policy owner */ + ownerAccountID?: number; - /** Error objects keyed by field name containing errors keyed by microtime */ - errorFields?: OnyxCommon.ErrorFields; + /** The output currency for the policy */ + outputCurrency: string; - /** Indicates the type of change made to the policy that hasn't been synced with the server yet */ - pendingAction?: OnyxCommon.PendingAction; + /** The URL for the policy avatar */ + avatar?: string; - /** A list of errors keyed by microtime */ - errors?: OnyxCommon.Errors; + /** Error objects keyed by field name containing errors keyed by microtime */ + errorFields?: OnyxCommon.ErrorFields; - /** Whether this policy was loaded from a policy summary, or loaded completely with all of its values */ - isFromFullPolicy?: boolean; + /** A list of errors keyed by microtime */ + errors?: OnyxCommon.Errors; - /** When this policy was last modified */ - lastModified?: string; + /** Whether this policy was loaded from a policy summary, or loaded completely with all of its values */ + isFromFullPolicy?: boolean; - /** The custom units data for this policy */ - customUnits?: Record; + /** When this policy was last modified */ + lastModified?: string; - /** Whether policy expense chats can be created and used on this policy. Enabled manually by CQ/JS snippet. Always true for free policies. */ - isPolicyExpenseChatEnabled: boolean; + /** The custom units data for this policy */ + customUnits?: Record; - /** Whether the auto reporting is enabled */ - autoReporting?: boolean; + /** Whether policy expense chats can be created and used on this policy. Enabled manually by CQ/JS snippet. Always true for free policies. */ + isPolicyExpenseChatEnabled: boolean; - /** The scheduled submit frequency set up on this policy */ - autoReportingFrequency?: ValueOf; + /** Whether the auto reporting is enabled */ + autoReporting?: boolean; - /** Whether the scheduled submit is enabled */ - harvesting?: { - enabled: boolean; - }; + /** The scheduled submit frequency set up on this policy */ + autoReportingFrequency?: ValueOf; - /** @deprecated Whether the self approval or submitting is enabled */ - isPreventSelfApprovalEnabled?: boolean; + /** Whether the scheduled submit is enabled */ + harvesting?: { + enabled: boolean; + }; - /** Whether the self approval or submitting is enabled */ - preventSelfApprovalEnabled?: boolean; + /** @deprecated Whether the scheduled submit is enabled */ + isPreventSelfApprovalEnabled?: boolean; - /** When the monthly scheduled submit should happen */ - autoReportingOffset?: AutoReportingOffset; + /** Whether the self approval or submitting is enabled */ + preventSelfApprovalEnabled?: boolean; - /** The accountID of manager who the employee submits their expenses to on paid policies */ - submitsTo?: number; + /** When the monthly scheduled submit should happen */ + autoReportingOffset?: AutoReportingOffset; - /** The employee list of the policy */ - employeeList?: []; + /** The accountID of manager who the employee submits their expenses to on paid policies */ + submitsTo?: number; - /** The reimbursement choice for policy */ - reimbursementChoice?: ValueOf; + /** The employee list of the policy */ + employeeList?: []; - /** The maximum report total allowed to trigger auto reimbursement. */ - autoReimbursementLimit?: number; + /** The reimbursement choice for policy */ + reimbursementChoice?: ValueOf; - /** Whether to leave the calling account as an admin on the policy */ - makeMeAdmin?: boolean; + /** The maximum report total allowed to trigger auto reimbursement. */ + autoReimbursementLimit?: number; - /** Pending fields for the policy */ - pendingFields?: Record; + /** Whether to leave the calling account as an admin on the policy */ + makeMeAdmin?: boolean; - /** Original file name which is used for the policy avatar */ - originalFileName?: string; + /** Original file name which is used for the policy avatar */ + originalFileName?: string; - /** Alert message for the policy */ - alertMessage?: string; + /** Alert message for the policy */ + alertMessage?: string; - /** Informative messages about which policy members were added with primary logins when invited with their secondary login */ - primaryLoginsInvited?: Record; + /** Informative messages about which policy members were added with primary logins when invited with their secondary login */ + primaryLoginsInvited?: Record; - /** Whether policy is updating */ - isPolicyUpdating?: boolean; + /** Whether policy is updating */ + isPolicyUpdating?: boolean; - /** The approver of the policy */ - approver?: string; + /** The approver of the policy */ + approver?: string; - /** The approval mode set up on this policy */ - approvalMode?: ValueOf; + /** The approval mode set up on this policy */ + approvalMode?: ValueOf; - /** Whether the auto approval is enabled */ - isAutoApprovalEnabled?: boolean; + /** Whether the auto approval is enabled */ + isAutoApprovalEnabled?: boolean; - /** Whether transactions should be billable by default */ - defaultBillable?: boolean; + /** Whether transactions should be billable by default */ + defaultBillable?: boolean; - /** The workspace description */ - description?: string; + /** The workspace description */ + description?: string; - /** List of field names that are disabled */ - disabledFields?: DisabledFields; + /** List of field names that are disabled */ + disabledFields?: DisabledFields; - /** Whether new transactions need to be tagged */ - requiresTag?: boolean; + /** Whether new transactions need to be tagged */ + requiresTag?: boolean; - /** Whether new transactions need to be categorized */ - requiresCategory?: boolean; + /** Whether new transactions need to be categorized */ + requiresCategory?: boolean; - /** Whether the workspace has multiple levels of tags enabled */ - hasMultipleTagLists?: boolean; + /** Whether the workspace has multiple levels of tags enabled */ + hasMultipleTagLists?: boolean; - /** - * Whether or not the policy has tax tracking enabled - * - * @deprecated - use tax.trackingEnabled instead - */ - isTaxTrackingEnabled?: boolean; + /** + * Whether or not the policy has tax tracking enabled + * + * @deprecated - use tax.trackingEnabled instead + */ + isTaxTrackingEnabled?: boolean; - /** Whether or not the policy has tax tracking enabled */ - tax?: { - trackingEnabled: boolean; - }; + /** Whether or not the policy has tax tracking enabled */ + tax?: { + trackingEnabled: boolean; + }; - /** Collection of tax rates attached to a policy */ - taxRates?: TaxRatesWithDefault; + /** Collection of tax rates attached to a policy */ + taxRates?: TaxRatesWithDefault; - /** ReportID of the admins room for this workspace */ - chatReportIDAdmins?: number; + /** ReportID of the admins room for this workspace */ + chatReportIDAdmins?: number; - /** ReportID of the announce room for this workspace */ - chatReportIDAnnounce?: number; + /** ReportID of the announce room for this workspace */ + chatReportIDAnnounce?: number; - /** All the integration connections attached to the policy */ - connections?: Record; -}; + /** All the integration connections attached to the policy */ + connections?: Record; + }, + 'generalSettings' | 'addWorkspaceRoom' +>; export default Policy; diff --git a/src/types/onyx/PolicyMember.ts b/src/types/onyx/PolicyMember.ts index 6439888b9144..f68fe194df0e 100644 --- a/src/types/onyx/PolicyMember.ts +++ b/src/types/onyx/PolicyMember.ts @@ -1,6 +1,6 @@ import type * as OnyxCommon from './OnyxCommon'; -type PolicyMember = { +type PolicyMember = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** Role of the user in the policy */ role?: string; @@ -9,10 +9,7 @@ type PolicyMember = { * {: 'error message', : 'error message 2'} */ errors?: OnyxCommon.Errors; - - /** Is this action pending? */ - pendingAction?: OnyxCommon.PendingAction; -}; +}>; type PolicyMembers = Record; diff --git a/src/types/onyx/ReimbursementAccount.ts b/src/types/onyx/ReimbursementAccount.ts index 5b16d15bf5cc..3f256162863b 100644 --- a/src/types/onyx/ReimbursementAccount.ts +++ b/src/types/onyx/ReimbursementAccount.ts @@ -37,7 +37,7 @@ type ACHData = Partial; export default ReimbursementAccount; export type {BankAccountStep, BankAccountSubStep, ACHData}; diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index f5c4606fd335..bb86d2cf4ae4 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -10,11 +10,10 @@ type WriteCapability = ValueOf; type RoomVisibility = ValueOf; -type Note = { +type Note = OnyxCommon.OnyxValueWithOfflineFeedback<{ note: string; errors?: OnyxCommon.Errors; - pendingAction?: OnyxCommon.PendingAction; -}; +}>; type Participant = { hidden: boolean; @@ -23,160 +22,157 @@ type Participant = { type Participants = Record; -type Report = { - /** The specific type of chat */ - chatType?: ValueOf; - - /** Whether the report has a child that is an outstanding money request that is awaiting action from the current user */ - hasOutstandingChildRequest?: boolean; - - /** List of icons for report participants */ - icons?: OnyxCommon.Icon[]; +type Report = OnyxCommon.OnyxValueWithOfflineFeedback< + { + /** The specific type of chat */ + chatType?: ValueOf; - /** Whether the user is not an admin of policyExpenseChat chat */ - isOwnPolicyExpenseChat?: boolean; + /** Whether the report has a child that is an outstanding money request that is awaiting action from the current user */ + hasOutstandingChildRequest?: boolean; - /** Whether the report is policyExpenseChat */ - isPolicyExpenseChat?: boolean; + /** List of icons for report participants */ + icons?: OnyxCommon.Icon[]; - /** Indicates if the report is pinned to the LHN or not */ - isPinned?: boolean; + /** Whether the user is not an admin of policyExpenseChat chat */ + isOwnPolicyExpenseChat?: boolean; - /** The text of the last message on the report */ - lastMessageText?: string; + /** Whether the report is policyExpenseChat */ + isPolicyExpenseChat?: boolean; - /** The timestamp of the last message on the report */ - lastMessageTimestamp?: number; + /** Indicates if the report is pinned to the LHN or not */ + isPinned?: boolean; - /** The time of the last message on the report */ - lastVisibleActionCreated?: string; + /** The text of the last message on the report */ + lastMessageText?: string; - /** The time of the last read of the report */ - lastReadCreated?: string; + /** The timestamp of the last message on the report */ + lastMessageTimestamp?: number; - /** The time when user read the last message */ - lastReadTime?: string; + /** The time of the last message on the report */ + lastVisibleActionCreated?: string; - /** The sequence number of the last report visit */ - lastReadSequenceNumber?: number; + /** The time of the last read of the report */ + lastReadCreated?: string; - /** The time of the last mention of the report */ - lastMentionedTime?: string | null; + /** The time when user read the last message */ + lastReadTime?: string; - /** The current user's notification preference for this report */ - notificationPreference?: NotificationPreference; + /** The sequence number of the last report visit */ + lastReadSequenceNumber?: number; - /** The policy name to use */ - policyName?: string | null; + /** The time of the last mention of the report */ + lastMentionedTime?: string | null; - /** The policy name to use for an archived report */ - oldPolicyName?: string; + /** The current user's notification preference for this report */ + notificationPreference?: NotificationPreference; - /** Whether the report has parent access */ - hasParentAccess?: boolean; + /** The policy name to use */ + policyName?: string | null; - /** Description of the report */ - description?: string; + /** The policy name to use for an archived report */ + oldPolicyName?: string; - /** Whether the parent action was deleted */ - isDeletedParentAction?: boolean; + /** Whether the report has parent access */ + hasParentAccess?: boolean; - /** Linked policy's ID */ - policyID?: string; + /** Description of the report */ + description?: string; - /** Name of the report */ - reportName?: string; + /** Whether the parent action was deleted */ + isDeletedParentAction?: boolean; - /** ID of the report */ - reportID: string; + /** Linked policy's ID */ + policyID?: string; - /** ID of the report action */ - reportActionID?: string; + /** Name of the report */ + reportName?: string; - /** ID of the chat report */ - chatReportID?: string; + /** ID of the report */ + reportID: string; - /** The state that the report is currently in */ - stateNum?: ValueOf; + /** ID of the report action */ + reportActionID?: string; - /** The status of the current report */ - statusNum?: ValueOf; + /** ID of the chat report */ + chatReportID?: string; - /** Which user role is capable of posting messages on the report */ - writeCapability?: WriteCapability; + /** The state that the report is currently in */ + stateNum?: ValueOf; - /** The report type */ - type?: string; + /** The status of the current report */ + statusNum?: ValueOf; - /** If the admin room should be opened */ - openOnAdminRoom?: boolean; + /** Which user role is capable of posting messages on the report */ + writeCapability?: WriteCapability; - /** The report visibility */ - visibility?: RoomVisibility; + /** The report type */ + type?: string; - /** Report cached total */ - cachedTotal?: string; + /** If the admin room should be opened */ + openOnAdminRoom?: boolean; - lastMessageTranslationKey?: string; - parentReportID?: string; - parentReportActionID?: string; - isOptimisticReport?: boolean; - hasDraft?: boolean; - managerID?: number; - lastVisibleActionLastModified?: string; - displayName?: string; - lastMessageHtml?: string; - lastActorAccountID?: number; - ownerAccountID?: number; - ownerEmail?: string; - participants?: Participants; - participantAccountIDs?: number[]; - visibleChatMemberAccountIDs?: number[]; - total?: number; - currency?: string; - errors?: OnyxCommon.Errors; - managerEmail?: string; - parentReportActionIDs?: number[]; - errorFields?: OnyxCommon.ErrorFields; - - /** Whether the report is waiting on a bank account */ - isWaitingOnBankAccount?: boolean; + /** The report visibility */ + visibility?: RoomVisibility; - /** Whether the report is cancelled */ - isCancelledIOU?: boolean; + /** Report cached total */ + cachedTotal?: string; - /** Whether the last message was deleted */ - isLastMessageDeletedParentAction?: boolean; + lastMessageTranslationKey?: string; + parentReportID?: string; + parentReportActionID?: string; + isOptimisticReport?: boolean; + hasDraft?: boolean; + managerID?: number; + lastVisibleActionLastModified?: string; + displayName?: string; + lastMessageHtml?: string; + lastActorAccountID?: number; + ownerAccountID?: number; + ownerEmail?: string; + participants?: Participants; + participantAccountIDs?: number[]; + visibleChatMemberAccountIDs?: number[]; + total?: number; + currency?: string; + errors?: OnyxCommon.Errors; + managerEmail?: string; + parentReportActionIDs?: number[]; + errorFields?: OnyxCommon.ErrorFields; - /** The ID of the IOU report */ - iouReportID?: string; + /** Whether the report is waiting on a bank account */ + isWaitingOnBankAccount?: boolean; - /** Total amount of money owed for IOU report */ - iouReportAmount?: number; + /** Whether the report is cancelled */ + isCancelledIOU?: boolean; - /** Is this action pending? */ - pendingAction?: OnyxCommon.PendingAction; + /** Whether the last message was deleted */ + isLastMessageDeletedParentAction?: boolean; - /** Pending fields for the report */ - pendingFields?: Record; + /** The ID of the IOU report */ + iouReportID?: string; - /** The ID of the preexisting report (it is possible that we optimistically created a Report for which a report already exists) */ - preexistingReportID?: string; + /** Total amount of money owed for IOU report */ + iouReportAmount?: number; - /** If the report contains nonreimbursable expenses, send the nonreimbursable total */ - nonReimbursableTotal?: number; - isHidden?: boolean; - isChatRoom?: boolean; - participantsList?: PersonalDetails[]; - text?: string; - updateReportInLHN?: boolean; - privateNotes?: Record; - isLoadingPrivateNotes?: boolean; - selected?: boolean; + /** The ID of the preexisting report (it is possible that we optimistically created a Report for which a report already exists) */ + preexistingReportID?: string; - /** If the report contains reportFields, save the field id and its value */ - reportFields?: Record; -}; + /** If the report contains nonreimbursable expenses, send the nonreimbursable total */ + nonReimbursableTotal?: number; + isHidden?: boolean; + isChatRoom?: boolean; + participantsList?: PersonalDetails[]; + text?: string; + updateReportInLHN?: boolean; + privateNotes?: Record; + isLoadingPrivateNotes?: boolean; + selected?: boolean; + + /** If the report contains reportFields, save the field id and its value */ + reportFields?: Record; + }, + PolicyReportField['fieldID'] +>; export default Report; diff --git a/src/types/onyx/ReportAction.ts b/src/types/onyx/ReportAction.ts index ed3173381b32..9d24a5048455 100644 --- a/src/types/onyx/ReportAction.ts +++ b/src/types/onyx/ReportAction.ts @@ -111,7 +111,7 @@ type Person = { text?: string; }; -type ReportActionBase = { +type ReportActionBase = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** The ID of the reportAction. It is the string representation of the a 64-bit integer. */ reportActionID: string; @@ -189,8 +189,6 @@ type ReportActionBase = { /** ISO-formatted datetime */ lastModified?: string; - /** Is this action pending? */ - pendingAction?: OnyxCommon.PendingAction; delegateAccountID?: number; /** Server side errors keyed by microtime */ @@ -216,7 +214,7 @@ type ReportActionBase = { /** Flag for checking if data is from optimistic data */ isOptimisticAction?: boolean; -}; +}>; type ReportAction = ReportActionBase & OriginalMessage; diff --git a/src/types/onyx/ReportActionReactions.ts b/src/types/onyx/ReportActionReactions.ts index be117aafc4c5..983598e0b420 100644 --- a/src/types/onyx/ReportActionReactions.ts +++ b/src/types/onyx/ReportActionReactions.ts @@ -13,7 +13,7 @@ type UserReaction = { type UsersReactions = Record; -type ReportActionReaction = { +type ReportActionReaction = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** The time the emoji was added */ createdAt: string; @@ -22,10 +22,7 @@ type ReportActionReaction = { /** All the users who have added this emoji */ users: UsersReactions; - - /** Is this action pending? */ - pendingAction?: OnyxCommon.PendingAction; -}; +}>; type ReportActionReactions = Record; diff --git a/src/types/onyx/Transaction.ts b/src/types/onyx/Transaction.ts index 1324bb9c6902..44f7e529f5eb 100644 --- a/src/types/onyx/Transaction.ts +++ b/src/types/onyx/Transaction.ts @@ -1,4 +1,4 @@ -import type {ValueOf} from 'type-fest'; +import type {KeysOfUnion, ValueOf} from 'type-fest'; import type CONST from '@src/CONST'; import type {Participant, Split} from './IOU'; import type * as OnyxCommon from './OnyxCommon'; @@ -75,8 +75,6 @@ type Route = { type Routes = Record; -type TransactionPendingFieldsKey = keyof Transaction | keyof Comment; - type ReceiptError = {error?: string; source: string; filename: string}; type ReceiptErrors = Record; @@ -96,126 +94,125 @@ type TaxRate = { data?: TaxRateData; }; -type Transaction = { - /** The original transaction amount */ - amount: number; - - /** Whether the request is billable */ - billable?: boolean; +type Transaction = OnyxCommon.OnyxValueWithOfflineFeedback< + { + /** The original transaction amount */ + amount: number; - /** The category name */ - category?: string; + /** Whether the request is billable */ + billable?: boolean; - /** The comment object on the transaction */ - comment: Comment; + /** The category name */ + category?: string; - /** Date that the request was created */ - created: string; + /** The comment object on the transaction */ + comment: Comment; - /** The original currency of the transaction */ - currency: string; + /** Date that the request was created */ + created: string; - /** Any additional error message to show */ - errors?: OnyxCommon.Errors | ReceiptErrors; + /** The original currency of the transaction */ + currency: string; - /** Server side errors keyed by microtime */ - errorFields?: OnyxCommon.ErrorFields<'route'>; + /** Any additional error message to show */ + errors?: OnyxCommon.Errors | ReceiptErrors; - /** The name of the file used for a receipt (formerly receiptFilename) */ - filename?: string; + /** Server side errors keyed by microtime */ + errorFields?: OnyxCommon.ErrorFields<'route'>; - /** Used during the creation flow before the transaction is saved to the server */ - iouRequestType?: ValueOf; + /** The name of the file used for a receipt (formerly receiptFilename) */ + filename?: string; - /** The original merchant name */ - merchant: string; + /** Used during the creation flow before the transaction is saved to the server */ + iouRequestType?: ValueOf; - /** The edited transaction amount */ - modifiedAmount?: number; + /** The original merchant name */ + merchant: string; - /** The edited transaction date */ - modifiedCreated?: string; + /** The edited transaction amount */ + modifiedAmount?: number; - /** The edited currency of the transaction */ - modifiedCurrency?: string; + /** The edited transaction date */ + modifiedCreated?: string; - /** The edited merchant name */ - modifiedMerchant?: string; + /** The edited currency of the transaction */ + modifiedCurrency?: string; - /** The edited waypoints for the distance request */ - modifiedWaypoints?: WaypointCollection; + /** The edited merchant name */ + modifiedMerchant?: string; - /** - * Used during the creation flow before the transaction is saved to the server and helps dictate where - * the user is navigated to when pressing the back button on the confirmation step - */ - participantsAutoAssigned?: boolean; + /** The edited waypoints for the distance request */ + modifiedWaypoints?: WaypointCollection; - /** Selected participants */ - participants?: Participant[]; + /** + * Used during the creation flow before the transaction is saved to the server and helps dictate where + * the user is navigated to when pressing the back button on the confirmation step + */ + participantsAutoAssigned?: boolean; - /** The type of action that's pending */ - pendingAction?: OnyxCommon.PendingAction; + /** Selected participants */ + participants?: Participant[]; - /** The receipt object associated with the transaction */ - receipt?: Receipt; + /** The receipt object associated with the transaction */ + receipt?: Receipt; - /** The iouReportID associated with the transaction */ - reportID: string; + /** The iouReportID associated with the transaction */ + reportID: string; - /** Existing routes */ - routes?: Routes; + /** Existing routes */ + routes?: Routes; - /** The transaction id */ - transactionID: string; + /** The transaction id */ + transactionID: string; - /** The transaction tag */ - tag?: string; + /** The transaction tag */ + tag?: string; - /** Whether the transaction was created globally */ - isFromGlobalCreate?: boolean; + /** Whether the transaction was created globally */ + isFromGlobalCreate?: boolean; - /** The transaction tax rate */ - taxRate?: TaxRate; + /** The transaction tax rate */ + taxRate?: TaxRate; - /** Tax amount */ - taxAmount?: number; + /** Tax amount */ + taxAmount?: number; - /** Pending fields for the transaction */ - pendingFields?: Partial<{[K in keyof Transaction | keyof Comment]: ValueOf}>; + /** Card Transactions */ - /** Card Transactions */ + /** The parent transaction id */ + parentTransactionID?: string; - /** The parent transaction id */ - parentTransactionID?: string; + /** Whether the expense is reimbursable or not */ + reimbursable?: boolean; - /** Whether the expense is reimbursable or not */ - reimbursable?: boolean; + /** The CC for this transaction */ + cardID?: number; - /** The CC for this transaction */ - cardID?: number; + /** If the transaction is pending or posted */ + status?: ValueOf; - /** If the transaction is pending or posted */ - status?: ValueOf; + /** If an EReceipt should be generated for this transaction */ + hasEReceipt?: boolean; - /** If an EReceipt should be generated for this transaction */ - hasEReceipt?: boolean; + /** The MCC Group for this transaction */ + mccGroup?: ValueOf; - /** The MCC Group for this transaction */ - mccGroup?: ValueOf; + /** Modified MCC Group */ + modifiedMCCGroup?: ValueOf; - /** Modified MCC Group */ - modifiedMCCGroup?: ValueOf; + /** If the transaction was made in a foreign currency, we send the original amount and currency */ + originalAmount?: number; - /** If the transaction was made in a foreign currency, we send the original amount and currency */ - originalAmount?: number; + /** The original currency of the transaction */ + originalCurrency?: string; - /** The original currency of the transaction */ - originalCurrency?: string; + /** Indicates transaction loading */ + isLoading?: boolean; + }, + keyof Comment +>; - /** Indicates transaction loading */ - isLoading?: boolean; -}; +type TransactionPendingFieldsKey = KeysOfUnion; type AdditionalTransactionChanges = { comment?: string;