diff --git a/.changeset/thick-nails-explode.md b/.changeset/thick-nails-explode.md new file mode 100644 index 000000000000..5cf9020e1911 --- /dev/null +++ b/.changeset/thick-nails-explode.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Fixed the problem of not being possible to add a join code to a public room diff --git a/apps/meteor/client/views/room/composer/ComposerContainer.tsx b/apps/meteor/client/views/room/composer/ComposerContainer.tsx index 66e72de2a0f4..3988c080bff2 100644 --- a/apps/meteor/client/views/room/composer/ComposerContainer.tsx +++ b/apps/meteor/client/views/room/composer/ComposerContainer.tsx @@ -1,4 +1,5 @@ import { isOmnichannelRoom, isRoomFederated, isVoipRoom } from '@rocket.chat/core-typings'; +import { usePermission } from '@rocket.chat/ui-contexts'; import type { ReactElement } from 'react'; import React, { memo } from 'react'; @@ -18,19 +19,14 @@ import { useMessageComposerIsReadOnly } from './hooks/useMessageComposerIsReadOn const ComposerContainer = ({ children, ...props }: ComposerMessageProps): ReactElement => { const room = useRoom(); - - const mustJoinWithCode = !props.subscription && room.joinCodeRequired; + const canJoinWithoutCode = usePermission('join-without-join-code'); + const mustJoinWithCode = !props.subscription && room.joinCodeRequired && !canJoinWithoutCode; const isAnonymous = useMessageComposerIsAnonymous(); - const isBlockedOrBlocker = useMessageComposerIsBlocked({ subscription: props.subscription }); - const isReadOnly = useMessageComposerIsReadOnly(room._id, props.subscription); - const isOmnichannel = isOmnichannelRoom(room); - const isFederation = isRoomFederated(room); - const isVoip = isVoipRoom(room); if (isOmnichannel) { diff --git a/apps/meteor/client/views/room/composer/ComposerJoinWithPassword.tsx b/apps/meteor/client/views/room/composer/ComposerJoinWithPassword.tsx index 752306883095..bef2dfe3d354 100644 --- a/apps/meteor/client/views/room/composer/ComposerJoinWithPassword.tsx +++ b/apps/meteor/client/views/room/composer/ComposerJoinWithPassword.tsx @@ -1,53 +1,50 @@ -import { TextInput } from '@rocket.chat/fuselage'; +import { PasswordInput } from '@rocket.chat/fuselage'; import { MessageFooterCallout, MessageFooterCalloutAction, MessageFooterCalloutContent } from '@rocket.chat/ui-composer'; -import { useTranslation, useEndpoint } from '@rocket.chat/ui-contexts'; -import type { ChangeEvent, ReactElement, FormEventHandler } from 'react'; -import React, { useCallback, useState } from 'react'; +import { useTranslation, useEndpoint, useToastMessageDispatch } from '@rocket.chat/ui-contexts'; +import type { ReactElement } from 'react'; +import React from 'react'; +import { Controller, useForm } from 'react-hook-form'; import { useRoom } from '../contexts/RoomContext'; const ComposerJoinWithPassword = (): ReactElement => { - const room = useRoom(); - const [joinCode, setJoinPassword] = useState(''); - - const [error, setError] = useState(''); - const t = useTranslation(); - - const joinEndpoint = useEndpoint('POST', '/v1/channels.join'); - - const join = useCallback>( - async (e) => { - e.preventDefault(); - try { - await joinEndpoint({ - roomId: room._id, - joinCode, - }); - } catch (error: any) { - setError(error.error); - } - }, - [joinEndpoint, room._id, joinCode], - ); - - const handleChange = useCallback((e: ChangeEvent) => { - setJoinPassword(e.target.value); - setError(''); - }, []); + const room = useRoom(); + const dispatchToastMessage = useToastMessageDispatch(); + + const joinChannelEndpoint = useEndpoint('POST', '/v1/channels.join'); + const { + control, + handleSubmit, + setError, + formState: { errors, isDirty }, + } = useForm({ defaultValues: { joinCode: '' } }); + + const handleJoinChannel = async ({ joinCode }: { joinCode: string }) => { + try { + await joinChannelEndpoint({ + roomId: room._id, + joinCode, + }); + } catch (error: any) { + setError('joinCode', { type: error.errorType, message: error.error }); + dispatchToastMessage({ type: 'error', message: error }); + } + }; return ( - + {t('you_are_in_preview')} - ( + + )} /> - + {t('Join_with_password')} diff --git a/apps/meteor/client/views/room/contextualBar/Info/EditRoomInfo/EditRoomInfo.tsx b/apps/meteor/client/views/room/contextualBar/Info/EditRoomInfo/EditRoomInfo.tsx index bd472f4a7908..9b372c72ac8f 100644 --- a/apps/meteor/client/views/room/contextualBar/Info/EditRoomInfo/EditRoomInfo.tsx +++ b/apps/meteor/client/views/room/contextualBar/Info/EditRoomInfo/EditRoomInfo.tsx @@ -2,6 +2,7 @@ import type { IRoomWithRetentionPolicy } from '@rocket.chat/core-typings'; import { isRoomFederated } from '@rocket.chat/core-typings'; import type { SelectOption } from '@rocket.chat/fuselage'; import { + FieldError, Field, FieldRow, FieldLabel, @@ -97,7 +98,7 @@ const EditRoomInfo = ({ room, onClickClose, onClickBack }: EditRoomInfoProps) => const handleArchive = useArchiveRoom(room); - const handleUpdateRoomData = useMutableCallback(async ({ hideSysMes, ...formData }) => { + const handleUpdateRoomData = useMutableCallback(async ({ hideSysMes, joinCodeRequired, ...formData }) => { const data = getDirtyFields(formData, dirtyFields); delete data.archived; @@ -169,7 +170,7 @@ const EditRoomInfo = ({ room, onClickClose, onClickBack }: EditRoomInfoProps) => render={({ field }) => } /> - {errors.roomName && {errors.roomName.message}} + {errors.roomName && {errors.roomName.message}} {canViewDescription && (