-
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.
delete users on admin page is working. Had to add a new collection in…
… firebase database
- Loading branch information
Showing
8 changed files
with
151 additions
and
23 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
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 |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
color: black; | ||
} |
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 |
---|---|---|
@@ -1,15 +1,63 @@ | ||
// Code: src/pages/administration/Administration.jsx | ||
// src/pages/administration/Administration.jsx | ||
|
||
import { useEffect, useState } from 'react'; | ||
import { firestore } from '../../firebaseConfig'; | ||
import { collection, getDocs, deleteDoc, doc } from 'firebase/firestore'; | ||
|
||
const Administration = () => { | ||
const [users, setUsers] = useState([]); | ||
const [loading, setLoading] = useState(true); | ||
|
||
useEffect(() => { | ||
const fetchUsers = async () => { | ||
try { | ||
const querySnapshot = await getDocs(collection(firestore, 'users')); | ||
const userList = querySnapshot.docs.map((doc) => ({ | ||
id: doc.id, | ||
...doc.data(), | ||
})); | ||
setUsers(userList); | ||
} catch (error) { | ||
console.error('Error fetching users:', error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
fetchUsers(); | ||
}, []); | ||
|
||
const handleDelete = async (userId) => { | ||
try { | ||
await deleteDoc(doc(firestore, 'users', userId)); | ||
setUsers(users.filter((user) => user.id !== userId)); | ||
alert("User deleted successfully."); | ||
} catch (error) { | ||
console.error('Error deleting user:', error); | ||
alert("Failed to delete user."); | ||
} | ||
}; | ||
|
||
if (loading) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
return ( | ||
<div> | ||
<h2>Administration Page</h2> | ||
<p>Welcome to the administration area. You are successfully logged in!</p> | ||
{/* Her kan du legge til annet innhold for administrasjon */} | ||
<h2>User Management</h2> | ||
{users.length > 0 ? ( | ||
<ul> | ||
{users.map((user) => ( | ||
<li key={user.id}> | ||
{user.name} - {user.email} | ||
<button onClick={() => handleDelete(user.id)}>Delete</button> | ||
</li> | ||
))} | ||
</ul> | ||
) : ( | ||
<p>No users found.</p> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Administration; | ||
|
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,32 @@ | ||
.admin-page { | ||
padding: 20px; | ||
} | ||
|
||
table { | ||
width: 100%; | ||
border-collapse: collapse; | ||
} | ||
|
||
th, td { | ||
padding: 10px; | ||
text-align: left; | ||
border: 1px solid #ddd; | ||
} | ||
|
||
th { | ||
background-color: #f4f4f4; | ||
} | ||
|
||
.delete-button { | ||
background-color: #ff4d4f; | ||
color: white; | ||
border: none; | ||
padding: 5px 10px; | ||
cursor: pointer; | ||
border-radius: 3px; | ||
} | ||
|
||
.delete-button:hover { | ||
background-color: #d9534f; | ||
} | ||
|
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
const Home = () => { | ||
return ( | ||
<div>Home</div> | ||
<div>Homenjnjk</div> | ||
) | ||
} | ||
|
||
|