Skip to content

Commit

Permalink
Merge pull request #111 from rogershi-dev/feature/registration-auth
Browse files Browse the repository at this point in the history
Updated the refreshing mechanism after successfuly webhook configurat…
  • Loading branch information
rogershi-dev authored Jul 14, 2024
2 parents 2506f25 + 83b3997 commit 2dbb168
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 38 deletions.
10 changes: 5 additions & 5 deletions server/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ router.get('/webhook/config', async (req, res) => {
}
}

// res.json({
// success: true,
// hasSetWebhook: setWebhookAlready
// });
res.redirect(`/?page=${page}&per_page=${perPage}`);
res.json({
success: true,
hasSetWebhook: setWebhookAlready
});
// res.redirect(`/?page=${page}&per_page=${perPage}`);

} catch (error) {
console.error(`Error while setting webhooks for repos via /webhook/config`, error);
Expand Down
65 changes: 32 additions & 33 deletions server/views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -203,52 +203,51 @@ block content

document.getElementById('repoActionButton').innerText = "Revoke"
// Update the href attribute of the button
document.getElementById('repoWebhookAction').href = `/webhook/config?repo=${repoName}&hassetwebhook=true&page=${currentPage}&per_page=${perPage}`;
//- document.getElementById('repoActionButton').setAttribute('onclick', `handleRepoAction('${repoName}', true)`);
//- document.getElementById('repoWebhookAction').href = `/webhook/config?repo=${repoName}&hassetwebhook=true&page=${currentPage}&per_page=${perPage}`;
document.getElementById('repoActionButton').setAttribute('onclick', `handleRepoAction('${repoName}', true, ${currentPage}, ${perPage})`);

} else {
document.getElementById('repoWebhookStatus').innerText = "You haven't set up linkedin-auto-post for the repository ";
document.getElementById('repoNameModal').innerText = repoName;
document.getElementById('repoWebhookAction').innerText = ". Do you want to set it up now?";

document.getElementById('repoActionButton').innerText = "Set Now"
document.getElementById('repoWebhookAction').href = `/webhook/config?repo=${repoName}&hassetwebhook=false&page=${currentPage}&per_page=${perPage}`;
//- document.getElementById('repoActionButton').setAttribute('onclick', `handleRepoAction('${repoName}', false)`);
//- document.getElementById('repoWebhookAction').href = `/webhook/config?repo=${repoName}&hassetwebhook=false&page=${currentPage}&per_page=${perPage}`;
document.getElementById('repoActionButton').setAttribute('onclick', `handleRepoAction('${repoName}', false, ${currentPage}, ${perPage})`);
}
//- document.getElementById('repoNameModal').innerText = repoName + " - Do you want to modify it?";
const modal = document.getElementById('repoModal');
modal.style.display = 'flex';
}

//- function handleRepoAction(repoName, hasSetWebhook) {
//- fetch(`/webhook/config?repo=${repoName}&hassetwebhook=${hasSetWebhook}`)
//- .then(response => response.json())
//- .then(data => {
//- if (data.success) {
//- //- const repoCard = document.querySelector(`.card-body[data-repo-name="${repoName}"]`);
//- //- const webhookIcon = repoCard.querySelector('.bi-check2-all');
//- //- if (hasSetWebhook) {
//- //- if (webhookIcon) webhookIcon.remove();
//- //- } else {
//- //- if (!webhookIcon) {
//- //- const icon = document.createElement('i');
//- //- icon.className = 'bi bi-check2-all';
//- //- icon.style = 'font-weight: bolder; font-size: 24px; color: green;';
//- //- repoCard.querySelector('h5.card-title').appendChild(icon);
//- //- }
//- //- }
//- //- repoCard.setAttribute('webhook-repo-status', data.hasSetWebhook);
//- const page = parseInt(currentPage) || 1;
//- const perpage = parseInt(perPage) || 15;
//- window.location.href = `/?page=${page}&per_page=${perpage}`;
//- document.getElementById('repoModal').style.display = 'none';
//- }
//- })
//- .catch(error => {
//- console.error('Error:', error);
//- document.getElementById('repoModal').style.display = 'none';
//- });
//- }
function handleRepoAction(repoName, hasSetWebhook, currentPage, perPage) {
fetch(`/webhook/config?repo=${repoName}&hassetwebhook=${hasSetWebhook}&page=${currentPage}&per_page=${perPage}`)
.then(response => response.json())
.then(data => {
if (data.success) {
//- const repoCard = document.querySelector(`.card-body[data-repo-name="${repoName}"]`);
//- const webhookIcon = repoCard.querySelector('.bi-check2-all');
//- if (hasSetWebhook) {
//- if (webhookIcon) webhookIcon.remove();
//- } else {
//- if (!webhookIcon) {
//- const icon = document.createElement('i');
//- icon.className = 'bi bi-check2-all';
//- icon.style = 'font-weight: bolder; font-size: 24px; color: green;';
//- repoCard.querySelector('h5.card-title').appendChild(icon);
//- }
//- }
//- repoCard.setAttribute('webhook-repo-status', data.hasSetWebhook);

window.location.href = `/?page=${currentPage}&per_page=${perPage}`;
document.getElementById('repoModal').style.display = 'none';
}
})
.catch(error => {
console.error('Error:', error);
document.getElementById('repoModal').style.display = 'none';
});
}

window.onclick = function(event) {
const modal = document.getElementById('repoModal');
Expand Down

0 comments on commit 2dbb168

Please sign in to comment.