aboutsummaryrefslogtreecommitdiff
path: root/modern/src/reports/StopReportPage.js
diff options
context:
space:
mode:
Diffstat (limited to 'modern/src/reports/StopReportPage.js')
-rw-r--r--modern/src/reports/StopReportPage.js38
1 files changed, 21 insertions, 17 deletions
diff --git a/modern/src/reports/StopReportPage.js b/modern/src/reports/StopReportPage.js
index bacbe928..5d6e837d 100644
--- a/modern/src/reports/StopReportPage.js
+++ b/modern/src/reports/StopReportPage.js
@@ -46,25 +46,29 @@ const StopReportPage = () => {
const [loading, setLoading] = useState(false);
const [selectedItem, setSelectedItem] = useState(null);
- const handleSubmit = useCatch(async ({ deviceId, from, to, mail, headers }) => {
- setLoading(true);
- try {
- const query = new URLSearchParams({ deviceId, from, to, mail });
- const response = await fetch(`/api/reports/stops?${query.toString()}`, { headers });
- if (response.ok) {
- const contentType = response.headers.get('content-type');
- if (contentType) {
- if (contentType === 'application/json') {
- setItems(await response.json());
- } else {
- window.location.assign(window.URL.createObjectURL(await response.blob()));
- }
- }
- } else {
+ const handleSubmit = useCatch(async ({ deviceId, from, to, type }) => {
+ const query = new URLSearchParams({ deviceId, from, to });
+ if (type === 'export') {
+ window.location.assign(`/api/reports/stops/xlsx?${query.toString()}`);
+ } else if (type === 'mail') {
+ const response = await fetch(`/api/reports/stops/mail?${query.toString()}`);
+ if (!response.ok) {
throw Error(await response.text());
}
- } finally {
- setLoading(false);
+ } else {
+ setLoading(true);
+ try {
+ const response = await fetch(`/api/reports/stops?${query.toString()}`, {
+ headers: { Accept: 'application/json' },
+ });
+ if (response.ok) {
+ setItems(await response.json());
+ } else {
+ throw Error(await response.text());
+ }
+ } finally {
+ setLoading(false);
+ }
}
});