Skip to content

Commit

Permalink
Merge pull request #107 from rogershi-dev/feature/registration-auth
Browse files Browse the repository at this point in the history
Restructured refreshing mechanism after successful webhook configurat…
  • Loading branch information
rogershi-dev authored Jul 14, 2024
2 parents 47d8c1d + 8002cf6 commit c236746
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
13 changes: 9 additions & 4 deletions server/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ router.get('/', async function(req, res, next) {

router.get('/webhook/config', async (req, res) => {
const { repo, hassetwebhook} = req.query;
const page = parseInt(req.query.page) || 1;
const perPage = parseInt(req.query.per_page) || 15;


try {
const githubUsername = req.session.user[0].github_username;
const githubToken = req.session.user[0].github_token;
Expand Down Expand Up @@ -105,10 +109,11 @@ router.get('/webhook/config', async (req, res) => {
}
}

res.json({
success: true,
hasSetWebhook: setWebhookAlready
});
// 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
11 changes: 7 additions & 4 deletions server/views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -195,24 +195,27 @@ block content
function showModal(event) {
const repoName = event.currentTarget.getAttribute('data-repo-name');
const hasSetWebhook = event.currentTarget.getAttribute('webhook-repo-status');
const currentPage = currentPage || 1;
const perPage = perPage || 15;

if(hasSetWebhook != null) {
document.getElementById('repoWebhookStatus').innerText = "You've already set up linkedin-auto-post for the repository ";
document.getElementById('repoNameModal').innerText = repoName;
document.getElementById('repoWebhookAction').innerText = ". Do you want to revoke it?";

document.getElementById('repoActionButton').innerText = "Revoke"
// Update the href attribute of the button
//- document.getElementById('repoWebhookAction').href = `/webhook/config?repo=${repoName}&hassetwebhook=true`;
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)`);

} 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`;
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)`);
}
//- document.getElementById('repoNameModal').innerText = repoName + " - Do you want to modify it?";
const modal = document.getElementById('repoModal');
Expand Down

0 comments on commit c236746

Please sign in to comment.