diff --git a/hosting/src/app/(protected)/settings/page.tsx b/hosting/src/app/(protected)/settings/page.tsx index 6e98b7aa..d610ad5d 100644 --- a/hosting/src/app/(protected)/settings/page.tsx +++ b/hosting/src/app/(protected)/settings/page.tsx @@ -1,13 +1,22 @@ +"use client"; import PageHeader from "@/components/common/PageHeader"; -import {Metadata} from "next"; +import {useAuthentication} from "@/hooks/useAuthentication"; +import {useTanamUser} from "@/hooks/useTanamUser"; import Image from "next/image"; -export const metadata: Metadata = { - title: "Next.js Settings | TailAdmin - Next.js Dashboard Template", - description: "This is Next.js Settings page for TailAdmin - Next.js Tailwind CSS Admin Dashboard Template", -}; +export default function Settings() { + const {authUser} = useAuthentication(); + const {tanamUser, saveUserInfo} = useTanamUser(authUser?.uid); + + async function onPersonalInfoSubmit(event: React.FormEvent) { + event.preventDefault(); + const form = event.currentTarget; + const formData = { + fullName: form.fullName.value, + }; + await saveUserInfo(formData.fullName); + } -const Settings = () => { return ( <>
@@ -20,9 +29,9 @@ const Settings = () => {

Personal Information

-
+
-
+
@@ -33,82 +42,13 @@ const Settings = () => { type="text" name="fullName" id="fullName" - placeholder="Devid Jhon" - defaultValue="Devid Jhon" - /> -
-
- -
- -
- -
-
- -
- - - -
-
- -
- - -
- -
- -
- - -
-
-
); -}; - -export default Settings; +} diff --git a/hosting/src/hooks/useTanamUser.tsx b/hosting/src/hooks/useTanamUser.tsx index d7a0abaa..e2d64395 100644 --- a/hosting/src/hooks/useTanamUser.tsx +++ b/hosting/src/hooks/useTanamUser.tsx @@ -55,7 +55,21 @@ export function useTanamUser(uid?: string) { } } - return {tanamUser, saveColorMode, error}; + async function saveUserInfo(name: string) { + if (!uid) { + return; + } + + try { + const docRef = doc(firestore, `tanam-users`, uid); + return updateDoc(docRef, {name}); + } catch (error) { + const typedError = error as Error; + setError(new UserNotification("error", "Failed to update user info.", typedError.message)); + } + } + + return {tanamUser, saveColorMode, saveUserInfo, error}; } interface UseProfileImageResult {