Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
rfmt: show success message
Browse files Browse the repository at this point in the history
  • Loading branch information
AteKitty07 committed Nov 14, 2022
1 parent c77e4a6 commit f88f9f9
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 61 deletions.
3 changes: 2 additions & 1 deletion components/authentication/change_password.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ function savePassword() {
)
.then(() => {
const TIMEOUT = 3000
fillSuccessMessages(receivedErrors, successMessages)
setTimeout(cancel, 3000)
setTimeout(closeDialog, TIMEOUT)
})
.catch(responseWithErrors => extractAllErrorDetails(responseWithErrors, receivedErrors))
}
Expand Down
7 changes: 5 additions & 2 deletions components/comment/multiviewer/viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,15 @@ function closeArchiveOrRestore() {
function closeDialog() {
emit("archive", comment.value)
emit("restore", comment.value)
}
async function archiveComment(): Promise<void> {
await fetcher.archive([ comment.value.id ])
.then(() => {
const TIMEOUT = 3000
fillSuccessMessages(receivedErrors, successMessages)
setTimeout(closeDialog, 3000)
setTimeout(closeDialog, TIMEOUT)
})
.catch(responseWithErrors => extractAllErrorDetails(responseWithErrors, receivedErrors))
}
Expand All @@ -403,8 +405,9 @@ async function archiveComment(): Promise<void> {
async function restoreComment(): Promise<void> {
await fetcher.restore([ comment.value.id ])
.then(() => {
const TIMEOUT = 3000
fillSuccessMessages(receivedErrors, successMessages)
setTimeout(closeDialog, 3000)
setTimeout(closeDialog, TIMEOUT)
})
.catch(responseWithErrors => extractAllErrorDetails(responseWithErrors, receivedErrors))
}
Expand Down
38 changes: 33 additions & 5 deletions components/post/multiviewer/viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<h1>Enter the post details</h1>
</template>
<template #default>
<ReceivedErrors v-if="receivedErrors.length" :received-errors="receivedErrors"/>
<ReceivedSuccessMessages
v-if="successMessages.length"
:received-success-messages="successMessages"/>
<p v-if="mustArchive">
Do you really want to archive?
</p>
Expand Down Expand Up @@ -177,13 +181,19 @@ import pluralize from "$/string/pluralize"
import makeSwitch from "$@/helpers/make_switch"
import isUndefined from "$/type_guards/is_undefined"
import specializePath from "$/helpers/specialize_path"
import fillSuccessMessages from "$@/helpers/fill_success_messages"
import extractAllErrorDetails from "$@/helpers/extract_all_error_details"
import formatToFriendlyPastTime from "$@/helpers/format_to_friendly_past_time"
import formatToCompleteFriendlyTime from "$@/helpers/format_to_complete_friendly_time"
import formatToCompleteFriendlyTime from "$@/helpers/format_to_complete_friendly_time"
import ReceivedErrors from "@/helpers/message_handlers/received_errors.vue"
import ReceivedSuccessMessages from "@/helpers/message_handlers/received_success_messages.vue"
import Overlay from "@/helpers/overlay.vue"
import Menu from "@/post/multiviewer/viewer/menu.vue"
import ProfilePicture from "@/consultation/list/profile_picture_item.vue"
import UpdatePostForm from "@/post/multiviewer/viewer/update_post_form.vue"
import assignPath from "$@/external/assign_path"
const fetcher = new Fetcher()
Expand Down Expand Up @@ -242,9 +252,13 @@ const {
"off": closeRestore
} = makeSwitch(false)
const receivedErrors = ref<string[]>([])
const successMessages = ref<string[]>([])
const mustArchiveOrRestore = computed<boolean>(() => mustArchive.value || mustRestore.value)
function closeArchiveOrRestore() {
receivedErrors.value = []
successMessages.value = []
closeArchive()
closeRestore()
}
Expand Down Expand Up @@ -317,15 +331,29 @@ async function submitChangesSeparately(): Promise<void> {
})
}
function closeDialog() {
emit("archive", post.value)
emit("restore", post.value)
}
async function archivePost(): Promise<void> {
await fetcher.archive([ post.value.id ]).then(() => {
emit("archive", post.value)
await fetcher.archive([ post.value.id ])
.then(() => {
fillSuccessMessages(receivedErrors, successMessages)
setTimeout(closeDialog, 5000)
assignPath("/forum")
})
.catch(responseWithErrors => extractAllErrorDetails(responseWithErrors, receivedErrors))
}
async function restorePost(): Promise<void> {
await fetcher.restore([ post.value.id ]).then(() => {
emit("restore", post.value)
await fetcher.restore([ post.value.id ])
.then(() => {
fillSuccessMessages(receivedErrors, successMessages)
setTimeout(closeDialog, 5000)
assignPath("/forum")
})
.catch(responseWithErrors => extractAllErrorDetails(responseWithErrors, receivedErrors))
}
</script>
17 changes: 16 additions & 1 deletion components/settings/update_password_field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<h1>Update your password</h1>
</template>
<template #default>
<ReceivedErrors v-if="receivedErrors.length" :received-errors="receivedErrors"/>
<ReceivedSuccessMessages
v-if="successMessages.length"
:received-success-messages="successMessages"/>
<form class="verification">
<SensitiveTextField
v-model="currentPassword"
Expand Down Expand Up @@ -66,9 +70,13 @@ import isUndefined from "$/type_guards/is_undefined"
import Fetcher from "$@/fetchers/user"
import makeSwitch from "$@/helpers/make_switch"
import BodyCSSClasses from "$@/external/body_css_classes"
import fillSuccessMessages from "$@/helpers/fill_success_messages"
import extractAllErrorDetails from "$@/helpers/extract_all_error_details"
import Overlay from "@/helpers/overlay.vue"
import SensitiveTextField from "@/fields/sensitive_text.vue"
import ReceivedErrors from "@/helpers/message_handlers/received_errors.vue"
import ReceivedSuccessMessages from "@/helpers/message_handlers/received_success_messages.vue"
const pageContext = inject("pageContext") as PageContext<"deserialized">
const { pageProps } = pageContext
Expand Down Expand Up @@ -104,6 +112,8 @@ function open() {
}, MILLISECOND_IN_A_SECOND)
}
const receivedErrors = ref<string[]>([])
const successMessages = ref<string[]>([])
function cancel(): void {
clearPasswords()
Expand All @@ -116,6 +126,11 @@ function savePassword() {
currentPassword.value,
newPassword.value,
confirmNewPassword.value
).then(cancel)
).then(() => {
const TIMEOUT = 3000
fillSuccessMessages(receivedErrors, successMessages)
setTimeout(closeDialog, TIMEOUT)
})
.catch(responseWithErrors => extractAllErrorDetails(responseWithErrors, receivedErrors))
}
</script>
8 changes: 4 additions & 4 deletions pages/department/create.page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ import { ref, computed } from "vue"
import convertToTitle from "$/string/convert_to_title"
import DepartmentFetcher from "$@/fetchers/department"
import fillSuccessMessages from "$@/helpers/fill_success_messages"
import extractAllErrorDetails from "$@/helpers/extract_all_error_details"
import UserListRedirector from "@/resource_management/list_redirector.vue"
import ReceivedErrors from "@/helpers/message_handlers/received_errors.vue"
import ReceivedSuccessMessages from "@/helpers/message_handlers/received_success_messages.vue"
Expand Down Expand Up @@ -77,9 +78,8 @@ function createDepartment() {
"mayAdmit": mayAdmit.value
})
.then(() => {
if (receivedErrors.value.length) receivedErrors.value = []
successMessages.value.push("Department has been created successfully!")
fillSuccessMessages(receivedErrors, successMessages)
})
.catch(response => extractAllErrorDetails(response, receivedErrors, successMessages))
.catch(responseWithErrors => extractAllErrorDetails(responseWithErrors, receivedErrors))
}
</script>
12 changes: 6 additions & 6 deletions pages/role/create.page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ import Fetcher from "$@/fetchers/role"
import FlagSelector from "@/role/flag_selector.vue"
import TextualField from "@/fields/non-sensitive_text_capital.vue"
import fillSuccessMessages from "$@/helpers/fill_success_messages"
import extractAllErrorDetails from "$@/helpers/extract_all_error_details"
import UserListRedirector from "@/resource_management/list_redirector.vue"
import ReceivedErrors from "@/helpers/message_handlers/received_errors.vue"
import ReceivedSuccessMessages from "@/helpers/message_handlers/received_success_messages.vue"
import makeFlagSelectorInfos from "@/role/make_flag_selector_infos"
import UserListRedirector from "@/resource_management/list_redirector.vue"
import ReceivedSuccessMessages from "@/helpers/message_handlers/received_success_messages.vue"
const role = ref<RoleAttributes<"deserialized">>({
"auditTrailFlags": 0,
Expand All @@ -77,10 +78,9 @@ function createRole() {
roleFetcher.create({
...role.value,
"deletedAt": null
}).then(({ unusedBody, unusedStatus }) => {
if (receivedErrors.value.length) receivedErrors.value = []
successMessages.value.push("Role has been created successfully!")
}).then(() => {
fillSuccessMessages(receivedErrors, successMessages)
})
.catch(response => extractAllErrorDetails(response, receivedErrors, successMessages))
.catch(responseWithErrors => extractAllErrorDetails(responseWithErrors, receivedErrors))
}
</script>
14 changes: 7 additions & 7 deletions pages/role/read.page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import { UPDATE, ARCHIVE_AND_RESTORE } from "$/permissions/role_combinations"
import { role as permissionGroup } from "$/permissions/permission_list"
import FlagSelector from "@/role/flag_selector.vue"
import fillSuccessMessages from "$@/helpers/fill_success_messages"
import extractAllErrorDetails from "$@/helpers/extract_all_error_details"
import ReceivedErrors from "@/helpers/message_handlers/received_errors.vue"
import RoleNameField from "@/fields/non-sensitive_text_capital.vue"
Expand Down Expand Up @@ -154,25 +155,24 @@ async function updateRole() {
password.value = ""
nameFieldStatus.value = "locked"
if (receivedErrors.value.length) receivedErrors.value = []
successMessages.value.push("Role has been successfully!")
fillSuccessMessages(receivedErrors, successMessages)
})
.catch(response => extractAllErrorDetails(response, receivedErrors, successMessages))
.catch(responseWithErrors => extractAllErrorDetails(responseWithErrors, receivedErrors))
}
async function archiveRole() {
await fetcher.archive([ role.value.data.id ])
.then(() => {
successMessages.value.push("This role has been archived successfully")
fillSuccessMessages(receivedErrors, successMessages)
})
.catch(response => extractAllErrorDetails(response, receivedErrors, successMessages))
.catch(responseWithErrors => extractAllErrorDetails(responseWithErrors, receivedErrors))
}
async function restoreRole() {
await fetcher.restore([ role.value.data.id ])
.then(() => {
successMessages.value.push("This role has been restored successfully")
fillSuccessMessages(receivedErrors, successMessages)
})
.catch(response => extractAllErrorDetails(response, receivedErrors, successMessages))
.catch(responseWithErrors => extractAllErrorDetails(responseWithErrors, receivedErrors))
}
</script>
7 changes: 4 additions & 3 deletions pages/semester/create.page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ import convertToTitle from "$/string/convert_to_title"
import type { OptionInfo } from "$@/types/component"
import Selectable from "@/fields/selectable_options.vue"
import fillSuccessMessages from "$@/helpers/fill_success_messages"
import extractAllErrorDetails from "$@/helpers/extract_all_error_details"
import UserListRedirector from "@/resource_management/list_redirector.vue"
import ReceivedErrors from "@/helpers/message_handlers/received_errors.vue"
import ReceivedSuccessMessages from "@/helpers/message_handlers/received_success_messages.vue"
Expand Down Expand Up @@ -79,9 +81,8 @@ function createSemester() {
"startAt": new Date(startAt.value).toJSON()
})
.then(() => {
if (receivedErrors.value.length) receivedErrors.value = []
successMessages.value.push("Semester has been created successfully!")
fillSuccessMessages(receivedErrors, successMessages)
})
.catch(response => extractAllErrorDetails(response, receivedErrors, successMessages))
.catch(responseWithErrors => extractAllErrorDetails(responseWithErrors, receivedErrors))
}
</script>
6 changes: 3 additions & 3 deletions pages/semester/read.page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ function updateSemester() {
.then(() => {
closeConfirmation()
password.value = ""
if (receivedErrors.value.length) receivedErrors.value = []
successMessages.value.push("Semester has been read successfully!")
fillSuccessMessages(receivedErrors, successMessages)
})
.catch(response => extractAllErrorDetails(response, receivedErrors, successMessages))
.catch(responseWithErrors => extractAllErrorDetails(responseWithErrors, receivedErrors))
}
async function archiveSemester() {
Expand Down
33 changes: 17 additions & 16 deletions pages/settings/profile.page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ import PicturePicker from "@/fields/picture_picker.vue"
import TextualField from "@/fields/non-sensitive_text.vue"
import ProfilePicture from "@/helpers/profile_picture.vue"
import SettingsHeader from "@/helpers/tabbed_page_header.vue"
import fillSuccessMessages from "$@/helpers/fill_success_messages"
import SchedulePickerGroup from "@/settings/schedule_picker_group.vue"
import extractAllErrorDetails from "$@/helpers/extract_all_error_details"
import ReceivedErrors from "@/helpers/message_handlers/received_errors.vue"
Expand All @@ -236,10 +237,6 @@ if (pageContext.pageProps.parsedUnitError) {
receivedErrors.value = [ pageContext.pageProps.parsedUnitError.detail ]
}
function showSuccessMessage(message: string) {
if (receivedErrors.value.length) receivedErrors.value = []
successMessages.value.push(message)
}
function submitProfilePicture(formData: FormData) {
const profilePictureFetcher = new ProfilePictureFetcher()
Expand All @@ -250,20 +247,22 @@ function submitProfilePicture(formData: FormData) {
formData
)
.then(() => {
const message = "profile picture uploaded successfully. reload the page to see the changes"
showSuccessMessage(message)
fillSuccessMessages(
receivedErrors,
successMessages,
"Profile picture uploaded successfully."
)
})
.catch(response => extractAllErrorDetails(response, receivedErrors, successMessages))
.catch(responseWithErrors => extractAllErrorDetails(responseWithErrors, receivedErrors))
} else {
profilePictureFetcher.createFile(
userProfileData.value.id,
formData
)
.then(() => {
const message = "profile picture uploaded successfully. reload the page to see the changes"
showSuccessMessage(message)
fillSuccessMessages(receivedErrors, successMessages)
})
.catch(response => extractAllErrorDetails(response, receivedErrors, successMessages))
.catch(responseWithErrors => extractAllErrorDetails(responseWithErrors, receivedErrors))
}
}
function submitSignature(formData: FormData) {
Expand All @@ -274,23 +273,25 @@ function submitSignature(formData: FormData) {
formData
)
.then(() => {
const message = "Signature uploaded successfully. reload the page to see the changes"
showSuccessMessage(message)
fillSuccessMessages(
receivedErrors,
successMessages,
"Signature uploaded successfully."
)
})
.catch(response => extractAllErrorDetails(response, receivedErrors, successMessages))
.catch(responseWithErrors => extractAllErrorDetails(responseWithErrors, receivedErrors))
}
function updateUser() {
new UserFetcher().update(userProfileData.value.id, {
...userProfileData.value
})
.then(() => {
// eslint-disable-next-line max-len
showSuccessMessage("Your profile has been updated successfully. Please wait until the page reloads.")
fillSuccessMessages(receivedErrors, successMessages)
const SECONDS_BEFORE_PAGES_RELOAD = 3000
setTimeout(() => assignPath("/settings/profile"), SECONDS_BEFORE_PAGES_RELOAD)
})
.catch(response => extractAllErrorDetails(response, receivedErrors, successMessages))
.catch(responseWithErrors => extractAllErrorDetails(responseWithErrors, receivedErrors))
}
const emit = defineEmits([ "toggleDarkMode" ])
Expand Down
Loading

0 comments on commit f88f9f9

Please sign in to comment.