lavoce #2

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

View File

@@ -13,13 +13,17 @@ const SignIn = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const moveToSignUp = () => { const moveToSignUp = () => {
navigate("/signup"); navigate('/signup');
}; };
// ambil captcha // ambil captcha
const fetchCaptcha = async () => { const fetchCaptcha = async () => {
try { try {
const res = await SendRequest({ method: 'get', prefix: 'auth/generate-captcha', token: false }); const res = await SendRequest({
method: 'get',
prefix: 'auth/generate-captcha',
token: false,
});
setCaptchaSvg(res.data.svg || ''); setCaptchaSvg(res.data.svg || '');
setCaptchaText(res.data.text || ''); setCaptchaText(res.data.text || '');
} catch (err) { } catch (err) {
@@ -27,7 +31,9 @@ const SignIn = () => {
} }
}; };
useEffect(() => { fetchCaptcha(); }, []); useEffect(() => {
fetchCaptcha();
}, []);
const handleOnSubmit = async (values) => { const handleOnSubmit = async (values) => {
setLoading(true); setLoading(true);
@@ -41,7 +47,7 @@ const SignIn = () => {
captcha: values.captcha, captcha: values.captcha,
captchaText: captchaText, captchaText: captchaText,
}, },
withCredentials: true withCredentials: true,
}); });
const user = res?.data?.user || res?.user; const user = res?.data?.user || res?.user;
@@ -58,46 +64,84 @@ const SignIn = () => {
}); });
navigate('/dashboard/home'); navigate('/dashboard/home');
}
} catch (err) {
// hanya handle invalid captcha disini
if (err?.response?.data?.message?.toLowerCase().includes('captcha')) {
NotifAlert({
icon: 'warning',
title: 'Peringatan',
message: 'Invalid captcha',
});
fetchCaptcha();
} else { } else {
NotifAlert({ NotifAlert({
icon: 'error', icon: 'error',
title: 'Login Gagal', title: 'Login Gagal',
message: res?.message || 'Terjadi kesalahan', message: err?.message || 'Terjadi kesalahan',
}); });
fetchCaptcha(); fetchCaptcha();
} }
} catch (err) { } finally {
console.error(err); setLoading(false);
NotifAlert({ icon: 'error', title: 'Login Gagal', message: err?.message || 'Terjadi kesalahan' }); }
fetchCaptcha();
} finally { setLoading(false); }
}; };
return ( return (
<Flex align="center" justify="center" style={{ height: '100vh', backgroundImage: `url(${sypiu_ggcp})`, backgroundSize: 'cover', backgroundPosition: 'center' }}> <Flex
align="center"
justify="center"
style={{
height: '100vh',
backgroundImage: `url(${sypiu_ggcp})`,
backgroundSize: 'cover',
backgroundPosition: 'center',
}}
>
<Card style={{ boxShadow: '0px 4px 8px rgba(0,0,0,0.1)' }}> <Card style={{ boxShadow: '0px 4px 8px rgba(0,0,0,0.1)' }}>
<Flex align="center" justify="center"> <Flex align="center" justify="center">
<Image src={logo} height={150} width={220} preview={false} alt="logo" /> <Image src={logo} height={150} width={220} preview={false} alt="logo" />
</Flex> </Flex>
<br /> <br />
<Form layout="vertical" style={{ width: '250px' }} onFinish={handleOnSubmit}> <Form layout="vertical" style={{ width: '250px' }} onFinish={handleOnSubmit}>
<Form.Item label="Email" name="email" rules={[{ required: true, type: 'email', message: 'Email tidak boleh kosong' }]}> <Form.Item
label="Email"
name="email"
rules={[
{ required: true, type: 'email', message: 'Email tidak boleh kosong' },
]}
>
<Input placeholder="Email" size="large" /> <Input placeholder="Email" size="large" />
</Form.Item> </Form.Item>
<Form.Item label="Password" name="password" rules={[{ required: true, message: 'Password tidak boleh kosong' }]}> <Form.Item
label="Password"
name="password"
rules={[{ required: true, message: 'Password tidak boleh kosong' }]}
>
<Input.Password placeholder="Password" size="large" /> <Input.Password placeholder="Password" size="large" />
</Form.Item> </Form.Item>
<div dangerouslySetInnerHTML={{ __html: captchaSvg }} /> <div dangerouslySetInnerHTML={{ __html: captchaSvg }} />
<Form.Item label="CAPTCHA" name="captcha" rules={[{ required: true, message: 'Silahkan masukkan CAPTCHA' }]}> <Form.Item
label="CAPTCHA"
name="captcha"
rules={[{ required: true, message: 'Silahkan masukkan CAPTCHA' }]}
>
<Input placeholder="Masukkan CAPTCHA" size="large" /> <Input placeholder="Masukkan CAPTCHA" 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%' }}>Sign In</Button> <Button
type="primary"
htmlType="submit"
loading={loading}
style={{ width: '100%' }}
>
Sign In
</Button>
</Space> </Space>
</Form.Item> </Form.Item>
</Form> </Form>