diff --git a/img/Sicilia.jpg b/img/Sicilia.jpg new file mode 100644 index 0000000..0fa8e72 Binary files /dev/null and b/img/Sicilia.jpg differ diff --git a/src/api/communityuser_profile/get_fulldetailsprofile.js b/src/api/communityuser_profile/get_fulldetailsprofile.js new file mode 100644 index 0000000..d18556b --- /dev/null +++ b/src/api/communityuser_profile/get_fulldetailsprofile.js @@ -0,0 +1,36 @@ +export default async function fetchFullCommunityUserProfile(communityUserId) { + const apiUrl = import.meta.env.VITE_API_URL; + if (!apiUrl) { + console.error("VITE_API_URL is not defined in environment variables"); + return Promise.reject(new Error("API URL is not configured")); + } + + const token = localStorage.getItem("token"); + if (!token) { + return Promise.reject(new Error("Please log in to see full details on profile.")); + } + + const url = `${apiUrl}/community-users/${communityUserId}`; + console.log("Full API URL:", url); + + try { + const response = await fetch(url, { + method: "GET", + headers: { + "Authorization": `Token ${token}`, + "Accept": "application/json", + "Content-Type": "application/json", + }, + }); + + if (!response.ok) { + const errorMessage = await response.text(); + throw new Error(`Server responded with ${response.status}: ${errorMessage}`); + } + + return await response.json(); + } catch (error) { + console.error("Fetch error:", { message: error.message, url }); + return Promise.reject(error); + } +} \ No newline at end of file diff --git a/src/api/communityuser_profile/get_fulldetailsprofiles.js b/src/api/communityuser_profile/get_fulldetailsprofiles.js new file mode 100644 index 0000000..f076f99 --- /dev/null +++ b/src/api/communityuser_profile/get_fulldetailsprofiles.js @@ -0,0 +1,44 @@ +// const url = `${import.meta.env.VITE_API_URL}/community-users/`; + + +export default async function fetchFullCommunityUserProfiles() { + // Add debug logging for the API URL + if (!import.meta.env.VITE_API_URL) { + console.error('VITE_API_URL is not defined in environment variables'); + throw new Error('API URL is not configured'); + } + + + const token = window.localStorage.getItem("token"); + const url = `${import.meta.env.VITE_API_URL}/role-models/`; + console.log('Full API URL:', url); // This will help us verify the complete URL + + + // Check if the token exists + if (!token) { + throw new Error("Please log in to see full details on profile."); + } + + try { + const response = await fetch(url, { + method: "GET", + headers: { + "Authorization": `Token ${token}`, + 'Accept': 'application/json', + 'Content-Type': 'application/json' + } + }); + + if (!response.ok) { + throw new Error(`Server responded with ${response.status}`); + } + + return await response.json(); + } catch (error) { + console.error('Fetch error:', { + message: error.message, + url: url + }); + throw error; + } +} \ No newline at end of file diff --git a/src/api/communityuser_profile/get_profile.js b/src/api/communityuser_profile/get_profile.js deleted file mode 100644 index 9c640a2..0000000 --- a/src/api/communityuser_profile/get_profile.js +++ /dev/null @@ -1,19 +0,0 @@ -export const get_profile = async (userId) => { - try { - const token = localStorage.getItem('token'); - const response = await fetch(`${import.meta.env.VITE_API_URL}/community-user/profile/${userId}`, { - headers: { - Authorization: `Bearer ${token}` - } - }); - - if (!response.ok) { - throw new Error('Failed to fetch profile'); - } - - return await response.json(); - } catch (error) { - console.error('Error fetching profile:', error); - throw error; - } - }; \ No newline at end of file diff --git a/src/api/communityuser_profile/get_profiles.js b/src/api/communityuser_profile/get_profiles.js deleted file mode 100644 index 4fdeb07..0000000 --- a/src/api/communityuser_profile/get_profiles.js +++ /dev/null @@ -1,35 +0,0 @@ -export const fetchLimitedCommunityUserProfile = async (userId) => { - try { - const response = await fetch( - `${import.meta.env.VITE_API_URL}/community-user/public-profile/${userId}` - ); - if (!response.ok) { - throw new Error('Failed to fetch profile'); - } - return await response.json(); - } catch (error) { - console.error('Error fetching community user profile:', error); - throw error; - } - }; - - export const fetchFullCommunityUserProfile = async (userId) => { - const token = localStorage.getItem('token'); - try { - const response = await fetch( - `${import.meta.env.VITE_API_URL}/community-user/profile/${userId}`, - { - headers: { - Authorization: `Bearer ${token}`, - }, - } - ); - if (!response.ok) { - throw new Error('Failed to fetch profile'); - } - return await response.json(); - } catch (error) { - console.error('Error fetching full community user profile:', error); - throw error; - } - }; \ No newline at end of file diff --git a/src/api/communityuser_profile/get_publicview_profile.js b/src/api/communityuser_profile/get_publicview_profile.js new file mode 100644 index 0000000..7c76acc --- /dev/null +++ b/src/api/communityuser_profile/get_publicview_profile.js @@ -0,0 +1,32 @@ +export default async function fetchLimitedCommunityUserProfile(communityuserId) { + const apiUrl = import.meta.env.VITE_API_URL; + + if (!apiUrl) { + console.error("VITE_API_URL is not defined in environment variables"); + return Promise.reject(new Error("API URL is not configured")); + } + + const url = `${apiUrl}/community-users/public/${communityuserId}`; + console.log("Full API URL:", url); // Debugging + + try { + const response = await fetch(url, { + method: "GET", + headers: { + "Accept": "application/json", + "Content-Type": "application/json", + }, + }); + + if (!response.ok) { + const errorMessage = await response.text(); + throw new Error(`Server responded with ${response.status}: ${errorMessage}`); + } + + return await response.json(); + } catch (error) { + console.error("Fetch error:", { message: error.message, url }); + return Promise.reject(error); + } + } + \ No newline at end of file diff --git a/src/api/communityuser_profile/get_publicview_profiles.js b/src/api/communityuser_profile/get_publicview_profiles.js new file mode 100644 index 0000000..eb9b281 --- /dev/null +++ b/src/api/communityuser_profile/get_publicview_profiles.js @@ -0,0 +1,32 @@ +export default async function fetchLimitedCommunityUserProfiles() { + // Add debug logging for the API URL + if (!import.meta.env.VITE_API_URL) { + console.error('VITE_API_URL is not defined in environment variables'); + throw new Error('API URL is not configured'); + } + + const url = `${import.meta.env.VITE_API_URL}/community-users/public`; + console.log('Full API URL:', url); + + try { + const response = await fetch(url, { + method: "GET", + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + } + }); + + if (!response.ok) { + throw new Error(`Server responded with ${response.status}`); + } + + return await response.json(); + } catch (error) { + console.error('Fetch error:', { + message: error.message, + url: url + }); + throw error; + } + } \ No newline at end of file diff --git a/src/components/GeneralUserProfileDetails.jsx b/src/components/GeneralUserProfileDetails.jsx index d1b4280..7028019 100644 --- a/src/components/GeneralUserProfileDetails.jsx +++ b/src/components/GeneralUserProfileDetails.jsx @@ -1,110 +1,68 @@ -import React, { useState, useEffect } from 'react'; -import { useNavigate } from 'react-router-dom'; +import React, { useEffect, useState } from "react"; +import { useParams, useNavigate } from "react-router-dom"; +import fetchPublicCommunityUserProfile from "../api/communityuser_profile/get_publicview_profile"; +import fetchFullCommunityUserProfile from "../api/communityuser_profile/get_fulldetailsprofile"; -const GeneralUserProfileDetails = ({ communityuserId }) => { - const [profile, setProfile] = useState(null); +const GeneralUserProfileDetails = (props) => { + const { communityuserId } = useParams(); + const profile = props.profile; const [isAuthenticated, setIsAuthenticated] = useState(false); const [loading, setLoading] = useState(true); const navigate = useNavigate(); - useEffect(() => { - // Check authentication - const token = localStorage.getItem('token'); - if (token) { - setIsAuthenticated(true); - } + // useEffect(() => { + // // Check authentication + // const token = localStorage.getItem("token"); + // if (token) { + // setIsAuthenticated(true); + // } - // Fetch profile data based on authentication status - const fetchData = async () => { - try { - const url = isAuthenticated - ? `${import.meta.env.VITE_API_URL}/community-user/profile/${communityuserId}` - : `${import.meta.env.VITE_API_URL}/community-user/public-profile/${communityuserId}`; + // // Fetch profile data from the correct endpoint for public or authenticated user + // const fetchData = async () => { + // try { console.log(communityuserId) + // const data = isAuthenticated + // ? await fetchFullCommunityUserProfile(communityuserId) + // : await fetchPublicCommunityUserProfile(communityuserId); + // setProfile(data); + // } catch (error) { + // console.error("Error fetching profile:", error); + // } finally { + // setLoading(false); + // } + // }; - const response = await fetch(url, { - headers: token ? { - 'Authorization': `Bearer ${token}` - } : {} - }); - - if (!response.ok) { - throw new Error('Failed to fetch profile'); - } - - const data = await response.json(); - setProfile(data); - } catch (error) { - console.error('Error fetching profile:', error); - } finally { - setLoading(false); - } - }; - - fetchData(); - }, [communityuserId, isAuthenticated]); - - if (loading) return
Loading profile...
; - if (!profile) returnProfile not found.
; + // fetchData(); + // }, [communityuserId, isAuthenticated]); + // if (loading) returnLoading profile...
; + // if (!profile) returnProfile not found.
; + console.log(props.profile); return ( -Current Role: {profile.current_role}
-Industry: {profile.industry?.replace('_', ' ')}
-Location: {profile.location}
-Current Role: {profile.current_role}
+Industry: {profile.industry}
+Location: {profile.location}
{isAuthenticated ? ( -Email: {profile.email}
- {profile.phone_number && ( -Phone: {profile.phone_number}
- )} - {profile.linkedin && ( -- LinkedIn:{' '} - - View Profile - -
- )} -Skills: {profile.skills.join(', ')}
- )} - {profile.interests && profile.interests.length > 0 && ( -Interests: {profile.interests.join(', ')}
- )} -Skills: {profile.skills?.join(", ")}
+Interests: {profile.interests?.join(", ")}
+Email: {profile.email}
+ {profile.linkedin && ( ++ LinkedIn: + + View Profile + +
+ )} + > ) : ( -Loading profile...
; - if (error) returnError: {error.message}
; - if (!profile) returnNo profile found.
; + // if (isLoading) returnLoading...
; // Show loading state + // if (error) returnError: {error.message}
; // Handle errors + // if (profile) returnNo profile data found.
; // Handle empty profile + + const fakeProfile = {image: "https://sheinspire-ff5867c4dc81.herokuapp.com/role-models/public/image", first_name: "Sicilia", last_name: "Perumalsamy", current_role: "Public Health Researcher", industry: "Health", location: "Perth"} return ( + <>