Chore: Migrate NotificationPreferencesView to hooks (#4327)
* add none option * create showErrorAlertWithEMessage function * migrate NotificationPreferencesView to hooks and improves overall * change icon to right * fix navigation options * remove none * fix types * remove memo * cleaning * switching to destructuring * add observe for hideUnreadStatus * fix desktop options * remove unused options Co-authored-by: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com>
This commit is contained in:
parent
5875454a70
commit
41dbbf4d4b
|
@ -26,11 +26,16 @@ export const Item = React.memo(({ item, hide }: IActionSheetItem) => {
|
||||||
style={[styles.item, { backgroundColor: themes[theme].focusedBackground }]}
|
style={[styles.item, { backgroundColor: themes[theme].focusedBackground }]}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
testID={item.testID}>
|
testID={item.testID}>
|
||||||
|
{item.icon ? (
|
||||||
<CustomIcon name={item.icon} size={20} color={item.danger ? themes[theme].dangerColor : themes[theme].bodyText} />
|
<CustomIcon name={item.icon} size={20} color={item.danger ? themes[theme].dangerColor : themes[theme].bodyText} />
|
||||||
|
) : null}
|
||||||
<View style={styles.titleContainer}>
|
<View style={styles.titleContainer}>
|
||||||
<Text
|
<Text
|
||||||
numberOfLines={1}
|
numberOfLines={1}
|
||||||
style={[styles.title, { color: item.danger ? themes[theme].dangerColor : themes[theme].bodyText }]}>
|
style={[
|
||||||
|
styles.title,
|
||||||
|
{ color: item.danger ? themes[theme].dangerColor : themes[theme].bodyText, marginLeft: item.icon ? 16 : 0 }
|
||||||
|
]}>
|
||||||
{item.title}
|
{item.title}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
|
@ -6,7 +6,7 @@ import ActionSheet from './ActionSheet';
|
||||||
|
|
||||||
export type TActionSheetOptionsItem = {
|
export type TActionSheetOptionsItem = {
|
||||||
title: string;
|
title: string;
|
||||||
icon: TIconsName;
|
icon?: TIconsName;
|
||||||
danger?: boolean;
|
danger?: boolean;
|
||||||
testID?: string;
|
testID?: string;
|
||||||
onPress: () => void;
|
onPress: () => void;
|
||||||
|
|
|
@ -27,7 +27,6 @@ export default StyleSheet.create({
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
marginLeft: 16,
|
|
||||||
...sharedStyles.textRegular
|
...sharedStyles.textRegular
|
||||||
},
|
},
|
||||||
handle: {
|
handle: {
|
||||||
|
|
|
@ -237,6 +237,7 @@ export interface IRoomNotifications {
|
||||||
desktopNotifications?: TNotifications;
|
desktopNotifications?: TNotifications;
|
||||||
mobilePushNotifications?: TNotifications;
|
mobilePushNotifications?: TNotifications;
|
||||||
emailNotifications?: TNotifications;
|
emailNotifications?: TNotifications;
|
||||||
|
hideMentionStatus?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TRoomNotificationsModel = IRoomNotifications & Model;
|
export type TRoomNotificationsModel = IRoomNotifications & Model;
|
||||||
|
|
|
@ -5,6 +5,14 @@ import I18n from '../../../i18n';
|
||||||
export const showErrorAlert = (message: string, title?: string, onPress = () => {}): void =>
|
export const showErrorAlert = (message: string, title?: string, onPress = () => {}): void =>
|
||||||
Alert.alert(title || '', message, [{ text: 'OK', onPress }], { cancelable: true });
|
Alert.alert(title || '', message, [{ text: 'OK', onPress }], { cancelable: true });
|
||||||
|
|
||||||
|
export const showErrorAlertWithEMessage = (e: any): void => {
|
||||||
|
const messageError =
|
||||||
|
e.data && e.data.error.includes('[error-too-many-requests]')
|
||||||
|
? I18n.t('error-too-many-requests', { seconds: e.data.error.replace(/\D/g, '') })
|
||||||
|
: e.data.errorType;
|
||||||
|
showErrorAlert(messageError);
|
||||||
|
};
|
||||||
|
|
||||||
interface IShowConfirmationAlert {
|
interface IShowConfirmationAlert {
|
||||||
title?: string;
|
title?: string;
|
||||||
message: string;
|
message: string;
|
||||||
|
|
|
@ -111,11 +111,7 @@ const ChatsStackNavigator = () => {
|
||||||
<ChatsStack.Screen name='MessagesView' component={MessagesView} />
|
<ChatsStack.Screen name='MessagesView' component={MessagesView} />
|
||||||
<ChatsStack.Screen name='AutoTranslateView' component={AutoTranslateView} options={AutoTranslateView.navigationOptions} />
|
<ChatsStack.Screen name='AutoTranslateView' component={AutoTranslateView} options={AutoTranslateView.navigationOptions} />
|
||||||
<ChatsStack.Screen name='DirectoryView' component={DirectoryView} options={DirectoryView.navigationOptions} />
|
<ChatsStack.Screen name='DirectoryView' component={DirectoryView} options={DirectoryView.navigationOptions} />
|
||||||
<ChatsStack.Screen
|
<ChatsStack.Screen name='NotificationPrefView' component={NotificationPrefView} />
|
||||||
name='NotificationPrefView'
|
|
||||||
component={NotificationPrefView}
|
|
||||||
options={NotificationPrefView.navigationOptions}
|
|
||||||
/>
|
|
||||||
<ChatsStack.Screen name='ForwardLivechatView' component={ForwardLivechatView} />
|
<ChatsStack.Screen name='ForwardLivechatView' component={ForwardLivechatView} />
|
||||||
<ChatsStack.Screen name='CloseLivechatView' component={CloseLivechatView} />
|
<ChatsStack.Screen name='CloseLivechatView' component={CloseLivechatView} />
|
||||||
<ChatsStack.Screen name='LivechatEditView' component={LivechatEditView} options={LivechatEditView.navigationOptions} />
|
<ChatsStack.Screen name='LivechatEditView' component={LivechatEditView} options={LivechatEditView.navigationOptions} />
|
||||||
|
|
|
@ -151,11 +151,7 @@ const ModalStackNavigator = React.memo(({ navigation }: INavigation) => {
|
||||||
options={props => DirectoryView.navigationOptions!({ ...props, isMasterDetail: true })}
|
options={props => DirectoryView.navigationOptions!({ ...props, isMasterDetail: true })}
|
||||||
/>
|
/>
|
||||||
<ModalStack.Screen name='QueueListView' component={QueueListView} />
|
<ModalStack.Screen name='QueueListView' component={QueueListView} />
|
||||||
<ModalStack.Screen
|
<ModalStack.Screen name='NotificationPrefView' component={NotificationPrefView} />
|
||||||
name='NotificationPrefView'
|
|
||||||
component={NotificationPrefView}
|
|
||||||
options={NotificationPrefView.navigationOptions}
|
|
||||||
/>
|
|
||||||
<ModalStack.Screen name='ForwardLivechatView' component={ForwardLivechatView} />
|
<ModalStack.Screen name='ForwardLivechatView' component={ForwardLivechatView} />
|
||||||
<ModalStack.Screen name='CloseLivechatView' component={CloseLivechatView} />
|
<ModalStack.Screen name='CloseLivechatView' component={CloseLivechatView} />
|
||||||
<ModalStack.Screen name='CannedResponsesListView' component={CannedResponsesListView} />
|
<ModalStack.Screen name='CannedResponsesListView' component={CannedResponsesListView} />
|
||||||
|
|
|
@ -1,165 +1,127 @@
|
||||||
import React from 'react';
|
import { RouteProp, useNavigation, useRoute } from '@react-navigation/core';
|
||||||
import { StyleSheet, Switch, Text } from 'react-native';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { RouteProp } from '@react-navigation/core';
|
import { Switch, Text } from 'react-native';
|
||||||
import { StackNavigationProp } from '@react-navigation/stack';
|
|
||||||
import { Observable, Subscription } from 'rxjs';
|
|
||||||
import { connect } from 'react-redux';
|
|
||||||
|
|
||||||
import database from '../../lib/database';
|
import { TActionSheetOptionsItem, useActionSheet } from '../../containers/ActionSheet';
|
||||||
import { SWITCH_TRACK_COLOR, themes } from '../../lib/constants';
|
import { CustomIcon } from '../../containers/CustomIcon';
|
||||||
import StatusBar from '../../containers/StatusBar';
|
|
||||||
import * as List from '../../containers/List';
|
import * as List from '../../containers/List';
|
||||||
import I18n from '../../i18n';
|
|
||||||
import { TSupportedThemes, withTheme } from '../../theme';
|
|
||||||
import protectedFunction from '../../lib/methods/helpers/protectedFunction';
|
|
||||||
import SafeAreaView from '../../containers/SafeAreaView';
|
import SafeAreaView from '../../containers/SafeAreaView';
|
||||||
import log, { events, logEvent } from '../../lib/methods/helpers/log';
|
import StatusBar from '../../containers/StatusBar';
|
||||||
import sharedStyles from '../Styles';
|
import { IRoomNotifications, TRoomNotificationsModel } from '../../definitions';
|
||||||
import { IOptionsField, OPTIONS } from './options';
|
import I18n from '../../i18n';
|
||||||
import { ChatsStackParamList } from '../../stacks/types';
|
import { SWITCH_TRACK_COLOR } from '../../lib/constants';
|
||||||
import { IApplicationState, IRoomNotifications, TRoomNotificationsModel } from '../../definitions';
|
import { useAppSelector } from '../../lib/hooks';
|
||||||
import { Services } from '../../lib/services';
|
import { showErrorAlertWithEMessage } from '../../lib/methods/helpers';
|
||||||
import { compareServerVersion } from '../../lib/methods/helpers/compareServerVersion';
|
import { compareServerVersion } from '../../lib/methods/helpers/compareServerVersion';
|
||||||
|
import log, { events, logEvent } from '../../lib/methods/helpers/log';
|
||||||
|
import { Services } from '../../lib/services';
|
||||||
|
import { ChatsStackParamList } from '../../stacks/types';
|
||||||
|
import { useTheme } from '../../theme';
|
||||||
|
import sharedStyles from '../Styles';
|
||||||
|
import { OPTIONS } from './options';
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
type TOptions = keyof typeof OPTIONS;
|
||||||
pickerText: {
|
type TRoomNotifications = keyof IRoomNotifications;
|
||||||
...sharedStyles.textRegular,
|
type TUnionOptionsRoomNotifications = TOptions | TRoomNotifications;
|
||||||
fontSize: 16
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
interface INotificationPreferencesViewProps {
|
interface IBaseParams {
|
||||||
navigation: StackNavigationProp<ChatsStackParamList, 'NotificationPrefView'>;
|
preference: TUnionOptionsRoomNotifications;
|
||||||
route: RouteProp<ChatsStackParamList, 'NotificationPrefView'>;
|
|
||||||
theme: TSupportedThemes;
|
|
||||||
serverVersion: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface INotificationPreferencesViewState {
|
|
||||||
room: TRoomNotificationsModel;
|
room: TRoomNotificationsModel;
|
||||||
|
onChangeValue: (pref: TUnionOptionsRoomNotifications, param: { [key: string]: string }, onError: () => void) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
class NotificationPreferencesView extends React.Component<INotificationPreferencesViewProps, INotificationPreferencesViewState> {
|
const RenderListPicker = ({
|
||||||
static navigationOptions = () => ({
|
preference,
|
||||||
title: I18n.t('Notification_Preferences')
|
room,
|
||||||
});
|
|
||||||
|
|
||||||
private mounted: boolean;
|
|
||||||
private rid: string;
|
|
||||||
private roomObservable?: Observable<TRoomNotificationsModel>;
|
|
||||||
private subscription?: Subscription;
|
|
||||||
|
|
||||||
constructor(props: INotificationPreferencesViewProps) {
|
|
||||||
super(props);
|
|
||||||
this.mounted = false;
|
|
||||||
this.rid = props.route.params?.rid ?? '';
|
|
||||||
const room = props.route.params?.room;
|
|
||||||
this.state = {
|
|
||||||
room: room || {}
|
|
||||||
};
|
|
||||||
if (room && room.observe) {
|
|
||||||
this.roomObservable = room.observe();
|
|
||||||
this.subscription = this.roomObservable.subscribe(changes => {
|
|
||||||
if (this.mounted) {
|
|
||||||
this.setState({ room: changes });
|
|
||||||
} else {
|
|
||||||
// @ts-ignore
|
|
||||||
this.state.room = changes;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
this.mounted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
if (this.subscription && this.subscription.unsubscribe) {
|
|
||||||
this.subscription.unsubscribe();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
saveNotificationSettings = async (key: string, value: string | boolean, params: IRoomNotifications) => {
|
|
||||||
// @ts-ignore
|
|
||||||
logEvent(events[`NP_${key.toUpperCase()}`]);
|
|
||||||
const { room } = this.state;
|
|
||||||
const db = database.active;
|
|
||||||
|
|
||||||
try {
|
|
||||||
await db.write(async () => {
|
|
||||||
await room.update(
|
|
||||||
protectedFunction((r: IRoomNotifications) => {
|
|
||||||
r[key] = value;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await Services.saveNotificationSettings(this.rid, params);
|
|
||||||
if (result.success) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
await db.write(async () => {
|
|
||||||
await room.update(
|
|
||||||
protectedFunction((r: IRoomNotifications) => {
|
|
||||||
r[key] = room[key];
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
// @ts-ignore
|
|
||||||
logEvent(events[`NP_${key.toUpperCase()}_F`]);
|
|
||||||
log(e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
onValueChangeSwitch = (key: string, value: string | boolean) =>
|
|
||||||
this.saveNotificationSettings(key, value, { [key]: value ? '1' : '0' });
|
|
||||||
|
|
||||||
onValueChangePicker = (key: string, value: string) => this.saveNotificationSettings(key, value, { [key]: value.toString() });
|
|
||||||
|
|
||||||
pickerSelection = (title: string, key: string) => {
|
|
||||||
const { room } = this.state;
|
|
||||||
const { navigation } = this.props;
|
|
||||||
navigation.navigate('PickerView', {
|
|
||||||
title,
|
title,
|
||||||
data: OPTIONS[key],
|
testID,
|
||||||
value: room[key],
|
onChangeValue
|
||||||
onChangeValue: (value: string) => this.onValueChangePicker(key, value)
|
}: {
|
||||||
});
|
title: string;
|
||||||
};
|
testID: string;
|
||||||
|
} & IBaseParams) => {
|
||||||
|
const { showActionSheet, hideActionSheet } = useActionSheet();
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
const pref = room[preference]
|
||||||
|
? OPTIONS[preference as TOptions].find(option => option.value === room[preference])
|
||||||
|
: OPTIONS[preference as TOptions][0];
|
||||||
|
|
||||||
|
const [option, setOption] = useState(pref);
|
||||||
|
|
||||||
|
const options: TActionSheetOptionsItem[] = OPTIONS[preference as TOptions].map(i => ({
|
||||||
|
title: I18n.t(i.label, { defaultValue: i.label, second: i.second }),
|
||||||
|
onPress: () => {
|
||||||
|
hideActionSheet();
|
||||||
|
onChangeValue(preference, { [preference]: i.value.toString() }, () => setOption(option));
|
||||||
|
setOption(i);
|
||||||
|
},
|
||||||
|
right: option?.value === i.value ? () => <CustomIcon name={'check'} size={20} color={colors.tintActive} /> : undefined
|
||||||
|
}));
|
||||||
|
|
||||||
renderPickerOption = (key: string) => {
|
|
||||||
const { room } = this.state;
|
|
||||||
const { theme } = this.props;
|
|
||||||
const text = room[key] ? OPTIONS[key].find(option => option.value === room[key]) : (OPTIONS[key][0] as IOptionsField);
|
|
||||||
return (
|
return (
|
||||||
<Text style={[styles.pickerText, { color: themes[theme].actionTintColor }]}>
|
<List.Item
|
||||||
{text?.label ? I18n.t(text?.label, { defaultValue: text?.label, second: text?.second }) : text?.label}
|
title={title}
|
||||||
|
testID={testID}
|
||||||
|
onPress={() => showActionSheet({ options })}
|
||||||
|
right={() => (
|
||||||
|
<Text style={[{ ...sharedStyles.textRegular, fontSize: 16 }, { color: colors.actionTintColor }]}>
|
||||||
|
{option?.label ? I18n.t(option?.label, { defaultValue: option?.label, second: option?.second }) : option?.label}
|
||||||
</Text>
|
</Text>
|
||||||
);
|
)}
|
||||||
};
|
|
||||||
|
|
||||||
renderSwitch = (key: string) => {
|
|
||||||
const { room } = this.state;
|
|
||||||
return (
|
|
||||||
<Switch
|
|
||||||
value={!room[key]}
|
|
||||||
testID={key}
|
|
||||||
trackColor={SWITCH_TRACK_COLOR}
|
|
||||||
onValueChange={value => this.onValueChangeSwitch(key, !value)}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
const RenderSwitch = ({ preference, room, onChangeValue }: IBaseParams) => {
|
||||||
const { serverVersion } = this.props;
|
const [switchValue, setSwitchValue] = useState(!room[preference]);
|
||||||
const { room } = this.state;
|
return (
|
||||||
|
<Switch
|
||||||
|
value={switchValue}
|
||||||
|
testID={preference as string}
|
||||||
|
trackColor={SWITCH_TRACK_COLOR}
|
||||||
|
onValueChange={value => {
|
||||||
|
onChangeValue(preference, { [preference]: switchValue ? '1' : '0' }, () => setSwitchValue(switchValue));
|
||||||
|
setSwitchValue(value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const NotificationPreferencesView = (): React.ReactElement => {
|
||||||
|
const route = useRoute<RouteProp<ChatsStackParamList, 'NotificationPrefView'>>();
|
||||||
|
const { rid, room } = route.params;
|
||||||
|
const navigation = useNavigation();
|
||||||
|
const serverVersion = useAppSelector(state => state.server.version);
|
||||||
|
const [hideUnreadStatus, setHideUnreadStatus] = useState(room.hideUnreadStatus);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
navigation.setOptions({
|
||||||
|
title: I18n.t('Notification_Preferences')
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const observe = room.observe();
|
||||||
|
observe.subscribe(data => {
|
||||||
|
setHideUnreadStatus(data.hideUnreadStatus);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const saveNotificationSettings = async (key: TUnionOptionsRoomNotifications, params: IRoomNotifications, onError: Function) => {
|
||||||
|
try {
|
||||||
|
// @ts-ignore
|
||||||
|
logEvent(events[`NP_${key.toUpperCase()}`]);
|
||||||
|
await Services.saveNotificationSettings(rid, params);
|
||||||
|
} catch (e) {
|
||||||
|
// @ts-ignore
|
||||||
|
logEvent(events[`NP_${key.toUpperCase()}_F`]);
|
||||||
|
log(e);
|
||||||
|
onError();
|
||||||
|
showErrorAlertWithEMessage(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView testID='notification-preference-view'>
|
<SafeAreaView testID='notification-preference-view'>
|
||||||
<StatusBar />
|
<StatusBar />
|
||||||
|
@ -169,7 +131,7 @@ class NotificationPreferencesView extends React.Component<INotificationPreferenc
|
||||||
<List.Item
|
<List.Item
|
||||||
title='Receive_Notification'
|
title='Receive_Notification'
|
||||||
testID='notification-preference-view-receive-notification'
|
testID='notification-preference-view-receive-notification'
|
||||||
right={() => this.renderSwitch('disableNotifications')}
|
right={() => <RenderSwitch preference='disableNotifications' room={room} onChangeValue={saveNotificationSettings} />}
|
||||||
/>
|
/>
|
||||||
<List.Separator />
|
<List.Separator />
|
||||||
<List.Info info={I18n.t('Receive_notifications_from', { name: room.name })} translateInfo={false} />
|
<List.Info info={I18n.t('Receive_notifications_from', { name: room.name })} translateInfo={false} />
|
||||||
|
@ -180,7 +142,7 @@ class NotificationPreferencesView extends React.Component<INotificationPreferenc
|
||||||
<List.Item
|
<List.Item
|
||||||
title='Receive_Group_Mentions'
|
title='Receive_Group_Mentions'
|
||||||
testID='notification-preference-view-group-mentions'
|
testID='notification-preference-view-group-mentions'
|
||||||
right={() => this.renderSwitch('muteGroupMentions')}
|
right={() => <RenderSwitch preference='muteGroupMentions' room={room} onChangeValue={saveNotificationSettings} />}
|
||||||
/>
|
/>
|
||||||
<List.Separator />
|
<List.Separator />
|
||||||
<List.Info info='Receive_Group_Mentions_Info' />
|
<List.Info info='Receive_Group_Mentions_Info' />
|
||||||
|
@ -191,19 +153,19 @@ class NotificationPreferencesView extends React.Component<INotificationPreferenc
|
||||||
<List.Item
|
<List.Item
|
||||||
title='Mark_as_unread'
|
title='Mark_as_unread'
|
||||||
testID='notification-preference-view-mark-as-unread'
|
testID='notification-preference-view-mark-as-unread'
|
||||||
right={() => this.renderSwitch('hideUnreadStatus')}
|
right={() => <RenderSwitch preference='hideUnreadStatus' room={room} onChangeValue={saveNotificationSettings} />}
|
||||||
/>
|
/>
|
||||||
<List.Separator />
|
<List.Separator />
|
||||||
<List.Info info='Mark_as_unread_Info' />
|
<List.Info info='Mark_as_unread_Info' />
|
||||||
</List.Section>
|
</List.Section>
|
||||||
|
|
||||||
{room.hideUnreadStatus && compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '4.8.0') ? (
|
{hideUnreadStatus && compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '4.8.0') ? (
|
||||||
<List.Section>
|
<List.Section>
|
||||||
<List.Separator />
|
<List.Separator />
|
||||||
<List.Item
|
<List.Item
|
||||||
title='Show_badge_for_mentions'
|
title='Show_badge_for_mentions'
|
||||||
testID='notification-preference-view-badge-for-mentions'
|
testID='notification-preference-view-badge-for-mentions'
|
||||||
right={() => this.renderSwitch('hideMentionStatus')}
|
right={() => <RenderSwitch preference='hideMentionStatus' room={room} onChangeValue={saveNotificationSettings} />}
|
||||||
/>
|
/>
|
||||||
<List.Separator />
|
<List.Separator />
|
||||||
<List.Info info='Show_badge_for_mentions_Info' />
|
<List.Info info='Show_badge_for_mentions_Info' />
|
||||||
|
@ -212,71 +174,49 @@ class NotificationPreferencesView extends React.Component<INotificationPreferenc
|
||||||
|
|
||||||
<List.Section title='In_App_And_Desktop'>
|
<List.Section title='In_App_And_Desktop'>
|
||||||
<List.Separator />
|
<List.Separator />
|
||||||
<List.Item
|
<RenderListPicker
|
||||||
|
preference='desktopNotifications'
|
||||||
|
room={room}
|
||||||
title='Alert'
|
title='Alert'
|
||||||
testID='notification-preference-view-alert'
|
testID='notification-preference-view-alert'
|
||||||
onPress={(title: string) => this.pickerSelection(title, 'desktopNotifications')}
|
onChangeValue={saveNotificationSettings}
|
||||||
right={() => this.renderPickerOption('desktopNotifications')}
|
/>
|
||||||
|
<RenderListPicker
|
||||||
|
preference='audioNotificationValue'
|
||||||
|
room={room}
|
||||||
|
title='Sound'
|
||||||
|
testID='notification-preference-view-sound'
|
||||||
|
onChangeValue={saveNotificationSettings}
|
||||||
/>
|
/>
|
||||||
<List.Separator />
|
<List.Separator />
|
||||||
<List.Info info='In_App_and_Desktop_Alert_info' />
|
<List.Info info='In_App_and_Desktop_Alert_info' />
|
||||||
</List.Section>
|
</List.Section>
|
||||||
|
|
||||||
<List.Section title='Push_Notifications'>
|
<List.Section title='Push_Notifications'>
|
||||||
<List.Separator />
|
<List.Separator />
|
||||||
<List.Item
|
<RenderListPicker
|
||||||
|
preference='mobilePushNotifications'
|
||||||
|
room={room}
|
||||||
title='Alert'
|
title='Alert'
|
||||||
testID='notification-preference-view-push-notification'
|
testID='notification-preference-view-push-notification'
|
||||||
onPress={(title: string) => this.pickerSelection(title, 'mobilePushNotifications')}
|
onChangeValue={saveNotificationSettings}
|
||||||
right={() => this.renderPickerOption('mobilePushNotifications')}
|
|
||||||
/>
|
/>
|
||||||
<List.Separator />
|
<List.Separator />
|
||||||
<List.Info info='Push_Notifications_Alert_Info' />
|
<List.Info info='Push_Notifications_Alert_Info' />
|
||||||
</List.Section>
|
</List.Section>
|
||||||
|
|
||||||
<List.Section title='Desktop_Options'>
|
|
||||||
<List.Separator />
|
|
||||||
<List.Item
|
|
||||||
title='Audio'
|
|
||||||
testID='notification-preference-view-audio'
|
|
||||||
onPress={(title: string) => this.pickerSelection(title, 'audioNotifications')}
|
|
||||||
right={() => this.renderPickerOption('audioNotifications')}
|
|
||||||
/>
|
|
||||||
<List.Separator />
|
|
||||||
<List.Item
|
|
||||||
title='Sound'
|
|
||||||
testID='notification-preference-view-sound'
|
|
||||||
onPress={(title: string) => this.pickerSelection(title, 'audioNotificationValue')}
|
|
||||||
right={() => this.renderPickerOption('audioNotificationValue')}
|
|
||||||
/>
|
|
||||||
<List.Separator />
|
|
||||||
<List.Item
|
|
||||||
title='Notification_Duration'
|
|
||||||
testID='notification-preference-view-notification-duration'
|
|
||||||
onPress={(title: string) => this.pickerSelection(title, 'desktopNotificationDuration')}
|
|
||||||
right={() => this.renderPickerOption('desktopNotificationDuration')}
|
|
||||||
/>
|
|
||||||
<List.Separator />
|
|
||||||
</List.Section>
|
|
||||||
|
|
||||||
<List.Section title='Email'>
|
<List.Section title='Email'>
|
||||||
<List.Separator />
|
<List.Separator />
|
||||||
<List.Item
|
<RenderListPicker
|
||||||
|
preference='emailNotifications'
|
||||||
|
room={room}
|
||||||
title='Alert'
|
title='Alert'
|
||||||
testID='notification-preference-view-email-alert'
|
testID='notification-preference-view-email-alert'
|
||||||
onPress={(title: string) => this.pickerSelection(title, 'emailNotifications')}
|
onChangeValue={saveNotificationSettings}
|
||||||
right={() => this.renderPickerOption('emailNotifications')}
|
|
||||||
/>
|
/>
|
||||||
<List.Separator />
|
<List.Separator />
|
||||||
</List.Section>
|
</List.Section>
|
||||||
</List.Container>
|
</List.Container>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
|
||||||
const mapStateToProps = (state: IApplicationState) => ({
|
export default NotificationPreferencesView;
|
||||||
serverVersion: state.server.version
|
|
||||||
});
|
|
||||||
|
|
||||||
export default connect(mapStateToProps)(withTheme(NotificationPreferencesView));
|
|
||||||
|
|
|
@ -4,11 +4,9 @@ export interface IOptionsField {
|
||||||
second?: number;
|
second?: number;
|
||||||
}
|
}
|
||||||
export interface INotificationOptions {
|
export interface INotificationOptions {
|
||||||
[desktopNotifications: string]: IOptionsField[];
|
desktopNotifications: IOptionsField[];
|
||||||
audioNotifications: IOptionsField[];
|
|
||||||
mobilePushNotifications: IOptionsField[];
|
mobilePushNotifications: IOptionsField[];
|
||||||
emailNotifications: IOptionsField[];
|
emailNotifications: IOptionsField[];
|
||||||
desktopNotificationDuration: IOptionsField[];
|
|
||||||
audioNotificationValue: IOptionsField[];
|
audioNotificationValue: IOptionsField[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,24 +29,6 @@ export const OPTIONS: INotificationOptions = {
|
||||||
value: 'nothing'
|
value: 'nothing'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
audioNotifications: [
|
|
||||||
{
|
|
||||||
label: 'Default',
|
|
||||||
value: 'default'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'All_Messages',
|
|
||||||
value: 'all'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Mentions',
|
|
||||||
value: 'mentions'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Nothing',
|
|
||||||
value: 'nothing'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
mobilePushNotifications: [
|
mobilePushNotifications: [
|
||||||
{
|
{
|
||||||
label: 'Default',
|
label: 'Default',
|
||||||
|
@ -85,37 +65,6 @@ export const OPTIONS: INotificationOptions = {
|
||||||
value: 'nothing'
|
value: 'nothing'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
desktopNotificationDuration: [
|
|
||||||
{
|
|
||||||
label: 'Default',
|
|
||||||
value: 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Seconds',
|
|
||||||
second: 1,
|
|
||||||
value: 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Seconds',
|
|
||||||
second: 2,
|
|
||||||
value: 2
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Seconds',
|
|
||||||
second: 3,
|
|
||||||
value: 3
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Seconds',
|
|
||||||
second: 4,
|
|
||||||
value: 4
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Seconds',
|
|
||||||
second: 5,
|
|
||||||
value: 5
|
|
||||||
}
|
|
||||||
],
|
|
||||||
audioNotificationValue: [
|
audioNotificationValue: [
|
||||||
{
|
{
|
||||||
label: 'None',
|
label: 'None',
|
||||||
|
|
Loading…
Reference in New Issue