@@ -16,13 +16,9 @@ import {
1616 _cs ,
1717 isDefined ,
1818 isNotDefined ,
19- unique ,
2019} from '@togglecorp/fujs' ;
2120
22- import PageContainer from '#components/PageContainer' ;
23- import PageHeader from '#components/PageHeader' ;
2421import Page from '#components/Page' ;
25- import useUserMe from '#hooks/domain/useUserMe' ;
2622import Container from '#components/Container' ;
2723import IconButton from '#components/IconButton' ;
2824import BlockLoading from '#components/BlockLoading' ;
@@ -32,67 +28,25 @@ import HighlightedOperations from '#components/domain/HighlightedOperations';
3228import ActiveOperationMap from '#components/domain/ActiveOperationMap' ;
3329import AppealsTable from '#components/domain/AppealsTable' ;
3430import AppealsOverYearsChart from '#components/domain/AppealsOverYearsChart' ;
35- import OperationListItem , { type Props as OperationListItemProps } from '#components/domain/OperationListItem' ;
36- import List from '#components/List' ;
37- import Pager from '#components/Pager' ;
38- import TextOutput from '#components/TextOutput' ;
39- import Link from '#components/Link' ;
40- import useAuth from '#hooks/domain/useAuth' ;
4131import useTranslation from '#hooks/useTranslation' ;
42- import { getUserName } from '#utils/domain/user' ;
43- import { numericIdSelector } from '#utils/selectors' ;
44- import { getPercentage , joinList } from '#utils/common' ;
45- import useFilterState from '#hooks/useFilterState' ;
46- import { resolveToString } from '#utils/translation' ;
47- import { useRequest , type GoApiResponse } from '#utils/restRequest' ;
32+ import { getPercentage } from '#utils/common' ;
33+ import { useRequest } from '#utils/restRequest' ;
4834
4935import i18n from './i18n.json' ;
5036import styles from './styles.module.css' ;
5137
52- type OperationsResponse = GoApiResponse < '/api/v2/event/' > ;
53-
5438// eslint-disable-next-line import/prefer-default-export
5539export function Component ( ) {
5640 const strings = useTranslation ( i18n ) ;
5741
58- const {
59- page,
60- setPage,
61- limit,
62- offset,
63- } = useFilterState < object > ( {
64- filter : { } ,
65- pageSize : 5 ,
66- } ) ;
67-
68- const { isAuthenticated } = useAuth ( ) ;
69- const userResponse = useUserMe ( ) ;
70-
7142 const {
7243 pending : aggregatedAppealPending ,
7344 response : aggregatedAppealResponse ,
7445 } = useRequest ( {
7546 url : '/api/v2/appeal/aggregated' ,
7647 } ) ;
7748
78- const {
79- error : subscribedEventsResponseError ,
80- response : subscribedEventsResponse ,
81- pending : subscribedEventsResponsePending ,
82- retrigger : updateSubscribedEventsResponse ,
83- } = useRequest ( {
84- skip : ! isAuthenticated ,
85- url : '/api/v2/event/' ,
86- query : {
87- limit,
88- offset,
89- is_subscribed : true ,
90- } ,
91- preserveResponse : true ,
92- } ) ;
93-
9449 const pending = aggregatedAppealPending ;
95- const eventList = subscribedEventsResponse ?. results ;
9650
9751 const [
9852 presentationMode ,
@@ -179,28 +133,6 @@ export function Component() {
179133 </ >
180134 ) ;
181135
182- const rendererParams = useCallback (
183- (
184- _ : number ,
185- operation : NonNullable < OperationsResponse [ 'results' ] > [ number ] ,
186- i : number ,
187- data : unknown [ ] ,
188- ) : OperationListItemProps => ( {
189- eventItem : operation ,
190- updateSubscibedEvents : updateSubscribedEventsResponse ,
191- isLastItem : i === ( data . length - 1 ) ,
192- } ) ,
193- [ updateSubscribedEventsResponse ] ,
194- ) ;
195-
196- const userCountries = userResponse ?. user_countries_regions ;
197- // FIXME: The typing of country should no non-nullabe in the server
198- // NOTE: Only showing unique regions
199- const userRegions = unique (
200- userCountries ?? [ ] ,
201- ( item ) => item . region_details . id ,
202- ) ;
203-
204136 return (
205137 < Page
206138 title = { strings . homeTitle }
@@ -215,116 +147,6 @@ export function Component() {
215147 { ! pending && keyFigures }
216148 </ >
217149 ) }
218- beforeHeaderContent = { isAuthenticated && (
219- < >
220- < PageHeader
221- heading = { resolveToString (
222- strings . homeUserNameHeading ,
223- { userName : getUserName ( userResponse ) } ,
224- ) }
225- />
226- < PageContainer contentClassName = { styles . userDashContent } >
227- < Container
228- className = { styles . operationsFollowing }
229- heading = { strings . homeOperationFollowingHeading }
230- withHeaderBorder
231- footerActions = { (
232- < Pager
233- activePage = { page }
234- itemsCount = { subscribedEventsResponse ?. count ?? 0 }
235- maxItemsPerPage = { limit }
236- onActivePageChange = { setPage }
237- />
238- ) }
239- withInternalPadding
240- contentViewType = "vertical"
241- >
242- < List
243- className = { styles . operationsList }
244- data = { eventList }
245- pending = { subscribedEventsResponsePending }
246- errored = { isDefined ( subscribedEventsResponseError ) }
247- filtered = { false }
248- keySelector = { numericIdSelector }
249- renderer = { OperationListItem }
250- rendererParams = { rendererParams }
251- />
252- </ Container >
253- < Container
254- className = { styles . quickLinks }
255- heading = { strings . homeQuickLinksTitle }
256- withInternalPadding
257- withHeaderBorder
258- contentViewType = "vertical"
259- >
260- < TextOutput
261- label = { strings . homeYourCountryLabel }
262- value = { userCountries && (
263- joinList (
264- userCountries . map ( ( country ) => (
265- < Link
266- to = "countriesLayout"
267- urlParams = { {
268- countryId : country . country ,
269- } }
270- key = { country . country }
271- withUnderline
272- >
273- { country . country_name }
274- </ Link >
275- ) ) ,
276- ', ' ,
277- )
278- ) }
279- strongValue
280- />
281- < TextOutput
282- label = { strings . homeFieldReportLabel }
283- value = { (
284- < Link
285- to = "fieldReportFormNew"
286- withLinkIcon
287- >
288- { strings . homeCreateFieldReport }
289- </ Link >
290- ) }
291- strongValue
292- />
293- < TextOutput
294- label = { strings . homeYourRegionLabel }
295- value = { userRegions && (
296- joinList (
297- userRegions . map ( ( region ) => (
298- < Link
299- key = { region . region }
300- to = "regionsLayout"
301- urlParams = { { regionId : region . region } }
302- withUnderline
303- >
304- { region . region_details . name }
305- </ Link >
306- ) ) ,
307- ', ' ,
308- )
309- ) }
310- strongValue
311- />
312- < TextOutput
313- label = { strings . homeFlashUpdateLabel }
314- value = { (
315- < Link
316- to = "flashUpdateFormNew"
317- withLinkIcon
318- >
319- { strings . homeCreateFlashUpdate }
320- </ Link >
321- ) }
322- strongValue
323- />
324- </ Container >
325- </ PageContainer >
326- </ >
327- ) }
328150 >
329151 < HighlightedOperations variant = "global" />
330152 < ActiveOperationMap
0 commit comments