diff --git a/app/(pages)/(main)/admin/handleRoles.js b/app/(pages)/(main)/admin/handleRoles.js
deleted file mode 100644
index 3060d7d..0000000
--- a/app/(pages)/(main)/admin/handleRoles.js
+++ /dev/null
@@ -1,99 +0,0 @@
-
-
-import { useState } from "react";
-import { Autocomplete, Button, Stack, TextField, Typography } from "@mui/material";
-import prismaRequest from "@/app/middleware/prisma/prismaRequest";
-
-export default function handleRoles(users, roles, setRoles) {
-
- const [selectedUser, setSelectedUser] = useState(null)
- const [selectedRole, setSelectedRole] = useState(null)
-
- // const [name, setName] = useState("")
- // const [description, setDescription] = useState("")
-
- return (
-
- Set role
-
- e.firstName)}
- onChange={(e, v) => setSelectedUser(users.filter((e) => e.firstName == v)[0]) }
- renderInput={(params) => (
-
- )}
- />
- e.name)}
- onChange={(e, v) => setSelectedRole(roles.filter((e) => e.name == v)[0]) }
- renderInput={(params) => (
-
- )}
- />
-
-
-
- );
-
-}
-
-// async function handleAddition(name, description, refresh, setRefresh) {
-
-// const data = await prismaRequest({
-// model: "workGroup",
-// method: "create",
-// request: {
-// data: {
-// name: name,
-// description: description,
-// leaderTitle: "",
-// }
-// },
-// });
-
-// setRefresh(!refresh);
-// }
-
-// async function handleDeletion(group, refresh, setRefresh) {
-// console.log(group)
-
-// const data = await prismaRequest({
-// model: "workGroup",
-// method: "delete",
-// request: {
-// where: {
-// id: group.id
-// },
-// },
-// });
-
-// setRefresh(!refresh);
-// }
\ No newline at end of file
diff --git a/app/(pages)/(main)/admin/handleWorkGroups.js b/app/(pages)/(main)/admin/handleWorkGroups.js
deleted file mode 100644
index d722125..0000000
--- a/app/(pages)/(main)/admin/handleWorkGroups.js
+++ /dev/null
@@ -1,117 +0,0 @@
-
-import { useState } from "react";
-import { Autocomplete, Button, Stack, TextField, Typography } from "@mui/material";
-import prismaRequest from "@/app/middleware/prisma/prismaRequest";
-
-export default function handleWorkGroups(groups, setGroups) {
-
- const [name, setName] = useState("")
- const [description, setDescription] = useState("")
- const [selectedGroup, setSelectedGroup] = useState(null)
-
- return (
-
- Work Groups
- setName(event.target.value)}
- InputLabelProps={{ shrink: true }}
- />
- setDescription(event.target.value)}
- InputLabelProps={{ shrink: true }}
- />
-
-
- e.name)}
- onChange={(e, v) => {
- setSelectedGroup(groups.filter((e) => e.name == v)[0]);
- // console.log(v, selectedGroup)
- }}
- renderInput={(params) => (
-
- )}
- />
-
-
- );
-
-}
-
-// async function handleAddition(name, description, refresh, setRefresh) {
-
-// const data = await prismaRequest({
-// model: "workGroup",
-// method: "create",
-// request: {
-// data: {
-// name: name,
-// description: description,
-// leaderTitle: "",
-// }
-// },
-// });
-
-// setRefresh(!refresh);
-// }
-
-// async function handleDeletion(group, refresh, setRefresh) {
-// console.log(group)
-
-// const data = await prismaRequest({
-// model: "workGroup",
-// method: "delete",
-// request: {
-// where: {
-// id: group.id
-// },
-// },
-// });
-
-// setRefresh(!refresh);
-// }
\ No newline at end of file
diff --git a/app/(pages)/(main)/admin/page.js b/app/(pages)/(main)/admin/page.js
index e8bd419..edc7092 100644
--- a/app/(pages)/(main)/admin/page.js
+++ b/app/(pages)/(main)/admin/page.js
@@ -12,7 +12,6 @@ import {
Typography,
} from "@mui/material";
import { useEffect, useState } from "react";
-import prismaRequest from "@/app/middleware/prisma/prismaRequest";
import authWrapper from "@/app/middleware/authWrapper";
import CustomAutoComplete from "@/app/components/input/CustomAutocomplete";
import Link from "next/link";
@@ -23,14 +22,15 @@ import CustomTable from "@/app/components/CustomTable";
import { format, parseISO } from "date-fns";
const TABLE_HEADERS_LOGS = [
- { id: "workedAt", name: "Date", sortBy: "workedAt_num" },
- { id: "loggedBy", name: "Logged by" },
- { id: "duration", name: "duration" },
- { id: "description", name: "Description" },
+ { id: "workedAt", type: "date", flex: 1, name: "Date", sortBy: "workedAt_num" },
+ { id: "loggedBy", type: "string", flex: 1, name: "Logged by" },
+ { id: "duration", type: "string", flex: 1, name: "duration" },
+ { id: "description", type: "string", flex: 1, name: "Description" },
];
-function AdminPage(params) {
-
+function AdminPage({ props }) {
+
+
const [roles, setRoles] = useState([]);
const [users, setUsers] = useState([]);
const [logs, setLogs] = useState([]);
@@ -44,69 +44,66 @@ function AdminPage(params) {
const [roleChangeResponse, setRoleChangeResponse] = useState("");
useEffect(() => {
-
- prismaRequest({
- model: "role",
- method: "find",
- callback: (data) => setRoles(data.data),
- });
+ fetch("/api/v2/roles")
+ .then(res => res.json())
+ .then(roles => {
+ setRoles(roles.roles)
+ })
- prismaRequest({
- model: "user",
- method: "find",
- request: {
- include: {
- roles: {
- include: {
- role: true,
- },
- },
- },
- },
- callback: (data) => {
- const users = data.data.map((e) => {
- return {
- ...e,
- name: `${e.firstName} ${e.lastName ? e.lastName : ""}`,
- };
- })
- setUsers(users)
- },
- });
+ fetch("/api/v2/users")
+ .then(res => res.json())
+ .then((data) => {
+ const users = data.users.map((e) => {
+ return {
+ ...e,
+ name: `${e.firstName} ${e.lastName ? e.lastName : ""}`,
+ };
+ })
+ setUsers(users)
+ })
}, []);
useEffect(() => {
- if (selectedUser && showLogSettings) {
- prismaRequest({
- model: "workLog",
- method: "find",
- request: {
- where: { loggedFor: selectedUser.id },
- include: { LoggedByUser: true },
- },
- callback: (data) => {
- const newLogs = data.data.map((e) => {
- const user = e.LoggedByUser;
- const name = user ? `${user.firstName} ${user.lastName}` : null;
- return {
- ...e,
- loggedBy: name,
- workedAt_num: parseISO(e.workedAt).getTime(),
- workedAt: format(
- parseISO(e.workedAt),
- "dd MMM 'kl.'HH:mm"
- ).toLowerCase(),
- };
- });
-
- setLogs(newLogs);
- }
+ if (selectedUser && showLogSettings) {
+ fetch(`/api/v2/users/${selectedUser.id}/workLogs`)
+ .then(res => res.json())
+ .then(data => {
+ const newLogs = data.workLogs.map((e) => {
+ const user = e.LoggedByUser;
+ const name = user ? `${user.firstName} ${user.lastName}` : null;
+ return {
+ ...e,
+ loggedBy: name,
+ workedAt_num: parseISO(e.workedAt).getTime(),
+ workedAt: format(
+ parseISO(e.workedAt),
+ "dd MMM 'kl.'HH:mm"
+ ).toLowerCase(),
+ };
+ });
- });
+ setLogs(newLogs);
+ })
}
}, [selectedUser, showLogSettings])
+ function handleChangeUser(user) {
+ setSelectedUser(user);
+
+ if (user !== null) {
+
+ fetch(`/api/v2/users/${user.id}/roles`)
+ .then(res => res.json())
+ .then(data => {
+ setAssignedRoles(data.userRoles)
+ setAvailableRoles(roles.filter(e => !data.userRoles.includes(e)))
+ if (roleChangeResponse !== "") setRoleChangeResponse("");
+ })
+
+ }
+ }
+
return (
@@ -120,30 +117,7 @@ function AdminPage(params) {
{
- setSelectedUser(data);
-
- if (data !== null) {
- const roleIds =
- data.roles.length !== 0
- ? data.roles.map((e) => e.role.id)
- : [];
- const newAvailableRoles = roles.filter(
- (e) => !roleIds.includes(e.id) && e.id !== "hihih"
- );
-
- const newAssignedRoles = data.roles
- .filter((e) => e.role.id !== "hihih")
- .map((e) => e.role);
-
- console.log(newAvailableRoles, newAssignedRoles);
-
- setAvailableRoles(newAvailableRoles);
- setAssignedRoles(newAssignedRoles);
-
- if (roleChangeResponse !== "") setRoleChangeResponse("");
- }
- }}
+ callback={handleChangeUser}
data={users}
dataLabel="name"
subDataLabel="email"
@@ -206,6 +180,7 @@ function AdminPage(params) {
);
}
+
function roleSettings(
selectedUser,
availableRoles,
@@ -217,7 +192,7 @@ function roleSettings(
) {
const handleSave = async () => {
- const response = await fetch("/api/data/setRoles", {
+ const response = await fetch(`/api/v2/users/${selectedUser.id}/roles`, {
method: "post",
mode: "cors",
headers: {
@@ -270,7 +245,7 @@ function roleSettings(
"&:hover": { color: cybTheme.palette.primary.main },
}}
>
- {e.name}
+ {e}
);
@@ -304,7 +279,7 @@ function roleSettings(
"&:hover": { color: cybTheme.palette.primary.main },
}}
>
- {e.name}
+ {e}
);
@@ -330,7 +305,7 @@ function logSettings(logs) {
Logs
-
+
);
}
diff --git a/app/(pages)/(main)/board/page.js b/app/(pages)/(main)/board/page.js
index eabf00f..cee4831 100644
--- a/app/(pages)/(main)/board/page.js
+++ b/app/(pages)/(main)/board/page.js
@@ -2,55 +2,21 @@
"use client"
import { PageHeader } from "@/app/components/sanity/PageBuilder";
-import prismaRequest from "@/app/middleware/prisma/prismaRequest";
-import { Box, Typography } from "@mui/material";
+import { Box } from "@mui/material";
import { useEffect, useState } from "react";
import Forcegraph from "@/app/components/RecruitmentGraph"
export default function BoardPage() {
- const [data, setData] = useState({ nodes: [], links: [] });
+ const [data, setData] = useState({ nodes: [], edges: [] });
useEffect(() => {
- prismaRequest({
- model: "User",
- method: "find",
- request: {
- include: {
- recruitedByUser: true,
- recruitedUsers: true,
- },
- where: {
- OR: [
- { recruitedById: { not: null } },
- { recruitedUsers: { some: {} } }
- ]
- },
- },
- callback: (data) => {
-
- const links = data.data
- .filter((element) => element.recruitedByUser)
- .map((element) => ({
- source: element,
- target: element.recruitedByUser,
- }));
-
- const connectedNodes = new Set(
- links.flatMap((link) => [link.source.id, link.target.id])
- );
- const filteredNodes = data.data.filter((node) =>
- connectedNodes.has(node.id) || connectedNodes.has(node.recruitedById)
- );
- const filteredLinks = links.filter((link) =>
- connectedNodes.has(link.source.id) && connectedNodes.has(link.target.id)
- );
-
- const newData = { nodes: filteredNodes, links: filteredLinks };
-
- setData(newData);
- },
- });
+ fetch(`/api/v2/recruitGraph`)
+ .then(res => res.json())
+ .then(data => {
+ setData({ nodes: data.nodes, edges: data.edges})
+ })
+
}, []);
return (
diff --git a/app/(pages)/(main)/layout.js b/app/(pages)/(main)/layout.js
index 825b193..fd1b0c7 100644
--- a/app/(pages)/(main)/layout.js
+++ b/app/(pages)/(main)/layout.js
@@ -11,7 +11,7 @@ import {
ThemeProvider,
Paper,
} from "@mui/material";
-import { SessionProvider } from "next-auth/react";
+import { SessionProvider, useSession } from "next-auth/react";
import { usePathname } from "next/navigation";
import { NavBar } from "@/app/components/layout/AppBar";
import { cybTheme } from "@/app/components/themeCYB";
@@ -61,7 +61,10 @@ export default function AppLayout({ children }) {
}}
>
- {children}
+ {children}
diff --git a/app/(pages)/(main)/profile/page.js b/app/(pages)/(main)/profile/page.js
index e91c13f..515c852 100644
--- a/app/(pages)/(main)/profile/page.js
+++ b/app/(pages)/(main)/profile/page.js
@@ -14,14 +14,10 @@ import {
} from "@mui/material";
import { PageHeader } from "@/app/components/sanity/PageBuilder"
import authWrapper from "@/app/middleware/authWrapper"
-import prismaRequest from "@/app/middleware/prisma/prismaRequest"
import CustomAutoComplete from "@/app/components/input/CustomAutocomplete";
-import CustomTable from "@/app/components/CustomTable";
import { signOut, useSession } from "next-auth/react"
-import { redirect, useRouter } from "next/navigation"
+import { useRouter } from "next/navigation"
import { useEffect, useState } from "react"
-import { format, parseISO } from "date-fns";
-import { getInitials } from "@/app/components/calendar/schedulerUtils";
const RECRUIT_TABLE_HEADERS = [
{ id: "workedAt", name: "work date", sortBy: "workedAt_num", flex: 2 },
@@ -46,61 +42,22 @@ function ProfilePage() {
);
const email = session.data.user.email;
- const userRoles = session.data.user.roles.map((e) => e.name);
+ const userRoles = session.data.user.roles;
const recruiter = session.data.user.recruitedByUser;
const usersRecruited = session.data.user.recruitedUsers?.length;
useEffect(() => {
if (!recruiter) {
- prismaRequest({
- model: "user",
- method: "find",
- callback: (data) => setUsers(data.data),
- });
+ fetch("/api/v2/users")
+ .then(res => res.json())
+ .then(data => setUsers(data.users))
}
- prismaRequest({
- model: "user",
- method: "find",
- request: {
- where: {
- recruitedById: session.data.user.id,
- },
- include: {
- LoggedForUser: {
- include: {
- LoggedForUser: true,
- LoggedByUser: true,
- },
- },
- },
- },
- callback: (data) => {
- let newLogs = [];
-
- data.data.forEach((e) => {
- e.LoggedForUser.forEach((f) => {
- const p1 = f.LoggedByUser;
- const p2 = f.LoggedForUser;
- const p1name = p1 ? `${p1.firstName} ${p1.lastName}` : "";
- const p2name = p2 ? `${p2.firstName} ${p2.lastName}` : "";
- ;
- newLogs.push({
- ...f,
- loggedBy: getInitials(p1name),
- loggedFor: getInitials(p2name),
- workedAt_num: parseISO(f.workedAt).getTime(),
- workedAt: format(
- parseISO(f.workedAt),
- "dd.MM HH:mm"
- ).toLowerCase(),
- });
- });
- });
- setRecruitHours(newLogs.reduce((sum, next) => sum += next.duration, 0))
- setRecruitLogs(newLogs);
- },
- });
+ fetch(`/api/v2/users/${session.data.user.id}/recruitInfo`)
+ .then(res => res.json())
+ .then(data => {
+ setRecruitHours(data.recruitHours)
+ })
}, []);
// queries database for user data
@@ -112,37 +69,33 @@ function ProfilePage() {
}
}, [session])
- const handleUpdateData = async () => {
- await prismaRequest({
- model: "user",
- method: "update",
- request: {
- where: {
- email: session.data.user.email
- },
- data: {
- firstName: firstName,
- lastName: lastName,
- }
- }
- });
- window.location.reload();
+ const handleUpdateData = () => {
+
+ fetch(`/api/v2/users/${session.data.user.id}`, {
+ method: "PATCH",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ firstName: firstName,
+ lastName: lastName,
+ }),
+ }).then(() => window.location.reload());
+
}
- const handleConfirmSelection = async () => {
- await prismaRequest({
- model: "user",
- method: "update",
- request: {
- where: {
- email: session.data.user.email,
- },
- data: {
- recruitedById: selectedRecruiter.id,
- },
+ const handleConfirmSelection = () => {
+ fetch(`/api/v2/users/${session.data.user.id}`, {
+ method: "PATCH",
+ headers: {
+ "Content-Type": "application/json",
},
- });
- window.location.reload()
+ body: JSON.stringify({
+ recruitedById: selectedRecruiter.id,
+ }),
+ }).then(() => window.location.reload());
+
+
}
@@ -322,7 +275,7 @@ function section3(props) {
}
const AdminRedirectButton = (session, router, buttonProps) => {
- const userRoles = session.data.user.roles.map((e) => e.name)
+ const userRoles = session.data.user.roles;
if (!userRoles.includes("admin")) return
return (