|
|
|
@ -9,10 +9,12 @@ import { |
|
|
|
|
|
|
|
|
|
|
|
import debounce from 'lodash/debounce' |
|
|
|
import debounce from 'lodash/debounce' |
|
|
|
|
|
|
|
|
|
|
|
import { useRecoilState } from 'recoil' |
|
|
|
import { useRecoilState, useSetRecoilState } from 'recoil' |
|
|
|
|
|
|
|
|
|
|
|
import { useUserFavoritesStore } from 'features/UserFavorites/store' |
|
|
|
import { useUserFavoritesStore } from 'features/UserFavorites/store' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import type { Match } from 'requests/getMatches/types' |
|
|
|
|
|
|
|
|
|
|
|
import { getSportList } from 'requests/getSportList' |
|
|
|
import { getSportList } from 'requests/getSportList' |
|
|
|
import { |
|
|
|
import { |
|
|
|
getSportTeams, |
|
|
|
getSportTeams, |
|
|
|
@ -26,13 +28,12 @@ import { playerMatchesState, dataForPayHighlights } from '../../storeHighlightsA |
|
|
|
|
|
|
|
|
|
|
|
export type SportType = { |
|
|
|
export type SportType = { |
|
|
|
id: number, |
|
|
|
id: number, |
|
|
|
lexic: string, |
|
|
|
lexic: number, |
|
|
|
name: string, |
|
|
|
|
|
|
|
name_eng: string, |
|
|
|
name_eng: string, |
|
|
|
name_rus?: string, |
|
|
|
name_rus: string, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type SportTypeName = SportType& { |
|
|
|
type SportTypeName = SportType & { |
|
|
|
name: string, |
|
|
|
name: string, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -44,18 +45,26 @@ type TeamType = Team & { |
|
|
|
name: string, |
|
|
|
name: string, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type Sound = { |
|
|
|
|
|
|
|
id: number, |
|
|
|
|
|
|
|
name: string, |
|
|
|
|
|
|
|
src?: string, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type StatsType = { |
|
|
|
|
|
|
|
id: number, |
|
|
|
|
|
|
|
name: string, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type FormType = { |
|
|
|
type FormType = { |
|
|
|
duration: string, |
|
|
|
duration: string, |
|
|
|
playerValue: string, |
|
|
|
playerValue: string, |
|
|
|
players: Array<string>, |
|
|
|
players: Array<string>, |
|
|
|
selectedPlayer: PlayerType | null, |
|
|
|
selectedPlayer: PlayerType | null, |
|
|
|
selectedSound: any, |
|
|
|
selectedSound: Sound | null, |
|
|
|
selectedTeam: Team | null, |
|
|
|
selectedTeam: Team | null, |
|
|
|
sport: SportTypeName, |
|
|
|
sport: SportTypeName, |
|
|
|
stats: { |
|
|
|
stats: StatsType, |
|
|
|
id: number, |
|
|
|
|
|
|
|
name: string, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
teamValue: string, |
|
|
|
teamValue: string, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -91,7 +100,7 @@ export const useHighlightsForm = () => { |
|
|
|
const [players, setPlayers] = useState<Array<PlayerType>>([]) |
|
|
|
const [players, setPlayers] = useState<Array<PlayerType>>([]) |
|
|
|
const [formState, setFormState] = useState<FormType>({} as FormType) |
|
|
|
const [formState, setFormState] = useState<FormType>({} as FormType) |
|
|
|
const [playerMatches, setPlayerMatches] = useRecoilState(playerMatchesState) |
|
|
|
const [playerMatches, setPlayerMatches] = useRecoilState(playerMatchesState) |
|
|
|
const [dataHighlights, setDatahighlights] = useRecoilState(dataForPayHighlights) |
|
|
|
const setDatahighlights = useSetRecoilState(dataForPayHighlights) |
|
|
|
|
|
|
|
|
|
|
|
const formRef = useRef<HTMLFormElement>(null) |
|
|
|
const formRef = useRef<HTMLFormElement>(null) |
|
|
|
|
|
|
|
|
|
|
|
@ -107,6 +116,7 @@ export const useHighlightsForm = () => { |
|
|
|
})) |
|
|
|
})) |
|
|
|
setTeams([]) |
|
|
|
setTeams([]) |
|
|
|
setPlayers([]) |
|
|
|
setPlayers([]) |
|
|
|
|
|
|
|
setPlayerMatches([]) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -127,7 +137,7 @@ export const useHighlightsForm = () => { |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const onSoundSelect = (selectedSound: any) => { |
|
|
|
const onSoundSelect = (selectedSound: Sound | null) => { |
|
|
|
if (!selectedSound) return |
|
|
|
if (!selectedSound) return |
|
|
|
setFormState((state) => ({ |
|
|
|
setFormState((state) => ({ |
|
|
|
...state, |
|
|
|
...state, |
|
|
|
@ -135,7 +145,7 @@ export const useHighlightsForm = () => { |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const onStatsSelect = (stats: any) => { |
|
|
|
const onStatsSelect = (stats: StatsType | null) => { |
|
|
|
if (!stats) return |
|
|
|
if (!stats) return |
|
|
|
setFormState((state) => ({ |
|
|
|
setFormState((state) => ({ |
|
|
|
...state, |
|
|
|
...state, |
|
|
|
@ -181,26 +191,35 @@ export const useHighlightsForm = () => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
getSportList().then((state: any) => setSports( |
|
|
|
getSportList() |
|
|
|
state?.map((sport: SportType) => ({ |
|
|
|
.then((res) => setSports( |
|
|
|
...sport, |
|
|
|
res?.map((sport: SportType) => ({ |
|
|
|
name: sport?.name_eng, |
|
|
|
...sport, |
|
|
|
})), |
|
|
|
name: sport?.name_eng, |
|
|
|
)) |
|
|
|
})), |
|
|
|
|
|
|
|
)) |
|
|
|
}, []) |
|
|
|
}, []) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (playerHighlight?.sportType) { |
|
|
|
if (playerHighlight?.sportType && playerHighlight?.profile) { |
|
|
|
setFormState((prevState: any) => ({ |
|
|
|
setFormState((state: any) => ({ |
|
|
|
...prevState, |
|
|
|
...state, |
|
|
|
|
|
|
|
selectedPlayer: { |
|
|
|
|
|
|
|
...playerHighlight.profile, |
|
|
|
|
|
|
|
name: `${playerHighlight.profile?.name_eng}`, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
selectedTeam: playerHighlight?.profile?.additionalInfo, |
|
|
|
sport: sports?.find((sportType) => sportType.id === playerHighlight.sportType), |
|
|
|
sport: sports?.find((sportType) => sportType.id === playerHighlight.sportType), |
|
|
|
teams: teams?.find(({ id }) => id === playerHighlight.profile.additionalInfo.id), |
|
|
|
|
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
}, [sports, playerHighlight, teams]) |
|
|
|
}, [sports, playerHighlight, teams]) |
|
|
|
|
|
|
|
|
|
|
|
const fetchTeams = useMemo( |
|
|
|
const fetchTeams = useMemo( |
|
|
|
() => debounce(() => getSportTeams(formState?.sport?.id, -1, formState.teamValue).then( |
|
|
|
() => debounce(() => getSportTeams( |
|
|
|
|
|
|
|
formState?.sport?.id, |
|
|
|
|
|
|
|
-1, |
|
|
|
|
|
|
|
formState.teamValue, |
|
|
|
|
|
|
|
).then( |
|
|
|
({ data }: SportTeamsType) => setTeams( |
|
|
|
({ data }: SportTeamsType) => setTeams( |
|
|
|
data?.map((team: Team) => ({ |
|
|
|
data?.map((team: Team) => ({ |
|
|
|
...team, |
|
|
|
...team, |
|
|
|
@ -208,6 +227,7 @@ export const useHighlightsForm = () => { |
|
|
|
})), |
|
|
|
})), |
|
|
|
), |
|
|
|
), |
|
|
|
), 300), |
|
|
|
), 300), |
|
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
[formState.teamValue], |
|
|
|
[formState.teamValue], |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
@ -215,36 +235,43 @@ export const useHighlightsForm = () => { |
|
|
|
if (formState?.teamValue?.length >= 3 && formState?.sport) { |
|
|
|
if (formState?.teamValue?.length >= 3 && formState?.sport) { |
|
|
|
fetchTeams() |
|
|
|
fetchTeams() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [formState.teamValue, formState?.sport, playerHighlight]) |
|
|
|
}, [formState.teamValue, formState?.sport, playerHighlight]) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (formState?.selectedPlayer?.id) { |
|
|
|
if (formState?.selectedPlayer?.id && formState?.sport) { |
|
|
|
setDatahighlights({ |
|
|
|
setDatahighlights({ |
|
|
|
data: { |
|
|
|
data: { |
|
|
|
duration: Number(formState?.duration), |
|
|
|
duration: Number(formState?.duration), |
|
|
|
lang: 'en', |
|
|
|
lang: 'en', |
|
|
|
matches: playerMatches?.map((match) => match.id), |
|
|
|
matches: playerMatches?.filter(({ isChecked }) => (isChecked)).map(({ id }) => id), |
|
|
|
player_id: formState?.selectedPlayer?.id, |
|
|
|
player_id: formState?.selectedPlayer?.id, |
|
|
|
price: playerMatches?.length * 25, |
|
|
|
price: playerMatches?.length * 25, |
|
|
|
sport_id: formState?.sport.id, |
|
|
|
sport_id: formState?.sport.id, |
|
|
|
stats: Boolean(formState?.stats?.id), |
|
|
|
stats: Boolean(formState?.stats?.id), |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
isDisabledButton: true, |
|
|
|
isOpenThanksPopup: false, |
|
|
|
isOpenThanksPopup: false, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [formState, playerMatches]) |
|
|
|
}, [formState, playerMatches]) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
formState?.selectedTeam |
|
|
|
formState?.selectedTeam?.id |
|
|
|
&& getTeamPlayers(formState?.sport?.id, formState?.selectedTeam?.id) |
|
|
|
&& getTeamPlayers( |
|
|
|
.then((state: any) => setPlayersData(state?.map((player: PlayerType) => ({ |
|
|
|
formState?.sport?.id || playerHighlight.sportType, formState?.selectedTeam?.id |
|
|
|
|
|
|
|
|| playerHighlight?.profile?.additionalInfo?.id, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.then((state) => setPlayersData(state?.map((player: Player) => ({ |
|
|
|
...player, |
|
|
|
...player, |
|
|
|
name: `${player?.firstname_eng} ${player?.lastname_eng}`, |
|
|
|
name: `${player?.firstname_eng} ${player?.lastname_eng}`, |
|
|
|
})))) |
|
|
|
})))) |
|
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [formState?.selectedTeam, playerHighlight]) |
|
|
|
}, [formState?.selectedTeam, playerHighlight]) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (!formState?.selectedPlayer) return |
|
|
|
if (!formState?.selectedPlayer || !formState?.sport) return |
|
|
|
|
|
|
|
|
|
|
|
formState?.selectedPlayer |
|
|
|
formState?.selectedPlayer |
|
|
|
&& getPlayerMatches({ |
|
|
|
&& getPlayerMatches({ |
|
|
|
@ -254,8 +281,9 @@ export const useHighlightsForm = () => { |
|
|
|
sportType: formState?.sport?.id, |
|
|
|
sportType: formState?.sport?.id, |
|
|
|
}) |
|
|
|
}) |
|
|
|
.then(({ broadcast }) => setPlayerMatches( |
|
|
|
.then(({ broadcast }) => setPlayerMatches( |
|
|
|
broadcast.map((match: any) => ({ ...match, isChecked: false })), |
|
|
|
broadcast.map((match: Match) => ({ ...match, isChecked: false })), |
|
|
|
)) |
|
|
|
)) |
|
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [formState?.selectedPlayer, formState?.selectedTeam]) |
|
|
|
}, [formState?.selectedPlayer, formState?.selectedTeam]) |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
|