diff --git a/FrontendV2/src/components/DeactivatedServices.tsx b/FrontendV2/src/components/DeactivatedServices.tsx new file mode 100644 index 0000000..100edfb --- /dev/null +++ b/FrontendV2/src/components/DeactivatedServices.tsx @@ -0,0 +1,67 @@ +import { Alert, Stack, VStack, Spinner, Text, Heading } from "@chakra-ui/react"; +import { useEffect, useState } from "react"; +import { API_BASE } from "@/config/api.config"; +import Cookies from "js-cookie"; +import { useTranslation } from "react-i18next"; + +export const DeactivatedServices = () => { + const { t } = useTranslation(); + + const [deactivatedServices, setDeactivatedServices] = useState< + { function_name: string }[] + >([]); + const [isLoading, setIsLoading] = useState(false); + + useEffect(() => { + const fetchDeactivatedServices = async () => { + setIsLoading(true); + try { + const response = await fetch( + `${API_BASE}/api/users/deactivated-services`, + { + headers: { + Authorization: `Bearer ${Cookies.get("token") || ""}`, + }, + }, + ); + + if (response.ok) { + const data = await response.json(); + setDeactivatedServices(data); + } else { + console.error("Failed to fetch deactivated services"); + } + } catch (error) { + console.error("Error fetching deactivated services:", error); + } + setIsLoading(false); + }; + + fetchDeactivatedServices(); + }, []); + + return ( + <> + {deactivatedServices.length >= 1 && ( + + {t("deactivated-services")} + {isLoading && ( + + + {t("loading")} + + )} + {deactivatedServices.length >= 1 && + deactivatedServices.map((item) => ( + + + + {item.function_name} {t("is-deactivated")} + + + ))} + + )} + + ); +}; diff --git a/FrontendV2/src/components/Header.tsx b/FrontendV2/src/components/Header.tsx index 545a103..52b48f2 100644 --- a/FrontendV2/src/components/Header.tsx +++ b/FrontendV2/src/components/Header.tsx @@ -69,6 +69,7 @@ export const Header = () => { className="mb-6" position="relative" pr={{ base: 10, md: 0 }} // Platz für den Mobile-Button rechts + marginBottom={1} > {/* Mobile: Drei-Punkte-Button, vertikal zentriert im Header */} { )}
+ {isMsg && ( { const [result] = await pool.query( "SELECT * FROM users WHERE username = ? AND password = ?", - [username, password] + [username, password], ); if (result.length > 0) return { success: true, data: result[0] }; return { success: false }; @@ -40,7 +40,7 @@ export const changePassword = async (username, oldPassword, newPassword) => { // get user current password const [user] = await pool.query( "SELECT * FROM users WHERE username = ? AND password = ?", - [username, oldPassword] + [username, oldPassword], ); if (user.length === 0) return { success: false }; @@ -48,8 +48,16 @@ export const changePassword = async (username, oldPassword, newPassword) => { const [result] = await pool.query( "UPDATE users SET password = ? WHERE username = ?", - [newPassword, username] + [newPassword, username], ); if (result.affectedRows > 0) return { success: true }; return { success: false }; }; + +export const getDeactivatedServices = async () => { + const [rows] = await pool.query("SELECT function_name FROM functions WHERE active = 0;"); + if (rows.length > 0) { + return { success: true, data: rows }; + } + return { success: false }; +}; diff --git a/backendV2/routes/app/userMgmt.route.js b/backendV2/routes/app/userMgmt.route.js index 654030b..e1eec7a 100644 --- a/backendV2/routes/app/userMgmt.route.js +++ b/backendV2/routes/app/userMgmt.route.js @@ -9,7 +9,11 @@ const user_frontend_service = "User Frontend"; const contact_form_service = "Contact Form Service"; // database funcs import -import { loginFunc, changePassword } from "./database/userMgmt.database.js"; +import { + loginFunc, + changePassword, + getDeactivatedServices, +} from "./database/userMgmt.database.js"; import { sendMail } from "./services/mailer_v2.js"; router.post( @@ -63,4 +67,13 @@ router.post( }, ); +router.get("/deactivated-services", authenticate, async (req, res) => { + const result = await getDeactivatedServices(); + if (result.success) { + res.status(200).json(result.data); + } else { + res.status(500).json({ message: "Failed to fetch deactivated services" }); + } +}); + export default router;