ajout routes

This commit is contained in:
AntoninoP 2024-07-09 16:23:09 +02:00
parent 74a4b3cb03
commit 4829bdb66a
7 changed files with 59 additions and 36 deletions

View File

@ -1,4 +1,3 @@
// src/App.js
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-dom'; import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-dom';
import { ToastContainer } from 'react-toastify'; import { ToastContainer } from 'react-toastify';
@ -9,21 +8,13 @@ import ServerDetails from './pages/ServerDetails/ServerDetails';
import { auth } from './service/firebase'; import { auth } from './service/firebase';
import styles from './App.module.scss'; import styles from './App.module.scss';
import Loading from './pages/Loading/loading'; import Loading from './pages/Loading/loading';
import NotFound from './pages/NotFound/NotFound'; import NotFoundPage from './pages/NotFoundPage/NotFoundPage';
const App = () => { const App = () => {
const [user, setUser] = useState(null); const [user, setUser] = useState(null);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
useEffect(() => { useEffect(() => {
const script = document.createElement('script');
script.src = 'https://static.cloudflareinsights.com/beacon.min.js';
script.async = true;
script.defer = true;
script.data = JSON.stringify({
token: '5cef39a7410e4a4e8ab3dfbe163b73d0',
});
const unsubscribe = auth.onAuthStateChanged((user) => { const unsubscribe = auth.onAuthStateChanged((user) => {
setUser(user); setUser(user);
setLoading(false); setLoading(false);
@ -42,9 +33,9 @@ const App = () => {
<Routes> <Routes>
<Route path="/login" element={user ? <Navigate to="/dashboard" /> : <LoginPage />} /> <Route path="/login" element={user ? <Navigate to="/dashboard" /> : <LoginPage />} />
<Route path="/dashboard" element={user ? <DashboardPage user={user} /> : <Navigate to="/login" />} /> <Route path="/dashboard" element={user ? <DashboardPage user={user} /> : <Navigate to="/login" />} />
<Route path="/server/:serverName" element={user ? <ServerDetails user={user} /> : <Navigate to="/login" />} /> {/* Ajout de cette ligne */} <Route path="/server/:serverName" element={user ? <ServerDetails user={user} /> : <Navigate to="/login" />} />
<Route path="/" element={<Navigate to={user ? "/dashboard" : "/login"} />} /> <Route path="/" element={<Navigate to={user ? "/dashboard" : "/login"} />} />
<Route path="*" element={<NotFound />} /> {/* route 404 */} <Route path="*" element={<NotFoundPage />} />
</Routes> </Routes>
<ToastContainer /> <ToastContainer />
</div> </div>

View File

@ -1,4 +1,3 @@
// src/components/serverCard/serverCard.jsx
import React from 'react'; import React from 'react';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import styles from './serverCard.module.scss'; import styles from './serverCard.module.scss';
@ -24,7 +23,8 @@ const ServerCard = ({ status, version, name, framework, onRunClick, onStopClick,
} }
}; };
const handleRun = async () => { const handleRun = async (event) => {
event.preventDefault();
try { try {
await onRunClick(name); await onRunClick(name);
} catch (error) { } catch (error) {
@ -32,7 +32,8 @@ const ServerCard = ({ status, version, name, framework, onRunClick, onStopClick,
} }
}; };
const handleStop = async () => { const handleStop = async (event) => {
event.preventDefault();
try { try {
await onStopClick(name); await onStopClick(name);
} catch (error) { } catch (error) {
@ -40,7 +41,8 @@ const ServerCard = ({ status, version, name, framework, onRunClick, onStopClick,
} }
}; };
const handleDelete = async () => { const handleDelete = async (event) => {
event.preventDefault();
try { try {
await onDeleteClick(name); await onDeleteClick(name);
} catch (error) { } catch (error) {

View File

@ -49,6 +49,15 @@
transition: background-color 0.3s ease; transition: background-color 0.3s ease;
margin-top: 1rem; margin-top: 1rem;
} }
.runningButton:hover{
background-color: #8d213ec1;
}
.stoppedButton:hover{
background-color: #008d5fc1;
}
.deleteButton{ .deleteButton{
width: 20px; width: 20px;
height: 20px; height: 20px;

View File

@ -1,7 +1,7 @@
// src/pages/NotFoundPage/NotFoundPage.jsx // src/pages/NotFoundPage/NotFoundPage.jsx
import React from 'react'; import React from 'react';
import Navbar from '../../components/navbar/Navbar'; import Navbar from '../../components/navbar/Navbar';
import styles from './NotFound.module.scss'; import styles from './NotFoundPage.module.scss';
const NotFoundPage = () => { const NotFoundPage = () => {
return ( return (

View File

@ -1,6 +1,5 @@
// src/pages/ServerDetails/ServerDetails.jsx
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom'; import { useParams, useNavigate } from 'react-router-dom';
import Navbar from '../../components/navbar/Navbar'; import Navbar from '../../components/navbar/Navbar';
import styles from './ServerDetails.module.scss'; import styles from './ServerDetails.module.scss';
import serviiApi from "../../service/api.tsx"; import serviiApi from "../../service/api.tsx";
@ -8,41 +7,56 @@ import Loading from '../Loading/loading';
const ServerDetails = ({ user }) => { const ServerDetails = ({ user }) => {
const { serverName } = useParams(); const { serverName } = useParams();
const navigate = useNavigate();
const [server, setServer] = useState(null); const [server, setServer] = useState(null);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => { useEffect(() => {
const loadServer = async () => { const fetchServer = async () => {
try { try {
const ApiResponse = await serviiApi.fetchServer(serverName); const ApiResponse = await serviiApi.fetchServers();
setServer(ApiResponse.message); const data = ApiResponse.message;
const foundServer = data.find(server => server.name === serverName);
if (foundServer) {
setServer(foundServer);
} else {
setError('Server not found');
}
} catch (error) { } catch (error) {
console.error('Error fetching server data:', error); console.error('Error fetching server:', error);
setError('Error fetching server');
} finally { } finally {
setLoading(false); setLoading(false);
} }
}; };
loadServer();
fetchServer();
}, [serverName]); }, [serverName]);
if (loading) { if (loading) {
return <Loading />; return <Loading />;
} }
if (error) {
return (
<div className={styles.serverDetailsContainer}>
<Navbar user={user} />
<div className={styles.error}>
<h1>{error}</h1>
<button onClick={() => navigate('/dashboard')}>Back to Dashboard</button>
</div>
</div>
);
}
return ( return (
<div className={styles.serverDetailsContainer}> <div className={styles.serverDetailsContainer}>
<Navbar user={user} /> <Navbar user={user} />
{server ? (
<div className={styles.details}> <div className={styles.details}>
<h1>{server.name}</h1> <h1>{server.name}</h1>
<p>Status: {server.running ? 'Running' : 'Stopped'}</p>
<p>Version: {server.version}</p>
<p>Framework: {server.framework}</p>
{/* Ajoutez d'autres détails ici */}
</div> </div>
) : (
<div>Server not found</div>
)}
</div> </div>
); );
}; };

View File

@ -0,0 +1,7 @@
.details{
color: white;
}
.serverDetailsContainer{
margin-top: 10rem;
}