Commit a7ed0a92 authored by Tomas Vaagen Gule's avatar Tomas Vaagen Gule
Browse files

#8 Make it possible to change personal information

parent 306b11be
Pipeline #162208 passed with stages
in 1 minute and 47 seconds
......@@ -100,6 +100,22 @@
required
/>
</div>
<!-- form-group// -->
<div class="d-grid">
<input
type="button"
class="btn btn-primary"
id="btn-edit-account"
value=" Edit "
/>
<input
type="button"
class="btn btn-primary hide"
id="btn-confirm-changes"
value=" Confirm changes "
/>
</div>
<!-- form-group// -->
</form>
</div>
......
getCurrentUser().then((user) => {
console.log(user);
let input = document.querySelector("#username");
input.value = user.username;
input.disabled = true;
input = document.querySelector("#email");
input.value = user.email;
input.disabled = true;
input = document.querySelector("#phone_number");
input.value = user.phone_number;
input.disabled = true;
input = document.querySelector("#country");
input.value = user.country;
input.disabled = true;
input = document.querySelector("#city");
input.value = user.city;
input.disabled = true;
input = document.querySelector("#street_address");
input.value = user.street_address;
input.disabled = true;
async function setUser() {
getCurrentUser().then((user) => {
console.log(user);
let input = document.querySelector("#username");
input.value = user.username;
input.disabled = true;
input = document.querySelector("#email");
input.value = user.email;
input.disabled = true;
input = document.querySelector("#phone_number");
input.value = user.phone_number;
input.disabled = true;
input = document.querySelector("#country");
input.value = user.country;
input.disabled = true;
input = document.querySelector("#city");
input.value = user.city;
input.disabled = true;
input = document.querySelector("#street_address");
input.value = user.street_address;
input.disabled = true;
});
}
function handleChangesButton() {
btnEditAccount = document.querySelector("#btn-edit-account");
btnConfirmChanges = document.querySelector("#btn-confirm-changes");
btnConfirmChanges.className += " hide";
btnEditAccount.className = btnEditAccount.className.replace(" hide", "");
setReadOnly(true, "#form-register-user");
document.querySelector("#username").readOnly = true;
console.log("Test");
createNewUser();
}
function handleEditButton() {
btnEditAccount = document.querySelector("#btn-edit-account");
btnConfirmChanges = document.querySelector("#btn-confirm-changes");
btnEditAccount.className += " hide";
btnConfirmChanges.className = btnConfirmChanges.className.replace(
" hide",
""
);
setReadOnly(false, "#form-register-user");
document.querySelector("#username").readOnly = true;
}
async function createNewUser() {
console.log("Test");
let form = document.querySelector("#form-register-user");
let formData = new FormData(form);
let body = {
username: formData.get("username"),
phone_number: formData.get("phone_number"),
country: formData.get("country"),
city: formData.get("city"),
street_address: formData.get("street_address"),
};
user = await getCurrentUser();
response = await sendRequest("PATCH", `${HOST}/api/users/${user.id}/`, body);
if (response.ok) {
} else {
}
window.location.replace("mypage.html");
}
window.addEventListener("DOMContentLoaded", async () => {
setUser();
btnEditAccount = document.querySelector("#btn-edit-account");
btnEditAccount.addEventListener("click", handleEditButton);
btnConfirmChanges = document.querySelector("#btn-confirm-changes");
btnConfirmChanges.addEventListener("click", handleChangesButton);
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment