-
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.
- Loading branch information
Hanna
committed
Nov 14, 2024
1 parent
4b517ea
commit edad9c5
Showing
5 changed files
with
81 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// admin.js | ||
async function fetchPendingReviews() { | ||
try { | ||
const response = await fetch('/api/reviews/pending'); // Запит на отримання несхвалених відгуків | ||
const reviews = await response.json(); | ||
|
||
const reviewsContainer = document.getElementById('reviewsContainer'); | ||
reviewsContainer.innerHTML = ''; // Очищуємо контейнер перед додаванням відгуків | ||
|
||
reviews.forEach(review => { | ||
const reviewElement = document.createElement('div'); | ||
reviewElement.classList.add('review'); | ||
reviewElement.innerHTML = ` | ||
<p><strong>Ім'я:</strong> ${review.name}</p> | ||
<p><strong>Відгук:</strong> ${review.text}</p> | ||
<button onclick="approveReview('${review.id}')">Схвалити</button> | ||
`; | ||
reviewsContainer.appendChild(reviewElement); | ||
}); | ||
} catch (error) { | ||
console.error('Помилка завантаження відгуків:', error); | ||
} | ||
} | ||
|
||
async function approveReview(reviewId) { | ||
try { | ||
const response = await fetch(`/api/reviews/approve/${reviewId}`, { | ||
method: 'PATCH', | ||
}); | ||
|
||
if (response.ok) { | ||
alert('Відгук схвалено!'); | ||
fetchPendingReviews(); // Оновлюємо список відгуків після схвалення | ||
} else { | ||
console.error('Помилка схвалення відгуку:', response.statusText); | ||
} | ||
} catch (error) { | ||
console.error('Помилка схвалення відгуку:', error); | ||
} | ||
} | ||
|
||
// Завантажуємо відгуки при завантаженні сторінки | ||
document.addEventListener('DOMContentLoaded', fetchPendingReviews); |
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