@@ -4,8 +4,9 @@ import React, { useMemo } from 'react';
44
55import { roomTypes } from '../../../../../app/utils/client' ;
66import { useSetModal } from '../../../../contexts/ModalContext' ;
7- import { useEndpoint } from '../../../../contexts/ServerContext ' ;
7+ import { useToastMessageDispatch } from '../../../../contexts/ToastMessagesContext ' ;
88import { useTranslation } from '../../../../contexts/TranslationContext' ;
9+ import { useEndpointActionExperimental } from '../../../../hooks/useEndpointAction' ;
910import ConfirmationModal from './ConfirmationModal' ;
1011
1112const useReactModal = ( Component , props ) => {
@@ -22,16 +23,27 @@ const useReactModal = (Component, props) => {
2223
2324const 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