2023-09-29 12:29:22 +00:00
|
|
|
'use client';
|
2024-01-29 09:32:05 +00:00
|
|
|
import { useState, Key } from 'react';
|
2024-01-29 11:15:22 +00:00
|
|
|
import { Item, Tabs, Button, Text, Icon, Loading } from 'react-basics';
|
2022-12-27 00:57:59 +00:00
|
|
|
import Link from 'next/link';
|
2024-01-29 11:15:22 +00:00
|
|
|
import Icons from 'components/icons';
|
2023-01-21 01:12:53 +00:00
|
|
|
import PageHeader from 'components/layout/PageHeader';
|
2023-09-29 12:29:22 +00:00
|
|
|
import WebsiteEditForm from './[id]/WebsiteEditForm';
|
|
|
|
|
import WebsiteData from './[id]/WebsiteData';
|
|
|
|
|
import TrackingCode from './[id]/TrackingCode';
|
|
|
|
|
import ShareUrl from './[id]/ShareUrl';
|
2024-01-29 09:32:05 +00:00
|
|
|
import { useWebsite, useMessages } from 'components/hooks';
|
2024-01-29 11:15:22 +00:00
|
|
|
import WebsiteContext from 'app/(main)/websites/[id]/WebsiteContext';
|
2023-01-21 01:12:53 +00:00
|
|
|
|
2023-12-06 03:22:14 +00:00
|
|
|
export function WebsiteSettings({ websiteId, openExternal = false }) {
|
2024-01-29 11:15:22 +00:00
|
|
|
const { formatMessage, labels } = useMessages();
|
|
|
|
|
const { data: website, isLoading, refetch } = useWebsite(websiteId, { gcTime: 0 });
|
2023-12-06 03:22:14 +00:00
|
|
|
const [tab, setTab] = useState<Key>('details');
|
2022-12-27 00:57:59 +00:00
|
|
|
|
2024-01-29 09:32:05 +00:00
|
|
|
const handleSave = () => {
|
2024-01-29 11:15:22 +00:00
|
|
|
refetch();
|
2023-01-28 05:53:13 +00:00
|
|
|
};
|
|
|
|
|
|
2024-01-29 09:32:05 +00:00
|
|
|
if (isLoading) {
|
2023-12-06 09:26:58 +00:00
|
|
|
return <Loading position="page" />;
|
2023-12-02 04:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-27 00:57:59 +00:00
|
|
|
return (
|
2024-01-29 11:15:22 +00:00
|
|
|
<WebsiteContext.Provider value={website}>
|
|
|
|
|
<PageHeader title={website?.name} icon={<Icons.Globe />}>
|
2024-01-29 09:32:05 +00:00
|
|
|
<Link href={`/websites/${websiteId}`} target={openExternal ? '_blank' : null}>
|
2023-03-09 04:23:32 +00:00
|
|
|
<Button variant="primary">
|
|
|
|
|
<Icon>
|
|
|
|
|
<Icons.External />
|
|
|
|
|
</Icon>
|
|
|
|
|
<Text>{formatMessage(labels.view)}</Text>
|
|
|
|
|
</Button>
|
2022-12-27 00:57:59 +00:00
|
|
|
</Link>
|
|
|
|
|
</PageHeader>
|
2023-01-10 07:59:26 +00:00
|
|
|
<Tabs selectedKey={tab} onSelect={setTab} style={{ marginBottom: 30 }}>
|
2023-01-25 15:42:46 +00:00
|
|
|
<Item key="details">{formatMessage(labels.details)}</Item>
|
|
|
|
|
<Item key="tracking">{formatMessage(labels.trackingCode)}</Item>
|
|
|
|
|
<Item key="share">{formatMessage(labels.shareUrl)}</Item>
|
|
|
|
|
<Item key="data">{formatMessage(labels.data)}</Item>
|
2022-12-27 00:57:59 +00:00
|
|
|
</Tabs>
|
2024-01-29 11:15:22 +00:00
|
|
|
{tab === 'details' && <WebsiteEditForm website={website} onSave={handleSave} />}
|
2023-12-06 03:22:14 +00:00
|
|
|
{tab === 'tracking' && <TrackingCode websiteId={websiteId} />}
|
2024-01-29 11:15:22 +00:00
|
|
|
{tab === 'share' && <ShareUrl website={website} onSave={handleSave} />}
|
|
|
|
|
{tab === 'data' && <WebsiteData websiteId={websiteId} />}
|
|
|
|
|
</WebsiteContext.Provider>
|
2022-12-27 00:57:59 +00:00
|
|
|
);
|
|
|
|
|
}
|
2023-04-21 15:00:42 +00:00
|
|
|
|
|
|
|
|
export default WebsiteSettings;
|