Regression: Create private team and channel as default (#4493)
* Regression: Create private team and channel as default * minor tweak
This commit is contained in:
parent
f9f13e7fe3
commit
1bc3f542f2
|
@ -1,21 +1,18 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { usePermissions } from '../../../lib/hooks';
|
|
||||||
import { SwitchItem } from './SwitchItem';
|
import { SwitchItem } from './SwitchItem';
|
||||||
|
|
||||||
export const SwitchItemType = ({
|
export const SwitchItemType = ({
|
||||||
isTeam,
|
isTeam,
|
||||||
type,
|
type,
|
||||||
onValueChangeType
|
onValueChangeType,
|
||||||
|
isDisabled
|
||||||
}: {
|
}: {
|
||||||
isTeam: boolean;
|
isTeam: boolean;
|
||||||
type: boolean;
|
type: boolean;
|
||||||
onValueChangeType: (value: boolean) => void;
|
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 = '';
|
let hint = '';
|
||||||
if (isTeam && type) {
|
if (isTeam && type) {
|
||||||
hint = 'Team_hint_private';
|
hint = 'Team_hint_private';
|
||||||
|
@ -31,13 +28,6 @@ export const SwitchItemType = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SwitchItem
|
<SwitchItem id={'type'} value={type} disabled={isDisabled} label={'Private'} hint={hint} onValueChange={onValueChangeType} />
|
||||||
id={'type'}
|
|
||||||
value={createPrivateChannelPermission ? type : false}
|
|
||||||
disabled={isDisabled}
|
|
||||||
label={'Private'}
|
|
||||||
hint={hint}
|
|
||||||
onValueChange={onValueChangeType}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,17 @@ import { SwitchItemReadOnly } from './SwitchItemReadOnly';
|
||||||
import { SwitchItemEncrypted } from './SwitchItemEncrypted';
|
import { SwitchItemEncrypted } from './SwitchItemEncrypted';
|
||||||
import { IFormData } from '..';
|
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 [type, setType] = useState(true);
|
||||||
const [readOnly, setReadOnly] = useState(false);
|
const [readOnly, setReadOnly] = useState(false);
|
||||||
const [encrypted, setEncrypted] = useState(false);
|
const [encrypted, setEncrypted] = useState(false);
|
||||||
|
@ -50,9 +60,17 @@ export const RoomSettings = ({ isTeam, setValue }: { isTeam: boolean; setValue:
|
||||||
setReadOnly(value ? true : readOnly);
|
setReadOnly(value ? true : readOnly);
|
||||||
setValue('readOnly', value ? true : readOnly);
|
setValue('readOnly', value ? true : readOnly);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isDisabled = [createChannelPermission, createPrivateChannelPermission].filter(r => r === true).length <= 1;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SwitchItemType isTeam={isTeam} type={type} onValueChangeType={onValueChangeType} />
|
<SwitchItemType
|
||||||
|
isTeam={isTeam}
|
||||||
|
type={createPrivateChannelPermission ? type : false}
|
||||||
|
onValueChangeType={onValueChangeType}
|
||||||
|
isDisabled={isDisabled}
|
||||||
|
/>
|
||||||
<SwitchItemReadOnly
|
<SwitchItemReadOnly
|
||||||
broadcast={broadcast}
|
broadcast={broadcast}
|
||||||
isTeam={isTeam}
|
isTeam={isTeam}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { RouteProp, useNavigation, useRoute } from '@react-navigation/native';
|
||||||
import { StackNavigationProp } from '@react-navigation/stack';
|
import { StackNavigationProp } from '@react-navigation/stack';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
|
|
||||||
import { useAppSelector } from '../../lib/hooks';
|
import { useAppSelector, usePermissions } from '../../lib/hooks';
|
||||||
import { sendLoadingEvent } from '../../containers/Loading';
|
import { sendLoadingEvent } from '../../containers/Loading';
|
||||||
import { createChannelRequest } from '../../actions/createChannel';
|
import { createChannelRequest } from '../../actions/createChannel';
|
||||||
import { removeUser as removeUserAction } from '../../actions/selectedUsers';
|
import { removeUser as removeUserAction } from '../../actions/selectedUsers';
|
||||||
|
@ -67,13 +67,15 @@ export interface IFormData {
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreateChannelView = () => {
|
const CreateChannelView = () => {
|
||||||
|
const [createChannelPermission, createPrivateChannelPermission] = usePermissions(['create-c', 'create-p']);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
control,
|
control,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
formState: { isDirty },
|
formState: { isDirty },
|
||||||
setValue
|
setValue
|
||||||
} = useForm<IFormData>({
|
} = 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'>>();
|
const navigation = useNavigation<StackNavigationProp<ChatsStackParamList, 'CreateChannelView'>>();
|
||||||
|
@ -148,7 +150,12 @@ const CreateChannelView = () => {
|
||||||
name={'channelName'}
|
name={'channelName'}
|
||||||
control={control}
|
control={control}
|
||||||
/>
|
/>
|
||||||
<RoomSettings isTeam={isTeam} setValue={setValue} />
|
<RoomSettings
|
||||||
|
createChannelPermission={createChannelPermission}
|
||||||
|
createPrivateChannelPermission={createPrivateChannelPermission}
|
||||||
|
isTeam={isTeam}
|
||||||
|
setValue={setValue}
|
||||||
|
/>
|
||||||
</View>
|
</View>
|
||||||
{users.length > 0 ? (
|
{users.length > 0 ? (
|
||||||
<>
|
<>
|
||||||
|
|
Loading…
Reference in New Issue