From 83b9b195841676e85b77128f7144204514a53302 Mon Sep 17 00:00:00 2001 From: Marcel <79279756+aofn@users.noreply.github.com> Date: Wed, 27 Nov 2024 11:04:45 +0100 Subject: [PATCH] feat: add functionality to edit room names --- pages/explore/manage-room/ChangeRoomName.js | 46 +++++++++++++++++++ .../manage-room/ExploreMatrixActions.js | 8 ++++ 2 files changed, 54 insertions(+) create mode 100644 pages/explore/manage-room/ChangeRoomName.js diff --git a/pages/explore/manage-room/ChangeRoomName.js b/pages/explore/manage-room/ChangeRoomName.js new file mode 100644 index 00000000..6c5eaad9 --- /dev/null +++ b/pages/explore/manage-room/ChangeRoomName.js @@ -0,0 +1,46 @@ +import React, { useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import { toast } from 'sonner'; + +import { useAuth } from '@/lib/Auth'; +import ConfirmCancelButtons from '@/components/UI/ConfirmCancelButtons'; +import { Input } from '@/components/UI/shadcn/Input'; + +const ChangeRoomName = ({ roomName, roomId }) => { + const matrixClient = useAuth().getAuthenticationProvider('matrix').getMatrixClient(); + const [newRoomName, setNewRoomName] = useState(''); + const [isChangingName, setIsChangingName] = useState(false); + const { t } = useTranslation('explore'); + + const handleSubmit = async (e) => { + e.preventDefault(); + setIsChangingName(true); + + try { + await matrixClient.setRoomName(roomId, newRoomName); + toast.success( + t('room name successfully changed to {{newRoomName}}. Please reload the page to see the changes.', { newRoomName }), + ); + } catch (error) { + toast.error(error.data?.error); + } finally { + setIsChangingName(false); + } + }; + + return ( + <> +
setNewRoomName(roomName)}> + setNewRoomName(e.target.value)} + /> + + + + ); +}; + +export default ChangeRoomName; diff --git a/pages/explore/manage-room/ExploreMatrixActions.js b/pages/explore/manage-room/ExploreMatrixActions.js index 75c9f003..05cc6dfd 100644 --- a/pages/explore/manage-room/ExploreMatrixActions.js +++ b/pages/explore/manage-room/ExploreMatrixActions.js @@ -8,6 +8,7 @@ import ChangeAvatar from './ChangeAvatar'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/UI/shadcn/Tabs'; import ChangeJoinRule from './ChangeJoinRule'; import { useAuth } from '@/lib/Auth'; +import ChangeRoomName from './ChangeRoomName'; /** * This component provides actions for managing contexts and items within a matrix room. @@ -77,6 +78,13 @@ const ExploreMatrixActions = ({ currentId, parentId, myPowerLevel }) => { )} + + {room.currentState.hasSufficientPowerLevelFor('m.room.title', myPowerLevel) && ( +
+

{t('Name')}

+ +
+ )}