import { useEffect, useState } from 'react'; import { Breadcrumbs, Item, Tabs, useToast, Button, Text, Icon, Icons } from 'react-basics'; import { useIntl } from 'react-intl'; import Link from 'next/link'; import Page from 'components/layout/Page'; import PageHeader from 'components/layout/PageHeader'; import WebsiteEditForm from 'components/pages/settings/websites/WebsiteEditForm'; import WebsiteReset from 'components/pages/settings/websites/WebsiteReset'; import TrackingCode from 'components/pages/settings/websites/TrackingCode'; import ShareUrl from 'components/pages/settings/websites/ShareUrl'; import useApi from 'hooks/useApi'; import { labels, messages } from 'components/messages'; const { External } = Icons; export default function WebsiteSettings({ websiteId }) { const { formatMessage } = useIntl(); const [values, setValues] = useState(null); const [tab, setTab] = useState('details'); const { get, useQuery } = useApi(); const { toast, showToast } = useToast(); const { data, isLoading } = useQuery( ['website', websiteId], () => { if (websiteId) { return get(`/websites/${websiteId}`); } }, { cacheTime: 0 }, ); const handleSave = data => { showToast({ message: formatMessage(messages.saved), variant: 'success' }); setValues(state => ({ ...state, ...data })); }; useEffect(() => { if (data) { setValues(data); } }, [data]); return ( {toast} {formatMessage(labels.websites)} {values?.name} {formatMessage(labels.details)} {formatMessage(labels.trackingCode)} {formatMessage(labels.shareUrl)} {formatMessage(labels.data)} {tab === 'details' && ( )} {tab === 'tracking' && } {tab === 'share' && } {tab === 'data' && } ); }