Regression: Create private team and channel as default (#4493)

* Regression: Create private team and channel as default

* minor tweak
This commit is contained in:
Reinaldo Neto 2022-09-09 11:49:06 -03:00 committed by GitHub
parent f9f13e7fe3
commit 1bc3f542f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 19 deletions

View File

@ -1,21 +1,18 @@
import React from 'react';
import { usePermissions } from '../../../lib/hooks';
import { SwitchItem } from './SwitchItem';
export const SwitchItemType = ({
isTeam,
type,
onValueChangeType
onValueChangeType,
isDisabled
}: {
isTeam: boolean;
type: boolean;
onValueChangeType: (value: boolean) => void;
isDisabled: boolean;
}) => {
const [createChannelPermission, createPrivateChannelPermission] = usePermissions(['create-c', 'create-p']);
const isDisabled = [createChannelPermission, createPrivateChannelPermission].filter(r => r === true).length <= 1;
let hint = '';
if (isTeam && type) {
hint = 'Team_hint_private';
@ -31,13 +28,6 @@ export const SwitchItemType = ({
}
return (
<SwitchItem
id={'type'}
value={createPrivateChannelPermission ? type : false}
disabled={isDisabled}
label={'Private'}
hint={hint}
onValueChange={onValueChangeType}
/>
<SwitchItem id={'type'} value={type} disabled={isDisabled} label={'Private'} hint={hint} onValueChange={onValueChangeType} />
);
};

View File

@ -9,7 +9,17 @@ import { SwitchItemReadOnly } from './SwitchItemReadOnly';
import { SwitchItemEncrypted } from './SwitchItemEncrypted';
import { IFormData } from '..';
export const RoomSettings = ({ isTeam, setValue }: { isTeam: boolean; setValue: UseFormSetValue<IFormData> }) => {
export const RoomSettings = ({
isTeam,
setValue,
createChannelPermission,
createPrivateChannelPermission
}: {
isTeam: boolean;
setValue: UseFormSetValue<IFormData>;
createChannelPermission: boolean;
createPrivateChannelPermission: boolean;
}) => {
const [type, setType] = useState(true);
const [readOnly, setReadOnly] = useState(false);
const [encrypted, setEncrypted] = useState(false);
@ -50,9 +60,17 @@ export const RoomSettings = ({ isTeam, setValue }: { isTeam: boolean; setValue:
setReadOnly(value ? true : readOnly);
setValue('readOnly', value ? true : readOnly);
};
const isDisabled = [createChannelPermission, createPrivateChannelPermission].filter(r => r === true).length <= 1;
return (
<>
<SwitchItemType isTeam={isTeam} type={type} onValueChangeType={onValueChangeType} />
<SwitchItemType
isTeam={isTeam}
type={createPrivateChannelPermission ? type : false}
onValueChangeType={onValueChangeType}
isDisabled={isDisabled}
/>
<SwitchItemReadOnly
broadcast={broadcast}
isTeam={isTeam}

View File

@ -5,7 +5,7 @@ import { RouteProp, useNavigation, useRoute } from '@react-navigation/native';
import { StackNavigationProp } from '@react-navigation/stack';
import { useForm } from 'react-hook-form';
import { useAppSelector } from '../../lib/hooks';
import { useAppSelector, usePermissions } from '../../lib/hooks';
import { sendLoadingEvent } from '../../containers/Loading';
import { createChannelRequest } from '../../actions/createChannel';
import { removeUser as removeUserAction } from '../../actions/selectedUsers';
@ -67,13 +67,15 @@ export interface IFormData {
}
const CreateChannelView = () => {
const [createChannelPermission, createPrivateChannelPermission] = usePermissions(['create-c', 'create-p']);
const {
control,
handleSubmit,
formState: { isDirty },
setValue
} = useForm<IFormData>({
defaultValues: { channelName: '', broadcast: false, encrypted: false, readOnly: false, type: false }
defaultValues: { channelName: '', broadcast: false, encrypted: false, readOnly: false, type: createPrivateChannelPermission }
});
const navigation = useNavigation<StackNavigationProp<ChatsStackParamList, 'CreateChannelView'>>();
@ -148,7 +150,12 @@ const CreateChannelView = () => {
name={'channelName'}
control={control}
/>
<RoomSettings isTeam={isTeam} setValue={setValue} />
<RoomSettings
createChannelPermission={createChannelPermission}
createPrivateChannelPermission={createPrivateChannelPermission}
isTeam={isTeam}
setValue={setValue}
/>
</View>
{users.length > 0 ? (
<>