lavoce #2

Merged
yogiedigital merged 118 commits from lavoce into main 2025-10-20 04:06:02 +00:00
Showing only changes of commit b9b5704232 - Show all commits

View File

@@ -1,5 +1,5 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Flex, Input, Form, Button, Card, Space, Image, Row, Col, Typography } from 'antd'; import { Flex, Input, Form, Button, Card, Space, Image, Row, Col } from 'antd';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import sypiu_ggcp from 'assets/sypiu_ggcp.jpg'; import sypiu_ggcp from 'assets/sypiu_ggcp.jpg';
import logo from 'assets/freepik/LOGOPIU.png'; import logo from 'assets/freepik/LOGOPIU.png';
@@ -8,8 +8,11 @@ import { NotifOk, NotifAlert } from '../../components/Global/ToastNotif';
const SignUp = () => { const SignUp = () => {
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [form] = Form.useForm();
const navigate = useNavigate(); const navigate = useNavigate();
const [isRegistered, setIsRegistered] = useState(false);
const moveToSignin = () => { const moveToSignin = () => {
navigate('/signin'); navigate('/signin');
}; };
@@ -17,15 +20,18 @@ const SignUp = () => {
const handleSignUp = async (values) => { const handleSignUp = async (values) => {
const { fullname, username, email, phone, password, confirmPassword } = values; const { fullname, username, email, phone, password, confirmPassword } = values;
// Validasi confirm password
if (password !== confirmPassword) { if (password !== confirmPassword) {
NotifAlert({ NotifAlert({
icon: 'error', icon: 'error',
title: 'Password Tidak Sama', title: 'Password Tidak Sama',
message: 'Password dan confirm password harus sama', message: 'Password dan confirm password harus sama',
}); });
form.resetFields(['password', 'confirmPassword']);
return; return;
} }
// Validasi nomor telepon Indonesia
const phoneRegex = /^(?:\+62|62|0)8[1-9][0-9]{6,11}$/; const phoneRegex = /^(?:\+62|62|0)8[1-9][0-9]{6,11}$/;
if (!phoneRegex.test(phone)) { if (!phoneRegex.test(phone)) {
NotifAlert({ NotifAlert({
@@ -33,29 +39,30 @@ const SignUp = () => {
title: 'Format Telepon Salah', title: 'Format Telepon Salah',
message: 'Nomor telepon tidak valid (harus nomor Indonesia)', message: 'Nomor telepon tidak valid (harus nomor Indonesia)',
}); });
form.resetFields(['phone']);
return; return;
} }
// Validasi password kompleks
const passwordErrors = []; const passwordErrors = [];
if (password.length < 8) passwordErrors.push('Minimal 8 karakter'); if (password.length < 8) passwordErrors.push('Minimal 8 karakter');
if (!/[A-Z]/.test(password)) passwordErrors.push('Harus ada huruf kapital'); if (!/[A-Z]/.test(password)) passwordErrors.push('Harus ada huruf kapital');
if (!/[0-9]/.test(password)) passwordErrors.push('Harus ada angka'); if (!/[0-9]/.test(password)) passwordErrors.push('Harus ada angka');
if (!/[!@#$%^&*(),.?":{}|<>]/.test(password)) passwordErrors.push('Harus ada karakter spesial'); if (!/[!@#$%^&*(),.?":{}|<>]/.test(password))
passwordErrors.push('Harus ada karakter spesial');
if (passwordErrors.length) { if (passwordErrors.length) {
NotifAlert({ NotifAlert({
icon: 'error', icon: 'error',
title: 'Password Tidak Valid', title: 'Password Tidak Valid',
message: passwordErrors.join(', '), message: passwordErrors.join(', '),
}); });
form.resetFields(['password', 'confirmPassword']);
return; return;
} }
setLoading(true); setLoading(true);
try { try {
const res = await register({ fullname, username, email, phone, password }); const res = await register({ fullname, username, email, phone, password });
// const user = res?.data?.user;
// // const tokens = res?.data?.tokens;
NotifOk({ NotifOk({
icon: 'success', icon: 'success',
@@ -63,33 +70,21 @@ const SignUp = () => {
message: res?.data?.message || 'Berhasil menambahkan user.', message: res?.data?.message || 'Berhasil menambahkan user.',
}); });
form.resetFields();
// if (user) { setIsRegistered(true);
// // localStorage.setItem('token', tokens.accessToken);
// // localStorage.setItem('refreshToken', tokens.refreshToken);
// // localStorage.setItem('user', JSON.stringify(user));
// NotifOk({
// icon: 'success',
// title: 'Registrasi Berhasil',
// message: res?.data?.message || 'Selamat datang! Anda akan diarahkan ke dashboard.',
// });
// navigate('/signin'); // navigate('/signin');
// } else {
// NotifAlert({
// icon: 'error',
// title: 'Registrasi Gagal',
// message: res?.data?.message || 'Terjadi kesalahan',
// });
// }
} catch (err) { } catch (err) {
console.error('Register error:', err); console.error('Register error:', err);
const errorMessage = err?.response?.data?.message || err.message || 'Terjadi kesalahan';
NotifAlert({ NotifAlert({
icon: 'error', icon: 'error',
title: 'Registrasi Gagal', title: 'Registrasi Gagal',
message: err?.response?.data?.message || err.message || 'Terjadi kesalahan', message: errorMessage || 'Terjadi kesalahan',
}); });
if (errorMessage.toLowerCase().includes('already')) {
form.resetFields();
}
} finally { } finally {
setLoading(false); setLoading(false);
} }
@@ -117,20 +112,27 @@ const SignUp = () => {
textAlign: 'center', textAlign: 'center',
}} }}
> >
{/* Logo di dalam Card */} <Image src={logo} height={150} width={220} preview={false} alt="logo" />
<Image src={logo} height={120} width={180} preview={false} alt="logo"/>
<h2 style={{ marginBottom: '20px', color: '#1a3c34' }}>Registration</h2> <h2 style={{ marginBottom: '20px', color: '#1a3c34' }}>Registration</h2>
<Form onFinish={handleSignUp} layout="vertical"> <Form form={form} onFinish={handleSignUp} layout="vertical">
<Row gutter={16}> <Row gutter={16}>
<Col span={12}> <Col span={12}>
<Form.Item label="Full Name" name="fullname" rules={[{ required: true }]}> <Form.Item
label="Full Name"
name="fullname"
rules={[{ required: true }]}
>
<Input placeholder="Full Name" size="large" /> <Input placeholder="Full Name" size="large" />
</Form.Item> </Form.Item>
</Col> </Col>
<Col span={12}> <Col span={12}>
<Form.Item label="Username" name="username" rules={[{ required: true }]}> <Form.Item
label="Username"
name="username"
rules={[{ required: true }]}
>
<Input placeholder="Username" size="large" /> <Input placeholder="Username" size="large" />
</Form.Item> </Form.Item>
</Col> </Col>
@@ -141,7 +143,13 @@ const SignUp = () => {
<Form.Item <Form.Item
label="Email" label="Email"
name="email" name="email"
rules={[{ required: true, type: 'email', message: 'Please input a valid email!' }]} rules={[
{
required: true,
type: 'email',
message: 'Please input a valid email!',
},
]}
> >
<Input placeholder="Email" size="large" /> <Input placeholder="Email" size="large" />
</Form.Item> </Form.Item>
@@ -157,24 +165,29 @@ const SignUp = () => {
<Input.Password placeholder="Password" size="large" /> <Input.Password placeholder="Password" size="large" />
</Form.Item> </Form.Item>
<Form.Item label="Confirm Password" name="confirmPassword" rules={[{ required: true }]}> <Form.Item
label="Confirm Password"
name="confirmPassword"
rules={[{ required: true }]}
>
<Input.Password placeholder="Confirm Password" size="large" /> <Input.Password placeholder="Confirm Password" size="large" />
</Form.Item> </Form.Item>
<Form.Item> <Form.Item>
<Space direction="vertical" style={{ width: '100%' }}> <Space direction="vertical" style={{ width: '100%' }}>
<Button type="primary" htmlType="submit" loading={loading} style={{ width: '100%' }} > <Button
type="primary"
htmlType="submit"
loading={loading}
style={{ width: '100%' }}
>
Sign Up Sign Up
</Button> </Button>
</Space> </Space>
</Form.Item> </Form.Item>
</Form> </Form>
<Button <Button type="primary" style={{ width: '100%' }} onClick={moveToSignin}>
type="default"
style={{ width: '100%', marginTop: '10px' }}
onClick={moveToSignin}
>
Sign In Sign In
</Button> </Button>
</Card> </Card>