Skip to content

Instantly share code, notes, and snippets.

@emanueleDiVizio
Created June 1, 2020 17:34
Show Gist options
  • Save emanueleDiVizio/ce54d32ca7bd59e3e25bdd6d5a237566 to your computer and use it in GitHub Desktop.
Save emanueleDiVizio/ce54d32ca7bd59e3e25bdd6d5a237566 to your computer and use it in GitHub Desktop.
const ShiftButton = () => {
const dispatch = useDispatch()
const isOnShift = useIsOnShift()
const onUserPressButton = () => {
isOnShift
? dispatch(shiftSlice.actions.endShift())
: dispatch(shiftSlice.actions.startShift())
}
const computeStyles = onShift => ({
backgroundColor: onShift ? config.colors.accent : config.colors.main,
})
return (
<TouchableOpacity
testID="shift-button"
style={[computeStyles(isOnShift), styles.container]}
onPress={onUserPressButton}
>
<Text style={styles.text}>{isOnShift ? 'End Shift' : 'Start shift'}</Text>
</TouchableOpacity>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment