-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
145 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React from 'react'; | ||
import { ButtonGroup, IconButton } from '@material-ui/core'; | ||
import StarIcon from '@material-ui/icons/Star'; | ||
import StarBorderIcon from '@material-ui/icons/StarBorder'; | ||
import StarsIcon from '@material-ui/icons/Stars'; | ||
import { AgendaEvent } from '../../data/dbSchema'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
import { getSelectedCategory } from './getSelectedCategory'; | ||
import { updateEventProps } from '../../services/api'; | ||
import { patchEvent } from '../../store/eventsSlice'; | ||
|
||
interface EventButtonGroupProps { | ||
event: AgendaEvent; | ||
} | ||
|
||
/* | ||
[x] display correct star | ||
on click | ||
[x] prepare DB update objetc | ||
[x] call endpoint to update DB | ||
[ ] patch the store with new version of event */ | ||
|
||
export const EventButtonGroup: React.FC<EventButtonGroupProps> = ({ | ||
event, | ||
}) => { | ||
const dispatch = useDispatch(); | ||
|
||
const selectedCategory = useSelector(getSelectedCategory); | ||
const eventStatus = event.state[selectedCategory]; | ||
const { id } = event; | ||
|
||
const stateIconMap = { | ||
candidate: <StarBorderIcon color="primary" />, | ||
highlight: <StarIcon color="primary" />, | ||
mainfocus: <StarsIcon color="primary" />, | ||
}; | ||
|
||
const StateButton = (): React.ReactElement => stateIconMap[eventStatus]; | ||
|
||
const nextStatusMap = { | ||
candidate: 'highlight', | ||
highlight: 'mainfocus', | ||
mainfocus: 'candidate', | ||
}; | ||
|
||
async function handlePromoteButtonClic(): Promise<void> { | ||
const statusUpdateObject = { | ||
id: id, | ||
state: { | ||
[selectedCategory]: nextStatusMap[eventStatus], | ||
}, | ||
}; | ||
|
||
const { event, error } = await updateEventProps(statusUpdateObject); | ||
|
||
if (error) { | ||
console.error(error); | ||
return; | ||
} | ||
|
||
if (event) { | ||
dispatch(patchEvent(event)); | ||
return; | ||
} | ||
} | ||
|
||
return ( | ||
<ButtonGroup> | ||
<IconButton onClick={handlePromoteButtonClic}> | ||
<StateButton /> | ||
</IconButton> | ||
</ButtonGroup> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { AppState } from '../../store/'; | ||
import { AgendaEventCategory } from '../../data/dbSchema'; | ||
|
||
export function getSelectedCategory(state: AppState): AgendaEventCategory { | ||
return state.events.selectedCategory; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters