import React from 'react'; import PropTypes from 'prop-types'; import api from 'flavours/glitch/api'; import { FormattedMessage, FormattedNumber, FormattedDate } from 'react-intl'; import classNames from 'classnames'; import { roundTo10 } from 'flavours/glitch/util/numbers'; const dateForCohort = cohort => { switch(cohort.frequency) { case 'day': return ; default: return ; } }; export default class Retention extends React.PureComponent { static propTypes = { start_at: PropTypes.string, end_at: PropTypes.string, frequency: PropTypes.string, }; state = { loading: true, data: null, }; componentDidMount () { const { start_at, end_at, frequency } = this.props; api().post('/api/v1/admin/retention', { start_at, end_at, frequency }).then(res => { this.setState({ loading: false, data: res.data, }); }).catch(err => { console.error(err); }); } render () { const { loading, data } = this.state; const { frequency } = this.props; let content; if (loading) { content = ; } else { content = ( {data[0].data.slice(1).map((retention, i) => ( ))} {data[0].data.slice(1).map((retention, i) => { const average = data.reduce((sum, cohort, k) => cohort.data[i + 1] ? sum + (cohort.data[i + 1].rate - sum)/(k + 1) : sum, 0); return ( ); })} {data.slice(0, -1).map(cohort => ( {cohort.data.slice(1).map(retention => ( ))} ))}
{i + 1}
sum + ((cohort.data[0].value * 1) - sum) / (i + 1), 0)} maximumFractionDigits={0} />
{dateForCohort(cohort)}
); } let title = null; switch(frequency) { case 'day': title = ; break; default: title = ; }; return (

{title}

{content}
); } }