Unverified Commit e68485bc authored by Gerzon Z's avatar Gerzon Z Committed by GitHub
Browse files

[FIX] Message parser switch not updating field properly (#3576)

parent bff99d5c
import { StackNavigationProp } from '@react-navigation/stack';
import React, { useEffect, useState } from 'react';
import React, { useEffect } from 'react';
import { Switch } from 'react-native';
import { useSelector } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import { setUser } from '../../actions/login';
import I18n from '../../i18n';
import log, { logEvent, events } from '../../utils/log';
import SafeAreaView from '../../containers/SafeAreaView';
......@@ -18,8 +19,8 @@ interface IUserPreferencesViewProps {
}
const UserPreferencesView = ({ navigation }: IUserPreferencesViewProps): JSX.Element => {
const user = useSelector(state => getUserSelector(state));
const [enableParser, setEnableParser] = useState(user.enableMessageParserEarlyAdoption);
const { enableMessageParserEarlyAdoption, id } = useSelector(state => getUserSelector(state));
const dispatch = useDispatch();
useEffect(() => {
navigation.setOptions({
......@@ -34,15 +35,15 @@ const UserPreferencesView = ({ navigation }: IUserPreferencesViewProps): JSX.Ele
const toggleMessageParser = async (value: boolean) => {
try {
await RocketChat.saveUserPreferences({ id: user.id, enableMessageParserEarlyAdoption: value });
setEnableParser(value);
dispatch(setUser({ enableMessageParserEarlyAdoption: value }));
await RocketChat.saveUserPreferences({ id, enableMessageParserEarlyAdoption: value });
} catch (e) {
log(e);
}
};
const renderMessageParserSwitch = () => (
<Switch value={enableParser} trackColor={SWITCH_TRACK_COLOR} onValueChange={toggleMessageParser} />
const renderMessageParserSwitch = (value: boolean) => (
<Switch value={value} trackColor={SWITCH_TRACK_COLOR} onValueChange={toggleMessageParser} />
);
return (
......@@ -64,7 +65,7 @@ const UserPreferencesView = ({ navigation }: IUserPreferencesViewProps): JSX.Ele
<List.Item
title='Enable_Message_Parser'
testID='preferences-view-enable-message-parser'
right={() => renderMessageParserSwitch()}
right={() => renderMessageParserSwitch(enableMessageParserEarlyAdoption)}
/>
<List.Separator />
</List.Section>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment