Skip to content
Snippets Groups Projects
ActionView.tsx 1.47 KiB
Newer Older
  • Learn to ignore specific revisions
  • Guilhem CARRON's avatar
    Guilhem CARRON committed
    import Content from 'components/Content/Content'
    
    import CozyBar from 'components/Header/CozyBar'
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    import Header from 'components/Header/Header'
    
    import { UserActionState } from 'enums'
    
    import { UserChallenge } from 'models'
    
    import React, { useState } from 'react'
    
    import { useAppSelector } from 'store/hooks'
    
    import ActionChoose from './ActionChoose/ActionChoose'
    import ActionDone from './ActionDone/ActionDone'
    import ActionOnGoing from './ActionOnGoing/ActionOnGoing'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    const ActionView = () => {
    
      const { currentChallenge } = useAppSelector(state => state.ecolyo.challenge)
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      const [headerHeight, setHeaderHeight] = useState<number>(0)
    
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      const renderAction = (challenge: UserChallenge) => {
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        switch (challenge.action.state) {
          case UserActionState.UNSTARTED:
            return <ActionChoose userChallenge={challenge} />
          case UserActionState.ONGOING:
            return <ActionOnGoing userAction={challenge.action} />
    
          case UserActionState.NOTIFICATION:
            return <ActionDone currentChallenge={challenge} />
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          default:
            return <ActionChoose userChallenge={challenge} />
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        }
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      }
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    
      return (
        <>
    
          <CozyBar titleKey="common.title_action" displayBackArrow={true} />
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          <Header
    
            setHeaderHeight={setHeaderHeight}
    
            desktopTitleKey="common.title_action"
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
            displayBackArrow={true}
    
          <Content heightOffset={headerHeight}>
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
            {currentChallenge && renderAction(currentChallenge)}
          </Content>
        </>
      )
    }
    
    export default ActionView