import { useEffect, useState } from 'react'; import { Breadcrumbs, Item, Tabs, useToast, Button, Icon } from 'react-basics'; import { useQuery } from '@tanstack/react-query'; import { useApi } from 'next-basics'; import Link from 'next/link'; import Page from 'components/layout/Page'; import WebsiteEditForm from 'components/forms/WebsiteEditForm'; import WebsiteReset from 'components/forms/WebsiteReset'; import PageHeader from 'components/layout/PageHeader'; import TrackingCodeForm from 'components/forms/TrackingCodeForm'; import ShareUrlForm from 'components/forms/ShareUrlForm'; import { getAuthToken } from 'lib/client'; import ExternalLink from 'assets/external-link.svg'; export default function Websites({ websiteId }) { const [values, setValues] = useState(null); const [tab, setTab] = useState('general'); const { get } = useApi(getAuthToken()); const { toast, showToast } = useToast(); const { data, isLoading } = useQuery( ['website', websiteId], () => { if (websiteId) { return get(`/websites/${websiteId}`); } }, { cacheTime: 0 }, ); const handleSave = data => { showToast({ message: 'Saved successfully.', variant: 'success' }); setValues(state => ({ ...state, ...data })); }; useEffect(() => { if (data) { setValues(data); } }, [data]); return ( {toast} Websites {values?.name} General Tracking code Share URL Danger zone {tab === 'general' && ( )} {tab === 'tracking' && } {tab === 'share' && } {tab === 'danger' && } ); }