From 88efbb5905d3b0757bb9c70876fe3b9540606cd0 Mon Sep 17 00:00:00 2001 From: Ahsan Date: Wed, 12 Jun 2024 09:30:02 +0700 Subject: [PATCH 1/4] fix: Remove page sub-organ in admin --- .../admin/organisasi/[slug]/[period]/page.tsx | 0 .../(admin)/admin/organisasi/[slug]/page.tsx | 16 +++++++++++++- .../(admin)/admin/organisasi/create/page.tsx | 0 src/app/(admin)/admin/organisasi/page.tsx | 8 +++++-- .../(admin)/admin/sub-organ/[slug]/page.tsx | 22 ------------------- src/app/(admin)/admin/sub-organ/page.tsx | 9 -------- 6 files changed, 21 insertions(+), 34 deletions(-) delete mode 100644 src/app/(admin)/admin/organisasi/[slug]/[period]/page.tsx delete mode 100644 src/app/(admin)/admin/organisasi/create/page.tsx delete mode 100644 src/app/(admin)/admin/sub-organ/[slug]/page.tsx delete mode 100644 src/app/(admin)/admin/sub-organ/page.tsx diff --git a/src/app/(admin)/admin/organisasi/[slug]/[period]/page.tsx b/src/app/(admin)/admin/organisasi/[slug]/[period]/page.tsx deleted file mode 100644 index e69de29b..00000000 diff --git a/src/app/(admin)/admin/organisasi/[slug]/page.tsx b/src/app/(admin)/admin/organisasi/[slug]/page.tsx index 213bb79a..fc695400 100644 --- a/src/app/(admin)/admin/organisasi/[slug]/page.tsx +++ b/src/app/(admin)/admin/organisasi/[slug]/page.tsx @@ -1,8 +1,22 @@ +import { Organisasi_Type } from "@prisma/client"; + +import { findOrganisasi } from "@/utils/database/organisasi.query"; +import { findLatestPeriod } from "@/utils/database/period.query"; + export default async function Edit({ params, }: { params: { organisasi: string }; }) { - console.log(params); + const latestPeriod = await findLatestPeriod(); + const organisasi = await findOrganisasi({ + organisasi_period_id: { + period_id: latestPeriod.id, + organisasi: params.organisasi as Organisasi_Type, + }, + }); + + console.log(organisasi); + return <>; } diff --git a/src/app/(admin)/admin/organisasi/create/page.tsx b/src/app/(admin)/admin/organisasi/create/page.tsx deleted file mode 100644 index e69de29b..00000000 diff --git a/src/app/(admin)/admin/organisasi/page.tsx b/src/app/(admin)/admin/organisasi/page.tsx index 2aba1d76..ef8bbe83 100644 --- a/src/app/(admin)/admin/organisasi/page.tsx +++ b/src/app/(admin)/admin/organisasi/page.tsx @@ -1,5 +1,9 @@ import { H1 } from "@/app/_components/global/Text"; -export default function SubOrgan() { - return

Sub-organ

; +export default function SuborAdmin() { + return ( + <> +

TOLONG DISLICE

+ + ); } diff --git a/src/app/(admin)/admin/sub-organ/[slug]/page.tsx b/src/app/(admin)/admin/sub-organ/[slug]/page.tsx deleted file mode 100644 index fc695400..00000000 --- a/src/app/(admin)/admin/sub-organ/[slug]/page.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { Organisasi_Type } from "@prisma/client"; - -import { findOrganisasi } from "@/utils/database/organisasi.query"; -import { findLatestPeriod } from "@/utils/database/period.query"; - -export default async function Edit({ - params, -}: { - params: { organisasi: string }; -}) { - const latestPeriod = await findLatestPeriod(); - const organisasi = await findOrganisasi({ - organisasi_period_id: { - period_id: latestPeriod.id, - organisasi: params.organisasi as Organisasi_Type, - }, - }); - - console.log(organisasi); - - return <>; -} diff --git a/src/app/(admin)/admin/sub-organ/page.tsx b/src/app/(admin)/admin/sub-organ/page.tsx deleted file mode 100644 index ef8bbe83..00000000 --- a/src/app/(admin)/admin/sub-organ/page.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { H1 } from "@/app/_components/global/Text"; - -export default function SuborAdmin() { - return ( - <> -

TOLONG DISLICE

- - ); -} From d94cc36f1e309557c9b54cecef13c0c7d8f70e39 Mon Sep 17 00:00:00 2001 From: Ahsan Date: Wed, 12 Jun 2024 09:50:38 +0700 Subject: [PATCH 2/4] fix: Remove hero section in organisai page --- .../[slug]/components/parts/Contact.tsx | 0 .../[slug]/components/parts/Gallery.tsx | 0 .../[slug]/components/parts/Overview.tsx | 0 .../[slug]/components/parts/RelatedNews.tsx | 0 .../[slug]/components/parts/Stucture.tsx | 0 .../[slug]/components/parts/VisiMisi.tsx | 0 .../{sub-organ => organisasi}/[slug]/page.tsx | 0 .../_components/OrganizationSection.tsx | 0 .../_components/Parts/Organizations.tsx | 34 ++----- .../(main)/{sub-organ => organisasi}/page.tsx | 4 +- .../sub-organ/_components/Parts/Hero.tsx | 94 ------------------- src/app/_components/global/Navbar.tsx | 2 +- 12 files changed, 8 insertions(+), 126 deletions(-) rename src/app/(main)/{sub-organ => organisasi}/[slug]/components/parts/Contact.tsx (100%) rename src/app/(main)/{sub-organ => organisasi}/[slug]/components/parts/Gallery.tsx (100%) rename src/app/(main)/{sub-organ => organisasi}/[slug]/components/parts/Overview.tsx (100%) rename src/app/(main)/{sub-organ => organisasi}/[slug]/components/parts/RelatedNews.tsx (100%) rename src/app/(main)/{sub-organ => organisasi}/[slug]/components/parts/Stucture.tsx (100%) rename src/app/(main)/{sub-organ => organisasi}/[slug]/components/parts/VisiMisi.tsx (100%) rename src/app/(main)/{sub-organ => organisasi}/[slug]/page.tsx (100%) rename src/app/(main)/{sub-organ => organisasi}/_components/OrganizationSection.tsx (100%) rename src/app/(main)/{sub-organ => organisasi}/_components/Parts/Organizations.tsx (72%) rename src/app/(main)/{sub-organ => organisasi}/page.tsx (53%) delete mode 100644 src/app/(main)/sub-organ/_components/Parts/Hero.tsx diff --git a/src/app/(main)/sub-organ/[slug]/components/parts/Contact.tsx b/src/app/(main)/organisasi/[slug]/components/parts/Contact.tsx similarity index 100% rename from src/app/(main)/sub-organ/[slug]/components/parts/Contact.tsx rename to src/app/(main)/organisasi/[slug]/components/parts/Contact.tsx diff --git a/src/app/(main)/sub-organ/[slug]/components/parts/Gallery.tsx b/src/app/(main)/organisasi/[slug]/components/parts/Gallery.tsx similarity index 100% rename from src/app/(main)/sub-organ/[slug]/components/parts/Gallery.tsx rename to src/app/(main)/organisasi/[slug]/components/parts/Gallery.tsx diff --git a/src/app/(main)/sub-organ/[slug]/components/parts/Overview.tsx b/src/app/(main)/organisasi/[slug]/components/parts/Overview.tsx similarity index 100% rename from src/app/(main)/sub-organ/[slug]/components/parts/Overview.tsx rename to src/app/(main)/organisasi/[slug]/components/parts/Overview.tsx diff --git a/src/app/(main)/sub-organ/[slug]/components/parts/RelatedNews.tsx b/src/app/(main)/organisasi/[slug]/components/parts/RelatedNews.tsx similarity index 100% rename from src/app/(main)/sub-organ/[slug]/components/parts/RelatedNews.tsx rename to src/app/(main)/organisasi/[slug]/components/parts/RelatedNews.tsx diff --git a/src/app/(main)/sub-organ/[slug]/components/parts/Stucture.tsx b/src/app/(main)/organisasi/[slug]/components/parts/Stucture.tsx similarity index 100% rename from src/app/(main)/sub-organ/[slug]/components/parts/Stucture.tsx rename to src/app/(main)/organisasi/[slug]/components/parts/Stucture.tsx diff --git a/src/app/(main)/sub-organ/[slug]/components/parts/VisiMisi.tsx b/src/app/(main)/organisasi/[slug]/components/parts/VisiMisi.tsx similarity index 100% rename from src/app/(main)/sub-organ/[slug]/components/parts/VisiMisi.tsx rename to src/app/(main)/organisasi/[slug]/components/parts/VisiMisi.tsx diff --git a/src/app/(main)/sub-organ/[slug]/page.tsx b/src/app/(main)/organisasi/[slug]/page.tsx similarity index 100% rename from src/app/(main)/sub-organ/[slug]/page.tsx rename to src/app/(main)/organisasi/[slug]/page.tsx diff --git a/src/app/(main)/sub-organ/_components/OrganizationSection.tsx b/src/app/(main)/organisasi/_components/OrganizationSection.tsx similarity index 100% rename from src/app/(main)/sub-organ/_components/OrganizationSection.tsx rename to src/app/(main)/organisasi/_components/OrganizationSection.tsx diff --git a/src/app/(main)/sub-organ/_components/Parts/Organizations.tsx b/src/app/(main)/organisasi/_components/Parts/Organizations.tsx similarity index 72% rename from src/app/(main)/sub-organ/_components/Parts/Organizations.tsx rename to src/app/(main)/organisasi/_components/Parts/Organizations.tsx index 04f39d37..e7f7ec36 100644 --- a/src/app/(main)/sub-organ/_components/Parts/Organizations.tsx +++ b/src/app/(main)/organisasi/_components/Parts/Organizations.tsx @@ -1,8 +1,6 @@ import { ReactElement } from "react"; - -import Book from "@/app/_components/icons/Book"; -import Language from "@/app/_components/icons/Language"; -import Weight from "@/app/_components/icons/Weight"; +import { FaGlobe } from "react-icons/fa"; +import { FaUserGroup } from "react-icons/fa6"; import OrganizationSection from "../OrganizationSection"; @@ -22,8 +20,8 @@ export interface SuborganSection { const organizations: SuborganSection[] = [ { - sectionName: "Olahraga", - sectionLogo: , + sectionName: "Organisasi", + sectionLogo: , sectionDesc: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam volutpat tellus quis urna gravida. Quis ultrices arcu consequat. Praesent aliquet ante molestie faucibus facilisis. Integer fermentum, sapien ac.", sectionOrgans: [ @@ -54,8 +52,8 @@ const organizations: SuborganSection[] = [ ], }, { - sectionName: "Seni & Bahasa", - sectionLogo: , + sectionName: "Sub-organisasi", + sectionLogo: , sectionDesc: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam volutpat tellus quis urna gravida. Quis ultrices arcu consequat. Praesent aliquet ante molestie faucibus facilisis. Integer fermentum, sapien ac.", sectionOrgans: [ @@ -85,26 +83,6 @@ const organizations: SuborganSection[] = [ }, ], }, - { - sectionName: "Ilmu", - sectionLogo: , - sectionDesc: - "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam volutpat tellus quis urna gravida. Quis ultrices arcu consequat. Praesent aliquet ante molestie faucibus facilisis. Integer fermentum, sapien ac.", - sectionOrgans: [ - { - name: "Palwaga", - desc: "Lorem ipsum dolor sit amet, consectetur adipiscing", - image: "https://placehold.co/62x62?text=Logo", - href: "#", - }, - { - name: "Comet", - desc: "Lorem ipsum dolor sit amet, consectetur adipiscing", - image: "https://placehold.co/62x62?text=Logo", - href: "#", - }, - ], - }, ]; export default function Organizations() { diff --git a/src/app/(main)/sub-organ/page.tsx b/src/app/(main)/organisasi/page.tsx similarity index 53% rename from src/app/(main)/sub-organ/page.tsx rename to src/app/(main)/organisasi/page.tsx index bfea73c8..9e52415f 100644 --- a/src/app/(main)/sub-organ/page.tsx +++ b/src/app/(main)/organisasi/page.tsx @@ -1,10 +1,8 @@ -import Hero from "./_components/Parts/Hero"; import Organizations from "./_components/Parts/Organizations"; -export default async function SubOrganPage() { +export default async function OrganisasiPage() { return ( <> - ); diff --git a/src/app/(main)/sub-organ/_components/Parts/Hero.tsx b/src/app/(main)/sub-organ/_components/Parts/Hero.tsx deleted file mode 100644 index 373e6a19..00000000 --- a/src/app/(main)/sub-organ/_components/Parts/Hero.tsx +++ /dev/null @@ -1,94 +0,0 @@ -"use client"; - -import { useEffect, useState } from "react"; - -import Image from "@/app/_components/global/Image"; -import { H4, P } from "@/app/_components/global/Text"; -import { SectionWrapper } from "@/app/_components/global/Wrapper"; - -export default function Hero() { - const [index, setIndex] = useState(0); - const [isAuto, setIsAuto] = useState(true); - - const photos = [ - "https://placehold.co/1192x462?text=Hero1", - "https://placehold.co/1192x462?text=Hero2", - "https://placehold.co/1192x462?text=Hero3", - ]; - - const Items = [ - { - title: "Lorem Ipsum", - desc: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ullamcorper odio justo, vitae blandit lacus facilisis lobortis.", - }, - { - title: "Lorem Ipsum", - desc: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ullamcorper odio justo, vitae blandit lacus facilisis lobortis.", - }, - { - title: "Lorem Ipsum", - desc: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ullamcorper odio justo, vitae blandit lacus facilisis lobortis.", - }, - ]; - - useEffect(() => { - if (index < 2 && isAuto) - setTimeout(() => { - setIndex(index + 1); - }, 5000); - if (index >= 2 && isAuto) - setTimeout(() => { - setIndex(0); - }, 5000); - else return; - }, [index, isAuto]); - - return ( - -
-
- -
-
- {Items.map((item, i) => ( -
{ - setIsAuto(false); - setIndex(i); - }} - > -
-
-

- {item.title} -

-

- {item.desc} -

-
-
- ))} -
-
-
- ); -} diff --git a/src/app/_components/global/Navbar.tsx b/src/app/_components/global/Navbar.tsx index 8b763cb9..2b93f4ac 100644 --- a/src/app/_components/global/Navbar.tsx +++ b/src/app/_components/global/Navbar.tsx @@ -17,7 +17,7 @@ interface NavOption { const navOptions: NavOption[] = [ { title: "Beranda", href: "/" }, { title: "Berita", href: "/berita" }, - { title: "Sub-organ", href: "/sub-organ" }, + { title: "Organisasi", href: "/organisasi" }, { title: "Tentang", href: "/tentang" }, { title: "Kontributor", href: "/kontributor" }, ]; From d16b977c06c1bc31ac72ff03d342477fa06f34b4 Mon Sep 17 00:00:00 2001 From: Ahsan Date: Wed, 12 Jun 2024 10:32:05 +0700 Subject: [PATCH 3/4] feat: Responsive organisasi detail page --- .../migration.sql | 8 +++++ prisma/schema.prisma | 31 ++++++++++--------- src/actions/organisasi.ts | 2 ++ .../[slug]/components/parts/Gallery.tsx | 23 ++------------ .../[slug]/components/parts/Overview.tsx | 27 +++++++++------- .../[slug]/components/parts/VisiMisi.tsx | 8 ++--- src/app/(main)/organisasi/[slug]/page.tsx | 16 +++------- .../_components/OrganizationSection.tsx | 14 ++++----- src/app/_components/global/Input.tsx | 2 +- 9 files changed, 62 insertions(+), 69 deletions(-) create mode 100644 prisma/migrations/20240612030730_add_organisasi_image_description/migration.sql diff --git a/prisma/migrations/20240612030730_add_organisasi_image_description/migration.sql b/prisma/migrations/20240612030730_add_organisasi_image_description/migration.sql new file mode 100644 index 00000000..ea94f0c0 --- /dev/null +++ b/prisma/migrations/20240612030730_add_organisasi_image_description/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - Added the required column `image_description` to the `Organisasi` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE `Organisasi` ADD COLUMN `image_description` VARCHAR(191) NOT NULL; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index c6650acc..158d925f 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -196,21 +196,22 @@ model Period_Year { } model Organisasi { - id String @id @default(uuid()) @map("suborgan_id") @db.Char(36) - period_id String - period Period_Year @relation(fields: [period_id], references: [id]) - organisasi Organisasi_Type - organisasi_name String @map("organisasi_name") - logo String - description String @db.LongText - vision String - mission String - image String - companion String - structure String @db.LongText - contact String - created_at DateTime @default(now()) - updated_at DateTime @updatedAt + id String @id @default(uuid()) @map("suborgan_id") @db.Char(36) + period_id String + period Period_Year @relation(fields: [period_id], references: [id]) + organisasi Organisasi_Type + organisasi_name String @map("organisasi_name") + logo String + description String @db.LongText + vision String + mission String + image String + image_description String + companion String + structure String @db.LongText + contact String + created_at DateTime @default(now()) + updated_at DateTime @updatedAt @@unique([organisasi, period_id]) @@map("Organisasi") diff --git a/src/actions/organisasi.ts b/src/actions/organisasi.ts index 988fc513..cac628df 100644 --- a/src/actions/organisasi.ts +++ b/src/actions/organisasi.ts @@ -30,6 +30,7 @@ export async function suborganCreate(data: FormData) { const companion = data.get("companion") as string; const structure = data.get("structure") as string; const contact = data.get("contact") as string; + const imageDescription = data.get("image_description") as string; const image = data.get("image") as File; const logo = data.get("logo") as File; @@ -55,6 +56,7 @@ export async function suborganCreate(data: FormData) { structure: structure, contact: contact, period: period, + image_description: imageDescription, }); } catch (e) { console.log(e); diff --git a/src/app/(main)/organisasi/[slug]/components/parts/Gallery.tsx b/src/app/(main)/organisasi/[slug]/components/parts/Gallery.tsx index e2b406fc..0dce0690 100644 --- a/src/app/(main)/organisasi/[slug]/components/parts/Gallery.tsx +++ b/src/app/(main)/organisasi/[slug]/components/parts/Gallery.tsx @@ -2,7 +2,7 @@ import Image from "@/app/_components/global/Image"; import { P, UnderlinedTitle } from "@/app/_components/global/Text"; import { SectionWrapper } from "@/app/_components/global/Wrapper"; -export default function OrgGallery({ Images }: { Images: string[] }) { +export default function OrgGallery({ image }: { image: string }) { return (
@@ -24,9 +24,9 @@ export default function OrgGallery({ Images }: { Images: string[] }) {
-
+
Image
-
- {Images.slice(1).map((image, i) => ( -
- Image -
- ))} -
diff --git a/src/app/(main)/organisasi/[slug]/components/parts/Overview.tsx b/src/app/(main)/organisasi/[slug]/components/parts/Overview.tsx index 4161ad08..ef677091 100644 --- a/src/app/(main)/organisasi/[slug]/components/parts/Overview.tsx +++ b/src/app/(main)/organisasi/[slug]/components/parts/Overview.tsx @@ -1,23 +1,28 @@ +import { SelectField } from "@/app/_components/global/Input"; import { H2, P } from "@/app/_components/global/Text"; import { SectionWrapper } from "@/app/_components/global/Wrapper"; export default function Overview() { return ( - +
-
-
-
-
+
+
+
+

Media Moklet

-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam - volutpat tellus quis urna gravida, quis ultrices arcu consequat. - Praesent aliquet ante molestie faucibus facilisis. Integer - fermentum, sapien ac tempor tempor. -

+
+

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam + volutpat tellus quis urna gravida, quis ultrices arcu consequat. + Praesent aliquet ante molestie faucibus facilisis. Integer + fermentum, sapien ac tempor tempor. +

diff --git a/src/app/(main)/organisasi/[slug]/components/parts/VisiMisi.tsx b/src/app/(main)/organisasi/[slug]/components/parts/VisiMisi.tsx index fe5ec4f3..8b46a6fc 100644 --- a/src/app/(main)/organisasi/[slug]/components/parts/VisiMisi.tsx +++ b/src/app/(main)/organisasi/[slug]/components/parts/VisiMisi.tsx @@ -6,10 +6,10 @@ export default function VisiMisi() { return ( -
-
+
+
@@ -21,7 +21,7 @@ export default function VisiMisi() {

-
+
diff --git a/src/app/(main)/organisasi/[slug]/page.tsx b/src/app/(main)/organisasi/[slug]/page.tsx index 8d0962fc..aa0b3368 100644 --- a/src/app/(main)/organisasi/[slug]/page.tsx +++ b/src/app/(main)/organisasi/[slug]/page.tsx @@ -7,18 +7,12 @@ import RelatedNews from "./components/parts/RelatedNews"; import Structure from "./components/parts/Stucture"; import VisiMisi from "./components/parts/VisiMisi"; -const images = [ - "https://placehold.co/750x500?text=1", - "https://placehold.co/750x500?text=2", - "https://placehold.co/750x500?text=3", - "https://placehold.co/750x500?text=4", - "https://placehold.co/750x500?text=5", -]; +const image = "https://placehold.co/750x500?text=1"; export default async function Organ({ params }: { params: { slug: string } }) { - const organ = params.slug.toUpperCase(); + const organisasiName = params.slug.toUpperCase(); const relatedNews = await findNewestPost(5, { - tags: { some: { tagName: organ } }, + tags: { some: { tagName: organisasiName } }, }); return ( @@ -26,8 +20,8 @@ export default async function Organ({ params }: { params: { slug: string } }) { - - + + ); diff --git a/src/app/(main)/organisasi/_components/OrganizationSection.tsx b/src/app/(main)/organisasi/_components/OrganizationSection.tsx index 494d92eb..ef654769 100644 --- a/src/app/(main)/organisasi/_components/OrganizationSection.tsx +++ b/src/app/(main)/organisasi/_components/OrganizationSection.tsx @@ -25,23 +25,23 @@ export default function OrganizationSection({

{data.sectionDesc}

- {data.sectionOrgans.map((organ) => ( + {data.sectionOrgans.map((organisasi) => (
{organ.name}
-

{organ.name}

-

{organ.desc}

+

{organisasi.name}

+

{organisasi.desc}

diff --git a/src/app/_components/global/Input.tsx b/src/app/_components/global/Input.tsx index b327f273..f527a6de 100644 --- a/src/app/_components/global/Input.tsx +++ b/src/app/_components/global/Input.tsx @@ -29,7 +29,7 @@ interface OptionFieldProps { } interface SelectFieldProps { - label: string; + label?: string; required?: boolean; options: { value: string; label: string }[]; className?: string; From 1e5a3e7beafec6cbace9c23e11915dfc46ed2613 Mon Sep 17 00:00:00 2001 From: Ahsan Date: Wed, 12 Jun 2024 11:09:06 +0700 Subject: [PATCH 4/4] feat: Setup queries for organisasi pages --- .../organisasi/[slug]/[period]/page.tsx | 24 +++++++++++++++++++ src/app/(main)/organisasi/[slug]/page.tsx | 17 ++++++++++--- src/utils/database/period.query.ts | 9 +++++-- 3 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 src/app/(main)/organisasi/[slug]/[period]/page.tsx diff --git a/src/app/(main)/organisasi/[slug]/[period]/page.tsx b/src/app/(main)/organisasi/[slug]/[period]/page.tsx new file mode 100644 index 00000000..f402fca8 --- /dev/null +++ b/src/app/(main)/organisasi/[slug]/[period]/page.tsx @@ -0,0 +1,24 @@ +import { Organisasi_Type } from "@prisma/client"; +import { notFound } from "next/navigation"; + +import { findOrganisasi } from "@/utils/database/organisasi.query"; +import { findPeriod } from "@/utils/database/period.query"; + +export default async function OrganisasiByPeriod({ + param, +}: { + param: { slug: string; period: string }; +}) { + const period = await findPeriod(param.period); + if (!period) return notFound(); + + const organisasi = await findOrganisasi({ + organisasi_period_id: { + organisasi: param.slug.toUpperCase() as Organisasi_Type, + period_id: period.id, + }, + }); + console.log(organisasi); + + return <>; +} diff --git a/src/app/(main)/organisasi/[slug]/page.tsx b/src/app/(main)/organisasi/[slug]/page.tsx index aa0b3368..391a1fb5 100644 --- a/src/app/(main)/organisasi/[slug]/page.tsx +++ b/src/app/(main)/organisasi/[slug]/page.tsx @@ -1,3 +1,7 @@ +import { Organisasi_Type } from "@prisma/client"; + +import { findOrganisasi } from "@/utils/database/organisasi.query"; +import { findLatestPeriod } from "@/utils/database/period.query"; import { findNewestPost } from "@/utils/database/post.query"; import Contact from "./components/parts/Contact"; @@ -10,9 +14,16 @@ import VisiMisi from "./components/parts/VisiMisi"; const image = "https://placehold.co/750x500?text=1"; export default async function Organ({ params }: { params: { slug: string } }) { - const organisasiName = params.slug.toUpperCase(); + const organisasiType = params.slug.toUpperCase() as Organisasi_Type; + const latestPeriod = await findLatestPeriod(); + const organisasi = await findOrganisasi({ + organisasi_period_id: { + organisasi: organisasiType, + period_id: latestPeriod.id, + }, + }); const relatedNews = await findNewestPost(5, { - tags: { some: { tagName: organisasiName } }, + tags: { some: { tagName: organisasiType } }, }); return ( @@ -21,7 +32,7 @@ export default async function Organ({ params }: { params: { slug: string } }) { - + ); diff --git a/src/utils/database/period.query.ts b/src/utils/database/period.query.ts index bdb9b6a3..198ff5fe 100644 --- a/src/utils/database/period.query.ts +++ b/src/utils/database/period.query.ts @@ -5,9 +5,14 @@ import prisma from "@/lib/prisma"; export const findLatestPeriod = async () => { const currentYear = new Date().getFullYear(); // Period year format example: 2023/2024 - const latestPeriod = await prisma.period_Year.findUnique({ + const latestPeriodYear = await prisma.period_Year.findUnique({ where: { period: `${currentYear}/${currentYear + 1}` }, }); - return latestPeriod as Period_Year; + return latestPeriodYear as Period_Year; +}; + +export const findPeriod = async (period: string) => { + const periodYear = await prisma.period_Year.findUnique({ where: { period } }); + return periodYear; };