Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generateMetadata function to retrieve metadata for Organ component #264

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/app/(main)/organisasi/[period]/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,36 @@ import Overview from "./components/parts/Overview";
import RelatedNews from "./components/parts/RelatedNews";
import Structure from "./components/parts/Stucture";
import VisiMisi from "./components/parts/VisiMisi";
import { Metadata } from "next";

export default async function Organ({
params,
}: {
interface Props {
params: { slug: string; period: string };
}) {
}
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const organisasiType = params.slug.toUpperCase() as Organisasi_Type;
const organisasi = await findOrganisasi({
organisasi: organisasiType,
period: {
period: params.period,
},
});

return {
title: organisasi?.organisasi_name ?? "Not Found",
description: organisasi?.description,
};
}

export default async function Organ({ params }: Readonly<Props>) {
const organisasiType = params.slug.toUpperCase() as Organisasi_Type;
const period = await findPeriod({ period: params.period });

if (!period) return notFound();

const organisasi = await findOrganisasi({
organisasi_period_id: {
organisasi: organisasiType,
period_id: period.id,
organisasi: organisasiType,
period: {
period: params.period,
},
});

Expand Down
6 changes: 2 additions & 4 deletions src/utils/database/organisasi.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ export const findOrganisasis = async (filter?: Prisma.OrganisasiWhereInput) => {
});
};

export const findOrganisasi = async (
filter: Prisma.OrganisasiWhereUniqueInput,
) => {
return await prisma.organisasi.findUnique({ where: filter });
export const findOrganisasi = async (filter: Prisma.OrganisasiWhereInput) => {
return await prisma.organisasi.findFirst({ where: filter });
};

export const createOrganisasi = async (data: Prisma.OrganisasiCreateInput) => {
Expand Down