refactor(907): changed endpoint of subscriptions list (#328)
* refactor(907): changed endpoint of subscriptions list * fix(907): pr fixkeep-around/af30b88d367751c9e05a735e4a0467a96238ef47
parent
ab7dae97f7
commit
5bf136ca2c
@ -0,0 +1,15 @@ |
||||
import map from 'lodash/map' |
||||
import isNumber from 'lodash/isNumber' |
||||
|
||||
import type { MatchSubscriptionsResponse } from 'requests' |
||||
|
||||
import { SubscriptionType } from '../types' |
||||
|
||||
export const transformSubsciptions = (subscriptions: MatchSubscriptionsResponse) => ( |
||||
map(subscriptions, (subscription) => ({ |
||||
id: subscription.id, |
||||
lexic: subscription.lexic, |
||||
price: subscription.price_month || subscription.price_year || 0, |
||||
type: isNumber(subscription.price_month) ? SubscriptionType.Month : SubscriptionType.Year, |
||||
})) |
||||
) |
||||
@ -0,0 +1,21 @@ |
||||
import { useCallback } from 'react' |
||||
|
||||
import isEmpty from 'lodash/isEmpty' |
||||
import map from 'lodash/map' |
||||
|
||||
import { useLexicsStore } from 'features/LexicsStore' |
||||
|
||||
import type { MatchSubscriptions } from '../../types' |
||||
|
||||
export const useLexicsFetcher = () => { |
||||
const { addLexicsConfig } = useLexicsStore() |
||||
const fetchLexics = useCallback((subscriptions: MatchSubscriptions) => { |
||||
const lexics = map(subscriptions, ({ lexic }) => lexic) |
||||
if (!isEmpty(lexics)) { |
||||
addLexicsConfig(lexics) |
||||
} |
||||
return subscriptions |
||||
}, [addLexicsConfig]) |
||||
|
||||
return { fetchLexics } |
||||
} |
||||
@ -1,18 +1,22 @@ |
||||
import map from 'lodash/map' |
||||
|
||||
import { API_ROOT } from 'config' |
||||
import { callApi } from 'helpers' |
||||
|
||||
export const buyMatchSubscriptions = () => { |
||||
const buyMatchSubscription = (subscriptionId: number) => { |
||||
const config = { |
||||
body: { |
||||
_p_c_subscription_plan: 1, |
||||
_p_is_scheduled: 0, |
||||
is_scheduled: 0, |
||||
subscription_plan: subscriptionId, |
||||
}, |
||||
} |
||||
|
||||
callApi({ |
||||
return callApi({ |
||||
config, |
||||
url: `${API_ROOT}/account/purchase`, |
||||
}) |
||||
|
||||
return Promise.resolve() |
||||
} |
||||
|
||||
export const buyMatchSubscriptions = (subscriptionIds: Array<number>) => ( |
||||
Promise.all(map(subscriptionIds, buyMatchSubscription)) |
||||
) |
||||
|
||||
@ -1,28 +0,0 @@ |
||||
import { API_ROOT } from 'config' |
||||
import { callApi } from 'helpers' |
||||
|
||||
export enum SubscriptionType { |
||||
Month = 'month', |
||||
Year = 'year', |
||||
} |
||||
|
||||
export type MatchSubscription = { |
||||
description: string, |
||||
header: string, |
||||
price: number, |
||||
subscription_id: number, |
||||
type: SubscriptionType, |
||||
} |
||||
|
||||
export type MatchSubscriptions = Array<MatchSubscription> |
||||
|
||||
export const getMatchSubscriptions = (): Promise<MatchSubscriptions> => { |
||||
const config = { |
||||
method: 'GET', |
||||
} |
||||
|
||||
return callApi({ |
||||
config, |
||||
url: `${API_ROOT}/account/get-subscriptions`, |
||||
}) |
||||
} |
||||
Loading…
Reference in new issue