summaryrefslogtreecommitdiff
path: root/src-migrate/modules/register
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-10-23 17:11:33 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-10-23 17:11:33 +0700
commit90710579ba1c12060877f6ec2d26103f9c31058d (patch)
tree307032cfb8cd13b790c569bc443258b00b07684e /src-migrate/modules/register
parenta001da95b9c03167656aec8a573cf60c12164b3f (diff)
Refactor and migrate register page
Diffstat (limited to 'src-migrate/modules/register')
-rw-r--r--src-migrate/modules/register/components/Form.tsx117
-rw-r--r--src-migrate/modules/register/components/Register.tsx39
-rw-r--r--src-migrate/modules/register/components/TermCondition.tsx16
-rw-r--r--src-migrate/modules/register/index.tsx3
4 files changed, 175 insertions, 0 deletions
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<HTMLInputElement>) => {
+ const { name, value } = event.target;
+ updateForm(name, value)
+ }
+
+ const mutation = useMutation({
+ mutationFn: (data: RegisterProps) => registerUser(data)
+ })
+
+ const handleSubmit = async (e: ChangeEvent<HTMLFormElement>) => {
+ e.preventDefault()
+
+ const response = await mutation.mutateAsync(form)
+ console.log(response);
+
+ }
+
+ return (
+ <form className="mt-6 grid grid-cols-1 gap-y-4" onSubmit={handleSubmit}>
+ <div>
+ <label htmlFor="company">
+ Nama Perusahaan <span className='text-gray_r-11'>(opsional)</span>
+ </label>
+
+ <input
+ type="text"
+ name="company"
+ id="company"
+ className="form-input mt-3"
+ placeholder="cth: INDOTEKNIK DOTCOM GEMILANG"
+ autoCapitalize="true"
+ value={form.company}
+ onChange={handleInputChange}
+ />
+ </div>
+
+ <div>
+ <label htmlFor='name'>Nama Lengkap</label>
+
+ <input
+ type='text'
+ id='name'
+ name='name'
+ className='form-input mt-3'
+ placeholder='Masukan nama lengkap anda'
+ value={form.name}
+ onChange={handleInputChange}
+ />
+ </div>
+
+ <div>
+ <label htmlFor='email'>Alamat Email</label>
+
+ <input
+ type='text'
+ id='email'
+ name='email'
+ className='form-input mt-3'
+ placeholder='Masukan alamat email anda'
+ value={form.email}
+ onChange={handleInputChange}
+ />
+ </div>
+
+ <div>
+ <label htmlFor='password'>Kata Sandi</label>
+ <input
+ type='password'
+ name='password'
+ id='password'
+ className='form-input mt-3'
+ placeholder='••••••••••••'
+ value={form.password}
+ onChange={handleInputChange}
+ />
+ </div>
+
+ <div className="mt-4">
+ <input
+ type="checkbox"
+ name="tnc"
+ id="tnc"
+ checked={isCheckedTNC}
+ onClick={toggleCheckTNC}
+ />
+ <label htmlFor="tnc" className="ml-2 cursor-pointer">Dengan ini saya menyetujui</label>
+ {' '}
+ <span
+ className="font-medium text-danger-500 cursor-pointer"
+ onClick={openTNC}
+ >
+ syarat dan ketentuan
+ </span>
+ <label htmlFor="tnc" className="ml-2 cursor-pointer">yang berlaku</label>
+ </div>
+
+ <button
+ type="submit"
+ className="btn-yellow w-full mt-2"
+ disabled={!isValid || !isCheckedTNC || mutation.isLoading}
+ >
+ {mutation.isLoading ? 'Loading...' : 'Daftar'}
+ </button>
+ </form>
+ )
+}
+
+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 (
+ <div className="container">
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-x-10 pt-16">
+ <section>
+ <h1 className="text-2xl font-semibold">
+ Daftar Akun Indoteknik
+ </h1>
+ <h2 className="text-gray_r-11 mt-1 mb-4">
+ Buat akun sekarang lebih mudah dan terverifikasi
+ </h2>
+
+ <Form />
+
+ <div className='text-gray_r-11 mt-10'>
+ Sudah punya akun Indoteknik?{' '}
+ <Link href='/login' className='inline font-medium text-danger-500'>
+ Masuk
+ </Link>
+ </div>
+ </section>
+
+ <section className="my-10 md:my-0">
+ <PageContent path="/register" />
+ </section>
+ </div>
+
+ <TermCondition />
+ </div>
+ )
+}
+
+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 (
+ <Modal active={isOpenTNC} close={closeTNC} >
+ <PageContent path='/register#tnd' />
+ </Modal>
+ )
+}
+
+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