feat(#2429): add payment history in user account
parent
c3379dbbc0
commit
3116d5ff3f
@ -0,0 +1,20 @@ |
||||
import { useState, useEffect } from 'react' |
||||
|
||||
import { useAuthStore } from 'features/AuthStore' |
||||
|
||||
import { getUserListPayments, PaymentsList } from 'requests/getUserListPayments' |
||||
|
||||
export const usePaymentHistory = () => { |
||||
const [payments, setPayments] = useState<PaymentsList>([]) |
||||
const timezoneOffset = new Date().getTimezoneOffset() |
||||
const { user } = useAuthStore() |
||||
|
||||
useEffect(() => { |
||||
(async () => { |
||||
const allPayments = await getUserListPayments(timezoneOffset, user?.profile?.email || '') |
||||
setPayments(allPayments) |
||||
})() |
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []) |
||||
return { payments } |
||||
} |
||||
@ -0,0 +1,73 @@ |
||||
import { DATA_URL, PROCEDURES } from 'config' |
||||
import { callApi } from 'helpers' |
||||
|
||||
const proc = PROCEDURES.get_user_payments |
||||
|
||||
type Payment = { |
||||
card: string, |
||||
currency: string, |
||||
currency_id: number, |
||||
id: number, |
||||
payment_service: string, |
||||
payment_type: string, |
||||
price: number, |
||||
purchase_type: string, |
||||
sub_id: number, |
||||
sub_info: MatchOfOneTeam | MatchOne | Tournaments, |
||||
sub_name: string, |
||||
sub_option: string, |
||||
ts_payment: string, |
||||
} |
||||
|
||||
type MatchOfOneTeam = { |
||||
country_en: string, |
||||
country_id: number, |
||||
country_ru: string, |
||||
sport_id: number, |
||||
team_en: string, |
||||
team_id: number, |
||||
team_ru: string, |
||||
} |
||||
|
||||
type MatchOne = { |
||||
country_en: string, |
||||
country_id: number, |
||||
country_ru: string, |
||||
date: string, |
||||
id: number, |
||||
name: string, |
||||
season: string, |
||||
sport_id: number, |
||||
tournament: string, |
||||
} |
||||
|
||||
type Tournament = { |
||||
id: number, |
||||
name_en: string, |
||||
name_ru: string, |
||||
sport_id: number, |
||||
} |
||||
|
||||
type Tournaments = Array<Tournament> |
||||
export type PaymentsList = Array<Payment> |
||||
|
||||
export const getUserListPayments = ( |
||||
timezoneOffset: number, |
||||
_p_email: string, |
||||
) |
||||
: Promise<PaymentsList> => { |
||||
const config = { |
||||
body: { |
||||
params: { |
||||
_p_email, |
||||
_p_gmt: timezoneOffset, |
||||
}, |
||||
proc, |
||||
}, |
||||
} |
||||
|
||||
return callApi({ |
||||
config, |
||||
url: DATA_URL, |
||||
}) |
||||
} |
||||
Loading…
Reference in new issue