From 0de0fda98dc35bd6503f1a45a52878b154a94c75 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Thu, 23 Feb 2023 10:52:40 +0700
Subject: fox

---
 src/lib/auth/components/Register.jsx | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

(limited to 'src/lib/auth/components/Register.jsx')

diff --git a/src/lib/auth/components/Register.jsx b/src/lib/auth/components/Register.jsx
index 135972d3..d02081ce 100644
--- a/src/lib/auth/components/Register.jsx
+++ b/src/lib/auth/components/Register.jsx
@@ -3,6 +3,8 @@ import Link from '@/core/components/elements/Link/Link'
 import IndoteknikLogo from '@/images/logo.png'
 import { useState } from 'react'
 import registerApi from '../api/registerApi'
+import Alert from '@/core/components/elements/Alert/Alert'
+import axios from 'axios'
 
 const Register = () => {
   const [fullname, setFullname] = useState('')
@@ -10,9 +12,12 @@ const Register = () => {
   const [password, setPassword] = useState('')
   const [companyName, setCompanyName] = useState('')
   const [isLoading, setIsLoading] = useState('')
+  const [alert, setAlert] = useState(null)
 
   const handleSubmit = async (e) => {
     e.preventDefault()
+    setAlert(null)
+    setIsLoading(true)
     const data = {
       name: fullname,
       company: companyName,
@@ -20,7 +25,27 @@ const Register = () => {
       password
     }
     const isRegistered = await registerApi({ data })
-    console.log(isRegistered)
+    setIsLoading(false)
+    if (isRegistered.register) {
+      await axios.post(`${process.env.SELF_HOST}/api/activation-request`, { email })
+      setAlert({
+        children: 'Berhasil mendaftarkan akun anda, cek email untuk melakukan aktivasi akun',
+        type: 'success'
+      })
+      setCompanyName('')
+      setFullname('')
+      setEmail('')
+      setPassword('')
+    } else {
+      switch (isRegistered.reason) {
+        case 'EMAIL_USED':
+          setAlert({
+            children: 'Email telah digunakan',
+            type: 'info'
+          })
+          break
+      }
+    }
   }
 
   return (
@@ -39,6 +64,15 @@ const Register = () => {
         Buat akun sekarang lebih mudah dan terverifikasi
       </h2>
 
+      {alert && (
+        <Alert
+          className='text-center'
+          type={alert.type}
+        >
+          {alert.children}
+        </Alert>
+      )}
+
       <form
         className='w-full mt-6 flex flex-col gap-y-4'
         onSubmit={handleSubmit}
-- 
cgit v1.2.3

