From f99e0aba70efad0deb907d8e27f09fc9f527c8a4 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 17 Feb 2023 17:07:50 +0700 Subject: Refactor --- src/pages/my/profile.js | 134 ------------------------------------------------ 1 file changed, 134 deletions(-) delete mode 100644 src/pages/my/profile.js (limited to 'src/pages/my/profile.js') diff --git a/src/pages/my/profile.js b/src/pages/my/profile.js deleted file mode 100644 index 97891259..00000000 --- a/src/pages/my/profile.js +++ /dev/null @@ -1,134 +0,0 @@ -import { useState } from "react"; -import { toast } from "react-hot-toast"; -import AppBar from "@/components/layouts/AppBar"; -import Layout from "@/components/layouts/Layout"; -import WithAuth from "@/components/auth/WithAuth"; -import apiOdoo from "@/core/utils/apiOdoo"; -import { - useAuth, - setAuth as setAuthCookie, - getAuth -} from "@/core/utils/auth"; - -export default function MyProfile() { - const [auth, setAuth] = useAuth(); - const [editMode, setEditMode] = useState(false); - const [password, setPassword] = useState(''); - - const update = async (e) => { - e.preventDefault(); - let dataToUpdate = { - name: auth.name, - phone: auth.phone, - mobile: auth.mobile - }; - if (password) dataToUpdate.password = password; - let update = await apiOdoo('PUT', `/api/v1/user/${auth.id}`, dataToUpdate); - setAuthCookie(update.user); - cancelEdit(); - toast.success('Berhasil mengubah profil', { duration: 1500 }); - }; - - const handleInput = (e) => { - let authToUpdate = auth; - authToUpdate[e.target.name] = e.target.value; - setAuth({ ...authToUpdate }); - }; - - const cancelEdit = () => { - setEditMode(false); - setAuth(getAuth()); - setPassword(''); - } - - return ( - - - - -
- { auth && ( - <> - - - - - - - - - - - - - - setPassword(e.target.value)} - disabled={!editMode} - /> - - ) } - - { editMode && ( -
- - -
- ) } - - { !editMode && ( - - ) } -
-
-
- ); -} \ No newline at end of file -- cgit v1.2.3