Skip to content

Commit

Permalink
Merge pull request #41199 from ahmedGaber93/issue-39636
Browse files Browse the repository at this point in the history
move message "admins only can post" from welcome message to footer
  • Loading branch information
robertjchen authored Jun 7, 2024
2 parents fb562ec + a59dd6b commit 1426c4e
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/components/ArchivedReportFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function ArchivedReportFooter({report, reportClosedAction, personalDetails = {}}

return (
<Banner
containerStyles={[styles.archivedReportFooter]}
containerStyles={[styles.chatFooterBanner]}
text={text}
shouldRenderHTML={shouldRenderHTML}
shouldShowIcon
Expand Down
2 changes: 1 addition & 1 deletion src/components/BlockedReportFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function BlockedReportFooter() {

return (
<Banner
containerStyles={[styles.archivedReportFooter]}
containerStyles={[styles.chatFooterBanner]}
text={text}
shouldShowIcon
shouldRenderHTML
Expand Down
4 changes: 1 addition & 3 deletions src/components/ReportWelcomeText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';
import type {IOUType} from '@src/CONST';
Expand Down Expand Up @@ -47,8 +46,7 @@ function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextP
.filter((accountID) => accountID !== session?.accountID || (!isOneOnOneChat && !isSystemChat));
const isMultipleParticipant = participantAccountIDs.length > 1;
const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, personalDetails), isMultipleParticipant);
const isUserPolicyAdmin = PolicyUtils.isPolicyAdmin(policy);
const roomWelcomeMessage = ReportUtils.getRoomWelcomeMessage(report, isUserPolicyAdmin);
const roomWelcomeMessage = ReportUtils.getRoomWelcomeMessage(report);
const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, policy, participantAccountIDs);
const additionalText = moneyRequestOptions
.filter((item): item is Exclude<IOUType, typeof CONST.IOU.TYPE.REQUEST | typeof CONST.IOU.TYPE.SEND | typeof CONST.IOU.TYPE.INVOICE> => item !== CONST.IOU.TYPE.INVOICE)
Expand Down
2 changes: 1 addition & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,6 @@ export default {
beginningOfChatHistoryDomainRoomPartTwo: ' to chat with colleagues, share tips, and ask questions.',
beginningOfChatHistoryAdminRoomPartOne: ({workspaceName}: BeginningOfChatHistoryAdminRoomPartOneParams) => `Collaboration among ${workspaceName} admins starts here! 🎉\nUse `,
beginningOfChatHistoryAdminRoomPartTwo: ' to chat about topics such as workspace configurations and more.',
beginningOfChatHistoryAdminOnlyPostingRoom: 'Only admins can send messages in this room.',
beginningOfChatHistoryAnnounceRoomPartOne: ({workspaceName}: BeginningOfChatHistoryAnnounceRoomPartOneParams) =>
`Collaboration between all ${workspaceName} members starts here! 🎉\nUse `,
beginningOfChatHistoryAnnounceRoomPartTwo: ({workspaceName}: BeginningOfChatHistoryAnnounceRoomPartTwo) => ` to chat about anything ${workspaceName} related.`,
Expand All @@ -538,6 +537,7 @@ export default {
invoice: 'invoice an expense',
},
},
adminOnlyCanPost: 'Only admins can send messages in this room.',
reportAction: {
asCopilot: 'as copilot for',
},
Expand Down
2 changes: 1 addition & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ export default {
beginningOfChatHistoryAdminRoomPartOne: ({workspaceName}: BeginningOfChatHistoryAdminRoomPartOneParams) =>
`¡Este es el lugar para que los administradores de ${workspaceName} colaboren! 🎉\nUsa `,
beginningOfChatHistoryAdminRoomPartTwo: ' para chatear sobre temas como la configuración del espacio de trabajo y mas.',
beginningOfChatHistoryAdminOnlyPostingRoom: 'Solo los administradores pueden enviar mensajes en esta sala.',
beginningOfChatHistoryAnnounceRoomPartOne: ({workspaceName}: BeginningOfChatHistoryAnnounceRoomPartOneParams) =>
`¡Este es el lugar para que todos los miembros de ${workspaceName} colaboren! 🎉\nUsa `,
beginningOfChatHistoryAnnounceRoomPartTwo: ({workspaceName}: BeginningOfChatHistoryAnnounceRoomPartTwo) => ` para chatear sobre cualquier cosa relacionada con ${workspaceName}.`,
Expand All @@ -532,6 +531,7 @@ export default {
invoice: 'facturar un gasto',
},
},
adminOnlyCanPost: 'Solo los administradores pueden enviar mensajes en esta sala.',
reportAction: {
asCopilot: 'como copiloto de',
},
Expand Down
5 changes: 1 addition & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ function canDeleteReportAction(reportAction: OnyxEntry<ReportAction>, reportID:
/**
* Get welcome message based on room type
*/
function getRoomWelcomeMessage(report: OnyxEntry<Report>, isUserPolicyAdmin: boolean): WelcomeMessage {
function getRoomWelcomeMessage(report: OnyxEntry<Report>): WelcomeMessage {
const welcomeMessage: WelcomeMessage = {showReportName: true};
const workspaceName = getPolicyName(report);

Expand All @@ -1597,9 +1597,6 @@ function getRoomWelcomeMessage(report: OnyxEntry<Report>, isUserPolicyAdmin: boo
} else if (isAdminRoom(report)) {
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAdminRoomPartOne', {workspaceName});
welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAdminRoomPartTwo');
} else if (isAdminsOnlyPostingRoom(report) && !isUserPolicyAdmin) {
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAdminOnlyPostingRoom');
welcomeMessage.showReportName = false;
} else if (isAnnounceRoom(report)) {
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAnnounceRoomPartOne', {workspaceName});
welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAnnounceRoomPartTwo', {workspaceName});
Expand Down
1 change: 1 addition & 0 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ function ReportScreen({
report={report}
reportMetadata={reportMetadata}
reportNameValuePairs={reportNameValuePairs}
policy={policy}
pendingAction={reportPendingAction}
isComposerFullSize={!!isComposerFullSize}
listHeight={listHeight}
Expand Down
27 changes: 26 additions & 1 deletion src/pages/home/report/ReportFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import AnonymousReportFooter from '@components/AnonymousReportFooter';
import ArchivedReportFooter from '@components/ArchivedReportFooter';
import Banner from '@components/Banner';
import BlockedReportFooter from '@components/BlockedReportFooter';
import * as Expensicons from '@components/Icon/Expensicons';
import OfflineIndicator from '@components/OfflineIndicator';
import {usePersonalDetails} from '@components/OnyxProvider';
import SwipeableView from '@components/SwipeableView';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import * as UserUtils from '@libs/UserUtils';
import variables from '@styles/variables';
Expand Down Expand Up @@ -44,6 +48,9 @@ type ReportFooterProps = ReportFooterOnyxProps & {

reportNameValuePairs?: OnyxEntry<OnyxTypes.ReportNameValuePairs>;

/** The policy of the report */
policy: OnyxEntry<OnyxTypes.Policy>;

/** The last report action */
lastReportAction?: OnyxEntry<OnyxTypes.ReportAction>;

Expand Down Expand Up @@ -76,6 +83,7 @@ function ReportFooter({
report = {reportID: '0'},
reportMetadata,
reportNameValuePairs,
policy,
shouldShowComposeInput = false,
isEmptyChat = true,
isReportReadyForDisplay = true,
Expand All @@ -87,6 +95,7 @@ function ReportFooter({
}: ReportFooterProps) {
const styles = useThemeStyles();
const {isOffline} = useNetwork();
const {translate} = useLocalize();
const {windowWidth, isSmallScreenWidth} = useWindowDimensions();
const chatFooterStyles = {...styles.chatFooter, minHeight: !isOffline ? CONST.CHAT_FOOTER_MIN_HEIGHT : 0};
const isArchivedRoom = ReportUtils.isArchivedRoom(report, reportNameValuePairs);
Expand All @@ -99,6 +108,8 @@ function ReportFooter({
const hideComposer = (!ReportUtils.canUserPerformWriteAction(report, reportNameValuePairs) && !showComposerOptimistically) || blockedFromChat;
const canWriteInReport = ReportUtils.canWriteInReport(report);
const isSystemChat = ReportUtils.isSystemChat(report);
const isAdminsOnlyPostingRoom = ReportUtils.isAdminsOnlyPostingRoom(report);
const isUserPolicyAdmin = PolicyUtils.isPolicyAdmin(policy);

const allPersonalDetails = usePersonalDetails();

Expand Down Expand Up @@ -156,7 +167,13 @@ function ReportFooter({
return (
<>
{hideComposer && (
<View style={[styles.chatFooter, isArchivedRoom || isAnonymousUser || !canWriteInReport ? styles.mt4 : {}, isSmallScreenWidth ? styles.mb5 : null]}>
<View
style={[
styles.chatFooter,
isArchivedRoom || isAnonymousUser || !canWriteInReport || (isAdminsOnlyPostingRoom && !isUserPolicyAdmin) ? styles.mt4 : {},
isSmallScreenWidth ? styles.mb5 : null,
]}
>
{isAnonymousUser && !isArchivedRoom && (
<AnonymousReportFooter
report={report}
Expand All @@ -166,6 +183,14 @@ function ReportFooter({
{isArchivedRoom && <ArchivedReportFooter report={report} />}
{!isArchivedRoom && blockedFromChat && <BlockedReportFooter />}
{!isAnonymousUser && !canWriteInReport && isSystemChat && <SystemChatReportFooterMessage />}
{isAdminsOnlyPostingRoom && !isUserPolicyAdmin && !isArchivedRoom && !isAnonymousUser && !blockedFromChat && (
<Banner
containerStyles={[styles.chatFooterBanner]}
text={translate('adminOnlyCanPost')}
icon={Expensicons.Lightbulb}
shouldShowIcon
/>
)}
{!isSmallScreenWidth && <View style={styles.offlineIndicatorRow}>{hideComposer && <OfflineIndicator containerStyles={[styles.chatItemComposeSecondaryRow]} />}</View>}
</View>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/SystemChatReportFooterMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function SystemChatReportFooterMessage({choice, policies, activePolicyID}: Syste

return (
<Banner
containerStyles={[styles.archivedReportFooter]}
containerStyles={[styles.chatFooterBanner]}
shouldShowIcon
icon={Expensicons.Lightbulb}
content={<Text suppressHighlighting>{content}</Text>}
Expand Down
2 changes: 1 addition & 1 deletion src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3729,7 +3729,7 @@ const styles = (theme: ThemeColors) =>
height: variables.optionRowHeight,
},

archivedReportFooter: {
chatFooterBanner: {
borderRadius: variables.componentBorderRadius,
...wordBreak.breakWord,
},
Expand Down

0 comments on commit 1426c4e

Please sign in to comment.