From 4e5257d73f18fd76c66cc61f1f09034d12bc02b8 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 21 Dec 2022 17:11:01 +0700 Subject: menu profil saya --- src/pages/my/profile.js | 95 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/pages/my/profile.js (limited to 'src/pages/my') diff --git a/src/pages/my/profile.js b/src/pages/my/profile.js new file mode 100644 index 00000000..a0aeb938 --- /dev/null +++ b/src/pages/my/profile.js @@ -0,0 +1,95 @@ +import { useEffect, useState } from "react"; +import { toast } from "react-hot-toast"; +import Header from "../../components/Header"; +import Layout from "../../components/Layout"; +import apiOdoo from "../../helpers/apiOdoo"; +import { + getAuth, + setAuth as setAuthCookie +} from "../../helpers/auth"; + +export default function MyProfile() { + const [auth, setAuth] = useState({ + name: '', + email: '', + phone: '', + mobile: '' + }); + + useEffect(() => { + setAuth(getAuth()); + }, []); + + const update = async (e) => { + e.preventDefault(); + let update = await apiOdoo('PUT', `/api/v1/user/${auth.id}`, { + name: auth.name, + phone: auth.phone, + mobile: auth.mobile, + token: auth.token + }); + setAuthCookie(update.user); + toast.success('Berhasil mengubah profil', { duration: 1500 }); + }; + + const handleInput = (e) => { + let authToUpdate = auth; + authToUpdate[e.target.name] = e.target.value; + setAuth({ ...authToUpdate }); + } + + return ( + <> +
+ +
+

Profil Saya

+ + + + + + + + + + + + + + + +
+
+ + ); +} \ No newline at end of file -- cgit v1.2.3