blob: ebbd7f2a41c83c90b5eb63f36db05a7fdc82264d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
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 {
useAuth,
setAuth as setAuthCookie
} from "../../helpers/auth";
export default function MyProfile() {
const [auth, setAuth] = useAuth();
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 (
<WithAuth>
<Layout>
<AppBar title="Akun Saya" />
<form onSubmit={update} className="w-full px-4">
{ auth?.id && (
<>
<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">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}
/>
</>
) }
<button type="submit" className="btn-yellow float-right mt-4">Simpan</button>
</form>
</Layout>
</WithAuth>
);
}
|