Merge pull request #31 from coracle-social/master

Bring back sendPostRequest
This commit is contained in:
Pablo Fernandez 2024-02-15 13:04:49 +00:00 committed by GitHub
commit 24eb27a949
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,6 +31,51 @@
}
}
}
function sendPostRequest(permissions) {
const url = '/requests/{{record.id}}';
const password = document.getElementById('password').value;
let callbackUrl;
{{#if callbackUrl}}
callbackUrl = '{{callbackUrl}}';
{{/if}}
const data = {
permissions,
password,
};
fetch(url, {
method: 'POST', // or 'PUT'
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then((response) => response.json())
.then((data) => {
console.log('Success:', data);
if (data.error) {
document.getElementById('error').innerText = data.error;
document.getElementById('error').classList.remove('hidden');
return;
}
// hide main content and show close message
document.getElementById('main').classList.add('hidden');
document.getElementById('closeit').classList.remove('hidden');
// redirect to callback url
if (callbackUrl) {
const url = new URL(callbackUrl);
url.searchParams.append('pubkey', data.pubkey);
window.location.href = url.toString();
}
})
.catch((error) => {
console.error('Error:', error);
});
}
</script>
<style>
body {
@ -107,4 +152,4 @@
}
</script>
</body>
</html>
</html>