46 lines
1.7 KiB
JavaScript
46 lines
1.7 KiB
JavaScript
import { auth } from "../lib/auth";
|
|
import { ownerFilter } from "../lib/authz";
|
|
import { getActividades, getSystemUsers } from "../lib/queries";
|
|
import { actAncla, actEstadoFinal, EJECUTIVOS_VENTA } from "../lib/derive";
|
|
import LoginPrompt from "../components/LoginPrompt";
|
|
import OwnerControl from "../components/OwnerControl";
|
|
import ErrorNotice from "../components/ErrorNotice";
|
|
import ActividadesClient from "../components/actividades/ActividadesClient";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export default async function ActividadesPage({ searchParams }) {
|
|
const session = await auth();
|
|
if (!session?.email) return <LoginPrompt />;
|
|
|
|
const { owner } = await searchParams;
|
|
const scope = ownerFilter(session, owner);
|
|
|
|
let raw, allUsers;
|
|
try {
|
|
[raw, allUsers] = await Promise.all([
|
|
getActividades(session.accessToken, scope),
|
|
session.isAdmin ? getSystemUsers(session.accessToken) : Promise.resolve([]),
|
|
]);
|
|
} catch (error) {
|
|
return <ErrorNotice error={error} />;
|
|
}
|
|
const owners = allUsers.filter((u) => EJECUTIVOS_VENTA.includes(u.name));
|
|
|
|
const actividades = raw
|
|
.filter((a) => a.estado !== "cancelada")
|
|
.map((a) => {
|
|
const ancla = actAncla(a);
|
|
return { ...a, fecha: ancla ? String(ancla).slice(0, 10) : null, estadoFinal: actEstadoFinal(a) };
|
|
});
|
|
|
|
return (
|
|
<div style={{ padding: 24 }}>
|
|
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", flexWrap: "wrap", gap: 12 }}>
|
|
<h2>Plan de Actividades</h2>
|
|
<OwnerControl owners={owners} current={scope.locked ? [session.email] : scope.emails} locked={scope.locked} lockedLabel={session.email} />
|
|
</div>
|
|
<ActividadesClient actividades={actividades} locked={scope.locked} />
|
|
</div>
|
|
);
|
|
}
|