-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
so far content shows up on profilepage
- Loading branch information
Showing
22 changed files
with
481 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// src/component/profile/Profile.jsx | ||
import useProfile from '../../hooks/useProfile'; | ||
|
||
const Profile = () => { | ||
const { profileData, loading } = useProfile(); | ||
|
||
if (loading) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
if (!profileData) { | ||
return <div>No profile data found.</div>; | ||
} | ||
|
||
return ( | ||
<div> | ||
<h1>Your Profile</h1> | ||
<p>Name: {profileData.name}</p> | ||
<p>Email: {profileData.email}</p> | ||
<p>City: {profileData.city}</p> | ||
<p>Country: {profileData.country}</p> | ||
<p>hh: {profileData.address}</p> | ||
{/* Legg til flere felt etter behov */} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Profile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
const ProfileForm = ({ profileData, setProfileData, isEditing, setIsEditing, uploadProfileImage }) => { | ||
return ( | ||
<form> | ||
<div> | ||
<label>Name:</label> | ||
<input | ||
type="text" | ||
value={profileData.name} | ||
onChange={(e) => setProfileData({ ...profileData, name: e.target.value })} | ||
disabled={!isEditing} | ||
/> | ||
</div> | ||
{/* ... andre input-felter ... */} | ||
<div> | ||
<label>Profile Image:</label> | ||
<input | ||
type="file" | ||
accept="image/*" | ||
onChange={(e) => uploadProfileImage(e.target.files[0])} // Kall uploadProfileImage her | ||
disabled={!isEditing} | ||
/> | ||
</div> | ||
<button type="button" onClick={() => setIsEditing(true)}>Edit</button> | ||
</form> | ||
); | ||
}; | ||
|
||
ProfileForm.propTypes = { | ||
profileData: PropTypes.object.isRequired, | ||
setProfileData: PropTypes.func.isRequired, | ||
isEditing: PropTypes.bool.isRequired, | ||
setIsEditing: PropTypes.func.isRequired, | ||
uploadProfileImage: PropTypes.func.isRequired, // Sørg for at denne er inkludert | ||
}; | ||
|
||
export default ProfileForm; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* ProfileForm.css */ | ||
|
||
.profile-form-container { | ||
background-color: #f8f9fa; | ||
border-radius: 8px; | ||
padding: 20px; | ||
max-width: 600px; | ||
margin: auto; | ||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); | ||
|
||
|
||
.profile-header { | ||
text-align: center; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.profile-header h2 { | ||
margin: 10px 0 5px; | ||
font-size: 24px; | ||
} | ||
|
||
.profile-header h3 { | ||
margin: 0; | ||
font-size: 16px; | ||
color: #666; | ||
} | ||
|
||
.profile-image { | ||
width: 100px; | ||
height: 100px; | ||
border-radius: 50%; | ||
object-fit: cover; | ||
margin-bottom: 15px; | ||
} | ||
|
||
.profile-form { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.input-group { | ||
margin-bottom: 15px; | ||
} | ||
|
||
.input-group label { | ||
margin-bottom: 5px; | ||
font-weight: bold; | ||
color: #333; | ||
} | ||
|
||
.input-group input { | ||
padding: 10px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
font-size: 16px; | ||
} | ||
|
||
.input-group input:focus { | ||
border-color: #007bff; | ||
outline: none; | ||
} | ||
|
||
.action-button, .save-button { | ||
padding: 10px; | ||
border: none; | ||
border-radius: 5px; | ||
background-color: #007bff; | ||
color: white; | ||
font-size: 16px; | ||
cursor: pointer; | ||
margin-top: 10px; | ||
} | ||
|
||
.action-button:hover, .save-button:hover { | ||
background-color: #0056b3; | ||
} | ||
|
||
/* Responsiv design */ | ||
@media (max-width: 600px) { | ||
.profile-form-container { | ||
padding: 10px; | ||
} | ||
|
||
.profile-image { | ||
width: 80px; | ||
height: 80px; | ||
} | ||
|
||
.action-button, .save-button { | ||
width: 100%; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// src/hooks/useAuth.js | ||
import { useState, useEffect } from 'react'; | ||
import { auth } from '../utils/firebaseConfig'; | ||
import { updateEmail, updatePassword, onAuthStateChanged } from 'firebase/auth'; | ||
|
||
const useAuth = () => { | ||
const [currentUser, setCurrentUser] = useState(null); | ||
|
||
useEffect(() => { | ||
const unsubscribe = onAuthStateChanged(auth, (user) => { | ||
console.log("User state changed:", user); // Logg brukerstatusendringer | ||
setCurrentUser(user); // Oppdaterer currentUser når autentiseringstilstanden endres | ||
}); | ||
|
||
return () => unsubscribe(); // Rydder opp abonnementet når komponenten avmonteres | ||
}, []); | ||
|
||
const updateUserEmail = async (newEmail) => { | ||
if (newEmail !== auth.currentUser.email) { | ||
await updateEmail(auth.currentUser, newEmail); | ||
console.log("User email updated to:", newEmail); // Logg når e-post oppdateres | ||
} | ||
}; | ||
|
||
const updateUserPassword = async (newPassword) => { | ||
if (newPassword) { | ||
await updatePassword(auth.currentUser, newPassword); | ||
console.log("User password updated."); // Logg når passord oppdateres | ||
} | ||
}; | ||
|
||
return { | ||
currentUser, // Returner currentUser for bruk i komponentene | ||
updateUserEmail, | ||
updateUserPassword, | ||
}; | ||
}; | ||
|
||
export default useAuth; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// src/hooks/useProfile.js | ||
import { useState, useEffect } from 'react'; | ||
import { firestore } from '../utils/firebaseConfig'; | ||
import { doc, getDoc } from 'firebase/firestore'; | ||
import useAuth from './useAuth'; | ||
|
||
const useProfile = () => { | ||
const [profileData, setProfileData] = useState(null); | ||
const [loading, setLoading] = useState(true); | ||
const { currentUser } = useAuth(); | ||
|
||
useEffect(() => { | ||
const fetchProfileData = async () => { | ||
if (!currentUser) { | ||
console.log("No current user found, setting loading to false."); // Logging if no user is found | ||
setLoading(false); | ||
return; | ||
} | ||
|
||
console.log("Current User UID:", currentUser.uid); // Logg UID-en her | ||
|
||
try { | ||
const userDocRef = doc(firestore, 'users', currentUser.uid); | ||
const userDoc = await getDoc(userDocRef); | ||
|
||
if (userDoc.exists()) { | ||
setProfileData(userDoc.data()); | ||
console.log("Profile data loaded:", userDoc.data()); // Logg profildata ved henting | ||
} else { | ||
console.error("User document does not exist."); | ||
} | ||
} catch (error) { | ||
console.error("Error fetching user profile:", error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
fetchProfileData(); | ||
}, [currentUser]); | ||
|
||
return { profileData, loading }; | ||
}; | ||
|
||
export default useProfile; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
Oops, something went wrong.