Populating the user form
This commit is contained in:
parent
b183e7bf43
commit
591525e97f
@ -20,6 +20,7 @@ type templateData struct {
|
||||
API string
|
||||
CSSVersion string
|
||||
IsAuthenticated int
|
||||
UserID int
|
||||
StripeSecretKey string
|
||||
StripePubKey string
|
||||
}
|
||||
@ -43,6 +44,7 @@ func (app *application) addDefaultData(td *templateData, r *http.Request) *templ
|
||||
|
||||
if app.Session.Exists(r.Context(), "userID") {
|
||||
td.IsAuthenticated = 1
|
||||
td.UserID = app.Session.GetInt(r.Context(), "userID")
|
||||
} else {
|
||||
td.IsAuthenticated = 0
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ Admin User
|
||||
<label for="first_name" class="form-label">First Name</label>
|
||||
<input type="text"
|
||||
name="first_name"
|
||||
id="first_name"
|
||||
class="form-control"
|
||||
required=""
|
||||
autocomplete="first_name-new">
|
||||
@ -24,6 +25,7 @@ Admin User
|
||||
<label for="last_name" class="form-label">Last Name</label>
|
||||
<input type="text"
|
||||
name="last_name"
|
||||
id="last_name"
|
||||
class="form-control"
|
||||
required=""
|
||||
autocomplete="last_name-new">
|
||||
@ -32,6 +34,7 @@ Admin User
|
||||
<label for="email" class="form-label">Email</label>
|
||||
<input type="text"
|
||||
name="email"
|
||||
id="email"
|
||||
class="form-control"
|
||||
required=""
|
||||
autocomplete="email-new">
|
||||
@ -40,6 +43,7 @@ Admin User
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="text"
|
||||
name="password"
|
||||
id="password"
|
||||
class="form-control"
|
||||
autocomplete="password-new">
|
||||
</div>
|
||||
@ -47,6 +51,7 @@ Admin User
|
||||
<label for="verify_password" class="form-label">Verify Password</label>
|
||||
<input type="text"
|
||||
name="verify_password"
|
||||
id="verify_password"
|
||||
class="form-control"
|
||||
autocomplete="veryfy_password-new">
|
||||
</div>
|
||||
@ -56,14 +61,15 @@ Admin User
|
||||
<a href="javascript:void(0)" class="btn btn-warning" id="cancelBtn">Cancel</a>
|
||||
</div>
|
||||
<div class="float-end">
|
||||
<a href="javascript:void(0)" class="btn btn-danger" id="deleteBtn">Delete</a>
|
||||
<a href="javascript:void(0)" class="btn btn-danger d-none" id="deleteBtn">Delete</a>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
</form>
|
||||
{{ end }}
|
||||
{{ define "js" }}
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
<script type="module">
|
||||
import {showUser} from "/static/js/users.js"
|
||||
showUser({{.API}});
|
||||
showUser({{.API}}, {{.UserID}});
|
||||
</script>
|
||||
{{ end }}
|
||||
|
@ -34,10 +34,18 @@ export function showUsers(api) {
|
||||
});
|
||||
}
|
||||
|
||||
export function showUser(api) {
|
||||
export function showUser(api, userID) {
|
||||
const token = localStorage.getItem("token");
|
||||
let id = window.location.pathname.split("/").pop();
|
||||
let delBtn = document.getElementById("deleteBtn");
|
||||
|
||||
if (id === "0") {
|
||||
return
|
||||
}
|
||||
|
||||
if (userID !== parseInt(id, 10)) {
|
||||
delBtn.classList.remove("d-none")
|
||||
}
|
||||
const requestOptions = {
|
||||
method: 'post',
|
||||
headers: {
|
||||
@ -51,6 +59,23 @@ export function showUser(api) {
|
||||
.then(response => response.json())
|
||||
.then(function (data) {
|
||||
console.log(data);
|
||||
document.getElementById("first_name").value = data.first_name;
|
||||
document.getElementById("last_name").value = data.last_name;
|
||||
document.getElementById("email").value = data.email;
|
||||
});
|
||||
|
||||
delBtn.addEventListener("click", function () {
|
||||
Swal.fire({
|
||||
title: "Are you sure?",
|
||||
text: "You won't be able to undo this!",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#3085d6",
|
||||
cancelButtonColor: "#d33",
|
||||
confirmButtonText: 'Delete User',
|
||||
}).then((result) => {
|
||||
console.log("would delete user id", id);
|
||||
});
|
||||
})
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user