AppFlowy-Cloud/admin_frontend/templates/components/admin_user_details.html

93 lines
3.1 KiB
HTML

<div>
{% include "user_details.html" %}
<div id="admin-controls">
<div id="admin-controls-password">
<button id="setPasswordBtn">Set Password</button>
<div id="passwordModal" style="display: none">
<label for="newPassword">New Password:</label>
<input type="password" id="newPassword" name="newPassword" />
<button id="submitPasswordBtn">Submit</button>
<button id="closePasswordModalBtn">Close</button>
</div>
</div>
<div id="admin-controls-generate-link">
<button id="generateInviteLinkBtn">Generate Invite Link</button>
<textarea id="inviteLink" readonly style="display: none"></textarea>
<button id="copyInviteLinkBtn" style="display: none">Copy Link</button>
</div>
</div>
<script>
// Set password button
document
.getElementById("setPasswordBtn")
.addEventListener("click", function () {
document.getElementById("passwordModal").style.display = "block";
});
document
.getElementById("closePasswordModalBtn")
.addEventListener("click", function () {
document.getElementById("passwordModal").style.display = "none";
});
document
.getElementById("submitPasswordBtn")
.addEventListener("click", function () {
const newPassword = document.getElementById("newPassword").value;
const user_uuid = "{{ user.id|escape }}";
fetch(`/web-api/admin/user/${user_uuid}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
password: newPassword,
}),
}).then((response) => {
if (!response.ok) {
displayHttpStatusAndPayload(response);
} else {
displaySuccess("Password set successfully!");
document.getElementById("passwordModal").style.display = "none";
}
});
});
// Generate invite link button
document
.getElementById("generateInviteLinkBtn")
.addEventListener("click", function () {
const userEmail = encodeURIComponent("{{ user.email|escape }}");
fetch(`/web-api/admin/user/${userEmail}/generate-link`, {
method: "POST",
}).then((response) => {
if (!response.ok) {
displayHttpStatusAndPayload(response);
} else {
response.json().then((data) => {
const inviteLink = data.data.action_link;
document.getElementById("inviteLink").style.display = "block";
document.getElementById("inviteLink").value = inviteLink;
document.getElementById("copyInviteLinkBtn").style.display =
"block";
});
}
});
});
document
.getElementById("copyInviteLinkBtn")
.addEventListener("click", function () {
const textarea = document.getElementById("inviteLink");
// Select the link text
textarea.select();
// Copy it to the clipboard
document.execCommand("copy");
displaySuccess("Copied invite link to clipboard!");
});
</script>
</div>