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 [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) => {
|
||||
</Button>
|
||||
</Stack>
|
||||
</Card.Body>
|
||||
<Card.Footer justifyContent="flex-end">
|
||||
<Button variant="outline" onClick={() => props.setUserDialog(false)}>
|
||||
{t("cancel")}
|
||||
</Button>
|
||||
<Card.Footer>
|
||||
<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")}
|
||||
</Button>
|
||||
<Button variant="outline" onClick={() => openNAAS()}>
|
||||
{t("try-naas")}
|
||||
</Button>
|
||||
</HStack>
|
||||
</Stack>
|
||||
</Card.Footer>
|
||||
</Card.Root>
|
||||
|
||||
{/* Passwort-Dialog (kontrolliert) */}
|
||||
{/* Passwort-Dialog */}
|
||||
<Dialog.Root open={isPwOpen} onOpenChange={(e: any) => setPwOpen(e.open)}>
|
||||
<Portal>
|
||||
<Dialog.Backdrop />
|
||||
@@ -215,6 +263,31 @@ export const UserDialogue = (props: UserDialogueProps) => {
|
||||
</Dialog.Positioner>
|
||||
</Portal>
|
||||
</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>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -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..."
|
||||
}
|
||||
@@ -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..."
|
||||
}
|
||||
+19
-2
@@ -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 });
|
||||
});
|
||||
|
||||
+13
-4
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user