From 51db92bfe172ace7f102b26776348a50323d31fa Mon Sep 17 00:00:00 2001 From: Aviad Pineles Date: Sat, 19 Aug 2023 15:50:23 +0300 Subject: [PATCH] fix: properly read default form values in RoomSettings --- .../CreateChannelView/RoomSettings/index.tsx | 16 ++++++---------- app/views/CreateChannelView/index.tsx | 10 +++++++++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/views/CreateChannelView/RoomSettings/index.tsx b/app/views/CreateChannelView/RoomSettings/index.tsx index 7d5cccd6d..5659767bc 100644 --- a/app/views/CreateChannelView/RoomSettings/index.tsx +++ b/app/views/CreateChannelView/RoomSettings/index.tsx @@ -13,7 +13,8 @@ export const RoomSettings = ({ isTeam, setValue, createChannelPermission, - createPrivateChannelPermission + createPrivateChannelPermission, + defaultEncryptionOn }: { isTeam: boolean; setValue: UseFormSetValue; @@ -22,18 +23,13 @@ export const RoomSettings = ({ }) => { const [type, setType] = useState(true); const [readOnly, setReadOnly] = useState(false); - - const { encryptionEnabled, defaultEncryptionOn } = useAppSelector(state => { - const defaultEncryptionOn = state.settings.E2E_Enabled_Default_PrivateRooms; - return { - encryptionEnabled: state.encryption.enabled, - defaultEncryptionOn - }; - }); - const [encrypted, setEncrypted] = useState(defaultEncryptionOn); const [broadcast, setBroadcast] = useState(false); + const { encryptionEnabled } = useAppSelector(state => ({ + encryptionEnabled: state.encryption.enabled + })); + const onValueChangeType = useCallback( (value: boolean) => { logEvent(events.CR_TOGGLE_TYPE); diff --git a/app/views/CreateChannelView/index.tsx b/app/views/CreateChannelView/index.tsx index 46ea017d5..949a5c6cf 100644 --- a/app/views/CreateChannelView/index.tsx +++ b/app/views/CreateChannelView/index.tsx @@ -68,13 +68,20 @@ export interface IFormData { const CreateChannelView = () => { const [createChannelPermission, createPrivateChannelPermission] = usePermissions(['create-c', 'create-p']); + const { defaultEncryptionOn } = useAppSelector(state => { + const defaultEncryptionOn = state.encryption.enabled && state.settings.E2E_Enabled_Default_PrivateRooms; + return { + defaultEncryptionOn + }; + }); + const { control, handleSubmit, formState: { isDirty }, setValue } = useForm({ - defaultValues: { channelName: '', broadcast: false, encrypted: false, readOnly: false, type: createPrivateChannelPermission } + defaultValues: { channelName: '', broadcast: false, encrypted: defaultEncryptionOn, readOnly: false, type: createPrivateChannelPermission } }); const navigation = useNavigation>(); @@ -154,6 +161,7 @@ const CreateChannelView = () => { createPrivateChannelPermission={createPrivateChannelPermission} isTeam={isTeam} setValue={setValue} + defaultEncryptionOn={defaultEncryptionOn} /> {users.length > 0 ? (