diff --git a/src/pages/Dashboard.tsx b/src/pages/Dashboard.tsx index 7a9cd86..64b8ccc 100644 --- a/src/pages/Dashboard.tsx +++ b/src/pages/Dashboard.tsx @@ -7,7 +7,7 @@ import { DashboardType } from "../type/Dashboard"; function Dashboard() { const [dashboard, setDashboard] = useState(null); - const username = localStorage.getItem("name"); + const username = localStorage.getItem("username"); useEffect(() => { axios.get("/api/dashboard").then((res) => { setDashboard(res.data); diff --git a/src/pages/Immersion.tsx b/src/pages/Immersion.tsx index e1a5701..1d40bde 100644 --- a/src/pages/Immersion.tsx +++ b/src/pages/Immersion.tsx @@ -4,11 +4,13 @@ import { useEffect, useState } from "react"; import { useParams } from "react-router-dom"; import { toast } from "react-toastify"; import { Ji } from "../type/JiType"; +import { Instance } from "../type/InstanceType"; function Immersion() { const { id } = useParams(); const [ji, setJi] = useState(); - + const [instance, setInstance] = useState(); + const username = localStorage.getItem("username"); const copyText = (copy: string) => { navigator.clipboard.writeText(copy); toast.success("Copied!", { @@ -22,6 +24,18 @@ function Immersion() { setJi(res.data); }); }, [id]); + + useEffect(() => { + axios.get(`/api/ji/${id}/instances`).then((res) => { + setInstance(res.data); + }); + }, [id]); + + useEffect(() => { + axios.get("/api/user/me").then((res) => { + localStorage.setItem("username", res.data.username); + }); + }, []); return ( <> @@ -41,44 +55,36 @@ function Immersion() { Description: {ji.description} -
  • - Tools Used: - Python, SSH, Vim -
  • -
  • - Difficulty: - Beginner -
  • Date: {ji.date}
  • -
    + { instance &&

    - Resources + Your credentials :

    • SSH:
      copyText(ji.ssh)} + onClick={() => copyText("ssh -P {$instance.port} {$username}@la-banquise.fr")} > - {ji.ssh} + ssh -P {instance.port} {username}@la-banquise.fr
    • - Port: + Instance name:
      copyText(ji.port)} + onClick={() => copyText(instance.name)} > - {ji.port} + {instance.name}
      @@ -97,7 +103,7 @@ function Immersion() {
    -
    +
    } user.name !== ""), - jiId: 1, // TODO: Unhardcode this + jiId: 1, }).then((res) => { if (res.status === 200) { - navigate(`/admin/users`); + alert(`Users succesfully created !\n${res}`); } - else if (res.status === 202) { + if (res.status === 202) alert(`Couldn't create some users`); - navigate(`/admin/users`); - } - else { + if (res.status === 500) alert(`Couldn't create ANY users`); - } }); }; @@ -120,7 +117,7 @@ function BulkUsers() { diff --git a/src/pages/admin/CreateJi.tsx b/src/pages/admin/CreateJi.tsx index 832ab05..1dbf442 100644 --- a/src/pages/admin/CreateJi.tsx +++ b/src/pages/admin/CreateJi.tsx @@ -62,12 +62,12 @@ function CreateJi() {