fix: login affichage, bulk user creation adjustement
This commit is contained in:
parent
69955ac433
commit
a75b432aa4
@ -7,7 +7,7 @@ import { DashboardType } from "../type/Dashboard";
|
||||
|
||||
function Dashboard() {
|
||||
const [dashboard, setDashboard] = useState<DashboardType | null>(null);
|
||||
const username = localStorage.getItem("name");
|
||||
const username = localStorage.getItem("username");
|
||||
useEffect(() => {
|
||||
axios.get("/api/dashboard").then((res) => {
|
||||
setDashboard(res.data);
|
||||
|
||||
@ -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<Ji>();
|
||||
|
||||
const [instance, setInstance] = useState<Instance>();
|
||||
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() {
|
||||
<span>Description:</span>
|
||||
<span className="font-medium">{ji.description}</span>
|
||||
</li>
|
||||
<li className="flex justify-between">
|
||||
<span>Tools Used:</span>
|
||||
<span className="font-medium">Python, SSH, Vim</span>
|
||||
</li>
|
||||
<li className="flex justify-between">
|
||||
<span>Difficulty:</span>
|
||||
<span className="font-medium">Beginner</span>
|
||||
</li>
|
||||
<li className="flex justify-between">
|
||||
<span>Date:</span>
|
||||
<span className="font-medium">{ji.date}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div className="bg-base-200 p-6 rounded-lg shadow-md mt-6">
|
||||
{ instance && <div className="bg-base-200 p-6 rounded-lg shadow-md mt-6">
|
||||
<h2 className="text-2xl font-semibold text-blue-600 mb-2">
|
||||
Resources
|
||||
Your credentials :
|
||||
</h2>
|
||||
<ul className="space-y-2">
|
||||
<li className="flex justify-between align-middle items-center">
|
||||
<span>SSH:</span>
|
||||
<div
|
||||
className="flex gap-2 items-center"
|
||||
onClick={() => copyText(ji.ssh)}
|
||||
onClick={() => copyText("ssh -P {$instance.port} {$username}@la-banquise.fr")}
|
||||
>
|
||||
<span className="font-medium">{ji.ssh}</span>
|
||||
<span className="font-medium">ssh -P {instance.port} {username}@la-banquise.fr</span>
|
||||
<div className="h-8 w-8 hover:bg-base-100 align-middle cursor-pointer flex items-center justify-center rounded">
|
||||
<ClipboardIcon className="size-6" />
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li className="flex justify-between align-middle items-center">
|
||||
<span>Port:</span>
|
||||
<span>Instance name:</span>
|
||||
<div
|
||||
className="flex gap-2 items-center"
|
||||
onClick={() => copyText(ji.port)}
|
||||
onClick={() => copyText(instance.name)}
|
||||
>
|
||||
<span className="font-medium">{ji.port}</span>
|
||||
<span className="font-medium">{instance.name}</span>
|
||||
<div className="h-8 w-8 hover:bg-base-100 align-middle cursor-pointer flex items-center justify-center rounded">
|
||||
<ClipboardIcon className="size-6" />
|
||||
</div>
|
||||
@ -97,7 +103,7 @@ function Immersion() {
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>}
|
||||
<a
|
||||
href={ji.pdfLink}
|
||||
target="_blank"
|
||||
|
||||
@ -53,18 +53,15 @@ function BulkUsers() {
|
||||
axios
|
||||
.post("/api/users", {
|
||||
users: userData.filter((user: CSVParseType) => 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() {
|
||||
<button
|
||||
onClick={handleSubmit}
|
||||
className="btn btn-primary mt-4"
|
||||
disabled={userData.length === 0}
|
||||
disabled={userData.length === 0 || practical == "0"}
|
||||
>
|
||||
Create Users
|
||||
</button>
|
||||
|
||||
@ -62,12 +62,12 @@ function CreateJi() {
|
||||
|
||||
<div>
|
||||
<label className="block text-gray-700 font-semibold mb-2">
|
||||
Respo:
|
||||
Description:
|
||||
</label>
|
||||
<textarea
|
||||
type="text"
|
||||
name="respo"
|
||||
value={ji.respo}
|
||||
name="desc"
|
||||
value={ji.desc}
|
||||
onChange={handleInputChange}
|
||||
className="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
placeholder="Enter ji description"
|
||||
|
||||
@ -1,11 +1,7 @@
|
||||
import { Ji } from "./JiType";
|
||||
import { User } from "./UserType";
|
||||
|
||||
export interface Instance {
|
||||
id: number;
|
||||
name: string;
|
||||
ssh: string;
|
||||
pwd: string;
|
||||
user: User;
|
||||
tp: Tp;
|
||||
port: string;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user