Files
kaunter/public/js/notification.js
T
2024-11-04 01:18:29 +08:00

76 lines
1.8 KiB
JavaScript
Vendored

import NotifyKhazanah from './Class/SubscribePusher.js';
let channel = 'notify-deposit';
let event = 'deposit-event';
let apikey = "{{ env('PUSHER_APP_KEY') }}";
let api = "{{ config('api.url') }}";
let kodcaw = "{{ Auth::user()->kodcaw }}";
let requestApi = (url, method, datarequest, callback) => {
$.ajax({
method: method,
url: url,
data: datarequest,
success: function(data) {
callback(data);
},
error: function(xhRequest, ajaxOptions, thrownError) {
console.error("Request failed:", xhRequest, thrownError);
}
});
};
let triggerPage = () =>{
const notify = new NotifyKhazanah(channel,event,apikey);
notify.channel_subscribe((data) => {
console.log(data);
const currentPath = window.location.pathname;
if (currentPath === "/home") {
notify_main();
} else if (currentPath === "/menu") {
notify_khazanah_main();
}else if(currentPath === '/pendahuluan'){
notify_pendahuluan();
}else if(currentPath === '/serahan'){
notify_serahan();
}
});
}
let notify_main = () =>{
const button = document.getElementById("btn-khazanah");
if(!button){
return;
}
button.classList.add('btn-danger');
button.classList.add('heartbeat');
}
let notify_khazanah_main = () =>{
requestApi(api + '/api/requestTeller/get/' + kodcaw,"GET",{}, (response) =>{
let countModal = 0;
let countSerahan = 0;
response.forEach((req) => {
if (req.modal !== 0) {
countModal++;
} else if (req.serahan !== 0) {
countSerahan++;
}
});
});
}
let notify_pendahuluan = () =>{
}
let notify_serahan = () =>{
}