feat(ott-1726): add choise of subscription on buy match popup (#546)
parent
b681fa3fd6
commit
64403dd85e
@ -0,0 +1,118 @@ |
|||||||
|
import { useState } from 'react' |
||||||
|
|
||||||
|
import styled from 'styled-components/macro' |
||||||
|
|
||||||
|
import map from 'lodash/map' |
||||||
|
|
||||||
|
import { MDASH } from 'config' |
||||||
|
import { SelectSubscriptionData } from 'requests' |
||||||
|
|
||||||
|
import { Name as Names } from 'features/Name' |
||||||
|
import { T9n } from 'features/T9n' |
||||||
|
import { useBuyMatchPopupStore } from 'features/BuyMatchPopup/store' |
||||||
|
import { CloseButton, HeaderActions } from 'features/PopupComponents' |
||||||
|
import { ArrowLoader } from 'features/ArrowLoader' |
||||||
|
|
||||||
|
import { |
||||||
|
Body, |
||||||
|
Button, |
||||||
|
Footer, |
||||||
|
Header, |
||||||
|
HeaderTitle, |
||||||
|
Wrapper, |
||||||
|
} from 'features/BuyMatchPopup/styled' |
||||||
|
import { |
||||||
|
Description, |
||||||
|
InfoWrapper, |
||||||
|
Item, |
||||||
|
List, |
||||||
|
Name, |
||||||
|
Pass, |
||||||
|
} from '../SubscriptionsList/styled' |
||||||
|
|
||||||
|
export const ChooseSub = styled.div` |
||||||
|
font-weight: 600; |
||||||
|
font-size: 16px; |
||||||
|
margin: 30px 0; |
||||||
|
` |
||||||
|
|
||||||
|
export const SelectSubscriptionStep = () => { |
||||||
|
const [active, setActive] = useState<number | null>(null) |
||||||
|
|
||||||
|
const { |
||||||
|
close, |
||||||
|
initialSubscription, |
||||||
|
loader, |
||||||
|
match, |
||||||
|
onChooseSub, |
||||||
|
onSubscriptionPackagesSelect, |
||||||
|
selectedSubscriptionPackage, |
||||||
|
setSelectSubName, |
||||||
|
} = useBuyMatchPopupStore() |
||||||
|
|
||||||
|
if (!match || !initialSubscription) return null |
||||||
|
|
||||||
|
const onItemClick = (subscription: SelectSubscriptionData, index: number) => { |
||||||
|
onSubscriptionPackagesSelect({ |
||||||
|
...subscription.packages, |
||||||
|
season: initialSubscription.season, |
||||||
|
}) |
||||||
|
setActive(index) |
||||||
|
setSelectSubName(subscription.lexic) |
||||||
|
} |
||||||
|
|
||||||
|
return ( |
||||||
|
<Wrapper> |
||||||
|
<Header> |
||||||
|
<HeaderTitle> |
||||||
|
<Names nameObj={match.team1} /> |
||||||
|
{` ${MDASH} `} |
||||||
|
<Names nameObj={match.team2} /> |
||||||
|
<ChooseSub> |
||||||
|
<T9n t='choose_subscription' /> |
||||||
|
</ChooseSub> |
||||||
|
</HeaderTitle> |
||||||
|
<HeaderActions position='right'> |
||||||
|
<CloseButton onClick={close} /> |
||||||
|
</HeaderActions> |
||||||
|
</Header> |
||||||
|
<Body marginTop={15}> |
||||||
|
<List> |
||||||
|
{ |
||||||
|
map(initialSubscription.data, (subscription, index) => ( |
||||||
|
<Item |
||||||
|
key={subscription.id} |
||||||
|
onClick={() => onItemClick(subscription, index)} |
||||||
|
active={active === index} |
||||||
|
> |
||||||
|
<InfoWrapper> |
||||||
|
<Pass> |
||||||
|
<T9n t={subscription.lexic} /> |
||||||
|
</Pass> |
||||||
|
<Name> |
||||||
|
<T9n t={subscription.lexic2} /> |
||||||
|
</Name> |
||||||
|
<Description> |
||||||
|
<T9n t={subscription.lexic3} /> |
||||||
|
</Description> |
||||||
|
</InfoWrapper> |
||||||
|
</Item> |
||||||
|
)) |
||||||
|
} |
||||||
|
</List> |
||||||
|
</Body> |
||||||
|
<Footer> |
||||||
|
{loader |
||||||
|
? <ArrowLoader width='204px' disabled /> |
||||||
|
: ( |
||||||
|
<Button |
||||||
|
disabled={!selectedSubscriptionPackage} |
||||||
|
onClick={onChooseSub} |
||||||
|
> |
||||||
|
<T9n t='next_choose' /> |
||||||
|
</Button> |
||||||
|
)} |
||||||
|
</Footer> |
||||||
|
</Wrapper> |
||||||
|
) |
||||||
|
} |
||||||
@ -0,0 +1,29 @@ |
|||||||
|
import { useCallback } from 'react' |
||||||
|
|
||||||
|
import isEmpty from 'lodash/isEmpty' |
||||||
|
import flatMap from 'lodash/flatMap' |
||||||
|
import uniq from 'lodash/uniq' |
||||||
|
|
||||||
|
import type { SelectSubscriptionData } from 'requests' |
||||||
|
|
||||||
|
import { useLexicsStore } from 'features/LexicsStore' |
||||||
|
|
||||||
|
export const useSubscriptionsLexics = () => { |
||||||
|
const { addLexicsConfig } = useLexicsStore() |
||||||
|
|
||||||
|
const fetchLexics = useCallback((data: Array<SelectSubscriptionData>) => { |
||||||
|
const lexics = uniq(flatMap(data, ({ |
||||||
|
lexic, |
||||||
|
lexic2, |
||||||
|
lexic3, |
||||||
|
}) => [lexic, lexic2, lexic3])) |
||||||
|
|
||||||
|
if (!isEmpty(lexics)) { |
||||||
|
addLexicsConfig(lexics) |
||||||
|
} |
||||||
|
|
||||||
|
return data |
||||||
|
}, [addLexicsConfig]) |
||||||
|
|
||||||
|
return { fetchLexics } |
||||||
|
} |
||||||
Loading…
Reference in new issue