diff --git a/assets/js/dashboard/stats/behaviours/index.js b/assets/js/dashboard/stats/behaviours/index.js index 2a767e98c..1a1bbaf81 100644 --- a/assets/js/dashboard/stats/behaviours/index.js +++ b/assets/js/dashboard/stats/behaviours/index.js @@ -10,55 +10,55 @@ import Conversions from './conversions' const ACTIVE_CLASS = 'inline-block h-5 text-indigo-700 dark:text-indigo-500 font-bold active-prop-heading truncate text-left' const DEFAULT_CLASS = 'hover:text-indigo-600 cursor-pointer truncate text-left' const CONVERSIONS = 'conversions' - - - -// export default function Behaviours({ query, site }) -// const [tab, setMode] = useState('conversions') -// const tabs = -// -// if (site.flags.funnels) { -// const selectedFunnel = site.funnels.find(funnel => funnel.name === tab) -// const funnelNames = site.funnels.map(({ name }) => name) -// -// return ( -//
-// {tab == 'conversions' && } -// {funnelNames.includes(tab) && } -//
-// ) -// } else { -// return
-// {tab == 'conversions' && } -//
-// } -// } +const FUNNELS = 'funnels' export default class Behaviours extends React.Component { constructor(props) { super(props) this.tabKey = `behavioursTab__${props.site.domain}` + this.funnelKey = `behavioursTabFunnel__${props.site.domain}` + const storedTab = storage.getItem(this.tabKey) + const storedFunnelName = storage.getItem(this.funnelKey) + + const funnelNames = props.site.funnels.map(({ name }) => name) + this.state = { - mode: storedTab || CONVERSIONS + mode: storedTab || CONVERSIONS, + funnelNames: funnelNames, + selectedFunnelName: storedFunnelName } } - setMode(mode) { - console.info('setMode', mode) + setConversions() { return () => { - storage.setItem(this.tabKey, mode) - this.setState({ mode }) + storage.setItem(this.tabKey, CONVERSIONS) + this.setState({ mode: CONVERSIONS }) } } - tabFunnelPicker() { - const funnelNames = this.props.site.funnels.map(({ name }) => name) + setFunnel(selectedFunnelName) { + return () => { + storage.setItem(this.tabKey, FUNNELS) + storage.setItem(this.funnelKey, selectedFunnelName) + this.setState({ mode: FUNNELS, selectedFunnelName: selectedFunnelName }) + } + } + + selectedFunnel() { + return this.props.site.funnels.find(funnel => funnel.name === this.state.selectedFunnelName) + } + + hasFunnels() { + const site = this.props.site + return site.flags.funnels && site.funnels.length > 0 + } + tabFunnelPicker() { return
- Funnels + Funnels
@@ -74,12 +74,12 @@ export default class Behaviours extends React.Component { >
- {funnelNames.map((option) => { + {this.state.funnelNames.map((option) => { return ( {({ active }) => ( Conversions
+
Conversions
) } tabs() { - console.info('tabs', this) return (
{this.tabConversions()} - {this.tabFunnelPicker()} + {this.hasFunnels() ? this.tabFunnelPicker() : null}
) } renderContent() { - const funnelNames = this.props.site.funnels.map(({ name }) => name) - const selectedFunnel = this.props.site.funnels.find(funnel => funnel.name === this.state.mode) - switch (this.state.mode) { case CONVERSIONS: return - default: - if (funnelNames.includes(this.state.mode)) { - console.info('yess', this.state.mode) - - return - } + case FUNNELS: + return } } render() { - console.info('renderxxx') return (
{this.renderContent()}
)