import { SubscriptionType } from 'features/BuyMatchPopup/types' import { T9n } from 'features/T9n' import { Loader } from 'features/Loader' import type { Subscribe } from 'requests/getUserSubscribes' import format from 'date-fns/format' import { useUserSubscribes } from './hooks' import { ChangeCardPopup } from '../ChangeCardPopup' import { CancelSubPopup } from '../CancelSubPopup' import { Wrapper, ScItem, ScText, ScSubscribe, ScCancelButton, ScBtnWrap, ScItemPaymentSum, ScCard, ScLoaderWrapper, } from './styled' type MatchSubscription = { description: string, header: string, isActive?: boolean, price: number, subscription_id: number, type: SubscriptionType, } export type MatchSubscriptions = Array export const PageSubscriptions = () => { const { cancelSub, changeCardPopupOpen, error, handleClose, isCancelPopupOpen, isFetching, isSubCanceled, selectedSubscribe, setChangeCardPopupOpen, setIsCancelPopupOpen, setSelectedSubscribe, subscribes, } = useUserSubscribes() return ( <> {isFetching ? ( ) : ( {subscribes?.map((subscribe: Subscribe) => { const { card, is_active, iso, name, option_sys_name, price, purchase_type, sub_id, ts_payment, } = subscribe const hideCancel = selectedSubscribe.sub_id === sub_id && isSubCanceled return ( {option_sys_name} — {name} {is_active && !hideCancel ? `${iso} ${price}` : '—'} {is_active && purchase_type === 'subscription' && !hideCancel ? ( <> / ) : ''} {is_active && !hideCancel ? format(new Date(ts_payment), 'd MMM yyyy') : '—'} {card} {/* setChangeCardPopupOpen(true)} /> setChangeCardPopupOpen(true)} /> */} {is_active && purchase_type === 'subscription' && !hideCancel ? ( {!error && !isSubCanceled && selectedSubscribe.sub_id === sub_id && isCancelPopupOpen ? null : ( { setIsCancelPopupOpen(true) setSelectedSubscribe(subscribe) }} > )}   {iso} {price}   ) : null} ) })} )} ) }