diff --git a/apps/meteor/client/sidebar/header/CreateChannel.tsx b/apps/meteor/client/sidebar/header/CreateChannel.tsx index 7f18bf7978f9..81694697f737 100644 --- a/apps/meteor/client/sidebar/header/CreateChannel.tsx +++ b/apps/meteor/client/sidebar/header/CreateChannel.tsx @@ -5,14 +5,15 @@ import React, { ReactElement, useEffect, useMemo, useState } from 'react'; import UserAutoCompleteMultiple from '../../components/UserAutoCompleteMultiple'; -type CreateChannelProps = { +export type CreateChannelProps = { values: { name: string; - type?: boolean; + type: boolean; readOnly?: boolean; encrypted?: boolean; broadcast?: boolean; users?: string[]; + description?: string; }; handlers: { handleName?: () => void; @@ -21,10 +22,10 @@ type CreateChannelProps = { handleReadOnly?: () => void; }; hasUnsavedChanges: boolean; - onChangeUsers: () => void; - onChangeType: () => void; - onChangeBroadcast: () => void; - canOnlyCreateOneType?: boolean; + onChangeUsers: (value: string, action: string) => void; + onChangeType: React.FormEventHandler; + onChangeBroadcast: React.FormEventHandler; + canOnlyCreateOneType?: false | 'p' | 'c'; e2eEnabledForPrivateByDefault?: boolean; onCreate: () => void; onClose: () => void; @@ -76,8 +77,8 @@ const CreateChannel = ({ checkName(values.name); }, [checkName, values.name]); - const e2edisabled = useMemo( - () => !values.type || values.broadcast || !e2eEnabled || e2eEnabledForPrivateByDefault, + const e2edisabled = useMemo( + () => !values.type || values.broadcast || Boolean(!e2eEnabled) || Boolean(e2eEnabledForPrivateByDefault), [e2eEnabled, e2eEnabledForPrivateByDefault, values.broadcast, values.type], ); diff --git a/apps/meteor/client/sidebar/header/CreateChannelWithData.js b/apps/meteor/client/sidebar/header/CreateChannelWithData.tsx similarity index 71% rename from apps/meteor/client/sidebar/header/CreateChannelWithData.js rename to apps/meteor/client/sidebar/header/CreateChannelWithData.tsx index 346f2ab1d15a..8af0453b5ed6 100644 --- a/apps/meteor/client/sidebar/header/CreateChannelWithData.js +++ b/apps/meteor/client/sidebar/header/CreateChannelWithData.tsx @@ -1,13 +1,30 @@ +import { RoomType } from '@rocket.chat/core-typings'; import { useMutableCallback } from '@rocket.chat/fuselage-hooks'; import { useSetting, usePermission } from '@rocket.chat/ui-contexts'; -import React, { memo, useCallback, useMemo } from 'react'; +import React, { memo, ReactElement, useCallback, useMemo } from 'react'; import { useEndpointActionExperimental } from '../../hooks/useEndpointActionExperimental'; import { useForm } from '../../hooks/useForm'; import { goToRoomById } from '../../lib/utils/goToRoomById'; -import CreateChannel from './CreateChannel'; +import CreateChannel, { CreateChannelProps } from './CreateChannel'; -const CreateChannelWithData = ({ onClose, teamId = '', reload }) => { +type CreateChannelWithDataProps = { + onClose: () => void; + teamId?: string; + reload: () => void; +}; + +type UseFormValues = { + users: string[]; + name: string; + type: RoomType; + description: string; + readOnly: boolean; + encrypted: boolean; + broadcast: boolean; +}; + +const CreateChannelWithData = ({ onClose, teamId = '', reload }: CreateChannelWithDataProps): ReactElement => { const createChannel = useEndpointActionExperimental('POST', 'channels.create'); const createPrivateChannel = useEndpointActionExperimental('POST', 'groups.create'); const canCreateChannel = usePermission('create-c'); @@ -24,7 +41,7 @@ const CreateChannelWithData = ({ onClose, teamId = '', reload }) => { }, [canCreateChannel, canCreatePrivateChannel]); const initialValues = { - users: [], + users: [''], name: '', description: '', type: canOnlyCreateOneType ? canOnlyCreateOneType === 'p' : true, @@ -34,7 +51,7 @@ const CreateChannelWithData = ({ onClose, teamId = '', reload }) => { }; const { values, handlers, hasUnsavedChanges } = useForm(initialValues); - const { users, name, description, type, readOnly, broadcast, encrypted } = values; + const { users, name, description, type, readOnly, broadcast, encrypted } = values as UseFormValues; const { handleUsers, handleEncrypted, handleType, handleBroadcast, handleReadOnly } = handlers; const onChangeUsers = useMutableCallback((value, action) => { @@ -59,7 +76,7 @@ const CreateChannelWithData = ({ onClose, teamId = '', reload }) => { }); const onCreate = useCallback(async () => { - const goToRoom = (rid) => { + const goToRoom = (rid: string): void => { goToRoomById(rid); }; @@ -74,14 +91,15 @@ const CreateChannelWithData = ({ onClose, teamId = '', reload }) => { ...(teamId && { teamId }), }, }; - let roomData; if (type) { - roomData = await createPrivateChannel(params); - !teamId && goToRoom(roomData.group._id); + const roomData = await createPrivateChannel(params); + console.log(roomData); + !teamId && goToRoom(roomData.group._id as string); } else { - roomData = await createChannel(params); - !teamId && goToRoom(roomData.channel._id); + const roomData = await createChannel(params); + console.log(roomData); + !teamId && goToRoom((roomData as any).channel._id); } onClose(); @@ -90,14 +108,14 @@ const CreateChannelWithData = ({ onClose, teamId = '', reload }) => { return ( diff --git a/packages/core-typings/src/IRoom.ts b/packages/core-typings/src/IRoom.ts index 14b3f9a0ba1a..fdcef247687f 100644 --- a/packages/core-typings/src/IRoom.ts +++ b/packages/core-typings/src/IRoom.ts @@ -83,6 +83,8 @@ export interface IRoom extends IRocketChatRecord { description?: string; createdOTR?: boolean; e2eKeyId?: string; + + channel?: { _id: string }; } export interface ICreatedRoom extends IRoom {