import React, { useState } from 'react';
import { FormattedMessage } from 'react-intl';
import classNames from 'classnames';
import Link from 'components/common/Link';
import Table from 'components/common/Table';
import Button from 'components/common/Button';
import OverflowText from 'components/common/OverflowText';
import PageHeader from 'components/layout/PageHeader';
import Modal from 'components/common/Modal';
import WebsiteEditForm from 'components/forms/WebsiteEditForm';
import ResetForm from 'components/forms/ResetForm';
import DeleteForm from 'components/forms/DeleteForm';
import TrackingCodeForm from 'components/forms/TrackingCodeForm';
import ShareUrlForm from 'components/forms/ShareUrlForm';
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
import ButtonLayout from 'components/layout/ButtonLayout';
import Toast from 'components/common/Toast';
import Favicon from 'components/common/Favicon';
import Pen from 'assets/pen.svg';
import Trash from 'assets/trash.svg';
import Reset from 'assets/redo.svg';
import Plus from 'assets/plus.svg';
import Code from 'assets/code.svg';
import LinkIcon from 'assets/link.svg';
import useFetch from 'hooks/useFetch';
import useUser from 'hooks/useUser';
import styles from './WebsiteSettings.module.css';
export default function WebsiteSettings() {
const { user } = useUser();
const [editWebsite, setEditWebsite] = useState();
const [resetWebsite, setResetWebsite] = useState();
const [deleteWebsite, setDeleteWebsite] = useState();
const [addWebsite, setAddWebsite] = useState();
const [showCode, setShowCode] = useState();
const [showUrl, setShowUrl] = useState();
const [saved, setSaved] = useState(0);
const [message, setMessage] = useState();
const { data } = useFetch('/websites', { params: { include_all: !!user?.is_admin } }, [saved]);
const Buttons = row => (
{row.share_id && (
}
size="small"
tooltip={}
tooltipId={`button-share-${row.website_id}`}
onClick={() => setShowUrl(row)}
/>
)}
}
size="small"
tooltip={
}
tooltipId={`button-code-${row.website_id}`}
onClick={() => setShowCode(row)}
/>
}
size="small"
tooltip={}
tooltipId={`button-edit-${row.website_id}`}
onClick={() => setEditWebsite(row)}
/>
}
size="small"
tooltip={}
tooltipId={`button-reset-${row.website_id}`}
onClick={() => setResetWebsite(row)}
/>
}
size="small"
tooltip={}
tooltipId={`button-delete-${row.website_id}`}
onClick={() => setDeleteWebsite(row)}
/>
);
const DetailsLink = ({ website_id, name, domain }) => (
{name}
);
const Domain = ({ domain, website_id }) => (
{domain}
);
const adminColumns = [
{
key: 'name',
label: ,
className: 'col-4 col-xl-3',
render: DetailsLink,
},
{
key: 'domain',
label: ,
className: 'col-4 col-xl-3',
render: Domain,
},
{
key: 'account',
label: ,
className: 'col-4 col-xl-1',
},
{
key: 'action',
className: classNames(styles.buttons, 'col-12 col-xl-5 pt-2 pt-xl-0'),
render: Buttons,
},
];
const columns = [
{
key: 'name',
label: ,
className: 'col-6 col-xl-4',
render: DetailsLink,
},
{
key: 'domain',
label: ,
className: 'col-6 col-xl-4',
render: Domain,
},
{
key: 'action',
className: classNames(styles.buttons, 'col-12 col-xl-4 pt-2 pt-xl-0'),
render: Buttons,
},
];
function handleSave() {
setSaved(state => state + 1);
setMessage();
handleClose();
}
function handleClose() {
setAddWebsite(null);
setEditWebsite(null);
setResetWebsite(null);
setDeleteWebsite(null);
setShowCode(null);
setShowUrl(null);
}
if (!data) {
return null;
}
const empty = (
}
>
} size="medium" onClick={() => setAddWebsite(true)}>
);
return (
<>
} size="small" onClick={() => setAddWebsite(true)}>
{editWebsite && (
}>
)}
{addWebsite && (
}>
)}
{resetWebsite && (
}
>
)}
{deleteWebsite && (
}
>
)}
{showCode && (
}>
)}
{showUrl && (
}>
)}
{message && setMessage(null)} />}
>
);
}