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
|
||||||
+3
-1
@@ -44,4 +44,6 @@ Thumbs.db
|
|||||||
vite.config.*.timestamp*
|
vite.config.*.timestamp*
|
||||||
vitest.config.*.timestamp*
|
vitest.config.*.timestamp*
|
||||||
|
|
||||||
storybook-static
|
storybook-static
|
||||||
|
|
||||||
|
.env
|
||||||
|
|||||||
@@ -1,10 +1,27 @@
|
|||||||
import { FC, ReactElement } from 'react';
|
import { FC, ReactElement, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router';
|
import { useNavigate } from 'react-router';
|
||||||
import { Button } from '@imphnen-frontend-service/ui/atoms';
|
import { Button } from '@imphnen-frontend-service/ui/atoms';
|
||||||
import { InputForm } from '@imphnen-frontend-service/ui/molecules';
|
import { InputForm } from '@imphnen-frontend-service/ui/molecules';
|
||||||
|
import { postLogin } from '@imphnen-frontend-service/service';
|
||||||
|
|
||||||
export const Components: FC = (): ReactElement => {
|
export const Components: FC = (): ReactElement => {
|
||||||
const navigate = useNavigate();
|
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 (
|
return (
|
||||||
<div className="flex justify-center items-center min-h-screen">
|
<div className="flex justify-center items-center min-h-screen">
|
||||||
@@ -13,21 +30,27 @@ export const Components: FC = (): ReactElement => {
|
|||||||
<h1 className="text-primary-500 text-p1 font-semibold">
|
<h1 className="text-primary-500 text-p1 font-semibold">
|
||||||
Welcome to IMPHNEN Backoffice
|
Welcome to IMPHNEN Backoffice
|
||||||
</h1>
|
</h1>
|
||||||
<InputForm
|
<form onSubmit={handleLogin} className="flex flex-col gap-8">
|
||||||
label="Email"
|
<InputForm
|
||||||
placeholder="Masukkan Email"
|
label="Email"
|
||||||
type="email"
|
placeholder="Masukkan Email"
|
||||||
size="lg"
|
type="email"
|
||||||
className="w-full"
|
size="lg"
|
||||||
/>
|
className="w-full"
|
||||||
<InputForm
|
value={email}
|
||||||
label="Password"
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
placeholder="Masukkan password"
|
/>
|
||||||
type="password"
|
<InputForm
|
||||||
size="lg"
|
label="Password"
|
||||||
className="w-full"
|
placeholder="Masukkan password"
|
||||||
/>
|
type="password"
|
||||||
<Button onClick={() => navigate('/dashboard')}>Login</Button>
|
size="lg"
|
||||||
|
className="w-full"
|
||||||
|
value={password}
|
||||||
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
|
/>
|
||||||
|
<Button type="submit">Login</Button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export const postLogin = async (
|
|||||||
): Promise<TLoginResponse> => {
|
): Promise<TLoginResponse> => {
|
||||||
const { data } = await api({
|
const { data } = await api({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/auth/login',
|
url: '/v1/auth/login',
|
||||||
data: payload,
|
data: payload,
|
||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
Reference in New Issue
Block a user