From 654ea94bd0fc4eed53893ed4ce4ee497506180d0 Mon Sep 17 00:00:00 2001 From: headlesdev Date: Sat, 17 May 2025 21:08:08 +0200 Subject: [PATCH] Settings Site --- app/api/user/validate/route.ts | 2 +- app/dashboard/settings/SettingsPage.tsx | 68 +++++++++++++++++++++++-- app/dashboard/settings/page.tsx | 4 +- 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/app/api/user/validate/route.ts b/app/api/user/validate/route.ts index 9573f4e..f985fd3 100644 --- a/app/api/user/validate/route.ts +++ b/app/api/user/validate/route.ts @@ -30,7 +30,7 @@ export async function POST(request: NextRequest) { return NextResponse.json({ error: "User not found" }, { status: 404 }); } - return NextResponse.json({ message: "Valid", username: user.username, name: user.name }, { status: 200 }); + return NextResponse.json({ message: "Valid", username: user.username, name: user.name, email: user.email }, { status: 200 }); } catch (error: any) { return NextResponse.json({ error: "Internal Server Error" }, { status: 500 }); diff --git a/app/dashboard/settings/SettingsPage.tsx b/app/dashboard/settings/SettingsPage.tsx index b16fe65..3f6f862 100644 --- a/app/dashboard/settings/SettingsPage.tsx +++ b/app/dashboard/settings/SettingsPage.tsx @@ -1,13 +1,37 @@ "use client"; import Sidebar from "@/components/Sidebar"; +import { useState } from "react"; +import axios from "axios"; +import Cookies from "js-cookie"; interface DashboardPageProps { username: string; name: string; + email: string; } -export default function DashboardPage({ username, name }: DashboardPageProps) { +export default function DashboardPage({ username, name, email }: DashboardPageProps) { + const [profileUsername, setProfileUsername] = useState(username); + const [profileName, setProfileName] = useState(name); + const [profileEmail, setProfileEmail] = useState(email); + const [password, setPassword] = useState(""); + const [passwordConfirm, setPasswordConfirm] = useState(""); + + const saveProfile = async () => { + const response = await axios.post("/api/user/change/profile", { token: Cookies.get("token"), username: profileUsername, name: profileName, email: profileEmail }); + if (response.data.message !== "Profile updated successfully") { + alert("Failed to update profile"); + } + } + + const savePassword = async () => { + const response = await axios.post("/api/user/change/password", { token: Cookies.get("token"), old_password: password, password: passwordConfirm }); + if (response.data.message !== "Password updated successfully") { + alert("Failed to update password"); + } + } + return (
Manage your instance settings

- -
User Settings
+ +
+
+
+
+

Profile Settings

+

Manage your profile settings

+
+
+ + setProfileUsername(e.target.value)} className="input w-full" /> +
+
+ + setProfileName(e.target.value)} className="input w-full" /> +
+
+ + setProfileEmail(e.target.value)} className="input w-full" /> +
+
+ +
+
+

Password Settings

+

Manage your password

+
+
+ + setPassword(e.target.value)} className="input w-full" /> +
+
+ + setPasswordConfirm(e.target.value)} className="input w-full" /> +
+
+ +
+
+
diff --git a/app/dashboard/settings/page.tsx b/app/dashboard/settings/page.tsx index 446fb7e..794771f 100644 --- a/app/dashboard/settings/page.tsx +++ b/app/dashboard/settings/page.tsx @@ -13,6 +13,7 @@ export default function Dashboard() { const [loading, setLoading] = useState(true); const [username, setUsername] = useState(""); const [name, setName] = useState(""); + const [email, setEmail] = useState(""); useEffect(() => { const init = async () => { @@ -27,6 +28,7 @@ export default function Dashboard() { } else { setUsername(response.data.username); setName(response.data.name); + setEmail(response.data.email); setLoading(false); } }; @@ -36,6 +38,6 @@ export default function Dashboard() { if (loading) { return ; } else { - return ; + return ; } } \ No newline at end of file