Skip to content

Commit

Permalink
Update edit-profile.html
Browse files Browse the repository at this point in the history
  • Loading branch information
Swapnilden authored Jul 6, 2024
1 parent f70fceb commit 9d9f514
Showing 1 changed file with 0 additions and 75 deletions.
75 changes: 0 additions & 75 deletions edit-profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,81 +45,6 @@ <h1>Edit Profile</h1>
</form>
</div>

<script>
function submitProfile(event) {
event.preventDefault(); // Prevent default form submission

// Get form elements
var name = document.getElementById("name").value.trim();
var email = document.getElementById("email").value.trim();
var additionalInfo = document.getElementById("additional-info").value.trim();
var profilePic = document.getElementById("profile-pic").files[0];

// Validate input fields
if (name === "" || email === "" || additionalInfo === "") {
// Show a SweetAlert error modal
Swal.fire({
icon: "error",
title: "Oops...",
text: "Please complete all fields before submitting.",
customClass: {
popup: "swal-popup",
title: "swal-title",
content: "swal-content",
confirmButton: "swal-confirm-button",
},
});
return; // Exit the function if any field is empty
}

// Check if a profile picture is selected
if (!profilePic) {
Swal.fire({
icon: "error",
title: "Oops...",
text: "Please select a profile picture before submitting.",
customClass: {
popup: "swal-popup",
title: "swal-title",
content: "swal-content",
confirmButton: "swal-confirm-button",
},
});
return;
}

// Save user profile to local storage
const userProfile = {
name: name,
email: email,
additionalInfo: additionalInfo,
profilePic: URL.createObjectURL(profilePic) // Save the URL of the profile picture
};
localStorage.setItem("userProfile", JSON.stringify(userProfile));

// Show a success message
Swal.fire({
icon: "success",
title: "Success!",
text: "Your profile has been updated.",
customClass: {
popup: "swal-popup",
title: "swal-title",
content: "swal-content",
confirmButton: "swal-confirm-button",
},
}).then((result) => {
// Clear the profile form after the user acknowledges the success modal
if (result.isConfirmed || result.isDismissed) {
document.getElementById("edit-profile").reset();
// Update the main profile picture in the header
document.getElementById("main-profile-pic").src = userProfile.profilePic;
}
});
}

// Attach the submitProfile function to the form's submit event
document.getElementById("edit-profile").addEventListener("submit", submitProfile);
</script>
</body>
</html>

0 comments on commit 9d9f514

Please sign in to comment.