67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
import { define, State } from "../../../utils.ts";
|
|
import { page } from "fresh";
|
|
import {
|
|
getObligationsByUser,
|
|
Obligation,
|
|
} from "../../../services/financhalServices.ts";
|
|
import ObligationList from "../../../islands/ObligationList.tsx";
|
|
import { SessionCookie } from "../../auth/callback.ts";
|
|
import { createPublicId } from "../../../helpers.ts";
|
|
|
|
export const handler = define.handlers({
|
|
GET: async (ctx) => {
|
|
const state = ctx.state as State;
|
|
const stateData: SessionCookie = state.data;
|
|
const url = new URL(ctx.req.url);
|
|
const modalParam = url.searchParams.get("modal");
|
|
const openModal = modalParam?.toLowerCase() === "on";
|
|
|
|
const obligations = stateData?.user_id
|
|
? await getObligationsByUser(stateData.user_id)
|
|
: [];
|
|
const orderedObligations = obligations.slice().reverse();
|
|
|
|
const publicId = stateData?.user_id
|
|
? await createPublicId(stateData.user_id)
|
|
: "";
|
|
const isEncrypted = stateData?.user_encrypted;
|
|
return page({
|
|
stateData,
|
|
obligations: orderedObligations,
|
|
publicId,
|
|
user_name: stateData.user_name,
|
|
isEncrypted,
|
|
urlRoute: url.pathname,
|
|
stateId: state.stateId,
|
|
openModal,
|
|
});
|
|
},
|
|
});
|
|
|
|
export default define.page(
|
|
(
|
|
{ data }: {
|
|
data: {
|
|
stateData: SessionCookie;
|
|
obligations: Obligation[];
|
|
publicId: string;
|
|
user_name: string;
|
|
isEncrypted: boolean;
|
|
urlRoute: string;
|
|
stateId: string;
|
|
openModal: boolean;
|
|
};
|
|
},
|
|
) => (
|
|
<main class="calendar-route-shell">
|
|
<div class="calendar-route-content">
|
|
<ObligationList
|
|
obligations={data.obligations || []}
|
|
userId={data.publicId}
|
|
openModal={data.openModal}
|
|
/>
|
|
</div>
|
|
</main>
|
|
),
|
|
);
|