import { __ } from '@wordpress/i18n'; import { useCallback, useEffect, useState } from 'react'; import { bootstrap } from './api'; import { SupportFooter } from './components/SupportFooter'; import { isBigCommerce } from './host'; import { Activity } from './screens/Activity'; import { Alerts } from './screens/Alerts'; import { Billing } from './screens/Billing'; import { Feed } from './screens/Feed'; import { Home } from './screens/Home'; import { Optimize } from './screens/Optimize'; import { Profit } from './screens/Profit'; import { Sales } from './screens/Sales'; import { Settings } from './screens/Settings'; import { Visibility } from './screens/Visibility'; /** * Les memes ecrans que sur Shopify, dans le meme ordre, avec les memes libelles. * * L'onglet courant vit dans le fragment de l'URL (`#feed`): un marchand peut mettre une page en * favori, et un rechargement ne le ramene pas au debut. */ const TABS = [ { id: 'home', label: () => __('Home', 'convrail') }, { id: 'settings', label: () => __('Settings', 'convrail') }, { id: 'feed', label: () => __('Product feed', 'convrail') }, { id: 'sales', label: () => __('ChatGPT sales', 'convrail') }, { id: 'profit', label: () => __('Profit', 'convrail') }, { id: 'optimize', label: () => __('Improve my products', 'convrail') }, { id: 'visibility', label: () => __('Visibility', 'convrail') }, { id: 'alerts', label: () => __('Alerts', 'convrail') }, { id: 'activity', label: () => __('Activity', 'convrail') }, { id: 'billing', label: () => __('Plans and billing', 'convrail') }, ] as const; const tabFromHash = (): string => { const hash = window.location.hash.replace('#', ''); return TABS.some((tab) => tab.id === hash) ? hash : 'home'; }; export function App() { const [tab, setTab] = useState(tabFromHash); const config = bootstrap(); useEffect(() => { const onHashChange = () => setTab(tabFromHash()); window.addEventListener('hashchange', onHashChange); return () => window.removeEventListener('hashchange', onHashChange); }, []); const navigate = useCallback((next: string) => { window.location.hash = next; setTab(next); }, []); if (!config.connected) { return (

{__('Convrail', 'convrail')}

{__( 'Connect your store to send your products to ChatGPT and see every sale ChatGPT brings you. It takes one click, on the Connection page.', 'convrail', )}

{__('Connect my store', 'convrail')}
); } return (
{tab === 'home' ? : null} {tab === 'settings' ? : null} {tab === 'feed' ? : null} {tab === 'sales' ? : null} {tab === 'profit' ? : null} {tab === 'optimize' ? : null} {tab === 'visibility' ? : null} {tab === 'alerts' ? : null} {tab === 'activity' ? : null} {tab === 'billing' ? : null}
{isBigCommerce() ? : null}
); }