diff --git a/apps/dispatch/app/(app)/dispatch/_components/navbar/_components/Connection.tsx b/apps/dispatch/app/(app)/dispatch/_components/navbar/_components/Connection.tsx index 3ec4a56a..5189ab0f 100644 --- a/apps/dispatch/app/(app)/dispatch/_components/navbar/_components/Connection.tsx +++ b/apps/dispatch/app/(app)/dispatch/_components/navbar/_components/Connection.tsx @@ -3,11 +3,10 @@ import { useSession } from "next-auth/react"; import { useDispatchConnectionStore } from "../../../../../_store/dispatch/connectionStore"; import { useEffect, useRef, useState } from "react"; -import { toast } from "react-hot-toast"; import { useMutation } from "@tanstack/react-query"; import { Prisma } from "@repo/db"; import { changeDispatcherAPI } from "_querys/dispatcher"; -import { getNextDateWithTime } from "@repo/shared-components"; +import { Button, getNextDateWithTime } from "@repo/shared-components"; export const ConnectionBtn = () => { const modalRef = useRef(null); @@ -20,44 +19,19 @@ export const ConnectionBtn = () => { mutationFn: ({ id, data }: { id: number; data: Prisma.ConnectedDispatcherUpdateInput }) => changeDispatcherAPI(id, data), }); - const [logoffDebounce, setLogoffDebounce] = useState(null); const session = useSession(); const uid = session.data?.user?.id; // useEffect für die Logoff-Zeit const [logoffHours, logoffMinutes] = form.logoffTime?.split(":").map(Number) || []; - useEffect(() => { - if (!logoffHours || !logoffMinutes) return; - if (logoffDebounce) clearTimeout(logoffDebounce); - - const timeout = setTimeout(async () => { - if (!logoffHours || !logoffMinutes || !connection.connectedDispatcher) return; - await changeDispatcherMutation.mutateAsync({ - id: connection.connectedDispatcher?.id, - data: { - esimatedLogoutTime: - logoffHours && logoffMinutes ? getNextDateWithTime(logoffHours, logoffMinutes) : null, - }, - }); - toast.success("Änderung gespeichert!"); - modalRef.current?.close(); - }, 2000); - - setLogoffDebounce(timeout); - - // Cleanup function - return () => { - if (logoffDebounce) clearTimeout(logoffDebounce); - }; - }, [form.logoffTime, connection.connectedDispatcher]); - useEffect(() => { // Disconnect the socket when the component unmounts return () => { connection.disconnect(); }; }, [connection.disconnect]); + if (!uid) return null; return (
@@ -122,16 +96,36 @@ export const ConnectionBtn = () => {
{connection.status == "connected" ? ( - + <> + + + ) : ( {connection.status == "connected" ? ( - + <> + + + ) : ( - + )}
diff --git a/packages/shared-components/components/Button.tsx b/packages/shared-components/components/Button.tsx new file mode 100644 index 00000000..99d9ee42 --- /dev/null +++ b/packages/shared-components/components/Button.tsx @@ -0,0 +1,43 @@ +"use client"; +import React, { + ButtonHTMLAttributes, + DetailedHTMLProps, + useEffect, + useState, + forwardRef, +} from "react"; +import { cn } from "@repo/shared-components"; + +export const Button = forwardRef< + HTMLButtonElement, + DetailedHTMLProps, HTMLButtonElement> & { + isLoading?: boolean; + } +>(({ isLoading, ...props }, ref) => { + const [isLoadingState, setIsLoadingState] = useState(isLoading); + + useEffect(() => { + setIsLoadingState(isLoading); + }, [isLoading]); + + return ( + + ); +}); + +Button.displayName = "Button"; diff --git a/packages/shared-components/components/index.ts b/packages/shared-components/components/index.ts index 8f59c043..77206c39 100644 --- a/packages/shared-components/components/index.ts +++ b/packages/shared-components/components/index.ts @@ -1,3 +1,4 @@ export * from "./Badge"; export * from "./PenaltyDropdown"; export * from "./Maintenance"; +export * from "./Button"; diff --git a/packages/shared-components/package.json b/packages/shared-components/package.json index 574e5fab..193155fd 100644 --- a/packages/shared-components/package.json +++ b/packages/shared-components/package.json @@ -15,7 +15,7 @@ "tailwind-merge": "^3.3.0" }, "devDependencies": { - "@types/react": "^19.1.6", + "@types/react": "^19.1.8", "@types/react-dom": "^19.1.5", "react": "^19.1.0", "react-dom": "^19.1.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1c379cc7..e911870d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -630,11 +630,11 @@ importers: version: 3.3.0 devDependencies: '@types/react': - specifier: ^19.1.6 - version: 19.1.6 + specifier: ^19.1.8 + version: 19.1.8 '@types/react-dom': specifier: ^19.1.5 - version: 19.1.5(@types/react@19.1.6) + version: 19.1.5(@types/react@19.1.8) react: specifier: ^19.1.0 version: 19.1.0 @@ -8668,9 +8668,9 @@ snapshots: '@types/range-parser@1.2.7': {} - '@types/react-dom@19.1.5(@types/react@19.1.6)': + '@types/react-dom@19.1.5(@types/react@19.1.8)': dependencies: - '@types/react': 19.1.6 + '@types/react': 19.1.8 '@types/react-dom@19.1.6(@types/react@19.1.8)': dependencies: