Skip to content

Commit

Permalink
Added cancel edit profile button
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewzpu committed Apr 23, 2024
1 parent f7db0ea commit e1dac68
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion frontend/src/Pages/Profile.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@

<svelte:head>
<title> HKN Portal | Profile </title>
<meta name="viewport" content="width=device-width, initial-sclae=1.0">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</svelte:head>

<Layout>
Expand Down
36 changes: 36 additions & 0 deletions frontend/src/Pages/ProfileEdit.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
.split("=")[1];
async function onSubmit(event) {
event.preventDefault();
const form = event.target;
Expand All @@ -100,6 +101,12 @@
if (formData.get("degree") == "Other") {
formData.set("degree", formData.get("other_degree"))
}
const submitType = event.submitter.value;
if (submitType == "Cancel") {
onCancel(formData)
return;
}
const response = await fetch(`/api/profile/edit/`, {
method: "POST",
Expand All @@ -117,6 +124,34 @@
navigate("/profile/self")
}
}
function onCancel(formData) {
console.log(user_groups)
let changed = false;
for (const group of user_groups) {
if (group === "Member" || group == "Inductee") {
changed = changed || user_data.preferred_name != formData.get("preferred_name")
changed = changed || user_data[group].major != formData.get("major")
changed = changed || user_data[group].degree != formData.get("degree")
changed = changed || user_data[group].grad_year != formData.get("grad_year")
}
if (group == "Outreach Student") {
changed = changed || user_data[group].car
}
}
console.log(changed)
if (!changed || confirm("You have unsaved changes. Are you sure you want to leave?")) {
navigate("/profile/self")
}
}
</script>

<Layout>
Expand Down Expand Up @@ -323,6 +358,7 @@
{/if}
{/each}
<input type="submit" value="Save"/>
<input type="submit" value="Cancel"/>
</form>
</div>
{/await}
Expand Down

0 comments on commit e1dac68

Please sign in to comment.