Skip to content

Commit

Permalink
created an alert when local reports are uploaded (#1523)
Browse files Browse the repository at this point in the history
* created the alert

* added a check that reports had been uploaded

* grammar (yes I care)

* fixed inconsistency
  • Loading branch information
varCepheid authored Feb 15, 2023
1 parent eb52fa7 commit 60f0753
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/api/report/submit-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,6 +55,19 @@ export const uploadSavedReports = async () => {
[] as Report[] | Promise<Report[]>,
)
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 */
Expand Down
2 changes: 1 addition & 1 deletion src/components/report-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export const ReportEditor = ({
key: initialReport.key || generateReportKey(),
}
saveReportLocally(reportWithKey)
if (onSaveLocally) onSaveLocally(reportWithKey)
onSaveLocally?.(reportWithKey)
}
})
.finally(() => {
Expand Down

0 comments on commit 60f0753

Please sign in to comment.