2023-09-28 19:23:44 +01:00
|
|
|
import { useContext, useMemo } from "react";
|
|
|
|
import dynamic from "next/dynamic";
|
|
|
|
|
|
|
|
import { ShowDateContext } from "../../utils/contexts/calendar";
|
|
|
|
|
|
|
|
import MonthlyView from "./monthly-view";
|
|
|
|
|
|
|
|
import Container from "components/services/widget/container";
|
|
|
|
|
|
|
|
export default function Component({ service }) {
|
|
|
|
const { widget } = service;
|
|
|
|
const { showDate } = useContext(ShowDateContext);
|
|
|
|
|
|
|
|
// params for API fetch
|
|
|
|
const params = useMemo(() => {
|
|
|
|
if (!showDate) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2023-10-17 23:26:55 -07:00
|
|
|
start: showDate.minus({ months: 3 }).toFormat("yyyy-MM-dd"),
|
|
|
|
end: showDate.plus({ months: 3 }).toFormat("yyyy-MM-dd"),
|
|
|
|
unmonitored: "false",
|
2023-09-28 19:23:44 +01:00
|
|
|
};
|
|
|
|
}, [showDate]);
|
|
|
|
|
|
|
|
// Load active integrations
|
2023-10-17 23:26:55 -07:00
|
|
|
const integrations = useMemo(
|
|
|
|
() =>
|
|
|
|
widget.integrations?.map((integration) => ({
|
|
|
|
service: dynamic(() => import(`./integrations/${integration?.type}`)),
|
|
|
|
widget: integration,
|
|
|
|
})) ?? [],
|
|
|
|
[widget.integrations],
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
|
|
|
<div className="flex flex-col w-full">
|
|
|
|
<div className="sticky top-0">
|
|
|
|
{integrations.map((integration) => {
|
|
|
|
const Integration = integration.service;
|
|
|
|
const key = integration.widget.type + integration.widget.service_name + integration.widget.service_group;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Integration
|
|
|
|
key={key}
|
|
|
|
config={integration.widget}
|
|
|
|
params={params}
|
|
|
|
className="fixed bottom-0 left-0 bg-red-500 w-screen h-12"
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
<MonthlyView service={service} className="flex" />
|
2023-09-28 19:23:44 +01:00
|
|
|
</div>
|
2023-10-17 23:26:55 -07:00
|
|
|
</Container>
|
|
|
|
);
|
2023-09-28 19:23:44 +01:00
|
|
|
}
|