Skip to content

Commit ca8ca68

Browse files
samsharafrozenhelium
authored andcommitted
feat: add xlsx download link for eru readiness information
1 parent 05d4bb4 commit ca8ca68

2 files changed

Lines changed: 56 additions & 8 deletions

File tree

  • app/src/views/SurgeOverview/EmergencyResponseUnit/EmergencyResponseUnitReadiness

app/src/views/SurgeOverview/EmergencyResponseUnit/EmergencyResponseUnitReadiness/i18n.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"eruReadinessCount": "ERU Capacity and Readiness ({count})",
55
"eruReadinessUpdateButton": "Update ERU Readiness",
66
"eruNationalSociety": "National Society",
7-
"eruType": "ERU Type"
7+
"eruType": "ERU Type",
8+
"exportEruReadiness": "Export ERU Readiness",
9+
"exportEruReadinessFailed": "Failed to export ERU readiness information.",
10+
"fetchEruReadinessFailed": "Failed to fetch ERU readiness information."
811
}
912
}

app/src/views/SurgeOverview/EmergencyResponseUnit/EmergencyResponseUnitReadiness/index.tsx

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
useState,
55
} from 'react';
66
import {
7+
Button,
78
Container,
89
Grid,
910
SelectInput,
@@ -29,11 +30,14 @@ import {
2930
} from '@togglecorp/fujs';
3031

3132
import Link from '#components/Link';
33+
import useAlert from '#hooks/useAlert';
3234
import useGlobalEnums from '#hooks/domain/useGlobalEnums';
3335
import useFilterState from '#hooks/useFilterState';
3436
import { joinStrings } from '#utils/common';
37+
import { api } from '#config';
3538
import {
3639
type GoApiResponse,
40+
useLazyRequest,
3741
useRequest,
3842
} from '#utils/restRequest';
3943

@@ -72,6 +76,8 @@ function EmergencyResponseUnitReadiness() {
7276
filter: {},
7377
});
7478

79+
const alert = useAlert();
80+
7581
const {
7682
error: eruOwnersError,
7783
response: eruOwnersResponse,
@@ -93,6 +99,12 @@ function EmergencyResponseUnitReadiness() {
9399
eru_type: filter.selectEruTypes,
94100
eru_owner: filter.selectEruOwner,
95101
},
102+
onFailure: () => {
103+
alert.show(
104+
strings.fetchEruReadinessFailed,
105+
{ variant: 'danger' },
106+
);
107+
},
96108
});
97109

98110
const {
@@ -107,8 +119,32 @@ function EmergencyResponseUnitReadiness() {
107119
type: filter.selectEruTypes,
108120
eru_owner: filter.selectEruOwner,
109121
},
122+
onFailure: () => {
123+
alert.show(
124+
strings.fetchEruReadinessFailed,
125+
{ variant: 'danger' },
126+
);
127+
},
128+
});
129+
130+
const {
131+
pending: eruReadinessExportPending,
132+
trigger: triggerEruReadinessExport,
133+
} = useLazyRequest({
134+
method: 'GET',
135+
url: '/api/v2/export-eru-readiness',
136+
onFailure: () => {
137+
alert.show(
138+
strings.exportEruReadinessFailed,
139+
{ variant: 'danger' },
140+
);
141+
},
110142
});
111143

144+
const handleEruReadinessExport = () => {
145+
triggerEruReadinessExport(null);
146+
};
147+
112148
const {
113149
deployments_eru_type: deploymentEruType,
114150
} = useGlobalEnums();
@@ -173,12 +209,21 @@ function EmergencyResponseUnitReadiness() {
173209
)}
174210
withHeaderBorder
175211
actions={(
176-
<Link
177-
to="eruReadinessForm"
178-
variant="primary"
179-
>
180-
{strings.eruReadinessUpdateButton}
181-
</Link>
212+
<>
213+
<Link
214+
href={`${api}/api/v2/export-eru-readiness`}
215+
variant="secondary"
216+
external
217+
>
218+
{strings.exportEruReadiness}
219+
</Link>
220+
<Link
221+
to="eruReadinessForm"
222+
variant="primary"
223+
>
224+
{strings.eruReadinessUpdateButton}
225+
</Link>
226+
</>
182227
)}
183228
contentViewType="vertical"
184229
filters={(
@@ -238,7 +283,7 @@ function EmergencyResponseUnitReadiness() {
238283
/>
239284
</TabPanel>
240285
</Container>
241-
</Tabs>
286+
</Tabs >
242287
);
243288
}
244289

0 commit comments

Comments
 (0)