2020-08-15 10:17:15 +02:00
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
import { useRouter } from 'next/router';
|
|
|
|
import Layout from 'components/layout/Layout';
|
|
|
|
import WebsiteDetails from 'components/WebsiteDetails';
|
|
|
|
import NotFound from 'pages/404';
|
|
|
|
import { get } from 'lib/web';
|
|
|
|
|
|
|
|
export default function SharePage() {
|
2020-08-22 23:28:23 +02:00
|
|
|
const [loading, setLoading] = useState(true);
|
2020-08-15 10:17:15 +02:00
|
|
|
const [websiteId, setWebsiteId] = useState();
|
|
|
|
const [notFound, setNotFound] = useState(false);
|
|
|
|
const router = useRouter();
|
|
|
|
const { id } = router.query;
|
|
|
|
|
|
|
|
async function loadData() {
|
|
|
|
const website = await get(`/api/share/${id?.[0]}`);
|
|
|
|
|
|
|
|
if (website) {
|
|
|
|
setWebsiteId(website.website_id);
|
2020-08-19 23:42:54 +02:00
|
|
|
} else if (typeof window !== 'undefined') {
|
2020-08-15 10:17:15 +02:00
|
|
|
setNotFound(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (id) {
|
2020-08-22 23:28:23 +02:00
|
|
|
loadData().finally(() => {
|
|
|
|
setLoading(false);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
setLoading(false);
|
2020-08-15 10:17:15 +02:00
|
|
|
}
|
|
|
|
}, [id]);
|
|
|
|
|
2020-08-22 23:28:23 +02:00
|
|
|
if (loading) return null;
|
|
|
|
|
2020-08-15 10:17:15 +02:00
|
|
|
if (!id || notFound) {
|
|
|
|
return <NotFound />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Layout>
|
|
|
|
<WebsiteDetails websiteId={websiteId} />
|
|
|
|
</Layout>
|
|
|
|
);
|
|
|
|
}
|