diff --git a/FrontendV2/src/components/UserDialogue.tsx b/FrontendV2/src/components/UserDialogue.tsx index d4e88b6..90b5aa3 100644 --- a/FrontendV2/src/components/UserDialogue.tsx +++ b/FrontendV2/src/components/UserDialogue.tsx @@ -36,12 +36,43 @@ export const UserDialogue = (props: UserDialogueProps) => { const [msgTitle, setMsgTitle] = 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 [newPassword, setNewPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); // Dialog control 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 () => { if (newPassword !== confirmPassword) { @@ -147,14 +178,31 @@ export const UserDialogue = (props: UserDialogueProps) => { - - + + + {isMsgNAAS && ( + + )} + + + + + - {/* Passwort-Dialog (kontrolliert) */} + {/* Passwort-Dialog */} setPwOpen(e.open)}> @@ -215,6 +263,31 @@ export const UserDialogue = (props: UserDialogueProps) => { + + + + + + + + + {t("naas-header")} + + +

{naas}

+
+ + setNaasDialog(false)} size="sm" /> + +
+
+
+
+
); }; diff --git a/FrontendV2/src/utils/i18n/locales/de/de.json b/FrontendV2/src/utils/i18n/locales/de/de.json index f6ed2dc..b02e852 100644 --- a/FrontendV2/src/utils/i18n/locales/de/de.json +++ b/FrontendV2/src/utils/i18n/locales/de/de.json @@ -88,5 +88,10 @@ "take-loan-success": "Ausleihe erfolgreich abgeholt", "return-loan-success": "Ausleihe erfolgreich zurückgegeben", "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..." } \ No newline at end of file diff --git a/FrontendV2/src/utils/i18n/locales/en/en.json b/FrontendV2/src/utils/i18n/locales/en/en.json index 6a52916..d093b1c 100644 --- a/FrontendV2/src/utils/i18n/locales/en/en.json +++ b/FrontendV2/src/utils/i18n/locales/en/en.json @@ -88,5 +88,10 @@ "take-loan-success": "Loan taken successfully", "return-loan-success": "Loan returned successfully", "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..." } \ No newline at end of file diff --git a/backendV2/server.js b/backendV2/server.js index 3b86597..a8d2006 100644 --- a/backendV2/server.js +++ b/backendV2/server.js @@ -1,6 +1,6 @@ import express from "express"; import cors from "cors"; -import env from "dotenv"; +import dotenv from "dotenv"; import info from "./info.json" assert { type: "json" }; import { authenticate } from "./services/authentication.js"; @@ -18,9 +18,12 @@ import userMgmtRouterADMIN from "./routes/admin/userMgmt.route.js"; // API routes import apiRouter from "./routes/api/api.route.js"; -env.config(); +dotenv.config(); const app = express(); const port = 8004; +const naasURL = process.env.NAAS_URL; + +console.log(naasURL); app.use(cors()); // Body-Parser VOR den Routen registrieren @@ -47,6 +50,20 @@ app.listen(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) => { res.status(200).json({ message: "Token is valid", user: req.user }); }); diff --git a/docker-compose.yml b/docker-compose.yml index 90ab08c..c0b95ef 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,14 +4,14 @@ services: # build: ./FrontendV2 # ports: # - "8001:80" - # restart: unless-stopped + # restart: always # admin-frontend: # container_name: borrow_system-admin-frontend # build: ./admin # ports: # - "8003:80" - # restart: unless-stopped + # restart: always backend_v2: container_name: borrow_system-backend_v2 @@ -26,12 +26,12 @@ services: DB_NAME: borrow_system_new depends_on: - mysql_v2 - restart: unless-stopped + restart: always mysql_v2: container_name: borrow_system-mysql-v2 image: mysql:8.0 - restart: unless-stopped + restart: always environment: MYSQL_ROOT_PASSWORD: ${DB_PASSWORD_V2} MYSQL_DATABASE: borrow_system_new @@ -42,6 +42,15 @@ services: ports: - "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: mysql-data: mysql-v2-data: