import './style.css' import _identity from 'lodash/identity' import React, { memo, useState } from 'react' import Countdown from 'react-countdown' import ReactDOM from 'react-dom' import SVG from 'react-inlinesvg' import Cross from '../../assets/images/cross.svg' import { showZero } from '../../utils/showZero' export interface ITimerWidgetPage { expires_at: number; buyLoading?: boolean; onCountdownFinish?: () => void; container?: string; } export interface IRenderer { minutes: number; seconds: number; completed: number; handleCountdownFinish: () => void; } const TimerWidget = ({ expires_at, buyLoading, onCountdownFinish = _identity, container, }: ITimerWidgetPage) => { const [showTimer, setShowTimer] = useState(true) const handleCountdownFinish = () => { setShowTimer(false) if (!buyLoading) { onCountdownFinish() } } const renderer = ({ minutes, seconds, completed, handleCountdownFinish, }: IRenderer) => { if (completed) { handleCountdownFinish() return null } return ( {showZero(minutes)}:{showZero(seconds)} ) } const hideTimer = () => { const timerRl: HTMLElement | null = document.querySelector('.timer') if (timerRl) { timerRl.style.visibility = 'hidden' } } const timerComponent = (
Please complete your purchase before the timer reaches zero.