mirror of
https://github.com/hubHarmony/servii-frontend.git
synced 2024-11-17 21:40:30 +00:00
ajout call api pour afficher les serveurs
This commit is contained in:
parent
f5b8f808c6
commit
3e427ce704
@ -1,3 +1,4 @@
|
|||||||
|
// 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';
|
||||||
|
@ -1,16 +1,62 @@
|
|||||||
import React from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import { getAuth } from 'firebase/auth';
|
||||||
import ServerCard from '../../components/serverCard/serverCard';
|
import ServerCard from '../../components/serverCard/serverCard';
|
||||||
import Navbar from '../../components/navbar/Navbar';
|
import Navbar from '../../components/navbar/Navbar';
|
||||||
import styles from './DashboardPage.module.scss';
|
import styles from './DashboardPage.module.scss';
|
||||||
|
|
||||||
const DashboardPage = ({ user }) => {
|
const DashboardPage = ({ user }) => {
|
||||||
|
const [servers, setServers] = useState([]);
|
||||||
|
const auth = getAuth();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchServers = async () => {
|
||||||
|
try {
|
||||||
|
const currentUser = auth.currentUser;
|
||||||
|
if (!currentUser) {
|
||||||
|
console.error('No current user found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const userId = currentUser.uid;
|
||||||
|
console.log('User ID:', userId);
|
||||||
|
|
||||||
|
const response = await fetch('http://api.servii.fr:3000/FetchServers', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': `Bearer ${userId}`
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ token: userId })
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorText = await response.text();
|
||||||
|
console.error('Error response text:', errorText);
|
||||||
|
throw new Error(`Network response was not ok: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
|
console.log('Data:', data);
|
||||||
|
setServers(data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching servers:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchServers();
|
||||||
|
}, [auth]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.dashboardContainer}>
|
<div className={styles.dashboardContainer}>
|
||||||
<Navbar user={user} />
|
<Navbar user={user} />
|
||||||
<div className={styles.cardsContainer}>
|
<div className={styles.cardsContainer}>
|
||||||
<ServerCard color="#f0f0f0" status="En cours" version="1.16.5" link="http://example.com" name="test1" />
|
{servers.map((server, index) => (
|
||||||
<ServerCard color="#f0f0f0" status="Démarrage" version="1.17.1" link="http://example.com" name="test2" />
|
<ServerCard
|
||||||
<ServerCard color="#f0f0f0" status="Hors ligne" version="1.15.2" link="http://example.com" name="test3" />
|
key={index}
|
||||||
|
color="#f0f0f0"
|
||||||
|
status={server.running ? 'En cours' : 'Hors ligne'}
|
||||||
|
version={server.version}
|
||||||
|
link={`http://example.com/${server.name}`}
|
||||||
|
name={server.name}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
// src/pages/LoginPage/LoginPage.js
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { auth, googleProvider, signInWithPopup } from './firebase';
|
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import { auth, googleProvider, signInWithPopup } from './firebase';
|
||||||
import styles from './LoginPage.module.scss';
|
import styles from './LoginPage.module.scss';
|
||||||
|
|
||||||
const LoginPage = () => {
|
const LoginPage = () => {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// src/firebase.js
|
||||||
import { initializeApp } from 'firebase/app';
|
import { initializeApp } from 'firebase/app';
|
||||||
import { getAuth, GoogleAuthProvider, signInWithPopup } from 'firebase/auth';
|
import { getAuth, GoogleAuthProvider, signInWithPopup } from 'firebase/auth';
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user