From e68485bccd2ecd69defb92662585a86d0e70f821 Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Wed, 12 Jan 2022 10:05:30 -0400 Subject: [PATCH] [FIX] Message parser switch not updating field properly (#3576) --- app/views/UserPreferencesView/index.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/views/UserPreferencesView/index.tsx b/app/views/UserPreferencesView/index.tsx index 59f0f9f3a..5cb9a2aa5 100644 --- a/app/views/UserPreferencesView/index.tsx +++ b/app/views/UserPreferencesView/index.tsx @@ -1,8 +1,9 @@ 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 = () => ( - + const renderMessageParserSwitch = (value: boolean) => ( + ); return ( @@ -64,7 +65,7 @@ const UserPreferencesView = ({ navigation }: IUserPreferencesViewProps): JSX.Ele renderMessageParserSwitch()} + right={() => renderMessageParserSwitch(enableMessageParserEarlyAdoption)} />