From 6b221cccd58710682c99db7afbc29322da042880 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Tue, 31 Oct 2023 10:44:25 +0700
Subject: - Add redirect after activation - Add register form validation

---
 .../account-activation/components/FormToken.tsx       | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

(limited to 'src-migrate/modules/account-activation/components/FormToken.tsx')

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<boolean>(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 (
     <Modal active={active} mode="desktop">
@@ -41,7 +43,7 @@ const FormToken = () => {
           </>
         )}
 
-        {!mutation.isLoading && (
+        {!mutation.isLoading && !mutation.data?.activation && (
           <Alert
             status={mutation.data?.activation ? 'success' : 'error'}
             flexDirection="column"
@@ -53,17 +55,10 @@ const FormToken = () => {
           >
             <AlertIcon boxSize="40px" mr={0} />
             <AlertTitle className="mt-4 mb-1 text-h-sm">
-              Aktivasi akun {mutation.data?.activation ? 'berhasil' : 'gagal'}
+              Aktivasi akun 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' && (
+              {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>
-- 
cgit v1.2.3

