feat(backoffice): send login request
- buat .env untuk menyimpan API dan memberikan .env.example juga untuk contohnya. Tambah .gitignore juga - tambah fungsi login pada Backoffice
This commit is contained in:
@@ -0,0 +1 @@
|
||||
VITE_API_URL=https://api.example.com
|
||||
@@ -45,3 +45,5 @@ vite.config.*.timestamp*
|
||||
vitest.config.*.timestamp*
|
||||
|
||||
storybook-static
|
||||
|
||||
.env
|
||||
|
||||
@@ -1,10 +1,27 @@
|
||||
import { FC, ReactElement } from 'react';
|
||||
import { FC, ReactElement, useState } from 'react';
|
||||
import { useNavigate } from 'react-router';
|
||||
import { Button } from '@imphnen-frontend-service/ui/atoms';
|
||||
import { InputForm } from '@imphnen-frontend-service/ui/molecules';
|
||||
import { postLogin } from '@imphnen-frontend-service/service';
|
||||
|
||||
export const Components: FC = (): ReactElement => {
|
||||
const navigate = useNavigate();
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
|
||||
const handleLogin = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
const payload = { email, password };
|
||||
console.log(payload); // for debugging
|
||||
const response = await postLogin(payload);
|
||||
|
||||
console.log('Login successful:', response); // for debugging
|
||||
navigate('/dashboard');
|
||||
} catch (error) {
|
||||
console.log('Login error:', error); // for debugging
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex justify-center items-center min-h-screen">
|
||||
@@ -13,12 +30,15 @@ export const Components: FC = (): ReactElement => {
|
||||
<h1 className="text-primary-500 text-p1 font-semibold">
|
||||
Welcome to IMPHNEN Backoffice
|
||||
</h1>
|
||||
<form onSubmit={handleLogin} className="flex flex-col gap-8">
|
||||
<InputForm
|
||||
label="Email"
|
||||
placeholder="Masukkan Email"
|
||||
type="email"
|
||||
size="lg"
|
||||
className="w-full"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
/>
|
||||
<InputForm
|
||||
label="Password"
|
||||
@@ -26,8 +46,11 @@ export const Components: FC = (): ReactElement => {
|
||||
type="password"
|
||||
size="lg"
|
||||
className="w-full"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
/>
|
||||
<Button onClick={() => navigate('/dashboard')}>Login</Button>
|
||||
<Button type="submit">Login</Button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -12,7 +12,7 @@ export const postLogin = async (
|
||||
): Promise<TLoginResponse> => {
|
||||
const { data } = await api({
|
||||
method: 'POST',
|
||||
url: '/auth/login',
|
||||
url: '/v1/auth/login',
|
||||
data: payload,
|
||||
});
|
||||
return data;
|
||||
|
||||
Reference in New Issue
Block a user