import { useCallback } from 'react'; import { Trans, useTranslation } from 'react-i18next'; import LoginForm from '@/components/LoginForm'; import { useAppUrls } from '@/hooks/useAppUrls'; import { dialogModel } from '@/models/dialogModel'; import { fetchPayOrderCreate } from '@/services/config'; import { getToken } from '@/utils/authUtils'; import { currentUnixTimestamp } from '@/utils/timeUtils'; import { PayWaitingContent } from './PayWaitingContent'; import type { Plan } from '../../useService'; const ORDER_TYPE_PLAN = 1; export interface UseActionReturn { handlePayNow: () => void; } export interface UseActionParams { selectedPlan: Plan | null; selectedPayMethod: string | null; } export function useAction({ selectedPlan, selectedPayMethod }: UseActionParams): UseActionReturn { const { t } = useTranslation(); const { openDialog, closeDialog } = dialogModel.useModel(); const { deeplinkUrl, downloadUrlByPlatform } = useAppUrls(); const handlePayNow = useCallback(() => { if (!selectedPlan || !selectedPayMethod) return; console.log('🚀 ~ useAction.tsx:30 ~ useAction ~ downloadUrlByPlatform:', downloadUrlByPlatform); console.log('🚀 ~ useAction.tsx:30 ~ useAction ~ deeplinkUrl:', deeplinkUrl); const token = getToken(); const expired = !token?.accessExpires || (token.accessExpires ?? 0) - currentUnixTimestamp() <= 0; if (!token?.accessToken || expired) { const id = openDialog({ title: t('pages.pricing.payFlow.loginTitle'), content: (
{t('pages.pricing.payFlow.goToPayDesc')}
), buttons: [ { label: t('pages.pricing.payFlow.goToPayButton'), variant: 'primary', onClick: ( _e: React.MouseEvent