fix: build
This commit is contained in:
parent
6f9f4d8121
commit
5ac4bc1c56
@ -46,9 +46,10 @@ const Navigation: React.FC<NavigationProps> = ({
|
|||||||
navigate("/login");
|
navigate("/login");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
localStorage.setItem("theme", theme);
|
if (theme) localStorage.setItem("theme", theme);
|
||||||
const localTheme = localStorage.getItem("theme");
|
const localTheme = localStorage.getItem("theme");
|
||||||
document.querySelector("html").setAttribute("data-theme", localTheme);
|
const doc = document.querySelector("html");
|
||||||
|
if (doc) doc.setAttribute("data-theme", localTheme || "dark");
|
||||||
}, [theme, navigate]);
|
}, [theme, navigate]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -2,9 +2,10 @@ import { useEffect, useState } from "react";
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { Tp } from "../type/TpType";
|
import { Tp } from "../type/TpType";
|
||||||
|
import { DashboardType } from "../type/Dashboard";
|
||||||
|
|
||||||
function Dashboard() {
|
function Dashboard() {
|
||||||
const [dashboard, setDashboard] = useState(null);
|
const [dashboard, setDashboard] = useState<DashboardType | null>(null);
|
||||||
const username = localStorage.getItem("username");
|
const username = localStorage.getItem("username");
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
axios.get("/api/dashboard").then((res) => {
|
axios.get("/api/dashboard").then((res) => {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
import { Instance } from "../type/InstanceType";
|
||||||
|
|
||||||
function Instances() {
|
function Instances() {
|
||||||
const [instances, setInstances] = useState([]);
|
const [instances, setInstances] = useState([]);
|
||||||
@ -15,7 +16,7 @@ function Instances() {
|
|||||||
<div className="container mx-auto py-10">
|
<div className="container mx-auto py-10">
|
||||||
<h1 className="text-3xl font-bold mb-6 text-center">Your instances</h1>
|
<h1 className="text-3xl font-bold mb-6 text-center">Your instances</h1>
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||||
{instances.map((instance) => (
|
{instances.map((instance: Instance) => (
|
||||||
<div
|
<div
|
||||||
key={instance.id}
|
key={instance.id}
|
||||||
className="card card-compact bg-base-200 shadow-lg p-4"
|
className="card card-compact bg-base-200 shadow-lg p-4"
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
import axios from "axios";
|
|
||||||
import { useState } from "react";
|
|
||||||
|
|
||||||
function PageTest() {
|
function PageTest() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
import { Tp } from "../type/TpType";
|
||||||
|
|
||||||
function Practicals() {
|
function Practicals() {
|
||||||
const [tps, setTps] = useState([]);
|
const [tps, setTps] = useState([]);
|
||||||
@ -15,7 +16,7 @@ function Practicals() {
|
|||||||
<div className="container mx-auto py-10">
|
<div className="container mx-auto py-10">
|
||||||
<h1 className="text-3xl font-bold mb-6 text-center">Your TPs</h1>
|
<h1 className="text-3xl font-bold mb-6 text-center">Your TPs</h1>
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||||
{tps.map((practical) => (
|
{tps.map((practical: Tp) => (
|
||||||
<div
|
<div
|
||||||
key={practical.id}
|
key={practical.id}
|
||||||
className="card card-compact bg-base-200 shadow-lg p-4"
|
className="card card-compact bg-base-200 shadow-lg p-4"
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { BulkUserCreattionType } from "../../type/BulkUserCreattionType";
|
||||||
|
import { Tp } from "../../type/TpType";
|
||||||
|
import { CSVParseType } from "../../type/CSVParseType";
|
||||||
|
|
||||||
function BulkUsers() {
|
function BulkUsers() {
|
||||||
const [userData, setUserData] = useState([]);
|
const [userData, setUserData] = useState<CSVParseType[]>([]);
|
||||||
const [practical, setPractical] = useState("0");
|
const [practical, setPractical] = useState("0");
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [tps, setTps] = useState([]);
|
const [tps, setTps] = useState([]);
|
||||||
@ -19,14 +22,17 @@ function BulkUsers() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
if (event.target.files) {
|
||||||
const selectedFile = event.target.files[0];
|
const selectedFile = event.target.files[0];
|
||||||
parseCSV(selectedFile);
|
parseCSV(selectedFile);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const parseCSV = (file: File) => {
|
const parseCSV = (file: File) => {
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = (event: ProgressEvent<FileReader>) => {
|
reader.onload = (event: ProgressEvent<FileReader>) => {
|
||||||
const text = event.target.result;
|
if (event.target) {
|
||||||
|
const text = event.target.result!.toString();
|
||||||
const rows = text.split("\n").map((row) => row.split(","));
|
const rows = text.split("\n").map((row) => row.split(","));
|
||||||
const formattedData = rows.map((row) => ({
|
const formattedData = rows.map((row) => ({
|
||||||
name: row[0],
|
name: row[0],
|
||||||
@ -38,32 +44,31 @@ function BulkUsers() {
|
|||||||
instance_pwd: row[6],
|
instance_pwd: row[6],
|
||||||
}));
|
}));
|
||||||
setUserData(formattedData);
|
setUserData(formattedData);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
// Handle submission logic (e.g., sending data to the backend)
|
|
||||||
console.log(practical);
|
|
||||||
axios
|
axios
|
||||||
.post("/api/users/jdmi", {
|
.post("/api/users/jdmi", {
|
||||||
users: userData.filter((user) => user.name !== ""),
|
users: userData.filter((user: CSVParseType) => user.name !== ""),
|
||||||
tpId: practical,
|
tpId: practical,
|
||||||
})
|
})
|
||||||
.then(() => navigate(`/admin/users`));
|
.then(() => navigate(`/admin/users`));
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="max-w-md mx-auto p-5">
|
<div className="max-w-7xl mx-auto p-5">
|
||||||
<h2 className="text-2xl font-bold mb-4">Bulk User Creation</h2>
|
<h2 className="text-2xl font-bold mb-4">Bulk User Creation</h2>
|
||||||
<input
|
<input
|
||||||
type="file"
|
type="file"
|
||||||
accept=".csv"
|
accept=".csv"
|
||||||
onChange={handleFileChange}
|
onChange={handleFileChange}
|
||||||
className="file-input file-input-bordered w-full mb-4"
|
className="file-input file-input-bordered mb-4"
|
||||||
/>
|
/>
|
||||||
{userData.length > 0 && (
|
{userData.length > 0 && (
|
||||||
<div className="overflow-x-auto">
|
<div className="overflow-x-auto w-full">
|
||||||
<table className="table w-full">
|
<table className="table w-full">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -77,7 +82,7 @@ function BulkUsers() {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{userData.map((user, index) => (
|
{userData.map((user: BulkUserCreattionType, index: number) => (
|
||||||
<tr key={index}>
|
<tr key={index}>
|
||||||
<td>{user.name}</td>
|
<td>{user.name}</td>
|
||||||
<td>{user.email}</td>
|
<td>{user.email}</td>
|
||||||
@ -102,7 +107,7 @@ function BulkUsers() {
|
|||||||
className="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
|
className="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||||
>
|
>
|
||||||
return <option value="0">Empty</option>;
|
return <option value="0">Empty</option>;
|
||||||
{tps.map((tp: TpType.Tp) => {
|
{tps.map((tp: Tp) => {
|
||||||
return <option value={tp.id}>{tp.name}</option>;
|
return <option value={tp.id}>{tp.name}</option>;
|
||||||
})}
|
})}
|
||||||
</select>
|
</select>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import { User } from "../../type/UserType";
|
||||||
|
|
||||||
function Users() {
|
function Users() {
|
||||||
const [users, setUsers] = useState([]);
|
const [users, setUsers] = useState([]);
|
||||||
@ -11,13 +12,12 @@ function Users() {
|
|||||||
});
|
});
|
||||||
}, [reload]);
|
}, [reload]);
|
||||||
|
|
||||||
const handleEditUser = (userId) => {
|
const handleEditUser = (userId: number) => {
|
||||||
alert(`Edit user with ID: ${userId}`);
|
alert(`Edit user with ID: ${userId}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteJDMIUsers = () => {
|
const deleteJDMIUsers = () => {
|
||||||
axios.delete("/api/users").then((res) => {
|
axios.delete("/api/users").then(() => {
|
||||||
console.log(res.data);
|
|
||||||
setReload(reload + 1);
|
setReload(reload + 1);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -48,7 +48,7 @@ function Users() {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{users.map((user, index) => (
|
{users.map((user: User, index: number) => (
|
||||||
<tr key={user.id} className="hover:bg-gray-100">
|
<tr key={user.id} className="hover:bg-gray-100">
|
||||||
<td className="p-4">{index + 1}</td>
|
<td className="p-4">{index + 1}</td>
|
||||||
<td className="p-4">{user.name}</td>
|
<td className="p-4">{user.name}</td>
|
||||||
|
9
src/type/BulkUserCreattionType.ts
Normal file
9
src/type/BulkUserCreattionType.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export interface BulkUserCreattionType {
|
||||||
|
name: string;
|
||||||
|
email: string;
|
||||||
|
password: string;
|
||||||
|
instance_name: string;
|
||||||
|
instance_ssh: string;
|
||||||
|
instance_port: string;
|
||||||
|
instance_pwd: string;
|
||||||
|
}
|
9
src/type/CSVParseType.ts
Normal file
9
src/type/CSVParseType.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export interface CSVParseType {
|
||||||
|
name: string;
|
||||||
|
email: string;
|
||||||
|
password: string;
|
||||||
|
instance_name: string;
|
||||||
|
instance_ssh: string;
|
||||||
|
instance_port: string;
|
||||||
|
instance_pwd: string;
|
||||||
|
}
|
7
src/type/Dashboard.ts
Normal file
7
src/type/Dashboard.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { Instance } from "./InstanceType";
|
||||||
|
import { Tp } from "./TpType";
|
||||||
|
|
||||||
|
export interface DashboardType {
|
||||||
|
tps: Tp[];
|
||||||
|
instances: Instance[];
|
||||||
|
}
|
@ -5,4 +5,7 @@ export interface Tp {
|
|||||||
pdfLink: string;
|
pdfLink: string;
|
||||||
respo: string;
|
respo: string;
|
||||||
date: string;
|
date: string;
|
||||||
|
ssh: string;
|
||||||
|
port: string;
|
||||||
|
pwd: string;
|
||||||
}
|
}
|
||||||
|
@ -4,4 +4,6 @@ export interface User {
|
|||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
instances: Instance[];
|
instances: Instance[];
|
||||||
|
email: string;
|
||||||
|
roles: string;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user