import React, { Fragment, useState, useEffect } from 'react' import { Menu, Transition } from '@headlessui/react' import { ChevronDownIcon } from '@heroicons/react/20/solid' import classNames from 'classnames' import * as storage from '../../util/storage' import Conversions from './conversions' import DeprecatedConversions from './deprecated-conversions' import Properties from './props' import Funnel from './funnel' import { FeatureSetupNotice } from '../../components/notice' 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' export const CONVERSIONS = 'conversions' export const PROPS = 'props' export const FUNNELS = 'funnels' export const sectionTitles = { [CONVERSIONS]: 'Goal Conversions', [PROPS]: 'Custom Properties', [FUNNELS]: 'Funnels' } export default function Behaviours(props) { const site = props.site const adminAccess = ['owner', 'admin', 'super_admin'].includes(props.currentUserRole) const tabKey = `behavioursTab__${site.domain}` const funnelKey = `behavioursTabFunnel__${site.domain}` const [enabledModes, setEnabledModes] = useState(getEnabledModes()) const [mode, setMode] = useState(defaultMode()) const [funnelNames, _setFunnelNames] = useState(site.funnels.map(({ name }) => name)) const [selectedFunnel, setSelectedFunnel] = useState(storage.getItem(funnelKey)) useEffect(() => { setMode(defaultMode()) }, [enabledModes]) function disableMode(mode) { setEnabledModes(enabledModes.filter((m) => { return m !== mode })) } function setFunnel(selectedFunnel) { return () => { storage.setItem(tabKey, FUNNELS) storage.setItem(funnelKey, selectedFunnel) setMode(FUNNELS) setSelectedFunnel(selectedFunnel) } } function hasFunnels() { return site.funnels.length > 0 } function tabFunnelPicker() { return
} function tabSwitcher(toMode, displayName) { const className = classNames({ [ACTIVE_CLASS]: mode == toMode, [DEFAULT_CLASS]: mode !== toMode }) const setTab = () => { storage.setItem(tabKey, toMode) setMode(toMode) } return (