-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Changes from all commits
ecdafb4
258cac7
b43148e
44fc179
86f683d
8def699
c026928
ff4172c
cb0b74e
a2840d4
f58dbbb
3227895
9b6a864
4aa4665
b159e3b
a1dc8bb
5cfeecd
02ca68e
21de4e2
8a233f8
41e21ea
588f60c
59bcd35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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)); | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have passed:
Coming from #30175 |
||
onTransitionEnd={() => { | ||
if (!welcomeMessageInputRef.current) { | ||
return; | ||
} | ||
welcomeMessageInputRef.current.focus(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
<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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coming from #19698 , |
||
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); |
There was a problem hiding this comment.
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.