-
Notifications
You must be signed in to change notification settings - Fork 0
Added profile page #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <link rel="stylesheet" href="./helpers/components.css" /> | ||
| <link rel="stylesheet" href="./styles.css" /> | ||
| <title>Profile</title> | ||
| <script src="./tailwind.js"></script> | ||
| </head> | ||
| <body> | ||
| <nav class="bg-gray-800 text-white p-6"> | ||
| <ul class="flex justify-between items-center"> | ||
| <li><a href="./transactions.html">Transactions</a></li> | ||
| <li><a href="./deposit.html">Deposit</a></li> | ||
| <li><a href="./withdraw.html">Withdraw</a></li> | ||
| <li><a href="./transfer.html">Transfer</a></li> | ||
| <li><a href="#">Account Profile</a></li> | ||
| <li><a id="logout-btn" href="#">Logout</a></li> | ||
| </ul> | ||
| </nav> | ||
| <div class="container-fixed"> | ||
| <h1>Account Profile</h1> | ||
| <form id="profile-form" class="account-profile" onsubmit="return false"> | ||
| <div class="form-group"> | ||
| <label class="form-control-label">Account Name</label> | ||
| <input type="text" id="account-name" class="form-control" required /> | ||
| </div> | ||
| <div class="form-group"> | ||
| <label class="form-control-label">Account Number</label> | ||
| <input | ||
| type="number" | ||
| id="account-number" | ||
| class="form-control" | ||
| required | ||
| readonly | ||
| /> | ||
| </div> | ||
| <label class="form-control-label"> | ||
| <input | ||
| type="checkbox" | ||
| id="change-pin" | ||
| onclick="displayFormToUpdate()" | ||
|
||
| /> | ||
| Change Pin</label | ||
| > | ||
| <div id="pin-update-section"> | ||
| <div class="form-group"> | ||
| <label class="form-control-label">Current PIN</label> | ||
| <input | ||
| type="password" | ||
| id="current-pin" | ||
| required | ||
|
||
| maxlength="4" | ||
| class="form-control" | ||
| /> | ||
| </div> | ||
| <div class="form-group"> | ||
| <label class="form-control-label">New PIN</label> | ||
| <input | ||
| type="password" | ||
| id="new-pin" | ||
| required | ||
|
||
| maxlength="4" | ||
| class="form-control" | ||
| /> | ||
| </div> | ||
| <div class="form-group"> | ||
| <label class="form-control-label">Confirm New PIN</label> | ||
| <input | ||
| type="password" | ||
| id="confirm-new-pin" | ||
| required | ||
|
||
| maxlength="4" | ||
| class="form-control" | ||
| /> | ||
| </div> | ||
| </div> | ||
| <div class="form-group"> | ||
| <button class="bg-gray-800 text-white p-2 rounded-md" id="update-btn"> | ||
| Update | ||
| </button> | ||
| </div> | ||
| </form> | ||
| <button id="close-btn" class="bg-red-800 text-white p-2 rounded-md"> | ||
| Close | ||
| </button> | ||
| </div> | ||
| </body> | ||
| <script src="./common.js"></script> | ||
| <script src="./common-session.js"></script> | ||
| <script src="./profile.js"></script> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| const profileForm = document.getElementById("profile-form"); | ||
| const accountNameElem = document.getElementById("account-name"); | ||
| const accountNumberElem = document.getElementById("account-number"); | ||
| const changePinElem = document.getElementById("change-pin"); | ||
| const currentPinElem = document.getElementById("current-pin"); | ||
| const newPinElem = document.getElementById("new-pin"); | ||
| const confirmNewPinElem = document.getElementById("confirm-new-pin"); | ||
| const closeBtnElem = document.getElementById("close-btn"); | ||
| const updateBtnElem = document.getElementById("update-btn"); | ||
| // display of aaccount number | ||
| accountNumberElem.value = currentUserAccountNumber; | ||
|
|
||
| const allUsers = JSON.parse(localStorage.getItem("MB_USER_ACCOUNTS")); | ||
|
||
|
|
||
| function displayFormToUpdate() { | ||
| const pinUpdateSection = document.getElementById("pin-update-section"); | ||
|
|
||
| if ((pinUpdateSection.style.display = "none")) { | ||
| pinUpdateSection.style.display = "block"; | ||
| } else { | ||
| pinUpdateSection.style.display = "none"; | ||
| } | ||
| } | ||
| function updateForm() { | ||
| if ( | ||
| currentPinElem.value !== | ||
| getUserByAccountNumber(currentUserAccountNumber).accountPin | ||
| ) { | ||
| alert("Incorrect Pin"); | ||
| return; | ||
| } | ||
| if (newPinElem.value !== confirmNewPinElem.value) { | ||
| alert("Pins do not match, try again"); | ||
| return; | ||
| } | ||
|
|
||
| // finding the current user to update profile | ||
|
|
||
| let userToBeUpdated = allUsers.find( | ||
|
||
| (user) => user.accountNumber == accountNumberElem.value | ||
| ); | ||
| userToBeUpdated.accountName = accountNameElem.value; | ||
| userToBeUpdated.accountPin = newPinElem.value; | ||
| // changing the updated properties to a string | ||
| const updatedObject = JSON.stringify(allUsers); | ||
| // storing it back in local storage | ||
| localStorage.setItem("MB_USER_ACCOUNTS", updatedObject); | ||
|
||
| location.href = "transactions.html"; | ||
| } | ||
| updateBtnElem.addEventListener("click", () => updateForm()); | ||
|
|
||
| function deleteUserAccount() { | ||
|
||
| const registeredUsers = localStorage.getItem("MB_USER_ACCOUNTS"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we have a function for getting all users defined in common.js? Why do this?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| console.log(registeredUsers); | ||
| let usersArray = JSON.parse(registeredUsers); | ||
|
||
| const index = getUserIndexByAccountNumber(currentUserAccountNumber); | ||
| usersArray.splice(index, 1); | ||
| const newArrayOfUsers = JSON.stringify(usersArray); | ||
|
||
| localStorage.setItem("MB_USER_ACCOUNTS", newArrayOfUsers); | ||
| // location.href = "/"; | ||
| } | ||
| closeBtnElem.addEventListener("click", () => deleteUserAccount()); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,3 +27,6 @@ table { | |
| margin-left: 780px; | ||
| margin-top: 10px; | ||
| } | ||
| div#pin-update-section { | ||
| display: none; | ||
| } | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where's the account balance section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed it