From 90710579ba1c12060877f6ec2d26103f9c31058d Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 23 Oct 2023 17:11:33 +0700 Subject: Refactor and migrate register page --- .../modules/header/components/HeaderDesktop.tsx | 82 +++++++++++++++ .../modules/header/components/HeaderMobile.tsx | 7 ++ .../modules/header/components/SearchBar.tsx | 24 +++++ src-migrate/modules/header/index.tsx | 13 +++ src-migrate/modules/home/components/Home.tsx | 15 +++ .../modules/home/components/VerticalBanner.tsx | 7 ++ src-migrate/modules/home/index.tsx | 3 + src-migrate/modules/page-content/index.tsx | 22 ++++ src-migrate/modules/register/components/Form.tsx | 117 +++++++++++++++++++++ .../modules/register/components/Register.tsx | 39 +++++++ .../modules/register/components/TermCondition.tsx | 16 +++ src-migrate/modules/register/index.tsx | 3 + 12 files changed, 348 insertions(+) create mode 100644 src-migrate/modules/header/components/HeaderDesktop.tsx create mode 100644 src-migrate/modules/header/components/HeaderMobile.tsx create mode 100644 src-migrate/modules/header/components/SearchBar.tsx create mode 100644 src-migrate/modules/header/index.tsx create mode 100644 src-migrate/modules/home/components/Home.tsx create mode 100644 src-migrate/modules/home/components/VerticalBanner.tsx create mode 100644 src-migrate/modules/home/index.tsx create mode 100644 src-migrate/modules/page-content/index.tsx create mode 100644 src-migrate/modules/register/components/Form.tsx create mode 100644 src-migrate/modules/register/components/Register.tsx create mode 100644 src-migrate/modules/register/components/TermCondition.tsx create mode 100644 src-migrate/modules/register/index.tsx (limited to 'src-migrate/modules') diff --git a/src-migrate/modules/header/components/HeaderDesktop.tsx b/src-migrate/modules/header/components/HeaderDesktop.tsx new file mode 100644 index 00000000..3860bded --- /dev/null +++ b/src-migrate/modules/header/components/HeaderDesktop.tsx @@ -0,0 +1,82 @@ +import Logo from "~/images/logo.png"; +import { DocumentCheckIcon, HeartIcon } from "@heroicons/react/24/outline"; + +import Image from 'next/image' +import Link from 'next/link' + +// Components +import SearchBar from "./SearchBar"; + +// Constants +import { SECONDARY_MENU_ITEMS } from "~/common/constants/menu"; + +const LOGO_WIDTH = 210; +const LOGO_HEIGHT = LOGO_WIDTH / 3; + +const HeaderDesktop = () => { + return ( +
+ +
+ ) +} + +export default HeaderDesktop \ No newline at end of file diff --git a/src-migrate/modules/header/components/HeaderMobile.tsx b/src-migrate/modules/header/components/HeaderMobile.tsx new file mode 100644 index 00000000..626f30d7 --- /dev/null +++ b/src-migrate/modules/header/components/HeaderMobile.tsx @@ -0,0 +1,7 @@ +const HeaderMobile = () => { + return ( +
HeaderMobile
+ ) +} + +export default HeaderMobile \ No newline at end of file diff --git a/src-migrate/modules/header/components/SearchBar.tsx b/src-migrate/modules/header/components/SearchBar.tsx new file mode 100644 index 00000000..ec17abe8 --- /dev/null +++ b/src-migrate/modules/header/components/SearchBar.tsx @@ -0,0 +1,24 @@ + +import { MagnifyingGlassIcon } from '@heroicons/react/24/outline' + +const SearchBar = () => { + return ( +
+ + + + +
+ ) +} + +export default SearchBar \ No newline at end of file diff --git a/src-migrate/modules/header/index.tsx b/src-migrate/modules/header/index.tsx new file mode 100644 index 00000000..5c0e2933 --- /dev/null +++ b/src-migrate/modules/header/index.tsx @@ -0,0 +1,13 @@ +import React from 'react' +import { useWindowSize } from "usehooks-ts" + +import HeaderDesktop from './components/HeaderDesktop' +import HeaderMobile from './components/HeaderMobile' + +const Header = () => { + const { width } = useWindowSize() + + return width > 768 ? : +} + +export default Header \ No newline at end of file diff --git a/src-migrate/modules/home/components/Home.tsx b/src-migrate/modules/home/components/Home.tsx new file mode 100644 index 00000000..5d3bf104 --- /dev/null +++ b/src-migrate/modules/home/components/Home.tsx @@ -0,0 +1,15 @@ +import VerticalBanner from "./VerticalBanner" + +const Home = () => { + return ( + <> +
+
+ +
+
+ + ) +} + +export default Home \ No newline at end of file diff --git a/src-migrate/modules/home/components/VerticalBanner.tsx b/src-migrate/modules/home/components/VerticalBanner.tsx new file mode 100644 index 00000000..57328037 --- /dev/null +++ b/src-migrate/modules/home/components/VerticalBanner.tsx @@ -0,0 +1,7 @@ +const VerticalBanner = () => { + return ( +
VerticalBanner
+ ) +} + +export default VerticalBanner \ No newline at end of file diff --git a/src-migrate/modules/home/index.tsx b/src-migrate/modules/home/index.tsx new file mode 100644 index 00000000..6993d9cf --- /dev/null +++ b/src-migrate/modules/home/index.tsx @@ -0,0 +1,3 @@ +import Home from "./components/Home"; + +export default Home \ No newline at end of file diff --git a/src-migrate/modules/page-content/index.tsx b/src-migrate/modules/page-content/index.tsx new file mode 100644 index 00000000..cbd58633 --- /dev/null +++ b/src-migrate/modules/page-content/index.tsx @@ -0,0 +1,22 @@ +import { useQuery } from "react-query" +import PageContentSkeleton from "~/common/components/skeleton/PageContentSkeleton" +import { PageContentProps } from "~/common/types/pageContent" +import { getPageContent } from "~/services/pageContent" + +type Props = { + path: string +} + +const PageContent = ({ path }: Props) => { + const { data, isLoading } = useQuery(`page-content:${path}`, async () => await getPageContent({ path })) + + if (isLoading) { + return + } + + return ( +
+ ) +} + +export default PageContent \ No newline at end of file diff --git a/src-migrate/modules/register/components/Form.tsx b/src-migrate/modules/register/components/Form.tsx new file mode 100644 index 00000000..ac194b46 --- /dev/null +++ b/src-migrate/modules/register/components/Form.tsx @@ -0,0 +1,117 @@ +import { ChangeEvent } from "react"; +import { useMutation } from "react-query"; +import { useRegisterStore } from "~/common/stores/useRegisterStore"; +import { RegisterProps } from "~/common/types/auth"; +import { registerUser } from "~/services/auth"; + +const Form = () => { + const { form, isValid, isCheckedTNC, updateForm, toggleCheckTNC, openTNC } = useRegisterStore() + + const handleInputChange = (event: ChangeEvent) => { + const { name, value } = event.target; + updateForm(name, value) + } + + const mutation = useMutation({ + mutationFn: (data: RegisterProps) => registerUser(data) + }) + + const handleSubmit = async (e: ChangeEvent) => { + e.preventDefault() + + const response = await mutation.mutateAsync(form) + console.log(response); + + } + + return ( +
+
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + +
+ +
+ + + {' '} + + syarat dan ketentuan + + +
+ + +
+ ) +} + +export default Form \ No newline at end of file diff --git a/src-migrate/modules/register/components/Register.tsx b/src-migrate/modules/register/components/Register.tsx new file mode 100644 index 00000000..e3e29b9f --- /dev/null +++ b/src-migrate/modules/register/components/Register.tsx @@ -0,0 +1,39 @@ +import PageContent from "~/modules/page-content" +import Form from "./Form" +import Link from "next/link" +import Modal from "~/common/components/elements/Modal" +import TermCondition from "./TermCondition" + +const Register = () => { + return ( +
+
+
+

+ Daftar Akun Indoteknik +

+

+ Buat akun sekarang lebih mudah dan terverifikasi +

+ +
+ +
+ Sudah punya akun Indoteknik?{' '} + + Masuk + +
+
+ +
+ +
+
+ + +
+ ) +} + +export default Register \ No newline at end of file diff --git a/src-migrate/modules/register/components/TermCondition.tsx b/src-migrate/modules/register/components/TermCondition.tsx new file mode 100644 index 00000000..304ffd69 --- /dev/null +++ b/src-migrate/modules/register/components/TermCondition.tsx @@ -0,0 +1,16 @@ +import React from 'react' +import Modal from '~/common/components/elements/Modal' +import { useRegisterStore } from '~/common/stores/useRegisterStore' +import PageContent from '~/modules/page-content' + +const TermCondition = () => { + const { isOpenTNC, closeTNC } = useRegisterStore() + + return ( + + + + ) +} + +export default TermCondition \ No newline at end of file diff --git a/src-migrate/modules/register/index.tsx b/src-migrate/modules/register/index.tsx new file mode 100644 index 00000000..ba5efa3a --- /dev/null +++ b/src-migrate/modules/register/index.tsx @@ -0,0 +1,3 @@ +import Register from "./components/Register"; + +export default Register \ No newline at end of file -- cgit v1.2.3 From cf6da809621b4ebe8c9acedb035b689e7e1b60b1 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 25 Oct 2023 17:27:32 +0700 Subject: Update register page --- .../account-activation/components/FormEmail.tsx | 7 ++ .../account-activation/components/FormOTP.tsx | 23 ++++++ .../account-activation/components/FormToken.tsx | 83 ++++++++++++++++++++++ src-migrate/modules/account-activation/index.tsx | 12 ++++ src-migrate/modules/register/components/Form.tsx | 53 ++++++++------ .../modules/register/components/FormCaptcha.tsx | 14 ++++ .../modules/register/components/Register.tsx | 39 ---------- .../modules/register/components/TermCondition.tsx | 26 +++++-- src-migrate/modules/register/index.tsx | 46 +++++++++++- 9 files changed, 238 insertions(+), 65 deletions(-) create mode 100644 src-migrate/modules/account-activation/components/FormEmail.tsx create mode 100644 src-migrate/modules/account-activation/components/FormOTP.tsx create mode 100644 src-migrate/modules/account-activation/components/FormToken.tsx create mode 100644 src-migrate/modules/account-activation/index.tsx create mode 100644 src-migrate/modules/register/components/FormCaptcha.tsx delete mode 100644 src-migrate/modules/register/components/Register.tsx (limited to 'src-migrate/modules') diff --git a/src-migrate/modules/account-activation/components/FormEmail.tsx b/src-migrate/modules/account-activation/components/FormEmail.tsx new file mode 100644 index 00000000..f16ab93f --- /dev/null +++ b/src-migrate/modules/account-activation/components/FormEmail.tsx @@ -0,0 +1,7 @@ +const FormEmail = () => { + return ( +
FormEmail
+ ) +} + +export default FormEmail \ No newline at end of file diff --git a/src-migrate/modules/account-activation/components/FormOTP.tsx b/src-migrate/modules/account-activation/components/FormOTP.tsx new file mode 100644 index 00000000..24e9e7f6 --- /dev/null +++ b/src-migrate/modules/account-activation/components/FormOTP.tsx @@ -0,0 +1,23 @@ +import { HStack, PinInput, PinInputField } from "@chakra-ui/react" +import Modal from '~/common/components/elements/Modal' + +const FormOTP = () => { + return ( + +
+
Masukan Kode OTP
+ + + + + + + + +
Kode OTP dikirimkan ke email anda
+
+
+ ) +} + +export default FormOTP \ No newline at end of file diff --git a/src-migrate/modules/account-activation/components/FormToken.tsx b/src-migrate/modules/account-activation/components/FormToken.tsx new file mode 100644 index 00000000..041fbae8 --- /dev/null +++ b/src-migrate/modules/account-activation/components/FormToken.tsx @@ -0,0 +1,83 @@ +import { Alert, AlertDescription, AlertIcon, AlertTitle, Spinner } from "@chakra-ui/react" +import { useRouter } from "next/router" +import { useEffect, useState } from "react" +import Link from "next/link" +import { useMutation } from "react-query" + +import Modal from "~/common/components/elements/Modal" +import { ActivationTokenProps } from "~/common/types/auth" +import { activationUserToken } from "~/services/auth" + +type StatusProps = "success" | "error" | "loading"; + +const FormToken = () => { + const { query } = useRouter() + const [status, setStatus] = useState("loading") + const [active, setActive] = useState(false) + + const mutation = useMutation({ + mutationFn: (data: ActivationTokenProps) => activationUserToken(data), + onSuccess: (data) => { + if (data.activation === true) { + setStatus("success") + } else { + setStatus("error") + } + } + }) + + useEffect(() => { + if (query?.activation === 'token' && typeof query?.token === 'string') { + mutation.mutate({ token: query.token }) + setActive(true) + } + //eslint-disable-next-line + }, [query.activation, query.token]) + + return ( + +
+ {status === 'loading' && ( + <> + +
Mohon tunggu sedang memverifikasi akun
+ + )} + + {status !== 'loading' && ( + + + + Aktivasi akun {status === 'success' ? 'berhasil' : 'gagal'} + + + {status === 'success' && ( + <> + Akun anda berhasil diaktifkan, selamat berbelanja di Indoteknik. + Kembali ke halaman utama + + )} + + {status === 'error' && mutation.data?.reason === 'INVALID_TOKEN' && ( + <> + Token sudah kadaluwarsa, silahkan coba kembali. + Aktivasi Akun + + )} + + + )} +
+
+ ) +} + +export default FormToken \ No newline at end of file diff --git a/src-migrate/modules/account-activation/index.tsx b/src-migrate/modules/account-activation/index.tsx new file mode 100644 index 00000000..edcc6652 --- /dev/null +++ b/src-migrate/modules/account-activation/index.tsx @@ -0,0 +1,12 @@ +import { useRouter } from "next/router" +import FormToken from "./components/FormToken" + +const AccountActivation = () => { + return ( + <> + + + ) +} + +export default AccountActivation \ No newline at end of file diff --git a/src-migrate/modules/register/components/Form.tsx b/src-migrate/modules/register/components/Form.tsx index ac194b46..fc1567ab 100644 --- a/src-migrate/modules/register/components/Form.tsx +++ b/src-migrate/modules/register/components/Form.tsx @@ -3,9 +3,17 @@ import { useMutation } from "react-query"; import { useRegisterStore } from "~/common/stores/useRegisterStore"; import { RegisterProps } from "~/common/types/auth"; import { registerUser } from "~/services/auth"; +import TermCondition from "./TermCondition"; +import FormCaptcha from "./FormCaptcha"; const Form = () => { - const { form, isValid, isCheckedTNC, updateForm, toggleCheckTNC, openTNC } = useRegisterStore() + const { + form, + isValid, + isCheckedTNC, + isValidCaptcha, + updateForm, + } = useRegisterStore() const handleInputChange = (event: ChangeEvent) => { const { name, value } = event.target; @@ -20,8 +28,10 @@ const Form = () => { e.preventDefault() const response = await mutation.mutateAsync(form) - console.log(response); + if (response?.register === true) { + + } } return ( @@ -57,6 +67,20 @@ const Form = () => { /> +
+ + + +
+
@@ -68,6 +92,7 @@ const Form = () => { placeholder='Masukan alamat email anda' value={form.email} onChange={handleInputChange} + autoComplete="username" />
@@ -81,32 +106,18 @@ const Form = () => { placeholder='••••••••••••' value={form.password} onChange={handleInputChange} + autoComplete="current-password" /> -
- - - {' '} - - syarat dan ketentuan - - -
+ + + diff --git a/src-migrate/modules/register/components/FormCaptcha.tsx b/src-migrate/modules/register/components/FormCaptcha.tsx new file mode 100644 index 00000000..967be017 --- /dev/null +++ b/src-migrate/modules/register/components/FormCaptcha.tsx @@ -0,0 +1,14 @@ +import ReCaptcha from '~/common/components/elements/ReCaptcha' +import { useRegisterStore } from '~/common/stores/useRegisterStore' + +const FormCaptcha = () => { + const { updateValidCaptcha } = useRegisterStore() + + const handleCaptchaChange = (value: string | null) => { + updateValidCaptcha(value !== null) + } + + return +} + +export default FormCaptcha \ No newline at end of file diff --git a/src-migrate/modules/register/components/Register.tsx b/src-migrate/modules/register/components/Register.tsx deleted file mode 100644 index e3e29b9f..00000000 --- a/src-migrate/modules/register/components/Register.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import PageContent from "~/modules/page-content" -import Form from "./Form" -import Link from "next/link" -import Modal from "~/common/components/elements/Modal" -import TermCondition from "./TermCondition" - -const Register = () => { - return ( -
-
-
-

- Daftar Akun Indoteknik -

-

- Buat akun sekarang lebih mudah dan terverifikasi -

- - - -
- Sudah punya akun Indoteknik?{' '} - - Masuk - -
-
- -
- -
-
- - -
- ) -} - -export default Register \ No newline at end of file diff --git a/src-migrate/modules/register/components/TermCondition.tsx b/src-migrate/modules/register/components/TermCondition.tsx index 304ffd69..aaba6604 100644 --- a/src-migrate/modules/register/components/TermCondition.tsx +++ b/src-migrate/modules/register/components/TermCondition.tsx @@ -1,15 +1,33 @@ +import { Checkbox } from '@chakra-ui/react' import React from 'react' import Modal from '~/common/components/elements/Modal' import { useRegisterStore } from '~/common/stores/useRegisterStore' import PageContent from '~/modules/page-content' const TermCondition = () => { - const { isOpenTNC, closeTNC } = useRegisterStore() + const { isOpenTNC, closeTNC, isCheckedTNC, toggleCheckTNC, openTNC } = useRegisterStore() return ( - - - + <> +
+ +
+ + {' '} + + syarat dan ketentuan + + +
+
+ + + + + ) } diff --git a/src-migrate/modules/register/index.tsx b/src-migrate/modules/register/index.tsx index ba5efa3a..6325ee09 100644 --- a/src-migrate/modules/register/index.tsx +++ b/src-migrate/modules/register/index.tsx @@ -1,3 +1,47 @@ -import Register from "./components/Register"; +import PageContent from "~/modules/page-content" +import Form from "./components/Form" +import Link from "next/link" +import Image from "next/image" +import IndoteknikLogo from "~/images/logo.png" +import AccountActivation from "../account-activation" + +const LOGO_WIDTH = 150; +const LOGO_HEIGHT = LOGO_WIDTH / 3; + +const Register = () => { + return ( +
+
+
+ + Logo Indoteknik + + +

+ Daftar Akun Indoteknik +

+

+ Buat akun sekarang lebih mudah dan terverifikasi +

+ + + +
+ Sudah punya akun Indoteknik?{' '} + + Masuk + +
+
+ +
+ +
+
+ + +
+ ) +} export default Register \ No newline at end of file -- cgit v1.2.3 From c82110f7d3a2f85de99045fde7b579e369f15b2c Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Sat, 28 Oct 2023 09:05:00 +0700 Subject: Update authentication feature --- .../account-activation/components/FormEmail.tsx | 91 ++++++++++++++++- .../account-activation/components/FormOTP.tsx | 112 ++++++++++++++++++++- .../account-activation/components/FormToken.tsx | 24 ++--- src-migrate/modules/account-activation/index.tsx | 4 + src-migrate/modules/register/components/Form.tsx | 35 ++++++- src-migrate/modules/register/index.tsx | 7 ++ 6 files changed, 251 insertions(+), 22 deletions(-) (limited to 'src-migrate/modules') diff --git a/src-migrate/modules/account-activation/components/FormEmail.tsx b/src-migrate/modules/account-activation/components/FormEmail.tsx index f16ab93f..cd917bc9 100644 --- a/src-migrate/modules/account-activation/components/FormEmail.tsx +++ b/src-migrate/modules/account-activation/components/FormEmail.tsx @@ -1,6 +1,95 @@ +import { Alert, AlertIcon } from "@chakra-ui/react" +import Link from "next/link" +import { useRouter } from "next/router" +import { ChangeEvent, useEffect, useState } from "react" +import { useMutation } from "react-query" +import Modal from "~/common/components/elements/Modal" +import { useRegisterStore } from "~/common/stores/useRegisterStore" +import { ActivationReqProps } from "~/common/types/auth" +import { activationReq } from "~/services/auth" + const FormEmail = () => { + const router = useRouter() + const { query } = router + const [active, setActive] = useState(false) + const [isBtnDisabled, setIsBtnDisabled] = useState(true) + const [email, setEmail] = useState('') + + const { form } = useRegisterStore() + + useEffect(() => { + if (form) setEmail(form?.email) + }, [form]) + + useEffect(() => { + setIsBtnDisabled(email === '') + }, [email]) + + useEffect(() => { + setActive(query?.activation === 'email') + }, [query.activation]) + + const mutation = useMutation({ + mutationFn: (data: ActivationReqProps) => activationReq(data) + }) + + const handleSubmit = (e: ChangeEvent) => { + e.preventDefault() + mutation.data = undefined + mutation.mutate({ email }) + } + + useEffect(() => { + if (mutation.data?.activation_request === true) { + const urlParams = new URLSearchParams({ + activation: 'otp', + email + }) + router.push(`${router.route}?${urlParams}`) + } + }, [mutation.data?.activation_request, router, email]) + return ( -
FormEmail
+ router.push(router.route)} title="Aktivasi Akun"> + + { + mutation.data !== undefined && + !mutation.data?.activation_request && + ( + + + {mutation.data?.reason === 'ACTIVE' && 'Akun sudah aktif.'} + {mutation.data?.reason === 'NOT_FOUND' && 'Akun tidak ditemukan.'} + + {mutation.data?.reason === 'ACTIVE' && ( + Klik untuk masuk akun anda + )} + + {mutation.data?.reason === 'NOT_FOUND' && ( + Klik untuk daftar akun baru + )} + + ) + } + + setEmail(e.target.value)} + autoFocus + /> + + + ) } diff --git a/src-migrate/modules/account-activation/components/FormOTP.tsx b/src-migrate/modules/account-activation/components/FormOTP.tsx index 24e9e7f6..e38fa8fe 100644 --- a/src-migrate/modules/account-activation/components/FormOTP.tsx +++ b/src-migrate/modules/account-activation/components/FormOTP.tsx @@ -1,23 +1,127 @@ -import { HStack, PinInput, PinInputField } from "@chakra-ui/react" +import { HStack, PinInput, PinInputField, Spinner } from "@chakra-ui/react" +import Link from "next/link" +import { useRouter } from "next/router" +import { useEffect, useState } from "react" +import { useMutation } from "react-query" +import { useCountdown } from "usehooks-ts" import Modal from '~/common/components/elements/Modal' +import { ActivationOtpProps, ActivationReqProps } from "~/common/types/auth" +import { activationReq, activationUserOTP } from "~/services/auth" const FormOTP = () => { + const router = useRouter() + const { query } = router + const [active, setActive] = useState(false) + const [email, setEmail] = useState('') + const [otp, setOtp] = useState('') + const [count, { startCountdown, resetCountdown }] = useCountdown({ + countStart: 60 * 3, + intervalMs: 1000, + }) + + useEffect(() => { + setEmail((query?.email || '') as string) + }, [query?.email]) + + useEffect(() => { + setActive(query?.activation === 'otp') + }, [query.activation]) + + useEffect(() => { + !!active && startCountdown() + }, [active, startCountdown]) + + const mutationActivationReq = useMutation({ + mutationFn: (data: ActivationReqProps) => activationReq(data), + onSuccess: () => { + resetCountdown() + startCountdown() + } + }) + + const mutationActivation = useMutation({ + mutationFn: (data: ActivationOtpProps) => activationUserOTP(data) + }) + + useEffect(() => { + if (otp.length === 4 && !mutationActivation.data?.activation) { + mutationActivation.mutate({ email, otp }) + } + //eslint-disable-next-line + }, [otp]) + + // TODO: Save user to local storage + return ( - +
Masukan Kode OTP
- + setOtp(val)}> -
Kode OTP dikirimkan ke email anda
+
+ {mutationActivation.isLoading && } + + {!mutationActivation.isLoading && + mutationActivation.data?.reason === 'INVALID_OTP' && + ( + Mohon maaf kode OTP yand anda masukan salah + ) + } + + {mutationActivation.data?.activation && ( + Akun anda berhasil diaktifkan, selamat berbelanja di Indoteknik. + )} +
+ + {!mutationActivation.data?.activation && ( +
+ Kode verifikasi telah dikirimkan ke alamat email {email}. Silakan periksa kotak masuk atau folder spam. +
+ )} + +
+ {!mutationActivation.data?.activation && ( + <> + {count > 0 && timeFormat(count)} + + {!mutationActivation.data?.activation && count == 0 && ( + + )} + + )} + + {mutationActivation.data?.activation && ( + Kembali ke halaman utama + )} + + +
) } +const timeFormat = (time: number): string => { + const minute = Math.floor(time / 60); + const second = time % 60; + + const minuteFormat = minute < 10 ? `0${minute}` : `${minute}` + const secondFormat = second < 10 ? `0${second}` : `${second}` + + return `${minuteFormat}:${secondFormat}` +} + export default FormOTP \ No newline at end of file diff --git a/src-migrate/modules/account-activation/components/FormToken.tsx b/src-migrate/modules/account-activation/components/FormToken.tsx index 041fbae8..6af24413 100644 --- a/src-migrate/modules/account-activation/components/FormToken.tsx +++ b/src-migrate/modules/account-activation/components/FormToken.tsx @@ -8,22 +8,12 @@ import Modal from "~/common/components/elements/Modal" import { ActivationTokenProps } from "~/common/types/auth" import { activationUserToken } from "~/services/auth" -type StatusProps = "success" | "error" | "loading"; - const FormToken = () => { const { query } = useRouter() - const [status, setStatus] = useState("loading") const [active, setActive] = useState(false) const mutation = useMutation({ mutationFn: (data: ActivationTokenProps) => activationUserToken(data), - onSuccess: (data) => { - if (data.activation === true) { - setStatus("success") - } else { - setStatus("error") - } - } }) useEffect(() => { @@ -34,19 +24,21 @@ const FormToken = () => { //eslint-disable-next-line }, [query.activation, query.token]) + // TODO: Save user to local storage + return (
- {status === 'loading' && ( + {mutation.isLoading && ( <>
Mohon tunggu sedang memverifikasi akun
)} - {status !== 'loading' && ( + {!mutation.isLoading && ( { > - Aktivasi akun {status === 'success' ? 'berhasil' : 'gagal'} + Aktivasi akun {mutation.data?.activation ? 'berhasil' : 'gagal'} - {status === 'success' && ( + {mutation.data?.activation && ( <> Akun anda berhasil diaktifkan, selamat berbelanja di Indoteknik. Kembali ke halaman utama )} - {status === 'error' && mutation.data?.reason === 'INVALID_TOKEN' && ( + {!mutation.data?.activation && mutation.data?.reason === 'INVALID_TOKEN' && ( <> Token sudah kadaluwarsa, silahkan coba kembali. Aktivasi Akun diff --git a/src-migrate/modules/account-activation/index.tsx b/src-migrate/modules/account-activation/index.tsx index edcc6652..97c96953 100644 --- a/src-migrate/modules/account-activation/index.tsx +++ b/src-migrate/modules/account-activation/index.tsx @@ -1,10 +1,14 @@ import { useRouter } from "next/router" import FormToken from "./components/FormToken" +import FormEmail from "./components/FormEmail" +import FormOTP from "./components/FormOTP" const AccountActivation = () => { return ( <> + + ) } diff --git a/src-migrate/modules/register/components/Form.tsx b/src-migrate/modules/register/components/Form.tsx index fc1567ab..3227a549 100644 --- a/src-migrate/modules/register/components/Form.tsx +++ b/src-migrate/modules/register/components/Form.tsx @@ -1,10 +1,13 @@ -import { ChangeEvent } from "react"; +import { ChangeEvent, useEffect } from "react"; import { useMutation } from "react-query"; import { useRegisterStore } from "~/common/stores/useRegisterStore"; import { RegisterProps } from "~/common/types/auth"; import { registerUser } from "~/services/auth"; import TermCondition from "./TermCondition"; import FormCaptcha from "./FormCaptcha"; +import { useRouter } from "next/router"; +import { UseToastOptions, useToast } from "@chakra-ui/react"; +import Link from "next/link"; const Form = () => { const { @@ -14,6 +17,8 @@ const Form = () => { isValidCaptcha, updateForm, } = useRegisterStore() + const router = useRouter() + const toast = useToast() const handleInputChange = (event: ChangeEvent) => { const { name, value } = event.target; @@ -30,7 +35,35 @@ const Form = () => { const response = await mutation.mutateAsync(form) if (response?.register === true) { + const urlParams = new URLSearchParams({ + activation: 'otp', + email: form.email + }) + router.push(`${router.route}?${urlParams}`) + } + + const toastProps: UseToastOptions = { + duration: 5000, + isClosable: true + } + switch (response?.reason) { + case 'EMAIL_USED': + toast({ + ...toastProps, + title: 'Email sudah digunakan', + status: 'warning' + }) + break; + case 'NOT_ACTIVE': + const activationUrl = `${router.route}?activation=email` + toast({ + ...toastProps, + title: 'Akun belum aktif', + description: <>Akun sudah terdaftar namun belum aktif. Klik untuk aktivasi akun, + status: 'warning' + }) + break } } diff --git a/src-migrate/modules/register/index.tsx b/src-migrate/modules/register/index.tsx index 6325ee09..00931284 100644 --- a/src-migrate/modules/register/index.tsx +++ b/src-migrate/modules/register/index.tsx @@ -32,6 +32,13 @@ const Register = () => { Masuk
+ +
+ Akun anda belum aktif?{' '} + + Aktivasi + +
-- cgit v1.2.3 From 1602cff06e13bb03e5c48e8369abf5c803426e4d Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 30 Oct 2023 09:53:40 +0700 Subject: Add set auth on authenticated --- src-migrate/modules/account-activation/components/FormOTP.tsx | 7 ++++++- src-migrate/modules/account-activation/components/FormToken.tsx | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src-migrate/modules') diff --git a/src-migrate/modules/account-activation/components/FormOTP.tsx b/src-migrate/modules/account-activation/components/FormOTP.tsx index e38fa8fe..a4775d61 100644 --- a/src-migrate/modules/account-activation/components/FormOTP.tsx +++ b/src-migrate/modules/account-activation/components/FormOTP.tsx @@ -5,6 +5,7 @@ import { useEffect, useState } from "react" import { useMutation } from "react-query" import { useCountdown } from "usehooks-ts" import Modal from '~/common/components/elements/Modal' +import { setAuth } from "~/common/libs/auth" import { ActivationOtpProps, ActivationReqProps } from "~/common/types/auth" import { activationReq, activationUserOTP } from "~/services/auth" @@ -50,7 +51,11 @@ const FormOTP = () => { //eslint-disable-next-line }, [otp]) - // TODO: Save user to local storage + useEffect(() => { + if (mutationActivation.data?.user) { + setAuth(mutationActivation.data.user) + } + }, [mutationActivation.data]) return ( diff --git a/src-migrate/modules/account-activation/components/FormToken.tsx b/src-migrate/modules/account-activation/components/FormToken.tsx index 6af24413..a1525fe6 100644 --- a/src-migrate/modules/account-activation/components/FormToken.tsx +++ b/src-migrate/modules/account-activation/components/FormToken.tsx @@ -7,6 +7,7 @@ import { useMutation } from "react-query" import Modal from "~/common/components/elements/Modal" import { ActivationTokenProps } from "~/common/types/auth" import { activationUserToken } from "~/services/auth" +import { setAuth } from "~/common/libs/auth" const FormToken = () => { const { query } = useRouter() @@ -24,7 +25,11 @@ const FormToken = () => { //eslint-disable-next-line }, [query.activation, query.token]) - // TODO: Save user to local storage + useEffect(() => { + if (mutation.data?.user) { + setAuth(mutation.data.user) + } + }, [mutation.data]) return ( -- cgit v1.2.3 From 6b221cccd58710682c99db7afbc29322da042880 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 31 Oct 2023 10:44:25 +0700 Subject: - Add redirect after activation - Add register form validation --- .../account-activation/components/FormEmail.tsx | 3 ++- .../modules/account-activation/components/FormOTP.tsx | 12 ++---------- .../account-activation/components/FormToken.tsx | 19 +++++++------------ src-migrate/modules/register/components/Form.tsx | 19 ++++++++++++++++++- 4 files changed, 29 insertions(+), 24 deletions(-) (limited to 'src-migrate/modules') diff --git a/src-migrate/modules/account-activation/components/FormEmail.tsx b/src-migrate/modules/account-activation/components/FormEmail.tsx index cd917bc9..ec300ba4 100644 --- a/src-migrate/modules/account-activation/components/FormEmail.tsx +++ b/src-migrate/modules/account-activation/components/FormEmail.tsx @@ -43,7 +43,8 @@ const FormEmail = () => { if (mutation.data?.activation_request === true) { const urlParams = new URLSearchParams({ activation: 'otp', - email + email, + redirect: (router.query?.redirect || '/') as string }) router.push(`${router.route}?${urlParams}`) } diff --git a/src-migrate/modules/account-activation/components/FormOTP.tsx b/src-migrate/modules/account-activation/components/FormOTP.tsx index a4775d61..47c69329 100644 --- a/src-migrate/modules/account-activation/components/FormOTP.tsx +++ b/src-migrate/modules/account-activation/components/FormOTP.tsx @@ -54,8 +54,9 @@ const FormOTP = () => { useEffect(() => { if (mutationActivation.data?.user) { setAuth(mutationActivation.data.user) + router.push((query?.redirect || '/') as string) } - }, [mutationActivation.data]) + }, [mutationActivation.data, router, query.redirect]) return ( @@ -78,10 +79,6 @@ const FormOTP = () => { Mohon maaf kode OTP yand anda masukan salah ) } - - {mutationActivation.data?.activation && ( - Akun anda berhasil diaktifkan, selamat berbelanja di Indoteknik. - )} {!mutationActivation.data?.activation && ( @@ -108,11 +105,6 @@ const FormOTP = () => { )} - {mutationActivation.data?.activation && ( - Kembali ke halaman utama - )} - - diff --git a/src-migrate/modules/account-activation/components/FormToken.tsx b/src-migrate/modules/account-activation/components/FormToken.tsx index a1525fe6..b68b244f 100644 --- a/src-migrate/modules/account-activation/components/FormToken.tsx +++ b/src-migrate/modules/account-activation/components/FormToken.tsx @@ -10,7 +10,8 @@ import { activationUserToken } from "~/services/auth" import { setAuth } from "~/common/libs/auth" const FormToken = () => { - const { query } = useRouter() + const router = useRouter() + const { query } = router const [active, setActive] = useState(false) const mutation = useMutation({ @@ -28,8 +29,9 @@ const FormToken = () => { useEffect(() => { if (mutation.data?.user) { setAuth(mutation.data.user) + router.push((query?.redirect || '/') as string) } - }, [mutation.data]) + }, [mutation.data, router, query.redirect]) return ( @@ -41,7 +43,7 @@ const FormToken = () => { )} - {!mutation.isLoading && ( + {!mutation.isLoading && !mutation.data?.activation && ( { > - Aktivasi akun {mutation.data?.activation ? 'berhasil' : 'gagal'} + Aktivasi akun gagal - {mutation.data?.activation && ( - <> - Akun anda berhasil diaktifkan, selamat berbelanja di Indoteknik. - Kembali ke halaman utama - - )} - - {!mutation.data?.activation && mutation.data?.reason === 'INVALID_TOKEN' && ( + {mutation.data?.reason === 'INVALID_TOKEN' && ( <> Token sudah kadaluwarsa, silahkan coba kembali. Aktivasi Akun diff --git a/src-migrate/modules/register/components/Form.tsx b/src-migrate/modules/register/components/Form.tsx index 3227a549..5b51d6f4 100644 --- a/src-migrate/modules/register/components/Form.tsx +++ b/src-migrate/modules/register/components/Form.tsx @@ -8,6 +8,7 @@ import FormCaptcha from "./FormCaptcha"; import { useRouter } from "next/router"; import { UseToastOptions, useToast } from "@chakra-ui/react"; import Link from "next/link"; +import { registerSchema } from "~/common/validations/auth"; const Form = () => { const { @@ -15,7 +16,9 @@ const Form = () => { isValid, isCheckedTNC, isValidCaptcha, + errors, updateForm, + validate, } = useRegisterStore() const router = useRouter() const toast = useToast() @@ -23,6 +26,7 @@ const Form = () => { const handleInputChange = (event: ChangeEvent) => { const { name, value } = event.target; updateForm(name, value) + validate() } const mutation = useMutation({ @@ -37,7 +41,8 @@ const Form = () => { if (response?.register === true) { const urlParams = new URLSearchParams({ activation: 'otp', - email: form.email + email: form.email, + redirect: (router.query?.next || '/') as string }) router.push(`${router.route}?${urlParams}`) } @@ -97,7 +102,10 @@ const Form = () => { placeholder='Masukan nama lengkap anda' value={form.name} onChange={handleInputChange} + aria-invalid={!!errors.name} /> + + {!!errors.name && {errors.name}}
@@ -111,7 +119,10 @@ const Form = () => { placeholder='08xxxxxxxx' value={form.phone} onChange={handleInputChange} + aria-invalid={!!errors.phone} /> + + {!!errors.phone && {errors.phone}}
@@ -126,7 +137,10 @@ const Form = () => { value={form.email} onChange={handleInputChange} autoComplete="username" + aria-invalid={!!errors.email} /> + + {!!errors.email && {errors.email}}
@@ -140,7 +154,10 @@ const Form = () => { value={form.password} onChange={handleInputChange} autoComplete="current-password" + aria-invalid={!!errors.password} /> + + {!!errors.password && {errors.password}}
-- cgit v1.2.3 From 4bed066c03dc55a8f811ff2e23e019d8adc64495 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 10 Nov 2023 14:47:52 +0700 Subject: Refactor register form --- src-migrate/modules/register/components/Form.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src-migrate/modules') diff --git a/src-migrate/modules/register/components/Form.tsx b/src-migrate/modules/register/components/Form.tsx index 5b51d6f4..ddc3397f 100644 --- a/src-migrate/modules/register/components/Form.tsx +++ b/src-migrate/modules/register/components/Form.tsx @@ -1,4 +1,4 @@ -import { ChangeEvent, useEffect } from "react"; +import { ChangeEvent, useEffect, useMemo } from "react"; import { useMutation } from "react-query"; import { useRegisterStore } from "~/common/stores/useRegisterStore"; import { RegisterProps } from "~/common/types/auth"; @@ -13,13 +13,17 @@ import { registerSchema } from "~/common/validations/auth"; const Form = () => { const { form, - isValid, isCheckedTNC, isValidCaptcha, errors, updateForm, validate, } = useRegisterStore() + + const isFormValid = useMemo(() => { + return Object.keys(errors).length === 0 + }, [errors]) + const router = useRouter() const toast = useToast() @@ -167,7 +171,7 @@ const Form = () => { -- cgit v1.2.3 From 5a9210e560ca47d8f4d8c43b06fc93d1d064a6f6 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 10 Nov 2023 16:23:33 +0700 Subject: Add close on modal otp activation, change validation register schema, fix term and condition checkbox --- src-migrate/modules/account-activation/components/FormOTP.tsx | 5 ++--- src-migrate/modules/register/components/Form.tsx | 7 ++----- src-migrate/modules/register/components/TermCondition.tsx | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) (limited to 'src-migrate/modules') diff --git a/src-migrate/modules/account-activation/components/FormOTP.tsx b/src-migrate/modules/account-activation/components/FormOTP.tsx index 47c69329..9bc0fb23 100644 --- a/src-migrate/modules/account-activation/components/FormOTP.tsx +++ b/src-migrate/modules/account-activation/components/FormOTP.tsx @@ -1,5 +1,4 @@ import { HStack, PinInput, PinInputField, Spinner } from "@chakra-ui/react" -import Link from "next/link" import { useRouter } from "next/router" import { useEffect, useState } from "react" import { useMutation } from "react-query" @@ -16,7 +15,7 @@ const FormOTP = () => { const [email, setEmail] = useState('') const [otp, setOtp] = useState('') const [count, { startCountdown, resetCountdown }] = useCountdown({ - countStart: 60 * 3, + countStart: 60 * 1, intervalMs: 1000, }) @@ -59,7 +58,7 @@ const FormOTP = () => { }, [mutationActivation.data, router, query.redirect]) return ( - + setActive(false)} mode="desktop">
Masukan Kode OTP
diff --git a/src-migrate/modules/register/components/Form.tsx b/src-migrate/modules/register/components/Form.tsx index ddc3397f..dc9107b2 100644 --- a/src-migrate/modules/register/components/Form.tsx +++ b/src-migrate/modules/register/components/Form.tsx @@ -1,4 +1,4 @@ -import { ChangeEvent, useEffect, useMemo } from "react"; +import { ChangeEvent, useMemo } from "react"; import { useMutation } from "react-query"; import { useRegisterStore } from "~/common/stores/useRegisterStore"; import { RegisterProps } from "~/common/types/auth"; @@ -8,7 +8,6 @@ import FormCaptcha from "./FormCaptcha"; import { useRouter } from "next/router"; import { UseToastOptions, useToast } from "@chakra-ui/react"; import Link from "next/link"; -import { registerSchema } from "~/common/validations/auth"; const Form = () => { const { @@ -20,9 +19,7 @@ const Form = () => { validate, } = useRegisterStore() - const isFormValid = useMemo(() => { - return Object.keys(errors).length === 0 - }, [errors]) + const isFormValid = useMemo(() => Object.keys(errors).length === 0, [errors]) const router = useRouter() const toast = useToast() diff --git a/src-migrate/modules/register/components/TermCondition.tsx b/src-migrate/modules/register/components/TermCondition.tsx index aaba6604..6b95ba19 100644 --- a/src-migrate/modules/register/components/TermCondition.tsx +++ b/src-migrate/modules/register/components/TermCondition.tsx @@ -10,7 +10,7 @@ const TermCondition = () => { return ( <>
- +
{' '} -- cgit v1.2.3 From 6a6ce21e5a552b0dc6cd541710a87fd0a0fd9d20 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 17 Nov 2023 15:23:22 +0700 Subject: Update button resend otp on OTP Form --- .../account-activation/components/FormOTP.tsx | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src-migrate/modules') diff --git a/src-migrate/modules/account-activation/components/FormOTP.tsx b/src-migrate/modules/account-activation/components/FormOTP.tsx index 9bc0fb23..6815a088 100644 --- a/src-migrate/modules/account-activation/components/FormOTP.tsx +++ b/src-migrate/modules/account-activation/components/FormOTP.tsx @@ -1,4 +1,4 @@ -import { HStack, PinInput, PinInputField, Spinner } from "@chakra-ui/react" +import { Button, HStack, PinInput, PinInputField, Spinner } from "@chakra-ui/react" import { useRouter } from "next/router" import { useEffect, useState } from "react" import { useMutation } from "react-query" @@ -86,20 +86,22 @@ const FormOTP = () => {
)} -
+
{!mutationActivation.data?.activation && ( <> {count > 0 && timeFormat(count)} {!mutationActivation.data?.activation && count == 0 && ( - + <> +
Belum menerima kode apapun?
+ + + )} )} -- cgit v1.2.3