implement ssr modal dialog for index and account
This commit is contained in:
@@ -1,24 +1,18 @@
|
||||
import { dialog } from "./dialog.js";
|
||||
import { requestAPI, setAppearance } from "./utils.js";
|
||||
import "./dialog.js";
|
||||
|
||||
window.addEventListener("DOMContentLoaded", init);
|
||||
|
||||
async function init () {
|
||||
setAppearance();
|
||||
|
||||
document.querySelector("#change-password").addEventListener("click", handlePasswordChangeForm);
|
||||
initPasswordChangeForm();
|
||||
document.querySelector("#change-password").addEventListener("click", handlePasswordChangeButton);
|
||||
}
|
||||
|
||||
function handlePasswordChangeForm () {
|
||||
const body = `
|
||||
<form method="dialog" class="input-grid" style="grid-template-columns: auto 1fr;" id="form">
|
||||
<label for="new-password">New Password</label>
|
||||
<input class="w3-input w3-border" id="new-password" name="new-password" type="password"required>
|
||||
<label for="confirm-password">Confirm Password</label>
|
||||
<input class="w3-input w3-border" id="confirm-password" name="confirm-password" type="password" required>
|
||||
</form>
|
||||
`;
|
||||
const d = dialog("Change Password", body, async (result, form) => {
|
||||
function initPasswordChangeForm () {
|
||||
const d = document.querySelector("#change-password-dialog");
|
||||
d.setOnClose(async (result, form) => {
|
||||
if (result === "confirm") {
|
||||
const result = await requestAPI("/access/password", "POST", { password: form.get("new-password") });
|
||||
if (result.status !== 200) {
|
||||
@@ -37,3 +31,8 @@ function handlePasswordChangeForm () {
|
||||
password.addEventListener("change", validatePassword);
|
||||
confirmPassword.addEventListener("keyup", validatePassword);
|
||||
}
|
||||
|
||||
function handlePasswordChangeButton () {
|
||||
const d = document.querySelector("#change-password-dialog");
|
||||
d.showModal();
|
||||
}
|
||||
|
Reference in New Issue
Block a user