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
+8 -27
View File
@@ -1,7 +1,8 @@
import { useState, useEffect, useCallback } from 'react';
import { API_BASE_URL } from '../constants/api';
import { DATA_KEY_ACCESS_TOKEN, DATA_KEY_USER_ID } from '../constants/app';
import { DATA_KEY_ACCESS_TOKEN } from '../constants/app';
import { tokenService } from '../services/TokenService';
import { contactApi } from '../api/contactApi';
import './ViewContact.css';
@@ -19,42 +20,22 @@ const ViewContact = ({ isOpen, onClose, title = 'View Contacts' }) => {
setError(null);
const accessToken = localStorage.getItem(DATA_KEY_ACCESS_TOKEN);
const userId = localStorage.getItem(DATA_KEY_USER_ID);
const userId = tokenService.getUserId();
if (!accessToken) {
throw new Error('Authentication required. Please log in again.');
}
console.log('Fetching contacts');
const response = await fetch(
`${API_BASE_URL}/api/v1/contact?user_id=${userId}`,
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`,
},
}
const result = await contactApi.getContactsWithUserId(
userId,
tokenService.bearerToken()
);
if (!response.ok) {
if (response.status === 401) {
throw new Error('Session expired. Please log in again.');
} else if (response.status === 404) {
console.log('No contacts associated with user');
setLoading(false);
return;
} else {
throw new Error(`Failed to fetch contacts: ${response.status}`);
}
}
const result = await response.json();
if (result.data) {
setContacts(result.data);
setLastUpdated(new Date());
} else {
setLoading(false);
throw new Error(result.message || 'Failed to load contacts');
}
} catch (err) {