Skip to content

Commit

Permalink
Merge pull request #51 from als904204/feat/topic-suggest-approve-page
Browse files Browse the repository at this point in the history
feat/토픽 문의 승인 요청 페이지
  • Loading branch information
als904204 authored Nov 6, 2024
2 parents 759cfa8 + 7ce2d15 commit d3872ce
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
39 changes: 38 additions & 1 deletion src/main/resources/static/js/admin/suggest-detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ document.addEventListener('DOMContentLoaded', () => {
const suggestId = getSuggestIdFromURL();
if (suggestId) {
loadSuggestDetail(suggestId);
approvedBtn(suggestId);
} else {
alert('유효한 토픽 문의 ID가 없습니다.');
}
Expand All @@ -18,7 +19,7 @@ function getSuggestIdFromURL() {

// 문의 정보를 로드하고 화면에 표시하는 함수
function loadSuggestDetail(id) {
fetch(`/api/v1/admin/topic_suggests/${id}`)
fetch(`/api/v1/admin/topic-suggests/${id}`)
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
Expand Down Expand Up @@ -57,6 +58,42 @@ function renderSuggestDetail(suggest) {
});
}

function approvedBtn(suggestId) {
const approvedBtn = document.getElementById('approvedBtn');
approvedBtn.addEventListener('click', () => {
const isConfirmed = confirm('정말로 승인하시겠습니까?');
if (isConfirmed) {
fetch(`/api/v1/admin/topic-suggests/${suggestId}`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ status: 'APPROVED' })
})
.then(response => {
if(!response.ok) {
throw new Error('승인 처리 중 오류가 발생했습니다.');
}
return response.json();
})
.then(data => {
alert('성공적으로 승인되었습니다.');
window.location.reload();
})
.catch(error => {
console.error('Error:', error);
alert('승인 처리 중 오류가 발생했습니다.');
});
}
});
}

function rejectedBtn() {
}




function updateStatusBadgeColor(element, status) {
element.classList.remove('bg-primary', 'bg-success', 'bg-warning', 'bg-danger');

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/js/admin/suggest-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ document.addEventListener('DOMContentLoaded', () => {
});

function loadSuggestList() {
fetch('/api/v1/admin/topic_suggests')
fetch('/api/v1/admin/topic-suggests')
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/js/suggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function sendForm() {

submitBtn.disabled = true;

fetch('/api/v1/topic_suggests', {
fetch('/api/v1/topic-suggests', {
method: 'POST',
body: formData
})
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/templates/admin/suggest-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ <h4 class="section-title">선택지 이미지</h4>
<!-- Images will be dynamically added here -->
</div>
</section>

<div class="text-center">
<button type="button" class="btn btn-success" id="approvedBtn">승인</button>
<button type="button" class="btn btn-danger" id="rejectedBtn">거절</button>
</div>
</div>

<a href="/admin/settings" class="btn btn-primary back-button">
Expand Down

0 comments on commit d3872ce

Please sign in to comment.