Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Welcome message functionality in room settings #18662

Merged
merged 23 commits into from
May 25, 2023
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
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,7 @@ const CONST = {
MEMBERS: 'member',
SETTINGS: 'settings',
LEAVE_ROOM: 'leaveRoom',
WELCOME_MESSAGE: 'welcomeMessage',
},

FOOTER: {
Expand Down
1 change: 1 addition & 0 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export default {
PROFILE_SETTINGS_FORM: 'profileSettingsForm',
DISPLAY_NAME_FORM: 'displayNameForm',
ROOM_NAME_FORM: 'roomNameForm',
WELCOME_MESSAGE_FORM: 'welcomeMessageForm',
LEGAL_NAME_FORM: 'legalNameForm',
WORKSPACE_INVITE_MESSAGE_FORM: 'workspaceInviteMessageForm',
DATE_OF_BIRTH_FORM: 'dateOfBirthForm',
Expand Down
8 changes: 5 additions & 3 deletions src/ROUTES.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ export default {
REPORT_WITH_ID_DETAILS: 'r/:reportID/details',
getReportDetailsRoute: (reportID) => `r/${reportID}/details`,
REPORT_SETTINGS: 'r/:reportID/settings',
REPORT_SETTINGS_ROOM_NAME: 'r/:reportID/settings/room-name',
REPORT_SETTINGS_NOTIFICATION_PREFERENCES: 'r/:reportID/settings/notification-preferences',
REPORT_SETTINGS_WRITE_CAPABILITY: 'r/:reportID/settings/who-can-post',
getReportSettingsRoute: (reportID) => `r/${reportID}/settings`,
REPORT_SETTINGS_ROOM_NAME: 'r/:reportID/settings/room-name',
getReportSettingsRoomNameRoute: (reportID) => `r/${reportID}/settings/room-name`,
REPORT_SETTINGS_NOTIFICATION_PREFERENCES: 'r/:reportID/settings/notification-preferences',
getReportSettingsNotificationPreferencesRoute: (reportID) => `r/${reportID}/settings/notification-preferences`,
REPORT_WELCOME_MESSAGE: 'r/:reportID/welcomeMessage',
getReportWelcomeMessageRoute: (reportID) => `r/${reportID}/welcomeMessage`,
REPORT_SETTINGS_WRITE_CAPABILITY: 'r/:reportID/settings/who-can-post',
getReportSettingsWriteCapabilityRoute: (reportID) => `r/${reportID}/settings/who-can-post`,
TRANSITION_FROM_OLD_DOT: 'transition',
VALIDATE_LOGIN: 'v/:accountID/:validateCode',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,10 @@ export default {
},
},
},
welcomeMessagePage: {
welcomeMessage: 'Welcome message',
explainerText: 'Set a custom welcome message that will be sent to users when they join this room.',
},
languagePage: {
language: 'Language',
languages: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,10 @@ export default {
},
},
},
welcomeMessagePage: {
welcomeMessage: 'Mensaje de bienvenida',
explainerText: 'Configura un mensaje de bienvenida privado y personalizado que se enviará cuando los usuarios se unan a esta sala de chat.',
},
languagePage: {
language: 'Idioma',
languages: {
Expand Down
6 changes: 6 additions & 0 deletions src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ class AuthScreens extends React.Component {
component={ModalStackNavigators.ReportSettingsModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="Report_WelcomeMessage"
options={modalScreenOptions}
component={ModalStackNavigators.ReportWelcomeMessageModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="Participants"
options={modalScreenOptions}
Expand Down
11 changes: 11 additions & 0 deletions src/libs/Navigation/AppNavigator/ModalStackNavigators.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ const TaskModalStackNavigator = createModalStackNavigator([
},
]);

const ReportWelcomeMessageModalStackNavigator = createModalStackNavigator([
{
getComponent: () => {
const ReportWelcomeMessagePage = require('../../../pages/ReportWelcomeMessagePage').default;
return ReportWelcomeMessagePage;
},
name: 'Report_WelcomeMessage_Root',
},
]);

const ReportParticipantsModalStackNavigator = createModalStackNavigator([
{
getComponent: () => {
Expand Down Expand Up @@ -683,6 +693,7 @@ export {
ReportDetailsModalStackNavigator,
TaskModalStackNavigator,
ReportSettingsModalStackNavigator,
ReportWelcomeMessageModalStackNavigator,
ReportParticipantsModalStackNavigator,
SearchModalStackNavigator,
NewGroupModalStackNavigator,
Expand Down
5 changes: 5 additions & 0 deletions src/libs/Navigation/linkingConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ export default {
},
},
},
Report_WelcomeMessage: {
screens: {
Report_WelcomeMessage_Root: ROUTES.REPORT_WELCOME_MESSAGE,
},
},
NewGroup: {
screens: {
NewGroup_Root: ROUTES.NEW_GROUP,
Expand Down
32 changes: 32 additions & 0 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,37 @@ function updateNotificationPreferenceAndNavigate(reportID, previousValue, newVal
Navigation.drawerGoBack(ROUTES.getReportSettingsRoute(reportID));
}

/**
* @param {String} reportID
* @param {String} previousValue
* @param {String} newValue
*/
function updateWelcomeMessage(reportID, previousValue, newValue) {
// No change needed, navigate back
if (previousValue === newValue) {
Navigation.goBack();
return;
}

const parsedWelcomeMessage = ReportUtils.getParsedComment(newValue);
const optimisticData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {welcomeMessage: newValue},
},
];
const failureData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {welcomeMessage: previousValue},
},
];
API.write('UpdateWelcomeMessage', {reportID, welcomeMessage: parsedWelcomeMessage}, {optimisticData, failureData});
Navigation.goBack();
}

/**
* @param {Object} report
* @param {String} newValue
Expand Down Expand Up @@ -1642,6 +1673,7 @@ export {
addComment,
addAttachment,
reconnect,
updateWelcomeMessage,
updateWriteCapabilityAndNavigate,
updateNotificationPreferenceAndNavigate,
subscribeToReportTypingEvents,
Expand Down
94 changes: 94 additions & 0 deletions src/pages/ReportWelcomeMessagePage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import React, {useCallback, useRef, useState} from 'react';
import PropTypes from 'prop-types';
import _ from 'underscore';
import {View} from 'react-native';
import ExpensiMark from 'expensify-common/lib/ExpensiMark';
import compose from '../libs/compose';
import withLocalize, {withLocalizePropTypes} from '../components/withLocalize';
import ScreenWrapper from '../components/ScreenWrapper';
import Navigation from '../libs/Navigation/Navigation';
import HeaderWithCloseButton from '../components/HeaderWithCloseButton';
import styles from '../styles/styles';
import reportPropTypes from './reportPropTypes';
import withReportOrNotFound from './home/report/withReportOrNotFound';
import Text from '../components/Text';
import TextInput from '../components/TextInput';
import * as Report from '../libs/actions/Report';
import ONYXKEYS from '../ONYXKEYS';
import CONST from '../CONST';
import FullPageNotFoundView from '../components/BlockingViews/FullPageNotFoundView';
import Form from '../components/Form';

const propTypes = {
...withLocalizePropTypes,

/** The report currently being looked at */
report: reportPropTypes.isRequired,

/** Route params */
route: PropTypes.shape({
params: PropTypes.shape({
/** Report ID passed via route r/:reportID/welcomeMessage */
reportID: PropTypes.string,
}),
}).isRequired,
};

function ReportWelcomeMessagePage(props) {
const parser = new ExpensiMark();
const [welcomeMessage, setWelcomeMessage] = useState(parser.htmlToMarkdown(props.report.welcomeMessage));
Copy link
Contributor

Choose a reason for hiding this comment

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

Coming from #19688:
Offline case was not handled while implementing welcome message feature. welcomeMessage value was not added optimistically when build report so app crashed on this line.

const welcomeMessageInputRef = useRef(null);

const handleWelcomeMessageChange = useCallback((value) => {
setWelcomeMessage(value);
}, []);

const submitForm = useCallback(() => {
Report.updateWelcomeMessage(props.report.reportID, props.report.welcomeMessage, welcomeMessage);
}, [props.report.reportID, props.report.welcomeMessage, welcomeMessage]);

return (
<ScreenWrapper
Copy link
Contributor

@s77rt s77rt Nov 3, 2023

Choose a reason for hiding this comment

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

We should have passed:

  • shouldEnableMaxHeight to avoid keyboard covering submit button (since we only have one input)
  • includeSafeAreaPaddingBottom={false} because we have Form that already includes the safe area bottom padding

Coming from #30175

onTransitionEnd={() => {
if (!welcomeMessageInputRef.current) {
return;
}
welcomeMessageInputRef.current.focus();
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi ✋ Coming from #21523

Since the input is multiline and the value can be set from the previous message saved, it makes sense to focus the input and put the cursor on to the end of the text.

}}
>
<FullPageNotFoundView shouldShow={_.isEmpty(props.report)}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi ✋ Coming from #22013

The page is only accessible for policy admin. The check for if report exist is handle from the HOC withReportOrNotFound.

<HeaderWithCloseButton
title={props.translate('welcomeMessagePage.welcomeMessage')}
onBackButtonPress={() => Navigation.goBack()}
onCloseButtonPress={() => Navigation.dismissModal()}
/>
<Form
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.WELCOME_MESSAGE_FORM}
onSubmit={submitForm}
validate={() => ({})}
submitButtonText={props.translate('common.save')}
enabledWhenOffline
>
<Text style={[styles.mb5]}>{props.translate('welcomeMessagePage.explainerText')}</Text>
<View style={[styles.mb6]}>
<TextInput
inputID="welcomeMessage"
label={props.translate('welcomeMessagePage.welcomeMessage')}
multiline
Copy link
Contributor

Choose a reason for hiding this comment

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

Coming from #19698 ,multiline by default aligns the text to the top on iOS, and centers it on Android. It should be used with textAlignVertical set to top for the same behavior in both platforms.

numberOfLines={10}
maxLength={CONST.MAX_COMMENT_LENGTH}
ref={welcomeMessageInputRef}
value={welcomeMessage}
onChangeText={handleWelcomeMessageChange}
autoCapitalize="none"
/>
</View>
</Form>
</FullPageNotFoundView>
</ScreenWrapper>
);
}

ReportWelcomeMessagePage.propTypes = propTypes;
export default compose(withLocalize, withReportOrNotFound)(ReportWelcomeMessagePage);
21 changes: 21 additions & 0 deletions src/pages/settings/Report/ReportSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import withReportOrNotFound from '../../home/report/withReportOrNotFound';
import FullPageNotFoundView from '../../../components/BlockingViews/FullPageNotFoundView';
import MenuItemWithTopDescription from '../../../components/MenuItemWithTopDescription';
import ROUTES from '../../../ROUTES';
import * as Expensicons from '../../../components/Icon/Expensicons';
import MenuItem from '../../../components/MenuItem';

const propTypes = {
/** Route params */
Expand Down Expand Up @@ -79,11 +81,22 @@ class ReportSettingsPage extends Component {
return !Policy.isPolicyOwner(linkedWorkspace) && linkedWorkspace.role !== CONST.POLICY.ROLE.ADMIN;
}

/**
* We only want policy owners and admins to be able to modify the welcome message.
*
* @param {Object|null} linkedWorkspace - the workspace the report is on, null if the user isn't a member of the workspace
* @returns {Boolean}
*/
shouldDisableWelcomeMessage(linkedWorkspace) {
return !ReportUtils.isArchivedRoom(this.props.report) && !_.isEmpty(linkedWorkspace) && Policy.isPolicyOwner(linkedWorkspace) && linkedWorkspace.role === CONST.POLICY.ROLE.ADMIN;
}

render() {
const shouldShowRoomName = !ReportUtils.isPolicyExpenseChat(this.props.report) && !ReportUtils.isThread(this.props.report);
const linkedWorkspace = _.find(this.props.policies, (policy) => policy && policy.id === this.props.report.policyID);
const shouldDisableRename = this.shouldDisableRename(linkedWorkspace) || ReportUtils.isThread(this.props.report);
const notificationPreference = this.props.translate(`notificationPreferencesPage.notificationPreferences.${this.props.report.notificationPreference}`);
const shouldDisableWelcomeMessage = this.shouldDisableRename(linkedWorkspace);
const writeCapability = this.props.report.writeCapability || CONST.REPORT.WRITE_CAPABILITIES.ALL;
const writeCapabilityText = this.props.translate(`writeCapabilityPage.writeCapability.${writeCapability}`);
const shouldAllowWriteCapabilityEditing = lodashGet(linkedWorkspace, 'role', '') === CONST.POLICY.ROLE.ADMIN;
Expand Down Expand Up @@ -196,6 +209,14 @@ class ReportSettingsPage extends Component {
</View>
)}
</View>
{!shouldDisableWelcomeMessage && (
<MenuItem
title={this.props.translate('welcomeMessagePage.welcomeMessage')}
icon={Expensicons.ChatBubble}
onPress={() => Navigation.navigate(ROUTES.getReportWelcomeMessageRoute(this.props.report.reportID))}
shouldShowRightIcon
/>
)}
</FullPageNotFoundView>
</ScreenWrapper>
);
Expand Down