11import React from "react" ;
2- import { useTranslation } from "react-i18next" ;
3- import { editFilterValue } from "../../../slices/tableFilterSlice" ;
42import { loadEventsIntoTable } from "../../../thunks/tableThunks" ;
5- import { getFilters } from "../../../selectors/tableFilterSelectors" ;
6- import { useAppDispatch , useAppSelector } from "../../../store" ;
73import { fetchEvents } from "../../../slices/eventSlice" ;
8- import { renderValidDate } from "../../../utils/dateUtils" ;
94import { Event } from "../../../slices/eventSlice" ;
10- import { IconButton } from "../../shared/IconButton " ;
5+ import DateTimeCell from "../../shared/DateTimeCell " ;
116
127/**
138 * This component renders the start date cells of events in the table view
@@ -17,39 +12,15 @@ const EventsDateCell = ({
1712} : {
1813 row : Event
1914} ) => {
20- const { t } = useTranslation ( ) ;
21- const dispatch = useAppDispatch ( ) ;
22-
23- const filterMap = useAppSelector ( state => getFilters ( state , "events" ) ) ;
24-
25- // Filter with value of current cell
26- const addFilter = async ( date : string ) => {
27- let filter = filterMap . find ( ( { name } ) => name === "startDate" ) ;
28- if ( ! ! filter ) {
29- let startDate = new Date ( date ) ;
30- startDate . setHours ( 0 ) ;
31- startDate . setMinutes ( 0 ) ;
32- startDate . setSeconds ( 0 ) ;
33- let endDate = new Date ( date ) ;
34- endDate . setHours ( 23 ) ;
35- endDate . setMinutes ( 59 ) ;
36- endDate . setSeconds ( 59 ) ;
37-
38- await dispatch ( editFilterValue ( { filterName : filter . name , value : startDate . toISOString ( ) + "/" + endDate . toISOString ( ) } ) ) ;
39- await dispatch ( fetchEvents ( ) ) ;
40- dispatch ( loadEventsIntoTable ( ) ) ;
41- }
42- } ;
43-
4415 return (
45- // Link template for start date of event
46- < IconButton
47- callback = { ( ) => addFilter ( row . date ) }
48- iconClassname = { "crosslink" }
49- tooltipText = { "EVENTS.EVENTS.TABLE.TOOLTIP.START" }
50- >
51- { t ( "dateFormats.date.short" , { date : renderValidDate ( row . date ) } ) }
52- </ IconButton >
16+ < DateTimeCell
17+ resource = "events"
18+ date = { row . date }
19+ filterName = "startDate"
20+ fetchResource = { fetchEvents }
21+ loadResourceIntoTable = { loadEventsIntoTable }
22+ tooltipText = "EVENTS.EVENTS.TABLE.TOOLTIP.START"
23+ / >
5324 ) ;
5425} ;
5526
0 commit comments