diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-10-30 09:21:30 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-10-30 09:21:30 +0700 |
| commit | e8c414325a1e32474e740cc6e7dca8396affc5e3 (patch) | |
| tree | e84feb31cd8619d208b4558c5fcf30becc5337e0 /src-migrate/modules/account-activation/components/FormToken.tsx | |
| parent | 1694c12f75ad06c5e40d6f9a66e245c3e683146c (diff) | |
| parent | c82110f7d3a2f85de99045fde7b579e369f15b2c (diff) | |
Merge branch 'refactor/all' into development
Diffstat (limited to 'src-migrate/modules/account-activation/components/FormToken.tsx')
| -rw-r--r-- | src-migrate/modules/account-activation/components/FormToken.tsx | 75 |
1 files changed, 75 insertions, 0 deletions
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..6af24413 --- /dev/null +++ b/src-migrate/modules/account-activation/components/FormToken.tsx @@ -0,0 +1,75 @@ +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" + +const FormToken = () => { + const { query } = useRouter() + const [active, setActive] = useState<boolean>(false) + + const mutation = useMutation({ + mutationFn: (data: ActivationTokenProps) => activationUserToken(data), + }) + + useEffect(() => { + if (query?.activation === 'token' && typeof query?.token === 'string') { + mutation.mutate({ token: query.token }) + setActive(true) + } + //eslint-disable-next-line + }, [query.activation, query.token]) + + // TODO: Save user to local storage + + return ( + <Modal active={active} mode="desktop"> + <div className="pb-6 flex flex-col items-center gap-y-6"> + {mutation.isLoading && ( + <> + <Spinner size='lg' borderWidth='3px' /> + <div className="text-h-sm">Mohon tunggu sedang memverifikasi akun</div> + </> + )} + + {!mutation.isLoading && ( + <Alert + status={mutation.data?.activation ? 'success' : 'error'} + flexDirection="column" + alignItems="center" + justifyContent="center" + textAlign="center" + height="200px" + bg="transparent" + > + <AlertIcon boxSize="40px" mr={0} /> + <AlertTitle className="mt-4 mb-1 text-h-sm"> + Aktivasi akun {mutation.data?.activation ? 'berhasil' : 'gagal'} + </AlertTitle> + <AlertDescription maxWidth="sm"> + {mutation.data?.activation && ( + <> + Akun anda berhasil diaktifkan, selamat berbelanja di Indoteknik. + <Link href='/' className="block mt-8 text-success-700 underline">Kembali ke halaman utama</Link> + </> + )} + + {!mutation.data?.activation && mutation.data?.reason === 'INVALID_TOKEN' && ( + <> + Token sudah kadaluwarsa, silahkan coba kembali. + <Link href='/register?activation=email' className="block mt-8 text-red-700 underline">Aktivasi Akun</Link> + </> + )} + </AlertDescription> + </Alert> + )} + </div> + </Modal> + ) +} + +export default FormToken
\ No newline at end of file |
