|
| 1 | +/* @flow strict-local */ |
| 2 | + |
| 3 | +import React, { Component } from 'react'; |
| 4 | +import { View, TouchableOpacity } from 'react-native'; |
| 5 | + |
| 6 | +import type { Auth, Stream, Dispatch, Narrow, UserOrBot, GetText } from '../types'; |
| 7 | +import { withGetText } from '../boot/TranslationProvider'; |
| 8 | +import { connect } from '../react-redux'; |
| 9 | +import * as api from '../api'; |
| 10 | +import { ZulipButton, RawLabel } from '../common'; |
| 11 | +import { getAuth, getStreamInNarrow, getUserForId } from '../selectors'; |
| 12 | +import styles from '../styles'; |
| 13 | + |
| 14 | +type SelectorProps = {| |
| 15 | + auth: Auth, |
| 16 | + stream: { ...Stream }, |
| 17 | + user: UserOrBot, |
| 18 | +|}; |
| 19 | + |
| 20 | +type Props = $ReadOnly<{| |
| 21 | + narrow: Narrow, |
| 22 | + userId: number, |
| 23 | + onDismiss: (user: UserOrBot) => void, |
| 24 | + dispatch: Dispatch, |
| 25 | + ...SelectorProps, |
| 26 | + _: GetText, |
| 27 | +|}>; |
| 28 | + |
| 29 | +class MentionedUserNotSubscribed extends Component<Props> { |
| 30 | + subscribeToStream = () => { |
| 31 | + const { auth, stream, user } = this.props; |
| 32 | + api.subscriptionAdd(auth, [{ name: stream.name }], [user.email]); |
| 33 | + this.handleDismiss(); |
| 34 | + }; |
| 35 | + |
| 36 | + handleDismiss = () => { |
| 37 | + const { user, onDismiss } = this.props; |
| 38 | + onDismiss(user); |
| 39 | + }; |
| 40 | + |
| 41 | + render() { |
| 42 | + const { user, _ } = this.props; |
| 43 | + |
| 44 | + const alertTitle = _.intl.formatMessage( |
| 45 | + { |
| 46 | + id: '{username} will not be notified unless you subscribe them to this stream.', |
| 47 | + defaultMessage: '{username} will not be notified unless you subscribe them to this stream.', |
| 48 | + }, |
| 49 | + { username: user.full_name }, |
| 50 | + ); |
| 51 | + |
| 52 | + return ( |
| 53 | + <View> |
| 54 | + <TouchableOpacity onPress={this.handleDismiss} style={styles.mentionedUserNotSubscribed}> |
| 55 | + <RawLabel style={styles.mentionedUserNotSubscribedText} text={alertTitle} /> |
| 56 | + <ZulipButton |
| 57 | + style={styles.mentionedUserNotSubscribedButton} |
| 58 | + text="Subscribe" |
| 59 | + onPress={this.subscribeToStream} |
| 60 | + /> |
| 61 | + </TouchableOpacity> |
| 62 | + </View> |
| 63 | + ); |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +export default connect<SelectorProps, _, _>((state, props) => ({ |
| 68 | + auth: getAuth(state), |
| 69 | + stream: getStreamInNarrow(state, props.narrow), |
| 70 | + user: getUserForId(state, props.userId), |
| 71 | +}))(withGetText(MentionedUserNotSubscribed)); |
0 commit comments