From 4a7b4d9e1f9e107fc76117ecccf85bffe42a3b67 Mon Sep 17 00:00:00 2001 From: julia foresti Date: Mon, 23 May 2022 09:40:33 -0300 Subject: [PATCH 1/3] wip --- .../client/sidebar/header/CreateChannel.tsx | 13 +++---- ...lWithData.js => CreateChannelWithData.tsx} | 36 ++++++++++++++----- 2 files changed, 34 insertions(+), 15 deletions(-) rename apps/meteor/client/sidebar/header/{CreateChannelWithData.js => CreateChannelWithData.tsx} (78%) diff --git a/apps/meteor/client/sidebar/header/CreateChannel.tsx b/apps/meteor/client/sidebar/header/CreateChannel.tsx index 7f18bf7978f9..3d7bc2bfde6c 100644 --- a/apps/meteor/client/sidebar/header/CreateChannel.tsx +++ b/apps/meteor/client/sidebar/header/CreateChannel.tsx @@ -1,3 +1,4 @@ +import { RoomType } from '@rocket.chat/core-typings'; import { Box, Modal, ButtonGroup, Button, TextInput, Icon, Field, ToggleSwitch, FieldGroup } from '@rocket.chat/fuselage'; import { useDebouncedCallback } from '@rocket.chat/fuselage-hooks'; import { useSetting, useMethod, useTranslation } from '@rocket.chat/ui-contexts'; @@ -8,7 +9,7 @@ import UserAutoCompleteMultiple from '../../components/UserAutoCompleteMultiple' type CreateChannelProps = { values: { name: string; - type?: boolean; + type: RoomType; readOnly?: boolean; encrypted?: boolean; broadcast?: boolean; @@ -21,11 +22,11 @@ type CreateChannelProps = { handleReadOnly?: () => void; }; hasUnsavedChanges: boolean; - onChangeUsers: () => void; - onChangeType: () => void; - onChangeBroadcast: () => void; - canOnlyCreateOneType?: boolean; - e2eEnabledForPrivateByDefault?: boolean; + onChangeUsers: (value: string, action: string) => void; + onChangeType: (value: string) => void; + onChangeBroadcast: (value: string) => void; + canOnlyCreateOneType?: false | 'p' | 'c'; + e2eEnabledForPrivateByDefault?: unknown; onCreate: () => void; onClose: () => void; }; diff --git a/apps/meteor/client/sidebar/header/CreateChannelWithData.js b/apps/meteor/client/sidebar/header/CreateChannelWithData.tsx similarity index 78% rename from apps/meteor/client/sidebar/header/CreateChannelWithData.js rename to apps/meteor/client/sidebar/header/CreateChannelWithData.tsx index 346f2ab1d15a..b4abf2ce83ca 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'; -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,13 +91,14 @@ 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); + const roomData = await createChannel(params); + console.log(roomData); !teamId && goToRoom(roomData.channel._id); } From 319905e2eb11485f6256873e6947a0fa95411ce2 Mon Sep 17 00:00:00 2001 From: julia foresti Date: Mon, 23 May 2022 09:41:04 -0300 Subject: [PATCH 2/3] wip --- packages/core-typings/src/IRoom.ts | 2 ++ 1 file changed, 2 insertions(+) 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 { From 31899b63f8887fc228608c3db6fb3a7f8c8e8ae9 Mon Sep 17 00:00:00 2001 From: juliajforesti Date: Fri, 27 May 2022 15:27:04 -0300 Subject: [PATCH 3/3] Convert CreateChannelWithData. Adjust CreateChannel --- .../client/sidebar/header/CreateChannel.tsx | 16 ++++++++-------- .../sidebar/header/CreateChannelWithData.tsx | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/meteor/client/sidebar/header/CreateChannel.tsx b/apps/meteor/client/sidebar/header/CreateChannel.tsx index 3d7bc2bfde6c..81694697f737 100644 --- a/apps/meteor/client/sidebar/header/CreateChannel.tsx +++ b/apps/meteor/client/sidebar/header/CreateChannel.tsx @@ -1,4 +1,3 @@ -import { RoomType } from '@rocket.chat/core-typings'; import { Box, Modal, ButtonGroup, Button, TextInput, Icon, Field, ToggleSwitch, FieldGroup } from '@rocket.chat/fuselage'; import { useDebouncedCallback } from '@rocket.chat/fuselage-hooks'; import { useSetting, useMethod, useTranslation } from '@rocket.chat/ui-contexts'; @@ -6,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: RoomType; + type: boolean; readOnly?: boolean; encrypted?: boolean; broadcast?: boolean; users?: string[]; + description?: string; }; handlers: { handleName?: () => void; @@ -23,10 +23,10 @@ type CreateChannelProps = { }; hasUnsavedChanges: boolean; onChangeUsers: (value: string, action: string) => void; - onChangeType: (value: string) => void; - onChangeBroadcast: (value: string) => void; + onChangeType: React.FormEventHandler; + onChangeBroadcast: React.FormEventHandler; canOnlyCreateOneType?: false | 'p' | 'c'; - e2eEnabledForPrivateByDefault?: unknown; + e2eEnabledForPrivateByDefault?: boolean; onCreate: () => void; onClose: () => void; }; @@ -77,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.tsx b/apps/meteor/client/sidebar/header/CreateChannelWithData.tsx index b4abf2ce83ca..8af0453b5ed6 100644 --- a/apps/meteor/client/sidebar/header/CreateChannelWithData.tsx +++ b/apps/meteor/client/sidebar/header/CreateChannelWithData.tsx @@ -6,7 +6,7 @@ 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'; type CreateChannelWithDataProps = { onClose: () => void; @@ -99,7 +99,7 @@ const CreateChannelWithData = ({ onClose, teamId = '', reload }: CreateChannelWi } else { const roomData = await createChannel(params); console.log(roomData); - !teamId && goToRoom(roomData.channel._id); + !teamId && goToRoom((roomData as any).channel._id); } onClose(); @@ -108,14 +108,14 @@ const CreateChannelWithData = ({ onClose, teamId = '', reload }: CreateChannelWi return (