import React, { useState, useRef, useEffect } from 'react'; import { FormattedMessage as T, useIntl } from 'react-intl'; import classNames from 'classnames'; import { plans } from 'common/subscriptionModels'; function BillingPlan({ name, description, price, slug, currency, onSelected, selected, }) { return ( onSelected(slug)} > {description.map((desc, index) => ( {desc} ))} {' '} {price} {currency} ); } function BillingPlans({ formik, title, selected = 1 }) { const planRef = useRef(null); useEffect(() => { const plans = planRef.current.querySelectorAll('a'); const planSelected = planRef.current.querySelector('.plan-selected'); plans.forEach((el) => { el.addEventListener('click', () => { planSelected.classList.remove('plan-selected'); el.classList.add('plan-selected'); }); }); }); return ( {plans.map((plan, index) => ( formik.setFieldValue('plan_slug', plan.slug)} selected={selected == index + 1} /> ))} ); } export default BillingPlans;