diff --git a/src/features/JoinMatchPage/hooks.tsx b/src/features/JoinMatchPage/hooks.tsx index 94e33bad..1fdbded8 100644 --- a/src/features/JoinMatchPage/hooks.tsx +++ b/src/features/JoinMatchPage/hooks.tsx @@ -1,4 +1,3 @@ -import type { FormEvent } from 'react' import { useEffect, useState, @@ -9,41 +8,33 @@ import format from 'date-fns/format' import type { UnauthenticatedMatch } from 'requests' import { getUnauthenticatedMatch } from 'requests' +import { parseDate } from 'helpers/parseDate' + import { usePageParams } from 'hooks/usePageParams' -import { useLexicsStore } from 'features/LexicsStore' -import { getName } from 'features/Name' import { useAuthStore } from 'features/AuthStore' export const useUnauthenticatedMatch = () => { + const { login } = useAuthStore() + const [ matchInfo, setMatchInfo, ] = useState(null) - const { suffix } = useLexicsStore() const { profileId: matchId, sportType } = usePageParams() - const teamName1 = getName({ nameObj: matchInfo?.team1 || {}, suffix }) - const teamName2 = getName({ nameObj: matchInfo?.team2 || {}, suffix }) - - const date = matchInfo?.date - const matchDate = (date && format(new Date(date), 'd MMM HH:mm')) || '' - - const { login } = useAuthStore() - const handleSubmit = (event: FormEvent) => { - event.preventDefault() - login() - } + const matchDate = matchInfo?.date + ? format(parseDate(matchInfo.date), 'd MMM HH:mm') + : '' useEffect(() => { getUnauthenticatedMatch(sportType, matchId).then(setMatchInfo) }, [sportType, matchId]) return { - handleSubmit, live: matchInfo?.live, matchDate, - teamName1, - teamName2, + matchInfo, + onJoinClick: login, } } diff --git a/src/features/JoinMatchPage/index.tsx b/src/features/JoinMatchPage/index.tsx index f0eee3b1..d2dfbac2 100644 --- a/src/features/JoinMatchPage/index.tsx +++ b/src/features/JoinMatchPage/index.tsx @@ -5,6 +5,7 @@ import { joinMatchLexics } from 'config/lexics/joinMatch' import { usePageParams } from 'hooks/usePageParams' import { T9n } from 'features/T9n' +import { Name } from 'features/Name' import { useLexicsConfig } from 'features/LexicsStore' import { useUnauthenticatedMatch } from './hooks' @@ -37,11 +38,10 @@ export const JoinMatchPage = () => { const { sportType } = usePageParams() const { - handleSubmit, live, matchDate, - teamName1, - teamName2, + matchInfo, + onJoinClick, } = useUnauthenticatedMatch() const currentYear = format(new Date(), 'Y') @@ -66,9 +66,9 @@ export const JoinMatchPage = () => { )} - {teamName1} + - {teamName2} + @@ -77,11 +77,9 @@ export const JoinMatchPage = () => { -
- - - -
+ + +