fix: [sms] API URL을 Blade route() 헬퍼로 변경 및 에러 상세 표시
- 하드코딩 URL → route() 기반으로 환경별 자동 대응 - 422 에러 시 validation 에러 메시지 상세 표시
This commit is contained in:
@@ -106,6 +106,11 @@
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
const SMS_API = {
|
||||
send: '{{ route('api.admin.barobill.sms.send') }}',
|
||||
fromNumbers: '{{ route('api.admin.barobill.sms.from-numbers') }}',
|
||||
sendState: '{{ route('api.admin.barobill.sms.send-state', ['sendKey' => '__KEY__']) }}',
|
||||
};
|
||||
function fillTestData() {
|
||||
document.querySelector('input[name="to_name"]').value = '김보곤';
|
||||
document.querySelector('input[name="to_number"]').value = '01051238210';
|
||||
@@ -146,7 +151,7 @@ function loadFromNumbers() {
|
||||
|
||||
area.innerHTML = '<div class="flex items-center gap-2 text-sm text-gray-500"><svg class="w-4 h-4 animate-spin" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"></path></svg> 발신번호 목록 로딩 중...</div>';
|
||||
|
||||
fetch('/api/admin/barobill/sms/from-numbers', {
|
||||
fetch(SMS_API.fromNumbers, {
|
||||
headers: { 'Accept': 'application/json', 'X-Requested-With': 'XMLHttpRequest' }
|
||||
})
|
||||
.then(r => r.json())
|
||||
@@ -227,7 +232,7 @@ function checkSendState(sendKey) {
|
||||
const stateArea = document.getElementById('send-state-result');
|
||||
stateArea.innerHTML = '<div class="text-sm text-gray-500">상태 조회 중...</div>';
|
||||
|
||||
fetch('/api/admin/barobill/sms/send-state/' + encodeURIComponent(sendKey), {
|
||||
fetch(SMS_API.sendState.replace('__KEY__', encodeURIComponent(sendKey)), {
|
||||
headers: { 'Accept': 'application/json', 'X-Requested-With': 'XMLHttpRequest' }
|
||||
})
|
||||
.then(r => r.json())
|
||||
@@ -270,7 +275,7 @@ function checkSendState(sendKey) {
|
||||
btn.disabled = true;
|
||||
btn.textContent = '발송 중...';
|
||||
|
||||
fetch('/api/admin/barobill/sms/send', {
|
||||
fetch(SMS_API.send, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -280,7 +285,14 @@ function checkSendState(sendKey) {
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(async r => {
|
||||
const data = await r.json();
|
||||
if (!r.ok && data.errors) {
|
||||
data.success = false;
|
||||
data.error = Object.values(data.errors).flat().join('\n');
|
||||
}
|
||||
return data;
|
||||
})
|
||||
.then(data => {
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = '<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 19l9 2-9-18-9 18 9-2zm0 0v-8" /></svg> SMS 발송';
|
||||
|
||||
Reference in New Issue
Block a user