Skip to content
Snippets Groups Projects
ChallengeCard.tsx 3.19 KiB
Newer Older
  • Learn to ignore specific revisions
  • Hugo NOUTS's avatar
    Hugo NOUTS committed
    import React, { useContext } from 'react'
    import { translate } from 'cozy-ui/react/I18n'
    import { UserChallenge, TypeChallenge } from 'services/dataChallengeContracts'
    import StyledChallengeCard from 'components/CommonKit/Card/StyledChallengeCard'
    import { NavLink } from 'react-router-dom'
    import { AppContext } from 'components/Contexts/AppContextProvider'
    import StyledIcon from 'components/CommonKit/Icon/StyledIcon'
    import OngoingChallengePile from 'components/ContentComponents/Challenge/OngoingChallengePile'
    import OngoingChallengeViewingDate from 'components/ContentComponents/Challenge/OngoingChallengeViewingDate'
    import FollowChallengeTimeline from 'components/ContentComponents/Challenge/FollowChallengeTimeline'
    import BlackArrowIcon from 'assets/icons/ico/black-arrow.svg'
    
    interface ChallengeCardProps {
      userChallenge: UserChallenge
    }
    
    const ChallengeCard: React.FC<ChallengeCardProps> = ({
      userChallenge,
    }: ChallengeCardProps) => {
      const { challengeNotification } = useContext(AppContext)
      const challengesPath = 'challenges'
      const challengeDetailPath = {
        pathname: `challenges/ongoing`,
        state: { challenge: userChallenge },
      }
      return (
        <NavLink
          className="cc-link"
          to={challengeNotification ? challengesPath : challengeDetailPath}
        >
          <div>
            {userChallenge.challengeType &&
            userChallenge.challengeType.type === TypeChallenge.CHALLENGE ? (
              <StyledChallengeCard displayBorder={true}>
                <div className="cc">
                  <div className="cc-content-left">
                    <div className="cc-content-title cc-content-title-padding text-18-normal">
                      {userChallenge.challengeType.title}
                    </div>
                    <div className="cc-content-progress">
                      <OngoingChallengePile
                        challenge={userChallenge}
                        small={true}
                      />
                    </div>
                    <div className="cc-content-timeline">
                      <FollowChallengeTimeline challenge={userChallenge} />
                    </div>
                    <div className="cc-content-visu text-15-normal">
                      <OngoingChallengeViewingDate challenge={userChallenge} />
                    </div>
                  </div>
                  <div className="cc-content-right">
                    <StyledIcon icon={BlackArrowIcon} size={18} />
                  </div>
                </div>
              </StyledChallengeCard>
            ) : (
              <StyledChallengeCard displayBorder={challengeNotification}>
                <div className="cc">
                  <div className="cc-content-left">
                    <div className="cc-content-title text-18-normal">
                      {userChallenge.challengeType
                        ? userChallenge.challengeType.title
                        : null}
                    </div>
                  </div>
                  <div className="cc-content-right">
                    {challengeNotification && (
                      <div className="cc-notification text-16-bold">1</div>
                    )}
                    <StyledIcon icon={BlackArrowIcon} size={18} />
                  </div>
                </div>
              </StyledChallengeCard>
            )}
          </div>
        </NavLink>
      )
    }
    
    export default translate()(ChallengeCard)