Skip to main content

max / makenotwork

1.1 KB · 26 lines History Blame Raw
1 (function() {
2 var cfg = document.getElementById('tab-project-code-cfg');
3 var projectId = cfg.dataset.projectId;
4 var projectSlug = cfg.dataset.projectSlug;
5 var btn = document.getElementById('link-repo-btn');
6 var sel = document.getElementById('link-repo-select');
7 if (!btn || !sel) return;
8 btn.addEventListener('click', function() {
9 var name = sel.value;
10 if (!name) return;
11 fetch('/api/projects/' + projectId + '/repos', {
12 method: 'POST',
13 headers: {'Content-Type': 'application/json', ...csrfHeaders()},
14 body: JSON.stringify({name: name})
15 }).then(function() {
16 htmx.ajax('GET', '/dashboard/project/' + projectSlug + '/tabs/code', {target: '#tab-content', swap: 'innerHTML'});
17 }).catch(function() {
18 var status = document.getElementById('create-repo-status');
19 if (status) {
20 status.textContent = 'Failed to link repository. Please try again.';
21 status.classList.add('is-error');
22 }
23 });
24 });
25 })();
26