|
806 | 806 | function closeConfirmModal() { |
807 | 807 | document.getElementById('confirmModal').style.display = 'none'; |
808 | 808 | document.getElementById('confirmModal').removeAttribute('data-review-only'); |
| 809 | + document.getElementById('confirmModal').removeAttribute('data-review-edit'); |
809 | 810 | } |
810 | 811 |
|
811 | 812 | function onBackdropClick(e) { if (e.target === document.getElementById('confirmModal')) closeConfirmModal(); } |
|
816 | 817 | btnOnly.style.display = ''; btnOnly.disabled = false; btnOnly.textContent = '후기 없이 멘토링 종료하기'; |
817 | 818 | btnReview.disabled = false; btnReview.textContent = '멘토링 종료 및 정산 완료'; |
818 | 819 | document.getElementById('confirmModal').removeAttribute('data-review-only'); |
| 820 | + document.getElementById('confirmModal').removeAttribute('data-review-edit'); |
819 | 821 | } |
820 | 822 |
|
821 | 823 | function updateStars(val) { |
|
832 | 834 |
|
833 | 835 | function doSettle(withReview) { |
834 | 836 | const isReviewOnly = document.getElementById('confirmModal').getAttribute('data-review-only') === 'true'; |
| 837 | + const isReviewEdit = document.getElementById('confirmModal').getAttribute('data-review-edit') === 'true'; |
835 | 838 | if (withReview && selectedRating === 0) { alert('별점을 선택해 주세요.'); return; } |
836 | 839 | const btnOnly = document.getElementById('btnSettleOnly'); |
837 | 840 | const btnReview = document.getElementById('btnSettleReview'); |
|
844 | 847 | const chain = withReview |
845 | 848 | ? settlePromise.then(function() { |
846 | 849 | return fetch('/orders/' + orderId + '/feedback', { |
847 | | - method: 'POST', headers: { 'Content-Type': 'application/json' }, |
| 850 | + method: (isReviewOnly && isReviewEdit) ? 'PATCH' : 'POST', |
| 851 | + headers: { 'Content-Type': 'application/json' }, |
848 | 852 | body: JSON.stringify({ orderId: orderId, rating: selectedRating, comment: comment || null }) |
849 | 853 | }).then(function(r) { if (!r.ok) throw new Error('review'); }); |
850 | 854 | }) |
|
1001 | 1005 | // query param으로 진입 시 후기 모달 자동 오픈 |
1002 | 1006 | const openReviewOnlyModalOnLoad = /*[[${openReviewOnlyModal}]]*/ false; |
1003 | 1007 | if (openReviewOnlyModalOnLoad) { |
1004 | | - try { openReviewOnlyModal(); } catch (e) {} |
| 1008 | + try { |
| 1009 | + openReviewOnlyModal(); |
| 1010 | + const hasReviewOnLoad = /*[[${workspace.hasReview}]]*/ false; |
| 1011 | + if (hasReviewOnLoad) { |
| 1012 | + fetch('/orders/' + orderId + '/feedback', { method: 'GET', headers: { 'Accept': 'application/json' } }) |
| 1013 | + .then(function(r) { if (!r.ok) throw new Error('fetch'); return r.json(); }) |
| 1014 | + .then(function(data) { |
| 1015 | + selectedRating = parseInt(data.rating || 0); |
| 1016 | + updateStars(selectedRating); |
| 1017 | + document.getElementById('commentInput').value = (data.comment || ''); |
| 1018 | + document.getElementById('confirmModal').setAttribute('data-review-edit', 'true'); |
| 1019 | + document.getElementById('btnSettleReview').textContent = '후기 수정하기'; |
| 1020 | + }) |
| 1021 | + .catch(function() { /* ignore */ }); |
| 1022 | + } |
| 1023 | + } catch (e) {} |
1005 | 1024 | } |
1006 | 1025 | </script> |
1007 | 1026 | </th:block> |
|
0 commit comments