Fix sous domaine bug

This commit is contained in:
AntoninoP 2024-07-07 19:52:54 +02:00
parent ca961f563c
commit dca9da9aa4
4 changed files with 46 additions and 31 deletions

View File

@ -3,8 +3,8 @@ import styles from './CreateServer.module.scss';
import { getUserSubdomain } from "../../service/firebase"; import { getUserSubdomain } from "../../service/firebase";
import serviiApi from "../../service/api.tsx"; import serviiApi from "../../service/api.tsx";
const CreateServer = ({ user, onCreateServer }) => { const CreateServer = ({ user, onCreateServer, onSubdomainUpdate }) => {
const [subdomain, setSubdomain] = useState('loading'); const [subdomain, setSubdomain] = useState(null);
const [subdomainInput, setSubdomainInput] = useState(''); const [subdomainInput, setSubdomainInput] = useState('');
const [serverName, setServerName] = useState(''); const [serverName, setServerName] = useState('');
const [serverVersion, setServerVersion] = useState(''); const [serverVersion, setServerVersion] = useState('');
@ -13,7 +13,8 @@ const CreateServer = ({ user, onCreateServer }) => {
try { try {
if (user && user.uid) { if (user && user.uid) {
const userSubdomain = await getUserSubdomain(user.uid); const userSubdomain = await getUserSubdomain(user.uid);
setSubdomain(userSubdomain); setSubdomain(userSubdomain || '');
onSubdomainUpdate(userSubdomain || '');
console.log('Subdomain:', userSubdomain); console.log('Subdomain:', userSubdomain);
} else { } else {
console.error('User or user.uid is undefined'); console.error('User or user.uid is undefined');
@ -31,6 +32,7 @@ const CreateServer = ({ user, onCreateServer }) => {
try { try {
await serviiApi.setSubdomain(subdomainInput); await serviiApi.setSubdomain(subdomainInput);
setSubdomain(subdomainInput); setSubdomain(subdomainInput);
onSubdomainUpdate(subdomainInput);
} catch (error) { } catch (error) {
console.error('Error setting subdomain:', error); console.error('Error setting subdomain:', error);
} }
@ -44,9 +46,10 @@ const CreateServer = ({ user, onCreateServer }) => {
} }
}; };
if (subdomain === 'loading') { if (subdomain === null) {
return ( return (
<div className={styles.container}> <div className={styles.container}>
<div>Loading...</div>
</div> </div>
); );
} }

View File

@ -4,7 +4,6 @@ import styles from './Navbar.module.scss';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faUser, faCog, faSignOutAlt } from '@fortawesome/free-solid-svg-icons'; import { faUser, faCog, faSignOutAlt } from '@fortawesome/free-solid-svg-icons';
const Navbar = ({ user }) => { const Navbar = ({ user }) => {
const [dropdownOpen, setDropdownOpen] = useState(false); const [dropdownOpen, setDropdownOpen] = useState(false);
const dropdownRef = useRef(null); const dropdownRef = useRef(null);
@ -34,19 +33,23 @@ const Navbar = ({ user }) => {
}; };
}, []); }, []);
useEffect(() => {
console.log('User data:', user);
}, [user]);
return ( return (
<div className={styles.navbar}> <div className={styles.navbar}>
<div className={styles.profileSection} onClick={toggleDropdown}> <div className={styles.profileSection} onClick={toggleDropdown}>
{user.photoURL ? ( {user && user.photoURL ? (
<img src={user.photoURL} alt="Profile" className={styles.profilePic} /> <img src={user.photoURL} alt="Profile" className={styles.profilePic} />
) : ( ) : (
<h1>hello</h1> <div className={styles.defaultProfilePic}>A</div>
)} )}
</div> </div>
{dropdownOpen && ( {dropdownOpen && (
<div className={styles.dropdownMenu} ref={dropdownRef}> <div className={styles.dropdownMenu} ref={dropdownRef}>
<div className={styles.menuItem} onClick={toggleDropdown}> <div className={styles.menuItem} onClick={toggleDropdown}>
{auth.currentUser.displayName} {user && user.displayName}
</div> </div>
<div className={styles.menuItem} onClick={toggleDropdown}> <div className={styles.menuItem} onClick={toggleDropdown}>
<FontAwesomeIcon icon={faUser} className={styles.icon}/> Informations <FontAwesomeIcon icon={faUser} className={styles.icon}/> Informations

View File

@ -18,11 +18,20 @@
cursor: pointer; cursor: pointer;
} }
.profilePic { .profilePic, .defaultProfilePic {
width: var(--profile-pic-size); width: var(--profile-pic-size);
height: var(--profile-pic-size); height: var(--profile-pic-size);
border-radius: 100%; border-radius: 100%;
margin-right: 3rem; margin-right: 3rem;
display: flex;
align-items: center;
justify-content: center;
}
.defaultProfilePic {
background-color: #ccc;
color: #fff;
font-size: 1.5rem;
} }
.dropdownMenu { .dropdownMenu {
@ -39,7 +48,7 @@
font-size: 1.1rem; font-size: 1.1rem;
} }
.menuItem { .menuItem, .menuItemLogout {
padding: 1.25rem 2rem; padding: 1.25rem 2rem;
cursor: pointer; cursor: pointer;
transition: background-color 0.3s, color 0.3s; transition: background-color 0.3s, color 0.3s;
@ -47,24 +56,15 @@
} }
.menuItemLogout { .menuItemLogout {
padding: 1.25rem 2rem;
cursor: pointer;
transition: background-color 0.3s, color 0.3s;
font-weight: bold;
border-top: .15rem solid #444444; border-top: .15rem solid #444444;
} }
.menuItem:hover { .menuItem:hover, .menuItemLogout:hover {
background-color: #1f202479; background-color: #1f202479;
color: var(--primary-color); color: var(--primary-color);
} }
.menuItemLogout:hover{ .icon {
background-color: #1f202479;
color: var(--primary-color);
}
.icon{
margin-right: 1rem; margin-right: 1rem;
font-size: 1.25rem; font-size: 1.25rem;
} }

View File

@ -10,9 +10,9 @@ import CreateServer from '../../components/CreateServer/CreateServer';
const DashboardPage = ({ user }) => { const DashboardPage = ({ user }) => {
const [servers, setServers] = useState([]); const [servers, setServers] = useState([]);
const [subdomain, setSubdomain] = useState(""); const [subdomain, setSubdomain] = useState(null);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [showCreateServer, setShowCreateServer] = useState(false); const [showCreateServer, setShowCreateServer] = useState(false);
const loadServers = async () => { const loadServers = async () => {
try { try {
@ -22,8 +22,12 @@ const DashboardPage = ({ user }) => {
const sortedServers = data.sort((a, b) => b.running - a.running); const sortedServers = data.sort((a, b) => b.running - a.running);
setServers(sortedServers); setServers(sortedServers);
const userSubdomain = await getUserSubdomain(user.uid); if (user && user.uid) {
setSubdomain(userSubdomain); const userSubdomain = await getUserSubdomain(user.uid);
setSubdomain(userSubdomain || '');
} else {
console.error('User or user.uid is undefined');
}
} catch (error) { } catch (error) {
console.error('Error fetching data:', error); console.error('Error fetching data:', error);
} finally { } finally {
@ -47,7 +51,7 @@ const DashboardPage = ({ user }) => {
}; };
const handleCreateServerPage = () => { const handleCreateServerPage = () => {
setShowCreateServer(true); setShowCreateServer(true);
}; };
const handleRunServer = async (serverName) => { const handleRunServer = async (serverName) => {
@ -77,15 +81,20 @@ const DashboardPage = ({ user }) => {
} }
}; };
if (showCreateServer) { if (loading) {
return <CreateServer user={user} onCreateServer={handleCreateServer} />; return (
<div className={styles.dashboardContainer}>
<Navbar user={user} />
<Loading />
</div>
);
} }
return ( return (
<div className={styles.dashboardContainer}> <div className={styles.dashboardContainer}>
<Navbar user={user} /> <Navbar user={user} />
{loading ? ( {showCreateServer ? (
<Loading /> <CreateServer user={user} onCreateServer={handleCreateServer} onSubdomainUpdate={setSubdomain} />
) : ( ) : (
<div className={styles.cardsContainer}> <div className={styles.cardsContainer}>
{servers.length === 0 ? ( {servers.length === 0 ? (