diff --git a/ui/src/components/LocalAuthPasswordDialog.tsx b/ui/src/components/LocalAuthPasswordDialog.tsx deleted file mode 100644 index 8154457..0000000 --- a/ui/src/components/LocalAuthPasswordDialog.tsx +++ /dev/null @@ -1,356 +0,0 @@ -import { GridCard } from "@/components/Card"; -import { useState } from "react"; -import { Button } from "@components/Button"; -import LogoBlueIcon from "@/assets/logo-blue.svg"; -import LogoWhiteIcon from "@/assets/logo-white.svg"; -import Modal from "@components/Modal"; -import { InputFieldWithLabel } from "./InputField"; -import api from "@/api"; -import { useLocalAuthModalStore } from "@/hooks/stores"; - -export default function LocalAuthPasswordDialog({ - open, - setOpen, -}: { - open: boolean; - setOpen: (open: boolean) => void; -}) { - return ( - setOpen(false)}> - - - ); -} - -export function Dialog({ setOpen }: { setOpen: (open: boolean) => void }) { - const { modalView, setModalView } = useLocalAuthModalStore(); - const [error, setError] = useState(null); - - const handleCreatePassword = async (password: string, confirmPassword: string) => { - if (password === "") { - setError("Please enter a password"); - return; - } - - if (password !== confirmPassword) { - setError("Passwords do not match"); - return; - } - - try { - const res = await api.POST("/auth/password-local", { password }); - if (res.ok) { - setModalView("creationSuccess"); - } else { - const data = await res.json(); - setError(data.error || "An error occurred while setting the password"); - } - } catch (error) { - setError("An error occurred while setting the password"); - } - }; - - const handleUpdatePassword = async ( - oldPassword: string, - newPassword: string, - confirmNewPassword: string, - ) => { - if (newPassword !== confirmNewPassword) { - setError("Passwords do not match"); - return; - } - - if (oldPassword === "") { - setError("Please enter your old password"); - return; - } - - if (newPassword === "") { - setError("Please enter a new password"); - return; - } - - try { - const res = await api.PUT("/auth/password-local", { - oldPassword, - newPassword, - }); - - if (res.ok) { - setModalView("updateSuccess"); - } else { - const data = await res.json(); - setError(data.error || "An error occurred while changing the password"); - } - } catch (error) { - setError("An error occurred while changing the password"); - } - }; - - const handleDeletePassword = async (password: string) => { - if (password === "") { - setError("Please enter your current password"); - return; - } - - try { - const res = await api.DELETE("/auth/local-password", { password }); - if (res.ok) { - setModalView("deleteSuccess"); - } else { - const data = await res.json(); - setError(data.error || "An error occurred while disabling the password"); - } - } catch (error) { - setError("An error occurred while disabling the password"); - } - }; - - return ( - -
- {modalView === "createPassword" && ( - setOpen(false)} - error={error} - /> - )} - - {modalView === "deletePassword" && ( - setOpen(false)} - error={error} - /> - )} - - {modalView === "updatePassword" && ( - setOpen(false)} - error={error} - /> - )} - - {modalView === "creationSuccess" && ( - setOpen(false)} - /> - )} - - {modalView === "deleteSuccess" && ( - setOpen(false)} - /> - )} - - {modalView === "updateSuccess" && ( - setOpen(false)} - /> - )} -
-
- ); -} - -function CreatePasswordModal({ - onSetPassword, - onCancel, - error, -}: { - onSetPassword: (password: string, confirmPassword: string) => void; - onCancel: () => void; - error: string | null; -}) { - const [password, setPassword] = useState(""); - const [confirmPassword, setConfirmPassword] = useState(""); - - return ( -
-
- - -
-
-
-

Local Device Protection

-

- Create a password to protect your device from unauthorized local access. -

-
- setPassword(e.target.value)} - /> - setConfirmPassword(e.target.value)} - /> - -
-
- {error &&

{error}

} -
-
- ); -} - -function DeletePasswordModal({ - onDeletePassword, - onCancel, - error, -}: { - onDeletePassword: (password: string) => void; - onCancel: () => void; - error: string | null; -}) { - const [password, setPassword] = useState(""); - - return ( -
-
- - -
-
-
-

Disable Local Device Protection

-

- Enter your current password to disable local device protection. -

-
- setPassword(e.target.value)} - /> -
-
- {error &&

{error}

} -
-
- ); -} - -function UpdatePasswordModal({ - onUpdatePassword, - onCancel, - error, -}: { - onUpdatePassword: ( - oldPassword: string, - newPassword: string, - confirmNewPassword: string, - ) => void; - onCancel: () => void; - error: string | null; -}) { - const [oldPassword, setOldPassword] = useState(""); - const [newPassword, setNewPassword] = useState(""); - const [confirmNewPassword, setConfirmNewPassword] = useState(""); - - return ( -
-
- - -
-
-
-

Change Local Device Password

-

- Enter your current password and a new password to update your local device - protection. -

-
- setOldPassword(e.target.value)} - /> - setNewPassword(e.target.value)} - /> - setConfirmNewPassword(e.target.value)} - /> -
-
- {error &&

{error}

} -
-
- ); -} - -function SuccessModal({ - headline, - description, - onClose, -}: { - headline: string; - description: string; - onClose: () => void; -}) { - return ( -
-
- - -
-
-
-

{headline}

-

{description}

-
-
-
- ); -} diff --git a/ui/src/components/sidebar/settings.tsx b/ui/src/components/sidebar/settings.tsx index 6c5f0d2..b6c3a2c 100644 --- a/ui/src/components/sidebar/settings.tsx +++ b/ui/src/components/sidebar/settings.tsx @@ -23,7 +23,7 @@ import { SystemVersionInfo } from "@/routes/devices.$id.update"; import notifications from "@/notifications"; import api from "../../api"; import { LocalDevice } from "@routes/devices.$id"; -import { useRevalidator, useNavigate } from "react-router-dom"; +import { useNavigate } from "react-router-dom"; import { ShieldCheckIcon } from "@heroicons/react/20/solid"; import { CLOUD_APP, DEVICE_API } from "@/ui.config"; import { InputFieldWithLabel } from "@/components/InputField"; @@ -432,7 +432,6 @@ export default function SettingsSidebar() { const { setModalView: setLocalAuthModalView, modalView: localAuthModalView } = useLocalAuthModalStore(); - const [isLocalAuthDialogOpen] = useState(false); useEffect(() => { if (isOnDevice) getDevice(); @@ -446,7 +445,7 @@ export default function SettingsSidebar() { ) { getDevice(); } - }, [getDevice, isLocalAuthDialogOpen, localAuthModalView]); + }, [getDevice, localAuthModalView]); const [currentTheme, setCurrentTheme] = useState(() => { return localStorage.theme || "system";