From e33a330786ffbfcd774de00dc697c6dff47faf27 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 20 Feb 2023 14:20:44 +0700 Subject: fix --- src/lib/auth/api/loginApi.js | 12 +++++ src/lib/auth/components/Login.jsx | 99 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 src/lib/auth/api/loginApi.js create mode 100644 src/lib/auth/components/Login.jsx (limited to 'src/lib/auth') diff --git a/src/lib/auth/api/loginApi.js b/src/lib/auth/api/loginApi.js new file mode 100644 index 00000000..4782680c --- /dev/null +++ b/src/lib/auth/api/loginApi.js @@ -0,0 +1,12 @@ +import odooApi from "@/core/api/odooApi" + +const loginApi = async ({email, password}) => { + let result = await odooApi( + 'POST', + '/api/v1/user/login', + {email, password} + ) + return result +} + +export default loginApi \ No newline at end of file diff --git a/src/lib/auth/components/Login.jsx b/src/lib/auth/components/Login.jsx new file mode 100644 index 00000000..e598fe48 --- /dev/null +++ b/src/lib/auth/components/Login.jsx @@ -0,0 +1,99 @@ +import Image from "next/image" +import IndoteknikLogo from "@/images/logo.png" +import Link from "@/core/components/elements/Link/Link" +import { useState } from "react" +import loginApi from "../api/loginApi" +import { useRouter } from "next/router" +import Alert from "@/core/components/elements/Alert/Alert" +import { setAuth } from "@/core/utils/auth" + +const Login = () => { + const router = useRouter() + const [ email, setEmail ] = useState('') + const [ password, setPassword ] = useState('') + const [ isLoading, setIsLoading ] = useState(false) + const [ alert, setAlert ] = useState(null) + + const handleSubmit = async (e) => { + e.preventDefault() + setIsLoading(true) + const login = await loginApi({ email, password }) + setIsLoading(false) + + if (login.isAuth) { + setAuth(login.user) + router.push('/') + return + } + switch (login.reason) { + case 'NOT_FOUND': + setAlert({ + children: 'Email atau password tidak cocok', + type: 'info' + }) + break + case 'NOT_ACTIVE': + setAlert({ + children: ( + <> + Email belum diaktivasi, + aktivasi sekarang + + ), + type: 'info' + }) + break + } + } + + return ( +
+ + Logo Indoteknik + +

Mulai Belanja Sekarang

+

Masuk ke akun kamu untuk belanja

+ + { alert && ( + + { alert.children } + + ) } + +
+
+ + setEmail(e.target.value)} + placeholder="contoh@email.com" + /> +
+
+ + setPassword(e.target.value)} + placeholder="••••••••••••" + /> +
+ +
+

Belum punya akun Indoteknik? Daftar

+
+ ) +} + +export default Login \ No newline at end of file -- cgit v1.2.3 From 4fd738fd54f81fa53c2b3e78b7a80fbfda250352 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 21 Feb 2023 10:19:32 +0700 Subject: fix --- src/lib/auth/components/Login.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib/auth') diff --git a/src/lib/auth/components/Login.jsx b/src/lib/auth/components/Login.jsx index e598fe48..acb6e8c3 100644 --- a/src/lib/auth/components/Login.jsx +++ b/src/lib/auth/components/Login.jsx @@ -64,7 +64,7 @@ const Login = () => {
Date: Wed, 22 Feb 2023 11:03:34 +0700 Subject: prettier --- src/lib/auth/api/loginApi.js | 12 ++--- src/lib/auth/components/Login.jsx | 93 +++++++++++++++++++++------------------ 2 files changed, 54 insertions(+), 51 deletions(-) (limited to 'src/lib/auth') diff --git a/src/lib/auth/api/loginApi.js b/src/lib/auth/api/loginApi.js index 4782680c..e393309c 100644 --- a/src/lib/auth/api/loginApi.js +++ b/src/lib/auth/api/loginApi.js @@ -1,12 +1,8 @@ -import odooApi from "@/core/api/odooApi" +import odooApi from '@/core/api/odooApi' -const loginApi = async ({email, password}) => { - let result = await odooApi( - 'POST', - '/api/v1/user/login', - {email, password} - ) +const loginApi = async ({ email, password }) => { + let result = await odooApi('POST', '/api/v1/user/login', { email, password }) return result } -export default loginApi \ No newline at end of file +export default loginApi diff --git a/src/lib/auth/components/Login.jsx b/src/lib/auth/components/Login.jsx index acb6e8c3..971188a2 100644 --- a/src/lib/auth/components/Login.jsx +++ b/src/lib/auth/components/Login.jsx @@ -1,18 +1,18 @@ -import Image from "next/image" -import IndoteknikLogo from "@/images/logo.png" -import Link from "@/core/components/elements/Link/Link" -import { useState } from "react" -import loginApi from "../api/loginApi" -import { useRouter } from "next/router" -import Alert from "@/core/components/elements/Alert/Alert" -import { setAuth } from "@/core/utils/auth" +import Image from 'next/image' +import IndoteknikLogo from '@/images/logo.png' +import Link from '@/core/components/elements/Link/Link' +import { useState } from 'react' +import loginApi from '../api/loginApi' +import { useRouter } from 'next/router' +import Alert from '@/core/components/elements/Alert/Alert' +import { setAuth } from '@/core/utils/auth' const Login = () => { const router = useRouter() - const [ email, setEmail ] = useState('') - const [ password, setPassword ] = useState('') - const [ isLoading, setIsLoading ] = useState(false) - const [ alert, setAlert ] = useState(null) + const [email, setEmail] = useState('') + const [password, setPassword] = useState('') + const [isLoading, setIsLoading] = useState(false) + const [alert, setAlert] = useState(null) const handleSubmit = async (e) => { e.preventDefault() @@ -36,8 +36,10 @@ const Login = () => { setAlert({ children: ( <> - Email belum diaktivasi, - aktivasi sekarang + Email belum diaktivasi, + + aktivasi sekarang + ), type: 'info' @@ -47,53 +49,58 @@ const Login = () => { } return ( -
- - Logo Indoteknik +
+ + Logo Indoteknik -

Mulai Belanja Sekarang

-

Masuk ke akun kamu untuk belanja

- - { alert && ( - - { alert.children } +

Mulai Belanja Sekarang

+

Masuk ke akun kamu untuk belanja

+ + {alert && ( + + {alert.children} - ) } + )} -
+
- - Alamat Email + setEmail(e.target.value)} - placeholder="contoh@email.com" + placeholder='contoh@email.com' />
- - Kata Sandi + setPassword(e.target.value)} - placeholder="••••••••••••" + placeholder='••••••••••••' />
-
-

Belum punya akun Indoteknik? Daftar

+

+ Belum punya akun Indoteknik?{' '} + + Daftar + +

) } -export default Login \ No newline at end of file +export default Login -- cgit v1.2.3 From ebda24f072741d11da7dd5e406eb5bce069dbf6a Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 22 Feb 2023 15:45:05 +0700 Subject: fix --- src/lib/auth/components/Login.jsx | 5 +- src/lib/auth/components/Register.jsx | 95 ++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 src/lib/auth/components/Register.jsx (limited to 'src/lib/auth') diff --git a/src/lib/auth/components/Login.jsx b/src/lib/auth/components/Login.jsx index 971188a2..92d38c11 100644 --- a/src/lib/auth/components/Login.jsx +++ b/src/lib/auth/components/Login.jsx @@ -93,12 +93,13 @@ const Login = () => { {!isLoading ? 'Masuk' : 'Loading...'} -

+ +

Belum punya akun Indoteknik?{' '} Daftar -

+
) } diff --git a/src/lib/auth/components/Register.jsx b/src/lib/auth/components/Register.jsx new file mode 100644 index 00000000..4b8a8053 --- /dev/null +++ b/src/lib/auth/components/Register.jsx @@ -0,0 +1,95 @@ +import Image from 'next/image' +import Link from '@/core/components/elements/Link/Link' +import IndoteknikLogo from '@/images/logo.png' +import { useState } from 'react' + +const Register = () => { + const [fullname, setFullname] = useState('') + const [email, setEmail] = useState('') + const [password, setPassword] = useState('') + const [companyName, setCompanyName] = useState('') + const [isLoading, setIsLoading] = useState('') + + const handleSubmit = (e) => { + e.preventDefault() + } + + return ( +
+ + Logo Indoteknik + + +

Daftar Akun Indoteknik

+

+ Buat akun sekarang lebih mudah dan terverifikasi +

+ +
+
+ + setCompanyName(e.target.value.toUpperCase())} + placeholder='cth: INDOTEKNIK DOTCOM GEMILANG' + autoCapitalize + /> +
+ +
+ + setFullname(e.target.value)} + placeholder='John Doe' + /> +
+
+ + setEmail(e.target.value)} + placeholder='contoh@email.com' + /> +
+
+ + setPassword(e.target.value)} + placeholder='••••••••••••' + /> +
+ + +
+ +
+ Sudah punya akun Indoteknik?{' '} + + Masuk + +
+
+ ) +} + +export default Register -- cgit v1.2.3 From 4360ec478bee28c1edae5e614065c31cb9da64c1 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 22 Feb 2023 15:46:23 +0700 Subject: fix --- src/lib/auth/components/Register.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib/auth') diff --git a/src/lib/auth/components/Register.jsx b/src/lib/auth/components/Register.jsx index 4b8a8053..1f7a55d5 100644 --- a/src/lib/auth/components/Register.jsx +++ b/src/lib/auth/components/Register.jsx @@ -35,7 +35,7 @@ const Register = () => { value={companyName} onChange={(e) => setCompanyName(e.target.value.toUpperCase())} placeholder='cth: INDOTEKNIK DOTCOM GEMILANG' - autoCapitalize + autoCapitalize='true' />
-- cgit v1.2.3 From 71a4dd291e9fc1d1bb72b57a22f21d1c03b92d8f Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 22 Feb 2023 15:48:38 +0700 Subject: fix --- src/lib/auth/components/Login.jsx | 4 ++-- src/lib/auth/components/Register.jsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/lib/auth') diff --git a/src/lib/auth/components/Login.jsx b/src/lib/auth/components/Login.jsx index 92d38c11..01b2a571 100644 --- a/src/lib/auth/components/Login.jsx +++ b/src/lib/auth/components/Login.jsx @@ -87,13 +87,13 @@ const Login = () => { - +
Belum punya akun Indoteknik?{' '} diff --git a/src/lib/auth/components/Register.jsx b/src/lib/auth/components/Register.jsx index 1f7a55d5..e3e3c4fa 100644 --- a/src/lib/auth/components/Register.jsx +++ b/src/lib/auth/components/Register.jsx @@ -75,7 +75,7 @@ const Register = () => { -- cgit v1.2.3 From 321e0c09be4b26d72b470407217262d10c88089d Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 22 Feb 2023 22:57:48 +0700 Subject: fix --- src/lib/auth/api/editPersonalProfileApi.js | 10 +++ src/lib/auth/components/CompanyProfile.jsx | 97 +++++++++++++++++++++++ src/lib/auth/components/PersonalProfile.jsx | 115 ++++++++++++++++++++++++++++ 3 files changed, 222 insertions(+) create mode 100644 src/lib/auth/api/editPersonalProfileApi.js create mode 100644 src/lib/auth/components/CompanyProfile.jsx create mode 100644 src/lib/auth/components/PersonalProfile.jsx (limited to 'src/lib/auth') diff --git a/src/lib/auth/api/editPersonalProfileApi.js b/src/lib/auth/api/editPersonalProfileApi.js new file mode 100644 index 00000000..af2ad4b2 --- /dev/null +++ b/src/lib/auth/api/editPersonalProfileApi.js @@ -0,0 +1,10 @@ +import odooApi from "@/core/api/odooApi" +import { getAuth } from "@/core/utils/auth" + +const editPersonalProfileApi = async ({ data }) => { + const auth = getAuth() + const dataProfile = await odooApi('PUT', `/api/v1/user/${auth.id}`, data) + return dataProfile +} + +export default editPersonalProfileApi \ No newline at end of file diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx new file mode 100644 index 00000000..d66a0209 --- /dev/null +++ b/src/lib/auth/components/CompanyProfile.jsx @@ -0,0 +1,97 @@ +import useAuth from '@/core/hooks/useAuth' +import addressApi from '@/lib/address/api/addressApi' +import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline' +import { useEffect, useState } from 'react' +import { useForm } from 'react-hook-form' + +const PersonalProfile = () => { + const auth = useAuth() + const [isOpen, setIsOpen] = useState(false) + const toggle = () => setIsOpen(!isOpen) + const { register, setValue } = useForm({ + defaultValues: { + email: '', + name: '', + mobile: '', + password: '' + } + }) + + useEffect(() => { + const loadProfile = async () => { + const dataProfile = await addressApi({ id: auth.partnerId }) + setValue('email', dataProfile?.email) + setValue('name', dataProfile?.name) + setValue('mobile', dataProfile?.mobile) + } + if (auth) loadProfile() + }, [auth, setValue]) + + return ( + <> + + + {isOpen && ( + +
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + + )} + + ) +} + +export default PersonalProfile diff --git a/src/lib/auth/components/PersonalProfile.jsx b/src/lib/auth/components/PersonalProfile.jsx new file mode 100644 index 00000000..29628be9 --- /dev/null +++ b/src/lib/auth/components/PersonalProfile.jsx @@ -0,0 +1,115 @@ +import useAuth from '@/core/hooks/useAuth' +import { setAuth } from '@/core/utils/auth' +import addressApi from '@/lib/address/api/addressApi' +import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline' +import { useEffect, useState } from 'react' +import { useForm } from 'react-hook-form' +import { toast } from 'react-hot-toast' +import editPersonalProfileApi from '../api/editPersonalProfileApi' + +const PersonalProfile = () => { + const auth = useAuth() + const [isOpen, setIsOpen] = useState(false) + const toggle = () => setIsOpen(!isOpen) + const { register, setValue, handleSubmit } = useForm({ + defaultValues: { + email: '', + name: '', + mobile: '', + password: '' + } + }) + + useEffect(() => { + const loadProfile = async () => { + const dataProfile = await addressApi({ id: auth.partnerId }) + setValue('email', dataProfile?.email) + setValue('name', dataProfile?.name) + setValue('mobile', dataProfile?.mobile) + } + if (auth) loadProfile() + }, [auth, setValue]) + + const onSubmitHandler = async (values) => { + let data = values + if (!values.password) delete data.password + const isUpdated = await editPersonalProfileApi({ data }) + console.log(isUpdated) + if (isUpdated?.user) { + setAuth(isUpdated.user) + setValue('password', '') + setIsOpen(false) + toast.success('Berhasil mengubah profil', { duration: 1500 }) + return + } + toast.error('Terjadi kesalahan internal') + } + + return ( + <> + + + {isOpen && ( +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ )} + + ) +} + +export default PersonalProfile -- cgit v1.2.3 From 89d99c0386750af7a29678344fe0ed8fb6435d4f Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 22 Feb 2023 22:58:00 +0700 Subject: fix --- src/lib/auth/components/PersonalProfile.jsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/lib/auth') diff --git a/src/lib/auth/components/PersonalProfile.jsx b/src/lib/auth/components/PersonalProfile.jsx index 29628be9..46253ef1 100644 --- a/src/lib/auth/components/PersonalProfile.jsx +++ b/src/lib/auth/components/PersonalProfile.jsx @@ -65,7 +65,10 @@ const PersonalProfile = () => { {isOpen && ( -
+
Date: Wed, 22 Feb 2023 23:05:10 +0700 Subject: fix --- src/lib/auth/components/PersonalProfile.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib/auth') diff --git a/src/lib/auth/components/PersonalProfile.jsx b/src/lib/auth/components/PersonalProfile.jsx index 46253ef1..0b387f2e 100644 --- a/src/lib/auth/components/PersonalProfile.jsx +++ b/src/lib/auth/components/PersonalProfile.jsx @@ -90,7 +90,7 @@ const PersonalProfile = () => {
-- cgit v1.2.3 From ac3fdf7be9982e65d8f83a20bc487f8dd62e3bfc Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 22 Feb 2023 23:36:47 +0700 Subject: fix --- src/lib/auth/api/editPersonalProfileApi.js | 6 +++--- src/lib/auth/components/Login.jsx | 27 ++++++++++++++++++++++----- src/lib/auth/components/Register.jsx | 17 ++++++++++++++--- 3 files changed, 39 insertions(+), 11 deletions(-) (limited to 'src/lib/auth') diff --git a/src/lib/auth/api/editPersonalProfileApi.js b/src/lib/auth/api/editPersonalProfileApi.js index af2ad4b2..39cd44c1 100644 --- a/src/lib/auth/api/editPersonalProfileApi.js +++ b/src/lib/auth/api/editPersonalProfileApi.js @@ -1,5 +1,5 @@ -import odooApi from "@/core/api/odooApi" -import { getAuth } from "@/core/utils/auth" +import odooApi from '@/core/api/odooApi' +import { getAuth } from '@/core/utils/auth' const editPersonalProfileApi = async ({ data }) => { const auth = getAuth() @@ -7,4 +7,4 @@ const editPersonalProfileApi = async ({ data }) => { return dataProfile } -export default editPersonalProfileApi \ No newline at end of file +export default editPersonalProfileApi diff --git a/src/lib/auth/components/Login.jsx b/src/lib/auth/components/Login.jsx index 01b2a571..b4e94e0a 100644 --- a/src/lib/auth/components/Login.jsx +++ b/src/lib/auth/components/Login.jsx @@ -37,7 +37,10 @@ const Login = () => { children: ( <> Email belum diaktivasi, - + aktivasi sekarang @@ -51,18 +54,29 @@ const Login = () => { return (
- Logo Indoteknik + Logo Indoteknik

Mulai Belanja Sekarang

Masuk ke akun kamu untuk belanja

{alert && ( - + {alert.children} )} - +
{
Belum punya akun Indoteknik?{' '} - + Daftar
diff --git a/src/lib/auth/components/Register.jsx b/src/lib/auth/components/Register.jsx index df08541d..135972d3 100644 --- a/src/lib/auth/components/Register.jsx +++ b/src/lib/auth/components/Register.jsx @@ -26,7 +26,12 @@ const Register = () => { return (
- Logo Indoteknik + Logo Indoteknik

Daftar Akun Indoteknik

@@ -34,7 +39,10 @@ const Register = () => { Buat akun sekarang lebih mudah dan terverifikasi - +