From 60f0753f6b832a6213466f141112e44c43b232f5 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 14 Feb 2023 16:54:42 -0800 Subject: [PATCH] created an alert when local reports are uploaded (#1523) * created the alert * added a check that reports had been uploaded * grammar (yes I care) * fixed inconsistency --- src/api/report/submit-report.ts | 15 +++++++++++++++ src/components/report-editor.tsx | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/api/report/submit-report.ts b/src/api/report/submit-report.ts index dd0bb66fe..1605681c1 100644 --- a/src/api/report/submit-report.ts +++ b/src/api/report/submit-report.ts @@ -2,6 +2,8 @@ import { request } from '../base' import { Report, OfflineReport } from '.' import { useEffect, useState } from 'preact/hooks' import { CancellablePromise } from '@/utils/cancellable-promise' +import { createAlert } from '@/router' +import { AlertType } from '@/components/alert' /** * Uploads a report via PUT or POST, depending on if the report already has an ID @@ -53,6 +55,19 @@ export const uploadSavedReports = async () => { [] as Report[] | Promise, ) localStorage.setItem(SAVED_REPORTS, JSON.stringify(unsuccessfulReports)) + + const uploadedReports = savedReports.length - unsuccessfulReports.length + if (uploadedReports > 1) { + createAlert({ + type: AlertType.Success, + message: `${uploadedReports} reports were uploaded!`, + }) + } else if (uploadedReports === 1) { + createAlert({ + type: AlertType.Success, + message: `1 report was uploaded!`, + }) + } } /** Only used for offline reports */ diff --git a/src/components/report-editor.tsx b/src/components/report-editor.tsx index 098d175c7..cd0a595eb 100644 --- a/src/components/report-editor.tsx +++ b/src/components/report-editor.tsx @@ -201,7 +201,7 @@ export const ReportEditor = ({ key: initialReport.key || generateReportKey(), } saveReportLocally(reportWithKey) - if (onSaveLocally) onSaveLocally(reportWithKey) + onSaveLocally?.(reportWithKey) } }) .finally(() => {