diff options
| author | Rafi Zadanly <rafizadanly@gmail.com> | 2022-12-22 15:29:18 +0700 |
|---|---|---|
| committer | Rafi Zadanly <rafizadanly@gmail.com> | 2022-12-22 15:29:18 +0700 |
| commit | 31d6352ab8855754ef18c01763d3c1b5a68de857 (patch) | |
| tree | e9b7e67a994574b5b1ccc7c8ef805a899f561d3d /src/pages/my/profile.js | |
| parent | 7ca4c68e3c509004a84d05ebd6d66019c7e92b72 (diff) | |
Appbar component and auth hook (useAuth)
Diffstat (limited to 'src/pages/my/profile.js')
| -rw-r--r-- | src/pages/my/profile.js | 104 |
1 files changed, 49 insertions, 55 deletions
diff --git a/src/pages/my/profile.js b/src/pages/my/profile.js index a0aeb938..44ccfebd 100644 --- a/src/pages/my/profile.js +++ b/src/pages/my/profile.js @@ -1,24 +1,17 @@ import { useEffect, useState } from "react"; import { toast } from "react-hot-toast"; +import AppBar from "../../components/AppBar"; import Header from "../../components/Header"; import Layout from "../../components/Layout"; +import WithAuth from "../../components/WithAuth"; import apiOdoo from "../../helpers/apiOdoo"; import { - getAuth, + useAuth, setAuth as setAuthCookie } from "../../helpers/auth"; export default function MyProfile() { - const [auth, setAuth] = useState({ - name: '', - email: '', - phone: '', - mobile: '' - }); - - useEffect(() => { - setAuth(getAuth()); - }, []); + const [auth, setAuth] = useAuth(); const update = async (e) => { e.preventDefault(); @@ -39,57 +32,58 @@ export default function MyProfile() { } return ( - <> - <Header title="Profil Saya - Indoteknik" /> + <WithAuth> <Layout> - <form onSubmit={update} className="w-full p-4"> - <h1 className="mb-6">Profil Saya</h1> - - <label className="form-label mt-4 mb-2">Email</label> - <input - type="text" - className="form-input bg-gray_r-2" - placeholder="johndoe@gmail.com" - name="email" - value={auth.email} - onChange={handleInput} - disabled={true} - /> + <AppBar title="Akun Saya" /> + <form onSubmit={update} className="w-full px-4"> + { auth && ( + <> + <label className="form-label mt-4 mb-2">Email</label> + <input + type="text" + className="form-input bg-gray_r-2" + placeholder="johndoe@gmail.com" + name="email" + value={auth.email} + onChange={handleInput} + disabled={true} + /> - <label className="form-label mt-4 mb-2">Nama Lengkap</label> - <input - type="text" - className="form-input bg-gray_r-2" - placeholder="John Doe" - name="name" - value={auth.name} - onChange={handleInput} - /> + <label className="form-label mt-4 mb-2">Nama Lengkap</label> + <input + type="text" + className="form-input bg-gray_r-2" + placeholder="John Doe" + name="name" + value={auth.name} + onChange={handleInput} + /> - <label className="form-label mt-4 mb-2">No Telepon</label> - <input - type="tel" - className="form-input bg-gray_r-2" - placeholder="08xxxxxxxx" - name="phone" - value={auth.phone} - onChange={handleInput} - /> + <label className="form-label mt-4 mb-2">No Telepon</label> + <input + type="tel" + className="form-input bg-gray_r-2" + placeholder="08xxxxxxxx" + name="phone" + value={auth.phone} + onChange={handleInput} + /> - <label className="form-label mt-4 mb-2">No Handphone</label> - <input - type="tel" - className="form-input bg-gray_r-2" - placeholder="08xxxxxxxx" - name="mobile" - value={auth.mobile} - onChange={handleInput} - /> + <label className="form-label mt-4 mb-2">No Handphone</label> + <input + type="tel" + className="form-input bg-gray_r-2" + placeholder="08xxxxxxxx" + name="mobile" + value={auth.mobile} + onChange={handleInput} + /> + </> + ) } <button type="submit" className="btn-yellow float-right mt-4">Simpan</button> - </form> </Layout> - </> + </WithAuth> ); }
\ No newline at end of file |
