diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 804c8dadd553..0405edbd4189 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -336,6 +336,7 @@ const ONYXKEYS = { WORKSPACE_INVITE_MEMBERS_DRAFT: 'workspaceInviteMembersDraft_', WORKSPACE_INVITE_MESSAGE_DRAFT: 'workspaceInviteMessageDraft_', REPORT: 'report_', + REPORT_NAME_VALUE_PAIRS: 'reportNameValuePairs_', REPORT_DRAFT: 'reportDraft_', // REPORT_METADATA is a perf optimization used to hold loading states (isLoadingInitialReportActions, isLoadingOlderReportActions, isLoadingNewerReportActions). // A lot of components are connected to the Report entity and do not care about the actions. Setting the loading state @@ -548,6 +549,7 @@ type OnyxCollectionValuesMapping = { [ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT]: OnyxTypes.InvitedEmailsToAccountIDs; [ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MESSAGE_DRAFT]: string; [ONYXKEYS.COLLECTION.REPORT]: OnyxTypes.Report; + [ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS]: OnyxTypes.ReportNameValuePairs; [ONYXKEYS.COLLECTION.REPORT_DRAFT]: OnyxTypes.Report; [ONYXKEYS.COLLECTION.REPORT_METADATA]: OnyxTypes.ReportMetadata; [ONYXKEYS.COLLECTION.REPORT_ACTIONS]: OnyxTypes.ReportActions; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a7147c7e3754..295ea99a57aa 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -29,6 +29,7 @@ import type { Report, ReportAction, ReportMetadata, + ReportNameValuePairs, Session, Task, Transaction, @@ -1223,7 +1224,11 @@ function isClosedExpenseReportWithNoExpenses(report: OnyxEntry): boolean /** * Whether the provided report is an archived room */ -function isArchivedRoom(report: OnyxEntry | EmptyObject): boolean { +function isArchivedRoom(report: OnyxEntry | EmptyObject, reportNameValuePairs?: OnyxEntry | EmptyObject): boolean { + if (reportNameValuePairs) { + return reportNameValuePairs.isArchived; + } + return report?.statusNum === CONST.REPORT.STATUS_NUM.CLOSED && report?.stateNum === CONST.REPORT.STATE_NUM.APPROVED; } @@ -5770,7 +5775,7 @@ function isMoneyRequestReportPendingDeletion(report: OnyxEntry | EmptyOb return parentReportAction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; } -function canUserPerformWriteAction(report: OnyxEntry) { +function canUserPerformWriteAction(report: OnyxEntry, reportNameValuePairs?: OnyxEntry) { const reportErrors = getAddWorkspaceRoomOrChatReportErrors(report); // If the expense report is marked for deletion, let us prevent any further write action. @@ -5778,7 +5783,7 @@ function canUserPerformWriteAction(report: OnyxEntry) { return false; } - return !isArchivedRoom(report) && isEmptyObject(reportErrors) && report && isAllowedToComment(report) && !isAnonymousUser && canWriteInReport(report); + return !isArchivedRoom(report, reportNameValuePairs) && isEmptyObject(reportErrors) && report && isAllowedToComment(report) && !isAnonymousUser && canWriteInReport(report); } /** diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index d4f554f4f7ab..31fdcfcab6db 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -81,6 +81,8 @@ type ReportScreenOnyxPropsWithoutParentReportAction = { /** The report currently being looked at */ report: OnyxEntry; + reportNameValuePairs: OnyxEntry; + /** The report metadata loading states */ reportMetadata: OnyxEntry; }; @@ -133,6 +135,7 @@ function ReportScreen({ betas = [], route, report: reportProp, + reportNameValuePairs, sortedAllReportActions, reportMetadata = { isLoadingInitialReportActions: true, @@ -725,6 +728,7 @@ function ReportScreen({ onComposerFocus={() => setIsComposerFocus(true)} onComposerBlur={() => setIsComposerFocus(false)} report={report} + reportNameValuePairs={reportNameValuePairs} pendingAction={reportPendingAction} isComposerFullSize={!!isComposerFullSize} listHeight={listHeight} @@ -761,6 +765,10 @@ export default withCurrentReportID( key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${getReportID(route)}`, allowStaleData: true, }, + reportNameValuePairs: { + key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${getReportID(route)}`, + allowStaleData: true, + }, reportMetadata: { key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_METADATA}${getReportID(route)}`, initialValue: { diff --git a/src/pages/home/report/ReportFooter.tsx b/src/pages/home/report/ReportFooter.tsx index b128b83f88fc..359d6ba93c15 100644 --- a/src/pages/home/report/ReportFooter.tsx +++ b/src/pages/home/report/ReportFooter.tsx @@ -36,6 +36,8 @@ type ReportFooterProps = ReportFooterOnyxProps & { /** Report object for the current report */ report?: OnyxTypes.Report; + reportNameValuePairs?: OnyxEntry; + /** The last report action */ lastReportAction?: OnyxEntry; @@ -66,6 +68,7 @@ function ReportFooter({ pendingAction, session, report = {reportID: '0'}, + reportNameValuePairs, shouldShowComposeInput = false, isEmptyChat = true, isReportReadyForDisplay = true, @@ -78,11 +81,11 @@ function ReportFooter({ const {isOffline} = useNetwork(); const {windowWidth, isSmallScreenWidth} = useWindowDimensions(); const chatFooterStyles = {...styles.chatFooter, minHeight: !isOffline ? CONST.CHAT_FOOTER_MIN_HEIGHT : 0}; - const isArchivedRoom = ReportUtils.isArchivedRoom(report); + const isArchivedRoom = ReportUtils.isArchivedRoom(report, reportNameValuePairs); const isAnonymousUser = session?.authTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS; const isSmallSizeLayout = windowWidth - (isSmallScreenWidth ? 0 : variables.sideBarWidth) < variables.anonymousReportFooterBreakpoint; - const hideComposer = !ReportUtils.canUserPerformWriteAction(report); + const hideComposer = !ReportUtils.canUserPerformWriteAction(report, reportNameValuePairs); const canWriteInReport = ReportUtils.canWriteInReport(report); const isSystemChat = ReportUtils.isSystemChat(report); diff --git a/src/types/onyx/ReportNameValuePairs.ts b/src/types/onyx/ReportNameValuePairs.ts new file mode 100644 index 000000000000..1cf56c300f00 --- /dev/null +++ b/src/types/onyx/ReportNameValuePairs.ts @@ -0,0 +1,7 @@ +import type * as OnyxCommon from './OnyxCommon'; + +type ReportNameValuePairs = OnyxCommon.OnyxValueWithOfflineFeedback<{ + isArchived: boolean; +}>; + +export default ReportNameValuePairs; diff --git a/src/types/onyx/index.ts b/src/types/onyx/index.ts index 1695daebace8..eb3ef2eefc8d 100644 --- a/src/types/onyx/index.ts +++ b/src/types/onyx/index.ts @@ -58,6 +58,7 @@ import type ReportActionReactions from './ReportActionReactions'; import type ReportActionsDraft from './ReportActionsDraft'; import type ReportActionsDrafts from './ReportActionsDrafts'; import type ReportMetadata from './ReportMetadata'; +import type ReportNameValuePairs from './ReportNameValuePairs'; import type ReportNextStep from './ReportNextStep'; import type ReportUserIsTyping from './ReportUserIsTyping'; import type Request from './Request'; @@ -134,6 +135,7 @@ export type { RecentlyUsedTags, ReimbursementAccount, Report, + ReportNameValuePairs, ReportAction, ReportActionReactions, ReportActions,