fix(#2429): add usecallback for formatted date

keep-around/8d4e801eeb457f2f33f8fe25bec663f95936171c
Andrei Dekterev 4 years ago
parent 6d73cf8d04
commit 8d4e801eeb
  1. 20
      src/features/UserAccount/components/PagePaymentsHistory/hooks.tsx
  2. 14
      src/features/UserAccount/components/PagePaymentsHistory/index.tsx
  3. 2
      src/requests/getUserListPayments.tsx

@ -1,7 +1,13 @@
import { useState, useEffect } from 'react' import {
useState,
useEffect,
useCallback,
} from 'react'
import { useAuthStore } from 'features/AuthStore' import { useAuthStore } from 'features/AuthStore'
import format from 'date-fns/format'
import { getUserListPayments, PaymentsList } from 'requests/getUserListPayments' import { getUserListPayments, PaymentsList } from 'requests/getUserListPayments'
export const usePaymentHistory = () => { export const usePaymentHistory = () => {
@ -9,12 +15,20 @@ export const usePaymentHistory = () => {
const timezoneOffset = new Date().getTimezoneOffset() const timezoneOffset = new Date().getTimezoneOffset()
const { user } = useAuthStore() const { user } = useAuthStore()
const formattedDate = useCallback(
(date: string) => format(new Date(date), 'd MMM yyyy'),
[],
)
useEffect(() => { useEffect(() => {
(async () => { (async () => {
const allPayments = await getUserListPayments(timezoneOffset, user?.profile?.email || '') const allPayments = await getUserListPayments(
timezoneOffset,
user?.profile?.email || '',
)
setPayments(allPayments) setPayments(allPayments)
})() })()
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, []) }, [])
return { payments } return { formattedDate, payments }
} }

@ -2,7 +2,7 @@ import { T9n } from 'features/T9n'
import { isMobileDevice } from 'config/userAgent' import { isMobileDevice } from 'config/userAgent'
import format from 'date-fns/format' import type { Payment } from 'requests/getUserListPayments'
import { usePaymentHistory } from './hooks' import { usePaymentHistory } from './hooks'
@ -22,9 +22,7 @@ import {
} from './styled' } from './styled'
export const PagePaymentsHistory = () => { export const PagePaymentsHistory = () => {
const { payments } = usePaymentHistory() const { formattedDate, payments } = usePaymentHistory()
const formattedDate = (date: string) => format(new Date(date), 'd MMM yyyy')
return ( return (
<Wrapper> <Wrapper>
@ -39,7 +37,7 @@ export const PagePaymentsHistory = () => {
sub_name, sub_name,
sub_option, sub_option,
ts_payment, ts_payment,
}: any) => ( }: Payment) => (
<ScPayment key={id}> <ScPayment key={id}>
<ScFirstBlock> <ScFirstBlock>
<Th> <Th>
@ -56,7 +54,9 @@ export const PagePaymentsHistory = () => {
<ScSecondBlock> <ScSecondBlock>
<Th className='subscription'> <Th className='subscription'>
<T9n t='subscription_plan' /> <T9n t='subscription_plan' />
<ScText>{sub_option} {sub_name}</ScText> <ScText>
{sub_option} {sub_name}
</ScText>
</Th> </Th>
<Th> <Th>
<T9n t='payment_method' /> <T9n t='payment_method' />
@ -95,7 +95,7 @@ export const PagePaymentsHistory = () => {
sub_name, sub_name,
sub_option, sub_option,
ts_payment, ts_payment,
}: any) => ( }: Payment) => (
<TRow key={id}> <TRow key={id}>
<Td className='subscription'> <Td className='subscription'>
{sub_option} {sub_name} {sub_option} {sub_name}

@ -3,7 +3,7 @@ import { callApi } from 'helpers'
const proc = PROCEDURES.get_user_payments const proc = PROCEDURES.get_user_payments
type Payment = { export type Payment = {
card: string, card: string,
currency: string, currency: string,
currency_id: number, currency_id: number,

Loading…
Cancel
Save