tsk-6: Send Message (#22)

Closes #6

Reviewed-on: phoenix/textsender#22
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
phoenix
2026-01-04 00:21:22 +00:00
committed by phoenix
parent a1a8b44da3
commit 34644d1cd2
24 changed files with 1690 additions and 146 deletions
+9 -16
View File
@@ -1,12 +1,11 @@
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { AUTH_API_BASE_URL } from '../constants/api';
import { DATA_KEY_ACCESS_TOKEN, DATA_KEY_USER_ID } from '../constants/app';
import { tokenService } from '../services/TokenService';
import { loginApi, LoginRequest } from '../api/loginApi';
import './Login.css';
// function Login() {
const Login = () => {
const navigate = useNavigate();
const [formData, setFormData] = useState({
@@ -64,22 +63,16 @@ const Login = () => {
// Simulate API call
await new Promise((resolve) => setTimeout(resolve, 1000));
const reqBod = {
username: formData.username,
password: formData.password,
};
const reponse = await fetch(`${AUTH_API_BASE_URL}/api/v1/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(reqBod),
});
let reqBod = new LoginRequest();
reqBod.username = formData.username;
reqBod.password = formData.password;
const response = await loginApi.login(reqBod);
if (reponse.ok) {
const response = await reponse.json();
if (response) {
const loginResult = response.data[0];
const token = loginResult.access_token;
localStorage.setItem(DATA_KEY_ACCESS_TOKEN, token);
localStorage.setItem(DATA_KEY_USER_ID, loginResult.user_id);
tokenService.setToken(token);
tokenService.setUserId(loginResult.user_id);
alert(`Login successful! Welcome, ${formData.username}`);
navigate('/dashboard');
} else {