Skip to content

Commit ccfc9c7

Browse files
authored
Merge pull request #90912 from margelo/@chrispader/composer-editing-regression-admin-only-room
[CP Staging] fix: Allow editing sent messages when chat "Who can post" in chat is set to "Admins only"
2 parents 740f820 + 196b838 commit ccfc9c7

4 files changed

Lines changed: 58 additions & 15 deletions

File tree

src/pages/inbox/report/ReportActionCompose/ReportActionCompose.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ import ComposerProvider from './ComposerProvider';
2525
import ComposerSendButton from './ComposerSendButton';
2626

2727
type ReportActionComposeProps = {
28+
/** Report ID */
2829
reportID: string;
30+
31+
/** Whether the composer is edit only */
32+
isEditOnly?: boolean;
2933
};
3034

31-
function ComposerInner({reportID}: ReportActionComposeProps) {
35+
function ComposerInner({reportID, isEditOnly = false}: ReportActionComposeProps) {
3236
const styles = useThemeStyles();
3337
const {shouldUseNarrowLayout} = useResponsiveLayout();
3438
const {isEditingInComposer} = useComposerEditState();
@@ -57,22 +61,27 @@ function ComposerInner({reportID}: ReportActionComposeProps) {
5761
<Composer.SendButton reportID={reportID} />
5862
</Composer.Box>
5963
</Composer.DropZone>
60-
<Composer.Footer>
61-
{!shouldUseNarrowLayout && <OfflineIndicator containerStyles={[styles.chatItemComposeSecondaryRow]} />}
62-
<Composer.TypingIndicator reportID={reportID} />
63-
<Composer.ExceededLength />
64-
</Composer.Footer>
64+
{!isEditOnly && (
65+
<Composer.Footer>
66+
{!shouldUseNarrowLayout && <OfflineIndicator containerStyles={[styles.chatItemComposeSecondaryRow]} />}
67+
<Composer.TypingIndicator reportID={reportID} />
68+
<Composer.ExceededLength />
69+
</Composer.Footer>
70+
)}
6571
</OfflineWithFeedback>
6672
<Composer.ImportedState />
6773
</View>
6874
</View>
6975
);
7076
}
7177

72-
function Composer({reportID}: ReportActionComposeProps) {
78+
function Composer({reportID, ...restProps}: ReportActionComposeProps) {
7379
return (
7480
<ComposerProvider reportID={reportID}>
75-
<ComposerInner reportID={reportID} />
81+
<ComposerInner
82+
reportID={reportID}
83+
{...restProps}
84+
/>
7685
</ComposerProvider>
7786
);
7887
}

src/pages/inbox/report/ReportActionsList.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import ShowPreviousMessagesButton from './ShowPreviousMessagesButton';
7979
import StaticReportActionsPreview from './StaticReportActionsPreview';
8080
import useReportActionsNewActionLiveTail from './useReportActionsNewActionLiveTail';
8181
import useReportUnreadMessageScrollTracking from './useReportUnreadMessageScrollTracking';
82+
import useShouldShowComposerForActiveEditDraft from './useShouldShowComposerForActiveEditDraft';
8283

8384
type ReportActionsListProps = {
8485
/** The report currently being looked at */
@@ -841,7 +842,8 @@ function ReportActionsList({
841842
() => [shouldUseNarrowLayout ? unreadMarkerReportActionID : undefined, isArchivedNonExpenseReport(report, isReportArchived), draftReportAction?.reportActionID, draftMessageHTML],
842843
[draftMessageHTML, draftReportAction?.reportActionID, unreadMarkerReportActionID, shouldUseNarrowLayout, report, isReportArchived],
843844
);
844-
const hideComposer = !canUserPerformWriteAction(report, isReportArchived);
845+
const shouldShowComposerForActiveEditDraft = useShouldShowComposerForActiveEditDraft();
846+
const hideComposer = !canUserPerformWriteAction(report, isReportArchived) && !shouldShowComposerForActiveEditDraft;
845847
const shouldShowReportRecipientLocalTime = canShowReportRecipientLocalTime(personalDetailsList, report, currentUserAccountID) && !isComposerFullSize;
846848
const canShowHeader = isOffline || hasHeaderRendered.current;
847849

src/pages/inbox/report/ReportFooter.tsx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {isLoadingInitialReportActionsSelector} from '@src/selectors/ReportMetaDa
3333
import type * as OnyxTypes from '@src/types/onyx';
3434
import ReportActionCompose from './ReportActionCompose/ReportActionCompose';
3535
import SystemChatReportFooterMessage from './SystemChatReportFooterMessage';
36+
import useShouldShowComposerForActiveEditDraft from './useShouldShowComposerForActiveEditDraft';
3637

3738
const policyRoleSelector = (policy: OnyxEntry<OnyxTypes.Policy>) => policy?.role;
3839

@@ -77,6 +78,7 @@ function ReportFooter() {
7778
const canWriteInReport = canWriteInReportUtil(report);
7879
const isSystemChat = isSystemChatUtil(report);
7980
const isAdminsOnlyPostingRoom = isAdminsOnlyPostingRoomUtil(report);
81+
const shouldShowComposerForActiveEditDraft = useShouldShowComposerForActiveEditDraft();
8082

8183
if (!isCurrentReportLoadedFromOnyx || !report || !reportIDFromRoute) {
8284
return null;
@@ -88,9 +90,7 @@ function ReportFooter() {
8890
if (!shouldHideComposer) {
8991
return (
9092
<View style={[chatFooterStyles, isComposerFullSize && styles.chatFooterFullCompose]}>
91-
<SwipeableView onSwipeDown={Keyboard.dismiss}>
92-
<ReportActionCompose reportID={reportIDFromRoute} />
93-
</SwipeableView>
93+
<ComposerSwipeable reportID={reportIDFromRoute} />
9494
</View>
9595
);
9696
}
@@ -151,12 +151,22 @@ function ReportFooter() {
151151
);
152152
}
153153

154-
// Admins-only room
154+
// Admins-only room — keep the banner visible; mount the composer above it while editing on narrow screens.
155155
if (isAdminsOnlyPostingRoom && !isUserPolicyAdmin) {
156+
const isEditingWithComposer = shouldShowComposerForActiveEditDraft;
157+
156158
return (
157-
<View style={[styles.chatFooter, styles.mt4, shouldUseNarrowLayout && styles.mb5]}>
159+
<View style={[styles.chatFooter, !isEditingWithComposer && styles.mt4, shouldUseNarrowLayout && styles.mb5]}>
160+
{isEditingWithComposer && (
161+
<View style={[isComposerFullSize ? styles.chatFooterFullCompose : undefined, styles.mb2]}>
162+
<ComposerSwipeable
163+
reportID={reportIDFromRoute}
164+
isEditOnly
165+
/>
166+
</View>
167+
)}
158168
<Banner
159-
containerStyles={[styles.chatFooterBanner]}
169+
containerStyles={[styles.chatFooterBanner, isEditingWithComposer && styles.mt2]}
160170
text={translate('adminOnlyCanPost')}
161171
icon={expensifyIcons.Lightbulb}
162172
shouldShowIcon
@@ -197,4 +207,15 @@ function ReportFooter() {
197207
return null;
198208
}
199209

210+
function ComposerSwipeable({reportID, isEditOnly = false}: {reportID: string; isEditOnly?: boolean}) {
211+
return (
212+
<SwipeableView onSwipeDown={Keyboard.dismiss}>
213+
<ReportActionCompose
214+
reportID={reportID}
215+
isEditOnly={isEditOnly}
216+
/>
217+
</SwipeableView>
218+
);
219+
}
220+
200221
export default ReportFooter;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import useResponsiveLayout from '@hooks/useResponsiveLayout';
2+
import {useReportActionActiveEdit} from './ReportActionEditMessageContext';
3+
4+
/** Narrow-screen edits use the bottom composer (#90516); mount it when a draft exists even if posting is admin-only. */
5+
function useShouldShowComposerForActiveEditDraft() {
6+
const {shouldUseNarrowLayout} = useResponsiveLayout();
7+
const {editingReportActionID} = useReportActionActiveEdit();
8+
return shouldUseNarrowLayout && editingReportActionID !== null;
9+
}
10+
11+
export default useShouldShowComposerForActiveEditDraft;

0 commit comments

Comments
 (0)