import { useState } from 'react';
import { Button, Icon, Text, Modal, useToast, Icons } from 'react-basics';
import { useIntl } from 'react-intl';
import Page from 'components/layout/Page';
import PageHeader from 'components/layout/PageHeader';
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
import WebsiteAddForm from 'components/pages/settings/websites/WebsiteAddForm';
import WebsitesTable from 'components/pages/settings/websites/WebsitesTable';
import useApi from 'hooks/useApi';
import useUser from 'hooks/useUser';
import { labels, messages } from 'components/messages';
const { Plus } = Icons;
export default function WebsitesList() {
const [edit, setEdit] = useState(false);
const { user } = useUser();
const { get, useQuery } = useApi();
const { data, isLoading, error, refetch } = useQuery(
['websites', user?.id],
() => get(`/users/${user?.id}/websites`),
{ enabled: !!user },
);
const { toast, showToast } = useToast();
const { formatMessage } = useIntl();
const hasData = data && data.length !== 0;
const handleSave = async () => {
await refetch();
setEdit(false);
showToast({ message: formatMessage(messages.saved), variant: 'success' });
};
const handleAdd = () => setEdit(true);
const handleClose = () => setEdit(false);
const addButton = (
);
return (
{toast}
{addButton}
{hasData && }
{!hasData && (
{addButton}
)}
{edit && (
{close => }
)}
);
}