From fdf4750919eaf65960f2b3746f98af23f8fef9b8 Mon Sep 17 00:00:00 2001 From: Project_IO Date: Mon, 24 Mar 2025 17:46:08 +0900 Subject: [PATCH] feat: middle save --- src/components/settings/index.tsx | 170 ++++++++++++++++---------- src/components/settings/settings.scss | 8 +- 2 files changed, 107 insertions(+), 71 deletions(-) diff --git a/src/components/settings/index.tsx b/src/components/settings/index.tsx index b800a45..cc9562f 100644 --- a/src/components/settings/index.tsx +++ b/src/components/settings/index.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useRef, useState } from "react"; -import { AuthState, useAuthStore } from "../../store/auth"; +import { useAuthStore } from "../../store/auth"; import "./settings.scss"; import { DynamicIcon } from "lucide-react/dynamic"; @@ -33,26 +33,16 @@ function Settings() { return (

General

- + -

Private Directory

- - {/* TODO: create private dir panel */} - <> - +

Private Directory

+
); } -function SettingBox({ children }: { children: React.ReactNode }) { - return ( -
- {children} -
- ); -} - -function AccountSetting({ auth }: { auth: AuthState }) { +function AccountSetting() { + const auth = useAuthStore(); const orRef = useRef(null); const pwRef = useRef(null); const ckRef = useRef(null); @@ -64,74 +54,69 @@ function AccountSetting({ auth }: { auth: AuthState }) {

Account Setting

You can modify your account. This is a sensitive option. Please reconsider if you want to change your account information.
+ {/* TODO: split to component */}
Change Password
If you change your password, you will need to log in again.
-
+ { + ev.preventDefault(); + const origin = orRef.current?.value; + const password = pwRef.current?.value; + const check = ckRef.current?.value; + + if (!origin || !password || !check) { + return; + } + + if (origin === "" || password === "" || check === "") { + alert("You must need to write all inputs"); + return; + } + + if (password !== check) { + alert("New password is not matches!"); + return; + } + + const form = new URLSearchParams(); + form.append("password", origin); + form.append("new_password", password); + + fetch("/api/auth/update", { + body: form, + method: "PATCH", + headers: { + "Authorization": `Basic ${auth.token}` + } + }).then((res) => { + if (res.status !== 200) { + alert(`${res.status} ${res.statusText}`); + return; + } + + alert("password changed!"); + document.location.href = "/logout"; + }); + }}> - +
+ + {/* TODO: split to component */}
Delete Account
You can delete account. This action is irreversible. Please proceed with caution.
-
- - - + }}> + + +
); } +function PrivateDirectory() { + const pathRef = useRef(null); + const [disabled, setDisabled] = useState(true); + + return ( + +

Directory Management

+ +
+ + {/* TODO: split to component */} +
+
+
Add Directory
+ You can add private directory here. +
+ +
{ + ev.preventDefault(); + }}> + { + setDisabled(ev.target.value === ""); + }} /> + +
+
+ + {/*
+
+
+
*/} +
+ ); +} + function PasswordInput({ placeholder, ref }: { placeholder: string; ref: React.RefObject }) { const [show, setShow] = useState(false); @@ -171,4 +199,12 @@ function PasswordInput({ placeholder, ref }: { placeholder: string; ref: React.R ); } +function SettingBox({ children }: { children: React.ReactNode }) { + return ( +
+ {children} +
+ ); +} + export default Settings; diff --git a/src/components/settings/settings.scss b/src/components/settings/settings.scss index a91f808..f1ebbba 100644 --- a/src/components/settings/settings.scss +++ b/src/components/settings/settings.scss @@ -15,6 +15,10 @@ color: var(--description-color); } + button { + margin-top: 1rem; + } + .setting-box { width: 100%; display: flex; @@ -77,10 +81,6 @@ border-radius: 25px 0 0 25px; } - button { - margin-top: 1rem; - } - .input-pass { height: 40; display: flex;