From c69aa2fff8d9c254d00cb057a456b1be69beddff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mai=20G=C3=A1bor?= Date: Thu, 14 Nov 2024 12:25:08 +0100 Subject: [PATCH] add functionality to claim room. --- .../managementservice/rooms/CurrentRoom.tsx | 217 ++++++++++-------- .../settingsdialog/ManagementSettings.tsx | 61 ++--- src/store/actions/managementActions.tsx | 4 +- 3 files changed, 140 insertions(+), 142 deletions(-) diff --git a/src/components/managementservice/rooms/CurrentRoom.tsx b/src/components/managementservice/rooms/CurrentRoom.tsx index 9a7b4eb7..9e59c5ad 100644 --- a/src/components/managementservice/rooms/CurrentRoom.tsx +++ b/src/components/managementservice/rooms/CurrentRoom.tsx @@ -4,7 +4,7 @@ import { Button, Dialog, DialogTitle, DialogContent, DialogContentText, TextFiel import React from 'react'; import { Roles, Room, Tenant } from '../../../utils/types'; import { useAppDispatch } from '../../../store/hooks'; -import { getRoles, getRoomByName, getTenants, modifyRoom } from '../../../store/actions/managementActions'; +import { createRoom, getRoles, getRoomByName, getTenants, modifyRoom } from '../../../store/actions/managementActions'; const CurrentRoomModal = () => { const dispatch = useAppDispatch(); @@ -15,6 +15,7 @@ const CurrentRoomModal = () => { type RoleTypes = Array + const [ roomExists, setRoomExists ] = useState(false); const [ roles, setRoles ] = useState([ { 'description': 'Test', 'id': 1, 'name': 'Test', 'tenantId': 1, 'permissions': [] } ]); const [ id, setId ] = useState(0); const [ name, setName ] = useState(''); @@ -61,6 +62,7 @@ const CurrentRoomModal = () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any dispatch(getRoomByName(window.location.pathname.substring(1))).then((tdata: any) => { + // eslint-disable-next-line no-console console.log('Rooms data', tdata); const r = tdata.data[0] as Room; @@ -171,10 +173,18 @@ const CurrentRoomModal = () => { } + function checkRoomExists() { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + dispatch(getRoomByName(window.location.pathname.substring(1))).then((tdata: any) => { + setRoomExists(tdata.total===1); + }); + } + useEffect(() => { // fetchProduct(); + checkRoomExists(); }, []); - + const [ open, setOpen ] = React.useState(false); const handleNameChange = (event: { target: { value: React.SetStateAction; }; }) => { @@ -224,6 +234,11 @@ const CurrentRoomModal = () => { const handleOpen = () => { fetchProduct(); }; + const handleCreateRoom = () => { + dispatch(createRoom(window.location.pathname.substring(1))).then(() => { + checkRoomExists(); + }); + }; const addTenant = async () => { @@ -252,38 +267,37 @@ const CurrentRoomModal = () => { }; return <> -
- - Add/Edit - - + + Add/Edit + + These are the parameters that you can change. - - - - - {/* + + + + {/* { onChange={handleTenantIdChange} value={tenantId} /> */} - option.name} - fullWidth - disableClearable - onChange={handleDefaultRoleIdChange} - value={defaultRoleIdOption} - sx={{ marginTop: '8px' }} - renderInput={(params) => } - /> - option.name} - fullWidth - disableClearable - readOnly - // onChange={handleTenantIdChange} - value={tenantIdOption} - sx={{ marginTop: '8px' }} - renderInput={(params) => } - /> - - - - - - - + + + + + + +
+
- + ; }; diff --git a/src/components/settingsdialog/ManagementSettings.tsx b/src/components/settingsdialog/ManagementSettings.tsx index cd86cf6c..b67287b0 100644 --- a/src/components/settingsdialog/ManagementSettings.tsx +++ b/src/components/settingsdialog/ManagementSettings.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from 'react'; +import { useEffect } from 'react'; import { getUserData } from '../../store/actions/managementActions'; import { useAppDispatch, useAppSelector } from '../../store/hooks'; import CurrentRoomModal from '../managementservice/rooms/CurrentRoom'; @@ -7,7 +7,6 @@ import ListItemButton from '@mui/material/ListItemButton/ListItemButton'; import ListItemIcon from '@mui/material/ListItemIcon/ListItemIcon'; import ListItemText from '@mui/material/ListItemText/ListItemText'; import InfoIcon from '@mui/icons-material/Info'; -import Box from '@mui/material/Box/Box'; import SignIn from './managementsettings/ManagementAdminLoginSettings'; import List from '@mui/material/List'; @@ -15,32 +14,40 @@ const ManagementSettings = (): JSX.Element => { const dispatch = useAppDispatch(); useEffect(() => { - dispatch(getUserData()).then((data) => { // eslint-disable-next-line no-console console.log('data', data); }); - }); + }, []); const loggedIn = useAppSelector((state) => state.permissions.loggedIn); useEffect(() => { }, [ loggedIn ]); - - const [ selectedComponent, setSelectedComponent ] = useState(''); // Function to render the selected component in the placeholder const renderComponent = () => { if (loggedIn) { - switch (selectedComponent) { - case 'currentroom': - return <> - - ; - default: - return ; - } + + return <> + + + + + + + + window.open('/mgmt-admin', 'edumeet-mgmt')}> + + + + + + + + + ; } else { return ; } @@ -48,30 +55,8 @@ const ManagementSettings = (): JSX.Element => { return ( <> - - setSelectedComponent('currentRoom')}> - - - - - - - - - - window.open('/mgmt-admin', 'edumeet-mgmt')}> - - - - - - - - - -
- {renderComponent()} -
+ {renderComponent()} + ); }; diff --git a/src/store/actions/managementActions.tsx b/src/store/actions/managementActions.tsx index d6447259..2cc2f35e 100644 --- a/src/store/actions/managementActions.tsx +++ b/src/store/actions/managementActions.tsx @@ -705,9 +705,7 @@ export const getRoomByName = (name: string): AppThunk