summaryrefslogtreecommitdiff
path: root/src/pages
diff options
context:
space:
mode:
authorRafi Zadanly <rafizadanly@gmail.com>2022-12-26 12:01:19 +0700
committerRafi Zadanly <rafizadanly@gmail.com>2022-12-26 12:01:19 +0700
commitf2dad674f9096ca2423cbbdc0228576f094f064c (patch)
treec5cf7d1ba8ca0f03a92222c6db4580275260d07a /src/pages
parentbdb08e1bbc1b4701e23d2c973ea3b8602919b878 (diff)
Fitur Logout
Diffstat (limited to 'src/pages')
-rw-r--r--src/pages/activate.js10
-rw-r--r--src/pages/logout.js14
-rw-r--r--src/pages/my/menu.js2
-rw-r--r--src/pages/my/profile.js55
4 files changed, 70 insertions, 11 deletions
diff --git a/src/pages/activate.js b/src/pages/activate.js
index 6d534909..c738af81 100644
--- a/src/pages/activate.js
+++ b/src/pages/activate.js
@@ -29,12 +29,12 @@ export default function Activate() {
if (activation.data.activation) {
setAuth(activation.data.user);
setAlert({
- component: <>Selamat, akun anda berhasil diaktifkan, <Link className="text-gray-900" href="/register">kembali ke beranda</Link>.</>,
+ component: <>Selamat, akun anda berhasil diaktifkan, <Link className="text-gray_r-12" href="/">kembali ke beranda</Link>.</>,
type: 'success'
});
} else {
setAlert({
- component: <>Mohon maaf token sudah tidak aktif, lakukan permintaan aktivasi akun kembali atau <Link className="text-gray-900" href="/register">masuk</Link> jika sudah memiliki akun.</>,
+ component: <>Mohon maaf token sudah tidak aktif, lakukan permintaan aktivasi akun kembali atau <Link className="text-gray_r-12" href="/login">masuk</Link> jika sudah memiliki akun.</>,
type: 'info'
});
}
@@ -60,13 +60,13 @@ export default function Activate() {
switch (activationRequest.data.reason) {
case 'NOT_FOUND':
setAlert({
- component: <>Email tersebut belum terdaftar, <Link className="text-gray-900" href="/register">daftar sekarang</Link>.</>,
+ component: <>Email tersebut belum terdaftar, <Link className="text-gray_r-12" href="/register">daftar sekarang</Link>.</>,
type: 'info'
});
break;
case 'ACTIVE':
setAlert({
- component: <>Email tersebut sudah terdaftar dan sudah aktif, <Link className="text-gray-900" href="/register">masuk sekarang</Link>.</>,
+ component: <>Email tersebut sudah terdaftar dan sudah aktif, <Link className="text-gray_r-12" href="/login">masuk sekarang</Link>.</>,
type: 'info'
});
break;
@@ -83,7 +83,7 @@ export default function Activate() {
<Link href="/" className="mt-16">
<Image src={Logo} alt="Logo Indoteknik" width={165} height={42} />
</Link>
- <h1 className="text-2xl text-gray-900 mt-4 text-center">Aktivasi Akun Indoteknik Anda</h1>
+ <h1 className="text-2xl text-gray_r-12 mt-4 text-center">Aktivasi Akun Indoteknik Anda</h1>
<h2 className="text-gray-800 mt-2 mb-4 text-center">Link aktivasi akan dikirimkan melalui email</h2>
{alert ? (
<Alert className="text-center" type={alert.type}>{alert.component}</Alert>
diff --git a/src/pages/logout.js b/src/pages/logout.js
new file mode 100644
index 00000000..de749a37
--- /dev/null
+++ b/src/pages/logout.js
@@ -0,0 +1,14 @@
+import { useRouter } from "next/router";
+import { useEffect } from "react";
+import { deleteAuth } from "../helpers/auth";
+
+export default function Logout() {
+ const router = useRouter();
+
+ useEffect(() => {
+ deleteAuth();
+ router.replace('/login');
+ }, [router]);
+
+ return null;
+} \ No newline at end of file
diff --git a/src/pages/my/menu.js b/src/pages/my/menu.js
index d86febf9..84de3892 100644
--- a/src/pages/my/menu.js
+++ b/src/pages/my/menu.js
@@ -35,7 +35,7 @@ const serviceMenus = [
const settingMenus = [
{ icon: (<MapIcon className="w-5" />),name: 'Daftar Alamat', url: '/my/profile' },
- { icon: (<ArrowRightOnRectangleIcon className="w-5" />),name: 'Keluar Akun', url: '/my/profile' },
+ { icon: (<ArrowRightOnRectangleIcon className="w-5" />),name: 'Keluar Akun', url: '/logout' },
];
export default function MyMenu() {
diff --git a/src/pages/my/profile.js b/src/pages/my/profile.js
index ebbd7f2a..f1d0a701 100644
--- a/src/pages/my/profile.js
+++ b/src/pages/my/profile.js
@@ -1,27 +1,32 @@
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
+ setAuth as setAuthCookie,
+ getAuth
} from "../../helpers/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 update = await apiOdoo('PUT', `/api/v1/user/${auth.id}`, {
+ let dataToUpdate = {
name: auth.name,
phone: auth.phone,
mobile: auth.mobile,
token: auth.token
- });
+ };
+ 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 });
};
@@ -29,6 +34,12 @@ export default function MyProfile() {
let authToUpdate = auth;
authToUpdate[e.target.name] = e.target.value;
setAuth({ ...authToUpdate });
+ };
+
+ const cancelEdit = () => {
+ setEditMode(false);
+ setAuth(getAuth());
+ setPassword('');
}
return (
@@ -58,6 +69,7 @@ export default function MyProfile() {
name="name"
value={auth.name}
onChange={handleInput}
+ disabled={!editMode}
/>
<label className="form-label mt-4 mb-2">No Telepon</label>
@@ -68,6 +80,7 @@ export default function MyProfile() {
name="phone"
value={auth.phone}
onChange={handleInput}
+ disabled={!editMode}
/>
<label className="form-label mt-4 mb-2">No Handphone</label>
@@ -78,11 +91,43 @@ export default function MyProfile() {
name="mobile"
value={auth.mobile}
onChange={handleInput}
+ disabled={!editMode}
+ />
+
+ <label className="form-label mt-4 mb-2">Kata Sandi</label>
+ <input
+ type="password"
+ className="form-input bg-gray_r-2"
+ placeholder="••••••••"
+ value={password}
+ onChange={(e) => setPassword(e.target.value)}
+ disabled={!editMode}
/>
</>
) }
- <button type="submit" className="btn-yellow float-right mt-4">Simpan</button>
+ { editMode && (
+ <div className="flex justify-end gap-x-3">
+ <button
+ type="button"
+ className="btn-light float-right mt-4"
+ onClick={cancelEdit}
+ >
+ Batal
+ </button>
+ <button type="submit" className="btn-yellow float-right mt-4">Simpan</button>
+ </div>
+ ) }
+
+ { !editMode && (
+ <button
+ type="button"
+ className="btn-light float-right mt-4"
+ onClick={() => setEditMode(true)}
+ >
+ Ubah Profil
+ </button>
+ ) }
</form>
</Layout>
</WithAuth>