Skip to content

Commit ac7791a

Browse files
authored
regression: Team Channels actions (RocketChat#21417)
1 parent 9b932c1 commit ac7791a

2 files changed

Lines changed: 36 additions & 21 deletions

File tree

client/sidebar/header/CreateChannel.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,8 @@ const CreateChannel = ({
3333
const namesValidation = useSetting('UTF8_Names_Validation');
3434
const allowSpecialNames = useSetting('UI_Allow_room_names_with_special_chars');
3535
const channelNameExists = useMethod('roomNameExists');
36-
const channelNameRegex = useMemo(() => {
37-
if (allowSpecialNames) {
38-
return '';
39-
}
40-
const regex = new RegExp(`^${namesValidation}$`);
4136

42-
return regex;
43-
}, [allowSpecialNames, namesValidation]);
37+
const channelNameRegex = useMemo(() => new RegExp(`^${namesValidation}$`), [namesValidation]);
4438

4539
const [nameError, setNameError] = useState();
4640

@@ -53,7 +47,7 @@ const CreateChannel = ({
5347
if (!name || name.length === 0) {
5448
return setNameError(t('Field_required'));
5549
}
56-
if (!channelNameRegex.test(name)) {
50+
if (!allowSpecialNames && !channelNameRegex.test(name)) {
5751
return setNameError(t('error-invalid-name'));
5852
}
5953
const isNotAvailable = await channelNameExists(name);
@@ -62,7 +56,7 @@ const CreateChannel = ({
6256
}
6357
},
6458
100,
65-
[name],
59+
[channelNameRegex],
6660
);
6761

6862
useEffect(() => {

client/views/teams/contextualBar/channels/RoomActions.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import React, { useMemo } from 'react';
44

55
import { roomTypes } from '../../../../../app/utils/client';
66
import { useSetModal } from '../../../../contexts/ModalContext';
7-
import { useEndpoint } from '../../../../contexts/ServerContext';
7+
import { useToastMessageDispatch } from '../../../../contexts/ToastMessagesContext';
88
import { useTranslation } from '../../../../contexts/TranslationContext';
9+
import { useEndpointActionExperimental } from '../../../../hooks/useEndpointAction';
910
import ConfirmationModal from './ConfirmationModal';
1011

1112
const useReactModal = (Component, props) => {
@@ -22,16 +23,27 @@ const useReactModal = (Component, props) => {
2223

2324
const RoomActions = ({ room, reload }) => {
2425
const t = useTranslation();
25-
const updateRoomEndpoint = useEndpoint('POST', 'teams.updateRoom');
26-
const removeRoomEndpoint = useEndpoint('POST', 'teams.removeRoom');
27-
const deleteRoomEndpoint = useEndpoint(
26+
const dispatchToastMessage = useToastMessageDispatch();
27+
28+
const updateRoomEndpoint = useEndpointActionExperimental('POST', 'teams.updateRoom');
29+
const removeRoomEndpoint = useEndpointActionExperimental(
30+
'POST',
31+
'teams.removeRoom',
32+
t('Success'),
33+
);
34+
const deleteRoomEndpoint = useEndpointActionExperimental(
2835
'POST',
2936
room.t === 'c' ? 'channels.delete' : 'groups.delete',
37+
t('Success'),
3038
);
3139

3240
const RemoveFromTeamAction = useReactModal(ConfirmationModal, {
33-
onConfirmAction: () => {
34-
removeRoomEndpoint({ teamId: room.teamId, roomId: room._id });
41+
onConfirmAction: async () => {
42+
try {
43+
await removeRoomEndpoint({ teamId: room.teamId, roomId: room._id });
44+
} catch (error) {
45+
dispatchToastMessage({ type: 'error', message: error });
46+
}
3547
reload();
3648
},
3749
labelButton: t('Remove'),
@@ -46,7 +58,11 @@ const RoomActions = ({ room, reload }) => {
4658

4759
const DeleteChannelAction = useReactModal(ConfirmationModal, {
4860
onConfirmAction: async () => {
49-
await deleteRoomEndpoint({ roomId: room._id });
61+
try {
62+
await deleteRoomEndpoint({ roomId: room._id });
63+
} catch (error) {
64+
dispatchToastMessage({ type: 'error', message: error });
65+
}
5066
reload();
5167
},
5268
labelButton: t('Delete'),
@@ -64,11 +80,15 @@ const RoomActions = ({ room, reload }) => {
6480
});
6581

6682
const menuOptions = useMemo(() => {
67-
const AutoJoinAction = () => {
68-
updateRoomEndpoint({
69-
roomId: room._id,
70-
isDefault: !room.teamDefault,
71-
});
83+
const AutoJoinAction = async () => {
84+
try {
85+
await updateRoomEndpoint({
86+
roomId: room._id,
87+
isDefault: !room.teamDefault,
88+
});
89+
} catch (error) {
90+
dispatchToastMessage({ type: 'error', message: error });
91+
}
7292

7393
reload();
7494
};
@@ -105,6 +125,7 @@ const RoomActions = ({ room, reload }) => {
105125
t,
106126
updateRoomEndpoint,
107127
reload,
128+
dispatchToastMessage,
108129
]);
109130

110131
return (

0 commit comments

Comments
 (0)