From cf0f7a934bcf256d1daeee98e9f66397fb64b1ee Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Tue, 20 Aug 2024 11:47:29 +0700
Subject: <iman> update new register

---
 .../register/components/RegistrasiBisnis.tsx       | 29 +++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

(limited to 'src-migrate/modules/register/components/RegistrasiBisnis.tsx')

diff --git a/src-migrate/modules/register/components/RegistrasiBisnis.tsx b/src-migrate/modules/register/components/RegistrasiBisnis.tsx
index 217b4c79..c093d556 100644
--- a/src-migrate/modules/register/components/RegistrasiBisnis.tsx
+++ b/src-migrate/modules/register/components/RegistrasiBisnis.tsx
@@ -1,4 +1,4 @@
-import { useState } from "react";
+import { useMemo, useState } from "react";
 import FormBisnis from "./FormBisnis";
 import Form from "./Form";
 import TermCondition from "./TermCondition";
@@ -9,6 +9,10 @@ import {
   ChevronDownIcon,
   ChevronRightIcon
 } from '@heroicons/react/24/outline';
+import { useRegisterStore } from "../stores/useRegisterStore";
+import { useMutation } from "react-query";
+import { RegisterProps } from "~/types/auth";
+import { registerUser } from "~/services/auth";
 
 const RegistrasiBisnis = () => {
   const [isPKP, setIsPKP] = useState(false);
@@ -16,6 +20,18 @@ const RegistrasiBisnis = () => {
   const [isIndividuRequired, setIsIndividuRequired] = useState(true);
   const [isBisnisRequired, setIsBisnisRequired] = useState(true);
   const [selectedValue, setSelectedValue] = useState('PKP');
+   const {
+    form,
+    isCheckedTNC,
+    isValidCaptcha,
+    errors,
+    updateForm,
+    validate,
+  } = useRegisterStore()
+  const isFormValid = useMemo(() => Object.keys(errors).length === 0, [errors])
+  const mutation = useMutation({
+    mutationFn: (data: RegisterProps) => registerUser(data)
+  })
 
   const handleChange = (value: string) => {
     setSelectedValue(value);
@@ -38,8 +54,8 @@ const RegistrasiBisnis = () => {
 
   return (
     <>
-      <div>
-        <p className="text-black font-bold">Tipe Bisnis</p>
+      <div className="mt-4">
+        <p className="text-black font-bold mb-2">Tipe Bisnis</p>
         <RadioGroup onChange={handleChange} value={selectedValue}>
           <Stack direction='row'>
             <Radio value='PKP'>PKP</Radio>
@@ -98,6 +114,13 @@ const RegistrasiBisnis = () => {
       </div>
       <FormCaptcha />
       <TermCondition />
+      <button
+        type="submit"
+        className="btn-yellow w-full mt-2"
+        disabled={!isFormValid || !isCheckedTNC || mutation.isLoading || !isValidCaptcha}
+      >
+        {mutation.isLoading ? 'Loading...' : 'Daftar'}
+      </button>
     </>
   );
 };
-- 
cgit v1.2.3

