AppFlowy-Cloud/admin_frontend/templates/user_details.html

122 lines
4.3 KiB
HTML

<!doctype html>
<html lang="en">
<body>
<a href="/web/admin/users">Back to User List</a>
<h1>User Detail</h1>
<h2>{{ user.email|escape }}</h2>
<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>
<br />
<br />
<button id="generateInviteLinkBtn">Generate Invite Link</button>
<textarea id="inviteLink" readonly style="display: none"></textarea>
<button id="copyInviteLinkBtn" style="display: none">Copy Link</button>
<br />
<br />
<p>Phone: {{ user.phone|escape }}</p>
<p>Email Confirmed At: {{ user.email_confirmed_at|default("-") }}</p>
<p>Phone Confirmed At: {{ user.phone_confirmed_at|default("-")|escape }}</p>
<p>Last Sign In At: {{ user.last_sign_in_at|default("-")|escape }}</p>
<p>Created At: {{ user.created_at|escape }}</p>
<p>Updated At: {{ user.updated_at|escape }}</p>
<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;
let confirmed = confirm("Set new password?");
if (confirmed && newPassword) {
const user_uuid = "{{ user.id|escape }}";
fetch(`/web-api/user/${user_uuid}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: "{{ user.email|escape }}",
password: newPassword,
}),
})
.then((response) => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
})
.then((data) => {
alert("Password set successfully!");
document.getElementById("passwordModal").style.display = "none";
})
.catch((error) => {
console.error("Error setting password:", error);
alert("Failed to set password. Please try again later.");
});
}
});
// Generate invite link button
document
.getElementById("generateInviteLinkBtn")
.addEventListener("click", function () {
const userEmail = encodeURIComponent("{{ user.email|escape }}");
fetch(`/web-api/user/${userEmail}/generate-link`, {
method: "POST",
})
.then((response) => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
return 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";
})
.catch((error) => {
console.error("Error generating invite link:", error);
alert("Failed to generate invite link. Please try again later.");
});
});
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");
// Optionally: Inform the user
alert("Invite link copied to clipboard!");
});
</script>
</body>
</html>