From ee4ea069a24f76f178277d8e1a9fb92e55f38aad Mon Sep 17 00:00:00 2001 From: Aleksey Miroshnichenko Date: Thu, 26 Aug 2021 12:07:19 +0300 Subject: [PATCH] fix(ott-1457): add default subscription setter (#441) --- .gitignore | 2 ++ .../BuyMatchPopup/store/hooks/useSubscriptions.tsx | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/.gitignore b/.gitignore index ca5881be..43724026 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,8 @@ yarn-error.log* yarn.lock package-lock.json + +/.vscode # IntelliJ IDEA products .idea .eslintcache diff --git a/src/features/BuyMatchPopup/store/hooks/useSubscriptions.tsx b/src/features/BuyMatchPopup/store/hooks/useSubscriptions.tsx index 438de230..4a8d2080 100644 --- a/src/features/BuyMatchPopup/store/hooks/useSubscriptions.tsx +++ b/src/features/BuyMatchPopup/store/hooks/useSubscriptions.tsx @@ -1,6 +1,7 @@ import { useState, useCallback, + useEffect, } from 'react' import find from 'lodash/find' @@ -52,6 +53,15 @@ export const useSubscriptions = () => { setSelectedSubscription(subscription === selectedSubscription ? null : subscription) } + useEffect(() => { + const isOnlySubscriptionVariant = matchSubscriptions[selectedPeriod].length === 1 + if (isOnlySubscriptionVariant) { + setSelectedSubscription(matchSubscriptions[selectedPeriod][0]) + } else { + setSelectedSubscription(null) + } + }, [matchSubscriptions, selectedPeriod]) + return { fetchSubscriptions, matchSubscriptions,