Skip to content

Commit 6d1f68b

Browse files
authored
background sync toast msg update #92 (#529)
background sync toast msg update #92 (#529)
1 parent a3b147f commit 6d1f68b

File tree

5 files changed

+15
-32
lines changed

5 files changed

+15
-32
lines changed

forms-flow-rsbcservice/src/helpers/helperDbServices.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ class DBServiceHelper {
146146
public static constructApplicationData(
147147
formId: string,
148148
submissionId: string,
149-
formData: any
149+
formData: any,
150+
submission: any
150151
): Application {
151152
const userDetails = this.getUserDetails();
152153
const randomId = this.generateRandomNumber();
@@ -172,6 +173,7 @@ class DBServiceHelper {
172173
processName: null,
173174
processTenant: null,
174175
submissionId,
176+
dashboardColumns: submission?.data?.dashboardColumns,
175177
};
176178
}
177179

forms-flow-rsbcservice/src/services/offlineSubmissions.ts

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,44 +26,29 @@ class OfflineSubmissions {
2626
* It returns the count of drafts and submissions processed.
2727
*/
2828
public static async processOfflineSubmissions(): Promise<void> {
29-
let draftsProcessed = 0;
30-
let submissionsProcessed = 0;
31-
let totalSubmission = 0;
32-
3329
try {
3430
await this.retryToken();
3531

3632
const submissions =
3733
await OfflineFetchService.fetchAllNonActiveOfflineSubmissions();
38-
totalSubmission = submissions.length ?? 0;
39-
console.log(submissions);
4034
const processPromises = [
41-
this.processDrafts(submissions, (count) => (draftsProcessed += count)),
42-
this.processSubmission(
43-
submissions,
44-
(count) => (submissionsProcessed += count)
45-
),
35+
this.processDrafts(submissions),
36+
this.processSubmission(submissions),
4637
this.processDraftDelete()
4738
];
4839

4940
// Wait for all processes to finish
5041
await Promise.all(processPromises);
5142
PubSub.publish("DRAFT_ENABLED_SYNC_COMPLETED", {
52-
status: "completed",
53-
totalSubmission: totalSubmission,
54-
draftsProcessed: draftsProcessed ?? 0,
55-
submissionsProcessed: submissionsProcessed ?? 0
43+
status: "completed"
5644
});
5745
} catch (error) {
5846
// Log error and track failed drafts/submissions
5947
console.error("Error processing drafts or submissions:", error);
6048

6149
// Publish the failure status with counts
6250
PubSub.publish("DRAFT_ENABLED_SYNC_COMPLETED", {
63-
status: "incompleted",
64-
totalSubmission: totalSubmission,
65-
draftsProcessed: draftsProcessed ?? 0,
66-
submissionsProcessed: submissionsProcessed ?? 0
51+
status: "incompleted"
6752
});
6853
}
6954
}
@@ -120,11 +105,9 @@ class OfflineSubmissions {
120105
* - If the draft exists and has both a server draft ID and application ID, it will be updated.
121106
* - If the draft is new (no server IDs), it will be created.
122107
* @param submissions List of offline submissions to process.
123-
* @param countCallback Callback to update the draft count.
124108
*/
125109
private static async processDrafts(
126-
submissions: OfflineSubmission[],
127-
countCallback: (count: number) => void
110+
submissions: OfflineSubmission[]
128111
): Promise<void> {
129112
const draftSubmissions = submissions.filter(
130113
(submission) => submission.type === "draft"
@@ -134,7 +117,6 @@ class OfflineSubmissions {
134117
await Promise.all(
135118
draftSubmissions.map(async (draft) => {
136119
await this.handleDraftSubmission(draft);
137-
countCallback(1); // Increment count for each processed draft
138120
})
139121
);
140122
}
@@ -206,11 +188,9 @@ class OfflineSubmissions {
206188
* - If the application exists and has both server draft ID and application ID, it will be updated.
207189
* - If the application is new (no server IDs), it will be created.
208190
* @param submissions List of offline submissions to process.
209-
* @param countCallback Callback to update the submission count.
210191
*/
211192
private static async processSubmission(
212-
submissions: OfflineSubmission[],
213-
countCallback: (count: number) => void
193+
submissions: OfflineSubmission[]
214194
): Promise<void> {
215195
const submittedData = submissions.filter(
216196
(submission) => submission.type === "application"
@@ -220,8 +200,6 @@ class OfflineSubmissions {
220200
await Promise.all(
221201
submittedData.map(async (data) => {
222202
await this.handleSubmission(data);
223-
// Increment count for each processed submission
224-
countCallback(1);
225203
})
226204
);
227205
}

forms-flow-rsbcservice/src/storage/dbInsertServices.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,8 @@ class OfflineSaveService {
436436
const applicationData = DBServiceHelper.constructApplicationData(
437437
formId,
438438
draft.localSubmissionId,
439-
formData
439+
formData,
440+
data
440441
);
441442
await this.saveFFDataToIndexedDB("offlineSubmission", draft);
442443
await this.saveFFDataToIndexedDB("applications", applicationData);

forms-flow-rsbcservice/src/storage/dbUpdateServices.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ class OfflineEditService {
8181
const applicationData = DBServiceHelper.constructApplicationData(
8282
formId,
8383
draft.localSubmissionId,
84-
formData
84+
formData,
85+
newSubmissionData
8586
);
8687
await OfflineSaveService.saveFFDataToIndexedDB(
8788
"applications",

forms-flow-rsbcservice/src/storage/ffDb.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export interface Application {
5959
processName: string;
6060
processTenant: string;
6161
submissionId: string;
62+
dashboardColumns: Record<string, any>[];
6263
}
6364

6465
export interface Draft {
@@ -178,7 +179,7 @@ class FormsFlowDB extends Dexie {
178179
"_id, title, description, name, path, type, created, modified, machineName, parentFormId",
179180
activeForm: "localDraftId, serverDraftId",
180181
formProcesses: "formId, formName",
181-
deletedDrafts: "serverDraftId"
182+
deletedDrafts: "serverDraftId",
182183
});
183184
}
184185
}

0 commit comments

Comments
 (0)