Skip to content

Commit

Permalink
#3035 - Enable Application Saving on Page Change (#4001)
Browse files Browse the repository at this point in the history
### As a part of this PR, the following is achieved:

- For draft applications, enabled saving the draft whenever the user
navigates between sections of the application. (Next Section/Prev
Section/Section Headings). Note: As a part of the discussion with the
business, no toast is shown on the UI for the automatic saving of the
draft.

**Video illustrating the PR work:**


https://github.com/user-attachments/assets/1c7fc402-8e98-42ca-a6a1-0a5759649021
  • Loading branch information
sh16011993 authored Dec 2, 2024
1 parent 274c0dc commit dfadd3f
Showing 1 changed file with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,17 @@ export default defineComponent({
const savingDraft = ref(false);
const submittingApplication = ref(false);
let applicationWizard: any;
let savedDraftData: string;
const isFirstPage = ref(true);
const isLastPage = ref(false);
const isReadOnly = ref(false);
const notDraft = ref(false);
const existingApplication = ref({} as ApplicationDataAPIOutDTO);
const editApplicationModal = ref({} as ModalDialog<boolean>);
const conditionsAccepted = ref(false);
// automaticDraftSaveInProgress is a boolean that ensures that multiple api calls for save
// draft are not made while a draft save is in progress.
let automaticDraftSaveInProgress = false;
const checkProgramYear = async () => {
// check program year, if not active allow only readonly mode with a snackBar
Expand Down Expand Up @@ -219,17 +223,21 @@ export default defineComponent({
existingApplication.value = applicationData;
});
const callSaveDraft = async () => {
const associatedFiles = formioUtils.getAssociatedFiles(applicationWizard);
await ApplicationService.shared.saveApplicationDraft(props.id, {
programYearId: props.programYearId,
data: applicationWizard.submission.data,
associatedFiles,
});
savedDraftData = JSON.stringify(applicationWizard.submission.data);
};
// Save the current state of the student application skipping all validations.
const saveDraft = async () => {
savingDraft.value = true;
try {
const associatedFiles =
formioUtils.getAssociatedFiles(applicationWizard);
await ApplicationService.shared.saveApplicationDraft(props.id, {
programYearId: props.programYearId,
data: applicationWizard.submission.data,
associatedFiles,
});
await callSaveDraft();
snackBar.success("Application draft saved with success.");
} catch {
snackBar.error("An unexpected error has happened.");
Expand All @@ -238,6 +246,15 @@ export default defineComponent({
}
};
const saveDraftAutomatically = async () => {
automaticDraftSaveInProgress = true;
try {
await callSaveDraft();
} finally {
automaticDraftSaveInProgress = false;
}
};
// Execute the final submission of the student application.
const submitApplication = async (args: any, form: any) => {
submittingApplication.value = true;
Expand Down Expand Up @@ -281,13 +298,28 @@ export default defineComponent({
applicationWizard = form;
};
const pageChanged = (
const pageChanged = async (
isInFirstPage: boolean,
currentPage: number,
_currentPage: number,
isInLastPage: boolean,
) => {
isFirstPage.value = isInFirstPage;
isLastPage.value = isInLastPage;
if (!savedDraftData) {
savedDraftData = JSON.stringify(applicationWizard.submission.data);
}
const dataChanged =
savedDraftData !== JSON.stringify(applicationWizard.submission.data);
if (
!notDraft.value &&
!isFirstPage.value &&
!submittingApplication.value &&
!automaticDraftSaveInProgress &&
!savingDraft.value &&
dataChanged
) {
await saveDraftAutomatically();
}
};
const customEventCallback = async (form: any, event: FormIOCustomEvent) => {
Expand Down

0 comments on commit dfadd3f

Please sign in to comment.