diff --git a/prisma/migrations/20240910025053_add_link_berkas/migration.sql b/prisma/migrations/20240910025053_add_link_berkas/migration.sql new file mode 100644 index 0000000..129d67d --- /dev/null +++ b/prisma/migrations/20240910025053_add_link_berkas/migration.sql @@ -0,0 +1,13 @@ +-- AlterEnum +-- This migration adds more than one value to an enum. +-- With PostgreSQL versions 11 and earlier, this is not possible +-- in a single migration. This can be worked around by creating +-- multiple migrations, each migration adding only one value to +-- the enum. + + +ALTER TYPE "Posisi" ADD VALUE 'CERDAS_CERMAT1'; +ALTER TYPE "Posisi" ADD VALUE 'CERDAS_CERMAT2'; + +-- AlterTable +ALTER TABLE "Tim" ADD COLUMN "link_berkas" TEXT; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index fbc85c9..f6e3402 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1,9 +1,3 @@ -// This is your Prisma schema file, -// learn more about it in the docs: https://pris.ly/d/prisma-schema - -// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions? -// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init - generator client { provider = "prisma-client-js" } @@ -13,62 +7,16 @@ datasource db { url = env("DATABASE_URL") } -enum Jenjang { - SMP - SMA -} - -enum Kelas { - VII - VIII - IX - X - XI - XII -} - -enum Role { - USER - ADMIN -} - -enum Tipe { - SMALL - NORMAL -} - -enum Posisi { - CERDAS_CERMAT1 - CERDAS_CERMAT2 - OFFICIAL - DANTON - B1S1 - B1S2 - B1S3 - B2S1 - B2S2 - B2S3 - B3S1 - B3S2 - B3S3 - B4S1 - B4S2 - B4S3 - B5S1 - B5S2 - B5S3 -} - model User { id String @id @default(uuid()) nama String email String @unique password String role Role + verified Boolean @default(false) + token String? penilaian Penilaian[] tim Tim? - token String? - verified Boolean @default(false) } model Anggota { @@ -80,8 +28,8 @@ model Anggota { posisi Posisi nisn String? kelas Kelas - Tim Tim @relation(fields: [timId], references: [id], onDelete: Cascade) timId String + Tim Tim @relation(fields: [timId], references: [id], onDelete: Cascade) @@unique([posisi, timId]) } @@ -90,49 +38,50 @@ model Penilaian { id String @id @default(uuid()) created_at DateTime? @default(now()) updated_at DateTime @updatedAt - user User @relation(references: [id], fields: [user_id], onDelete: Cascade) user_id String - tim Tim @relation(fields: [tim_id], references: [id]) tim_id String @unique - published Boolean @default(false) - pbb Int - variasi Int - formasi Int danpas Int + detail_url String + formasi Int + note String pasukan Int + pbb Int pbb_tambahan Int - mascot Int? + published Boolean @default(false) + variasi Int cerdas_cermat Int? - detail_url String - note String + mascot Int? + tim Tim @relation(fields: [tim_id], references: [id]) + user User @relation(fields: [user_id], references: [id], onDelete: Cascade) } model Tim { id String @id @default(uuid()) nama_tim String - asal_sekolah String updated_at DateTime @updatedAt - penilaian Penilaian? pelatih String - no_pelatih String - anggotas Anggota[] jenjang Jenjang - pembayaran Pembayaran? - tipe_tim Tipe confirmed Boolean @default(false) - user User @relation(fields: [userId], references: [id]) userId String @unique + asal_sekolah String + tipe_tim Tipe foto_mascot String? + no_pelatih String + anggotas Anggota[] + pembayaran Pembayaran? + penilaian Penilaian? + user User @relation(fields: [userId], references: [id]) + link_berkas String? } model Pembayaran { id String @id @default(uuid()) - tim Tim @relation(fields: [tim_id], references: [id], onDelete: Cascade) tim_id String @unique bukti_tf String bank String - isDP Boolean nama_rek String + isDP Boolean + tim Tim @relation(fields: [tim_id], references: [id], onDelete: Cascade) } model Pengumuman { @@ -140,3 +89,49 @@ model Pengumuman { createdAt DateTime @default(now()) content String } + +enum Jenjang { + SMP + SMA +} + +enum Kelas { + VII + VIII + IX + X + XI + XII +} + +enum Role { + USER + ADMIN +} + +enum Tipe { + SMALL + NORMAL +} + +enum Posisi { + OFFICIAL + DANTON + B1S1 + B1S2 + B1S3 + B2S1 + B2S2 + B2S3 + B3S1 + B3S2 + B3S3 + B4S1 + B4S2 + B4S3 + B5S1 + B5S2 + B5S3 + CERDAS_CERMAT1 + CERDAS_CERMAT2 +} diff --git a/src/actions/Tim.ts b/src/actions/Tim.ts index df1acb4..9f1c708 100644 --- a/src/actions/Tim.ts +++ b/src/actions/Tim.ts @@ -1,10 +1,26 @@ "use server"; import { revalidatePath } from "next/cache"; -import { deleteTim, updateTim } from "@/queries/tim.query"; -import { Tipe } from "@prisma/client"; +import { updateTim,deleteTim } from "@/queries/tim.query"; +import {Tipe} from "@prisma/client" -export async function updateTimForm(data: FormData, id: string) { +export async function updateTimForm(id: string, formData: FormData) { + const link_berkas = formData.get("link_berkas") as string; + + try { + await updateTim( + { id }, + { link_berkas } + ); + revalidatePath("/", "layout"); + return { success: true, message: "Berhasil memperbarui Link"}; + } catch (e) { + console.log(e); + return { success: false, message: "Gagal memperbarui Link"}; + } +} + +export async function updateTimFormAdmin(data: FormData, id: string) { const asal_sekolah = data.get("asal_sekolah") as string; const tipe_tim = data.get("tipe_tim") as Tipe; diff --git a/src/app/(admin)/admin/tim/[id]/components/Form.tsx b/src/app/(admin)/admin/tim/[id]/components/Form.tsx index 92f46b3..3c53ef1 100644 --- a/src/app/(admin)/admin/tim/[id]/components/Form.tsx +++ b/src/app/(admin)/admin/tim/[id]/components/Form.tsx @@ -1,6 +1,6 @@ "use client"; -import { updateTimForm } from "@/actions/Tim"; +import { updateTimForm, updateTimFormAdmin } from "@/actions/Tim"; import { Anggota, Tim } from "@prisma/client"; import { redirect } from "next/navigation"; import Select from "react-select"; @@ -8,8 +8,8 @@ import { toast } from "sonner"; import SubmitButton from "./parts/Button"; import TextField from "./parts/Input"; import { H1 } from "@/app/components/global/Text"; -import ProfileTim from "./ProfileTim"; -import { TimWithRelations } from "@/types/entityRelations"; +import { CopyLinkButton } from "@/app/components/global/Button"; + export default function TimForm({ data, @@ -34,7 +34,7 @@ export default function TimForm({ async function Update(data: FormData) { const toastId = toast.loading("Loading..."); - const result = await updateTimForm(data, id!); + const result = await updateTimFormAdmin(data, id!); if (!result.success) { toast.error("Gagal mengedit tim!", { id: toastId }); } else { @@ -42,6 +42,8 @@ export default function TimForm({ redirect("/admin/tim"); } } + + return (

Profile Tim

@@ -85,6 +87,21 @@ export default function TimForm({ required={edit ? false : true} disabled={true} /> + + + {data?.link_berkas ? ( + + ) : null} +
); diff --git a/src/app/components/global/Button.tsx b/src/app/components/global/Button.tsx index ce372ca..c841d2e 100644 --- a/src/app/components/global/Button.tsx +++ b/src/app/components/global/Button.tsx @@ -1,5 +1,5 @@ import cn from "@/lib/clsx"; -import { MouseEventHandler, ReactNode } from "react"; +import { MouseEventHandler, ReactNode, useState } from "react"; export function PrimaryButton({ children, @@ -84,3 +84,37 @@ export function TertiaryButton({ ); } + +export function CopyLinkButton({ + children, + href, + className, +}: Readonly<{ + children: ReactNode; + href: string; + className?: string; +}>) { + const [copied, setCopied] = useState(false); + + const handleCopy = async () => { + try { + await navigator.clipboard.writeText(href); + setCopied(true); + setTimeout(() => setCopied(false), 2000); + } catch (err) { + console.error('Failed to copy text: ', err); + } + }; + + return ( + + ); +}