Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 62 additions & 43 deletions src/components/AddCallerIdModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,90 +35,109 @@ const isValidCallerId = computed(() => {

const sendVerification = async () => {
if (!isValidCallerId.value) {
error.value = 'אנא הזן מספר טלפון תקין';
return;
error.value = 'אנא הזן מספר טלפון תקין'
return
}

loading.value = true;
error.value = '';

// ניקוי המספר
let cleanCallerId = callerId.value.replace(/\s/g, '').replace(/-/g, '');
loading.value = true
error.value = ''
const cleanCallerId = callerId.value.replace(/\s/g, '').replace(/-/g, '')

try {
const { getStoredToken } = await import('../services/api.service')
const token = getStoredToken()

console.log('[TOKEN] Value:', token) // ← בדיקה

if (!token) {
error.value = 'לא נמצא טוקן. אנא התחבר מחדש.'
console.error('[ERROR] No token found')
loading.value = false
return
}

const response = await fetch('https://www.call2all.co.il/ym/api/ValidationCallerId', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
token: `${localStorage.getItem('username')}:${localStorage.getItem('password')}`,
token,
action: 'send',
callerId: cleanCallerId,
validType: validType.value
})
});
})

const data = await response.json();
const data = await response.json()
console.log('[API RESPONSE]', data)

if (data.responseStatus === 'OK') {
reqId.value = data.reqId;
step.value = 'verification';
success.value = `קוד אימות נשלח ל${validType.value === 'SMS' ? 'הודעת SMS' : 'שיחת טלפון'} למספר ${callerId.value}`;
reqId.value = data.reqId
step.value = 'verification'
success.value = `קוד אימות נשלח ל${validType.value === 'SMS' ? 'הודעת SMS' : 'שיחת טלפון'} למספר ${callerId.value}`
} else {
error.value = data.message || 'שגיאה בשליחת קוד האימות';
error.value = data.message || 'שגיאה בשליחת קוד האימות'
}
} catch (err) {
error.value = 'שגיאה בחיבור לשרת';
console.error('Error sending verification:', err);
console.error('[FETCH ERROR]', err)
error.value = err.message.includes('fetch') ? 'אין חיבור לשרת (CORS/רשת)' : 'שגיאה בחיבור: ' + err.message
} finally {
loading.value = false;
loading.value = false
}
};
}

const verifyCode = async () => {
if (!verificationCode.value) {
error.value = 'אנא הזן את קוד האימות';
return;
error.value = 'אנא הזן את קוד האימות'
return
}

loading.value = true;
error.value = '';
loading.value = true
error.value = ''

try {
const { getStoredToken } = await import('../services/api.service')
const token = getStoredToken()

console.log('[TOKEN] Value:', token) // ← בדיקה

if (!token) {
error.value = 'לא נמצא טוקן. אנא התחבר מחדש.'
console.error('[ERROR] No token found')
loading.value = false
return
}

const response = await fetch('https://www.call2all.co.il/ym/api/ValidationCallerId', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
token: `${localStorage.getItem('username')}:${localStorage.getItem('password')}`,
token,
action: 'valid',
reId: reqId.value,
code: verificationCode.value
})
});
})

const data = await response.json();
const data = await response.json()
console.log('[API RESPONSE]', data)

if (data.responseStatus === 'OK' && data.status === true) {
step.value = 'success';
success.value = 'הזיהוי יוצא נוסף בהצלחה!';
step.value = 'success'
success.value = 'הזיהוי יוצא נוסף בהצלחה!'
setTimeout(() => {
emit('success');
closeModal();
}, 2000);
emit('success')
closeModal()
}, 2000)
} else {
error.value = data.message || 'קוד האימות שגוי';
error.value = data.message || 'קוד האימות שגוי'
}
} catch (err) {
error.value = 'שגיאה בחיבור לשרת';
console.error('Error verifying code:', err);
console.error('[FETCH ERROR]', err)
error.value = err.message.includes('fetch') ? 'אין חיבור לשרת (CORS/רשת)' : 'שגיאה בחיבור: ' + err.message
} finally {
loading.value = false;
loading.value = false
}
};

}
const closeModal = () => {
step.value = 'input';
callerId.value = '';
Expand Down Expand Up @@ -308,4 +327,4 @@ const goBack = () => {
.fade-leave-to {
opacity: 0;
}
</style>
</style>