Skip to content

Added profile page#9

Open
gabito1451 wants to merge 2 commits intomainfrom
feature/profile-page
Open

Added profile page#9
gabito1451 wants to merge 2 commits intomainfrom
feature/profile-page

Conversation

@gabito1451
Copy link
Owner

Added profile page

Copy link
Collaborator

@nwankwo-ikemefuna nwankwo-ikemefuna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More work required

profile.html Outdated
<input
type="checkbox"
id="change-pin"
onclick="displayFormToUpdate()"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

displayFormToUpdate() does not describe what this checkbox does. How about togglePinChangeSectionDisplay(). The idea is that when the checkbox is checked, the PIN change section will show, otherwise it will be hidden.

Also, it's advised to attach an "onchange" event listener to the element instead of directly adding the function to onclick attribute. This is to separate html and javascript properly and give you more control.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

profile.js Outdated
Comment on lines 39 to 47
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);
Copy link
Collaborator

@nwankwo-ikemefuna nwankwo-ikemefuna Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're not doing it right here. You haven't added the modified user to the users array. You're simply pushing back the same users array to local storage.

See sample of how to update a user's details in deposit.js:
Screenshot at Feb 22 9-00-21 PM

See how it's done on line 31.

Suggested pseudocode:

const currentUserIndex = getUserIndexByAccountNumber(currentUserAccountNumber);
allUsers[currentUserIndex].accountName = the updated account name;
// You need to check that user is updating PIN before you update it, otherwise, it will be updated to empty string
if (user is also changing PIN) {
  allUsers[currentUserIndex].accountPin = the updated account PIN;
}
setLocalStorageArrData("MB_USER_ACCOUNTS", allUsers);

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

profile.html Outdated
<input
type="password"
id="new-pin"
required
Copy link
Collaborator

@nwankwo-ikemefuna nwankwo-ikemefuna Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing PIN should be optional. You should programmatically add the required attribute if the checkbox is checked, and remove it otherwise. As it is now, you can't submit the form unless the checkbox is checked.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

profile.html Outdated
<input
type="password"
id="confirm-new-pin"
required
Copy link
Collaborator

@nwankwo-ikemefuna nwankwo-ikemefuna Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing PIN should be optional. You should programmatically add the required attribute if the checkbox is checked, and remove it otherwise. As it is now, you can't submit the form unless the checkbox is checked.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

profile.html Outdated
<input
type="password"
id="current-pin"
required
Copy link
Collaborator

@nwankwo-ikemefuna nwankwo-ikemefuna Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing PIN should be optional. You should programmatically add the required attribute if the checkbox is checked, and remove it otherwise. As it is now, you can't submit the form unless the checkbox is checked.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

updateBtnElem.addEventListener("click", () => updateForm());

function deleteUserAccount() {
const registeredUsers = localStorage.getItem("MB_USER_ACCOUNTS");
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

profile.js Outdated
function deleteUserAccount() {
const registeredUsers = localStorage.getItem("MB_USER_ACCOUNTS");
console.log(registeredUsers);
let usersArray = JSON.parse(registeredUsers);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is your justification for using let here instead of const?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it since i am nor re-assigning any variable to a new value

profile.js Outdated
let usersArray = JSON.parse(registeredUsers);
const index = getUserIndexByAccountNumber(currentUserAccountNumber);
usersArray.splice(index, 1);
const newArrayOfUsers = JSON.stringify(usersArray);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON.stringify(usersArray) will produce a string, so calling it newArrayOfUsers is misleading.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

profile.js Outdated
}
updateBtnElem.addEventListener("click", () => updateForm());

function deleteUserAccount() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be confirm action incase the user clicks the button by error.

Copy link
Collaborator

@nwankwo-ikemefuna nwankwo-ikemefuna Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't closeUserAccount()a more appropriate function name?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

<li><a href="#">Account Profile</a></li>
<li><a id="logout-btn" href="#">Logout</a></li>
</ul>
</nav>
Copy link
Collaborator

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?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed it

@nwankwo-ikemefuna
Copy link
Collaborator

More general comments:

  1. When I visit the profile page, I want my name to be populated in the Account Name field.
    Screenshot at Feb 22 8-43-28 PM

  2. If I don't interact with the "Change PIN" checkbox, I should be able to update only my account name.

  3. The "Change PIN" checkbox is meant to be a toggle for the PIN section (i.e. hide or show the PIN section). Currently, the checkbox only works the first time to show the PIN section and subsequently doesn't affect the display of the PIN section. This gives an unpleasant experience.

profile.js Outdated

// finding the current user to update profile

let userToBeUpdated = allUsers.find(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is your justification for using let here instead of const?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants