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