From: charleswrayjr Date: Sat, 13 Sep 2025 08:00:54 +0000 (-0500) Subject: Adding authentication, media, and messaging. X-Git-Url: https://git.phasecustomsoft.com/static/gitweb.css?a=commitdiff_plain;h=6b7666a9fa642903bb07f776451dd53eeccfc8eb;p=phs-admin.git Adding authentication, media, and messaging. --- diff --git a/src/app/components/PostsTable.js b/src/app/components/PostsTable.js index 5adcf49..dd2f259 100644 --- a/src/app/components/PostsTable.js +++ b/src/app/components/PostsTable.js @@ -15,18 +15,22 @@ const PostsTable = () => { const navigate = useNavigate(); const [posts, setPosts] = useState([]); + const fetchPosts = async () => { + try { + console.log('Fetching posts...'); + const response = await PostService.getPosts(); + setPosts(response.data); + } catch (error) { + enqueueSnackbar(`Error fetching posts: ${error.message}`, { variant: 'error' }); + } + }; + // Fetch posts on mount React.useEffect(() => { - const fetchPosts = async () => { - try { - const response = await PostService.getPosts(); - setPosts(response.data); - } catch (error) { - enqueueSnackbar(`Error fetching posts: ${error.message}`, { variant: 'error' }); - } - }; + console.log('loaded...'); + fetchPosts(); - }, [enqueueSnackbar]); + }, []); const columns = useMemo(() => [ { diff --git a/src/app/services/posts.js b/src/app/services/posts.js index a3211fc..d8713c7 100644 --- a/src/app/services/posts.js +++ b/src/app/services/posts.js @@ -4,29 +4,28 @@ import axios from 'axios'; -const BASE_URL = 'http://localhost:3601'; +const base_url = require('../../globals'); -const getAuthHeaders = () => ({ - headers: { Authorization: `Bearer ${localStorage.getItem('token')}` }, -}); export const PostService = { - async getPosts(params = {}) { - return await axios.get(`${BASE_URL}/post`, { ...getAuthHeaders(), params }); + async getPosts() { + const url = new URL(`${base_url}post`); + console.log(url.toString()); + return await axios.get(url.toString()); }, async getPostByTitle(title) { - return await axios.get(`${BASE_URL}/post/title/${title}`, getAuthHeaders()); + return await axios.get(`${base_url}/post/title/${title}`); }, async getPost(id) { - return await axios.get(`${BASE_URL}/post/${id}`, getAuthHeaders()); + return await axios.get(`${base_url}/post/${id}`); }, async createPost(data) { - return await axios.post(`${BASE_URL}/post/create`, data, getAuthHeaders()); + return await axios.post(`${base_url}/post/create`, data); }, async updatePost(id, data) { - return await axios.put(`${BASE_URL}/post/${id}`, data, getAuthHeaders()); + return await axios.put(`${base_url}/post/${id}`, data); }, async softDeletePost(id, data) { - return await axios.put(`${BASE_URL}/post/${id}/soft_delete`, data, getAuthHeaders()); + return await axios.put(`${base_url}/post/${id}/soft_delete`, data); }, }; \ No newline at end of file