Ott 2034 join match date parsing

keep-around/51e98a47165760f662e1a61204ad79a33ba1315b
Макситалиев Мирлан 4 years ago
parent 354bceaac7
commit 51e98a4716
  1. 27
      src/features/JoinMatchPage/hooks.tsx
  2. 14
      src/features/JoinMatchPage/index.tsx
  3. 8
      src/features/Matches/helpers/prepareMatches.tsx
  4. 9
      src/helpers/parseDate/index.tsx

@ -1,4 +1,3 @@
import type { FormEvent } from 'react'
import { import {
useEffect, useEffect,
useState, useState,
@ -9,41 +8,33 @@ import format from 'date-fns/format'
import type { UnauthenticatedMatch } from 'requests' import type { UnauthenticatedMatch } from 'requests'
import { getUnauthenticatedMatch } from 'requests' import { getUnauthenticatedMatch } from 'requests'
import { parseDate } from 'helpers/parseDate'
import { usePageParams } from 'hooks/usePageParams' import { usePageParams } from 'hooks/usePageParams'
import { useLexicsStore } from 'features/LexicsStore'
import { getName } from 'features/Name'
import { useAuthStore } from 'features/AuthStore' import { useAuthStore } from 'features/AuthStore'
export const useUnauthenticatedMatch = () => { export const useUnauthenticatedMatch = () => {
const { login } = useAuthStore()
const [ const [
matchInfo, setMatchInfo, matchInfo, setMatchInfo,
] = useState<UnauthenticatedMatch>(null) ] = useState<UnauthenticatedMatch>(null)
const { suffix } = useLexicsStore()
const { profileId: matchId, sportType } = usePageParams() const { profileId: matchId, sportType } = usePageParams()
const teamName1 = getName({ nameObj: matchInfo?.team1 || {}, suffix }) const matchDate = matchInfo?.date
const teamName2 = getName({ nameObj: matchInfo?.team2 || {}, suffix }) ? format(parseDate(matchInfo.date), 'd MMM HH:mm')
: ''
const date = matchInfo?.date
const matchDate = (date && format(new Date(date), 'd MMM HH:mm')) || ''
const { login } = useAuthStore()
const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault()
login()
}
useEffect(() => { useEffect(() => {
getUnauthenticatedMatch(sportType, matchId).then(setMatchInfo) getUnauthenticatedMatch(sportType, matchId).then(setMatchInfo)
}, [sportType, matchId]) }, [sportType, matchId])
return { return {
handleSubmit,
live: matchInfo?.live, live: matchInfo?.live,
matchDate, matchDate,
teamName1, matchInfo,
teamName2, onJoinClick: login,
} }
} }

@ -5,6 +5,7 @@ import { joinMatchLexics } from 'config/lexics/joinMatch'
import { usePageParams } from 'hooks/usePageParams' import { usePageParams } from 'hooks/usePageParams'
import { T9n } from 'features/T9n' import { T9n } from 'features/T9n'
import { Name } from 'features/Name'
import { useLexicsConfig } from 'features/LexicsStore' import { useLexicsConfig } from 'features/LexicsStore'
import { useUnauthenticatedMatch } from './hooks' import { useUnauthenticatedMatch } from './hooks'
@ -37,11 +38,10 @@ export const JoinMatchPage = () => {
const { sportType } = usePageParams() const { sportType } = usePageParams()
const { const {
handleSubmit,
live, live,
matchDate, matchDate,
teamName1, matchInfo,
teamName2, onJoinClick,
} = useUnauthenticatedMatch() } = useUnauthenticatedMatch()
const currentYear = format(new Date(), 'Y') const currentYear = format(new Date(), 'Y')
@ -66,9 +66,9 @@ export const JoinMatchPage = () => {
)} )}
</DateInfoWrapper> </DateInfoWrapper>
<TeamsNameWrapper> <TeamsNameWrapper>
<EmptySpan>{teamName1}</EmptySpan> <Name nameObj={matchInfo?.team1 || {}} />
<EmptySpan> </EmptySpan> <EmptySpan> </EmptySpan>
<EmptySpan>{teamName2}</EmptySpan> <Name nameObj={matchInfo?.team2 || {}} />
</TeamsNameWrapper> </TeamsNameWrapper>
<MainInfoTitle> <MainInfoTitle>
<T9n t='join_instat_tv' /> <T9n t='join_instat_tv' />
@ -77,11 +77,9 @@ export const JoinMatchPage = () => {
<MainInfoText> <MainInfoText>
<T9n t='promo_text' /> <T9n t='promo_text' />
</MainInfoText> </MainInfoText>
<form onSubmit={handleSubmit}> <MainInfoButton onClick={onJoinClick}>
<MainInfoButton type='submit'>
<T9n t='join_now' /> <T9n t='join_now' />
</MainInfoButton> </MainInfoButton>
</form>
</MatchInfo> </MatchInfo>
</BlockWrapper> </BlockWrapper>
<Footer> <Footer>

@ -1,11 +1,11 @@
import map from 'lodash/map' import map from 'lodash/map'
import parse from 'date-fns/parse'
import format from 'date-fns/format' import format from 'date-fns/format'
import type { Match } from 'requests' import type { Match } from 'requests'
import { getSportLexic } from 'helpers' import { getSportLexic } from 'helpers'
import { parseDate } from 'helpers/parseDate'
import { getMatchAccess } from './getMatchClickAction' import { getMatchAccess } from './getMatchClickAction'
@ -24,11 +24,7 @@ const prepareMatch = (match: Match) => {
team2, team2,
tournament, tournament,
} = match } = match
const date = parse( const date = parseDate(matchDate)
matchDate,
'yyyy-MM-dd HH:mm:ssx',
new Date(),
)
return { return {
access: getMatchAccess(match), access: getMatchAccess(match),
calc, calc,

@ -0,0 +1,9 @@
import parse from 'date-fns/parse'
export const parseDate = (dateString: string, format = 'yyyy-MM-dd HH:mm:ssx') => (
parse(
dateString,
format,
new Date(),
)
)
Loading…
Cancel
Save