implemented naas in to user frontend
This commit is contained in:
@@ -36,12 +36,43 @@ export const UserDialogue = (props: UserDialogueProps) => {
|
|||||||
const [msgTitle, setMsgTitle] = useState("");
|
const [msgTitle, setMsgTitle] = useState("");
|
||||||
const [msgDescription, setMsgDescription] = useState("");
|
const [msgDescription, setMsgDescription] = useState("");
|
||||||
|
|
||||||
|
const [isMsgNAAS, setIsMsgNAAS] = useState(false);
|
||||||
|
const [msgStatusNAAS, setMsgStatusNAAS] = useState<"error" | "success">(
|
||||||
|
"error",
|
||||||
|
);
|
||||||
|
const [msgTitleNAAS, setMsgTitleNAAS] = useState("");
|
||||||
|
const [msgDescriptionNAAS, setMsgDescriptionNAAS] = useState("");
|
||||||
|
|
||||||
const [oldPassword, setOldPassword] = useState("");
|
const [oldPassword, setOldPassword] = useState("");
|
||||||
const [newPassword, setNewPassword] = useState("");
|
const [newPassword, setNewPassword] = useState("");
|
||||||
const [confirmPassword, setConfirmPassword] = useState("");
|
const [confirmPassword, setConfirmPassword] = useState("");
|
||||||
|
|
||||||
// Dialog control
|
// Dialog control
|
||||||
const [isPwOpen, setPwOpen] = useState(false);
|
const [isPwOpen, setPwOpen] = useState(false);
|
||||||
|
const [naasDialog, setNaasDialog] = useState(false);
|
||||||
|
const [naas, setNaas] = useState("");
|
||||||
|
|
||||||
|
const openNAAS = async () => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_BASE}/no`, {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${Cookies.get("token")}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
setNaas(data.reason);
|
||||||
|
setNaasDialog(true);
|
||||||
|
} catch (error) {
|
||||||
|
setMsgStatusNAAS("error");
|
||||||
|
setMsgTitleNAAS(t("naas-error"));
|
||||||
|
setMsgDescriptionNAAS(t("naas-error-desc"));
|
||||||
|
setIsMsgNAAS(true);
|
||||||
|
|
||||||
|
console.log(msgStatusNAAS, msgTitleNAAS, msgDescriptionNAAS);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const changePassword = async () => {
|
const changePassword = async () => {
|
||||||
if (newPassword !== confirmPassword) {
|
if (newPassword !== confirmPassword) {
|
||||||
@@ -147,14 +178,31 @@ export const UserDialogue = (props: UserDialogueProps) => {
|
|||||||
</Button>
|
</Button>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Card.Body>
|
</Card.Body>
|
||||||
<Card.Footer justifyContent="flex-end">
|
<Card.Footer>
|
||||||
<Button variant="outline" onClick={() => props.setUserDialog(false)}>
|
<Stack w="100%" gap={3}>
|
||||||
|
{isMsgNAAS && (
|
||||||
|
<MyAlert
|
||||||
|
status={msgStatusNAAS}
|
||||||
|
title={msgTitleNAAS}
|
||||||
|
description={msgDescriptionNAAS}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<HStack justify="flex-end" gap={2} wrap="wrap">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => props.setUserDialog(false)}
|
||||||
|
>
|
||||||
{t("cancel")}
|
{t("cancel")}
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button variant="outline" onClick={() => openNAAS()}>
|
||||||
|
{t("try-naas")}
|
||||||
|
</Button>
|
||||||
|
</HStack>
|
||||||
|
</Stack>
|
||||||
</Card.Footer>
|
</Card.Footer>
|
||||||
</Card.Root>
|
</Card.Root>
|
||||||
|
|
||||||
{/* Passwort-Dialog (kontrolliert) */}
|
{/* Passwort-Dialog */}
|
||||||
<Dialog.Root open={isPwOpen} onOpenChange={(e: any) => setPwOpen(e.open)}>
|
<Dialog.Root open={isPwOpen} onOpenChange={(e: any) => setPwOpen(e.open)}>
|
||||||
<Portal>
|
<Portal>
|
||||||
<Dialog.Backdrop />
|
<Dialog.Backdrop />
|
||||||
@@ -215,6 +263,31 @@ export const UserDialogue = (props: UserDialogueProps) => {
|
|||||||
</Dialog.Positioner>
|
</Dialog.Positioner>
|
||||||
</Portal>
|
</Portal>
|
||||||
</Dialog.Root>
|
</Dialog.Root>
|
||||||
|
|
||||||
|
<HStack wrap="wrap" gap="4">
|
||||||
|
<Dialog.Root
|
||||||
|
placement={"center"}
|
||||||
|
open={naasDialog}
|
||||||
|
motionPreset="slide-in-bottom"
|
||||||
|
>
|
||||||
|
<Portal>
|
||||||
|
<Dialog.Backdrop />
|
||||||
|
<Dialog.Positioner>
|
||||||
|
<Dialog.Content>
|
||||||
|
<Dialog.Header>
|
||||||
|
<Dialog.Title>{t("naas-header")}</Dialog.Title>
|
||||||
|
</Dialog.Header>
|
||||||
|
<Dialog.Body>
|
||||||
|
<p>{naas}</p>
|
||||||
|
</Dialog.Body>
|
||||||
|
<Dialog.CloseTrigger asChild>
|
||||||
|
<CloseButton onClick={() => setNaasDialog(false)} size="sm" />
|
||||||
|
</Dialog.CloseTrigger>
|
||||||
|
</Dialog.Content>
|
||||||
|
</Dialog.Positioner>
|
||||||
|
</Portal>
|
||||||
|
</Dialog.Root>
|
||||||
|
</HStack>
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -88,5 +88,10 @@
|
|||||||
"take-loan-success": "Ausleihe erfolgreich abgeholt",
|
"take-loan-success": "Ausleihe erfolgreich abgeholt",
|
||||||
"return-loan-success": "Ausleihe erfolgreich zurückgegeben",
|
"return-loan-success": "Ausleihe erfolgreich zurückgegeben",
|
||||||
"network-error": "Netzwerkfehler. Kontaktieren Sie den Administrator.",
|
"network-error": "Netzwerkfehler. Kontaktieren Sie den Administrator.",
|
||||||
"contactPage_messageDescription": "Bitte geben Sie hier Ihre Nachricht ein. Der Systemadministrator (Theis Gaedigk) wird sich so schnell wie möglich bei Ihnen melden."
|
"contactPage_messageDescription": "Bitte geben Sie hier Ihre Nachricht ein. Der Systemadministrator (Theis Gaedigk) wird sich so schnell wie möglich bei Ihnen melden.",
|
||||||
|
"naas": "No-as-a-service",
|
||||||
|
"try-naas": "Klick mich",
|
||||||
|
"naas-error": "Fehler mit no-as-a-service",
|
||||||
|
"naas-error-desc": "Ein Fehler ist beim Kommunizieren mit no-as-a-service aufgetreten.",
|
||||||
|
"naas-header": "Eine gute Möglichkeit, nein zu sagen..."
|
||||||
}
|
}
|
||||||
@@ -88,5 +88,10 @@
|
|||||||
"take-loan-success": "Loan taken successfully",
|
"take-loan-success": "Loan taken successfully",
|
||||||
"return-loan-success": "Loan returned successfully",
|
"return-loan-success": "Loan returned successfully",
|
||||||
"network-error": "Network error. Please contact the administrator.",
|
"network-error": "Network error. Please contact the administrator.",
|
||||||
"contactPage_messageDescription": "Please enter your message here. The system administrator (Theis Gaedigk) will get back to you as soon as possible."
|
"contactPage_messageDescription": "Please enter your message here. The system administrator (Theis Gaedigk) will get back to you as soon as possible.",
|
||||||
|
"naas": "No-as-a-service",
|
||||||
|
"try-naas": "Click me",
|
||||||
|
"naas-error": "Error with no-as-a-service",
|
||||||
|
"naas-error-desc": "An error occurred while communicating with no-as-a-service.",
|
||||||
|
"naas-header": "A good way to say no..."
|
||||||
}
|
}
|
||||||
+19
-2
@@ -1,6 +1,6 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import env from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import info from "./info.json" assert { type: "json" };
|
import info from "./info.json" assert { type: "json" };
|
||||||
import { authenticate } from "./services/authentication.js";
|
import { authenticate } from "./services/authentication.js";
|
||||||
|
|
||||||
@@ -18,9 +18,12 @@ import userMgmtRouterADMIN from "./routes/admin/userMgmt.route.js";
|
|||||||
// API routes
|
// API routes
|
||||||
import apiRouter from "./routes/api/api.route.js";
|
import apiRouter from "./routes/api/api.route.js";
|
||||||
|
|
||||||
env.config();
|
dotenv.config();
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = 8004;
|
const port = 8004;
|
||||||
|
const naasURL = process.env.NAAS_URL;
|
||||||
|
|
||||||
|
console.log(naasURL);
|
||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
// Body-Parser VOR den Routen registrieren
|
// Body-Parser VOR den Routen registrieren
|
||||||
@@ -47,6 +50,20 @@ app.listen(port, () => {
|
|||||||
console.log(`Server is running on port: ${port}`);
|
console.log(`Server is running on port: ${port}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get("/no", async (req, res) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(naasURL);
|
||||||
|
if (!response.ok) {
|
||||||
|
res.status(500).send("Request to no-as-a-service went wrong.");
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
|
res.json(data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error communicating with no-as-a-service:", error);
|
||||||
|
res.status(500).send("Error communicating with no-as-a-service.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
app.get("/verify", authenticate, async (req, res) => {
|
app.get("/verify", authenticate, async (req, res) => {
|
||||||
res.status(200).json({ message: "Token is valid", user: req.user });
|
res.status(200).json({ message: "Token is valid", user: req.user });
|
||||||
});
|
});
|
||||||
|
|||||||
+13
-4
@@ -4,14 +4,14 @@ services:
|
|||||||
# build: ./FrontendV2
|
# build: ./FrontendV2
|
||||||
# ports:
|
# ports:
|
||||||
# - "8001:80"
|
# - "8001:80"
|
||||||
# restart: unless-stopped
|
# restart: always
|
||||||
|
|
||||||
# admin-frontend:
|
# admin-frontend:
|
||||||
# container_name: borrow_system-admin-frontend
|
# container_name: borrow_system-admin-frontend
|
||||||
# build: ./admin
|
# build: ./admin
|
||||||
# ports:
|
# ports:
|
||||||
# - "8003:80"
|
# - "8003:80"
|
||||||
# restart: unless-stopped
|
# restart: always
|
||||||
|
|
||||||
backend_v2:
|
backend_v2:
|
||||||
container_name: borrow_system-backend_v2
|
container_name: borrow_system-backend_v2
|
||||||
@@ -26,12 +26,12 @@ services:
|
|||||||
DB_NAME: borrow_system_new
|
DB_NAME: borrow_system_new
|
||||||
depends_on:
|
depends_on:
|
||||||
- mysql_v2
|
- mysql_v2
|
||||||
restart: unless-stopped
|
restart: always
|
||||||
|
|
||||||
mysql_v2:
|
mysql_v2:
|
||||||
container_name: borrow_system-mysql-v2
|
container_name: borrow_system-mysql-v2
|
||||||
image: mysql:8.0
|
image: mysql:8.0
|
||||||
restart: unless-stopped
|
restart: always
|
||||||
environment:
|
environment:
|
||||||
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD_V2}
|
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD_V2}
|
||||||
MYSQL_DATABASE: borrow_system_new
|
MYSQL_DATABASE: borrow_system_new
|
||||||
@@ -42,6 +42,15 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "3310:3306"
|
- "3310:3306"
|
||||||
|
|
||||||
|
no-as-a-service:
|
||||||
|
container_name: borrow_system-naas
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
build:
|
||||||
|
context: ./no-as-a-service
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
restart: always
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
mysql-data:
|
mysql-data:
|
||||||
mysql-v2-data:
|
mysql-v2-data:
|
||||||
|
|||||||
Reference in New Issue
Block a user