Skip to content

Commit

Permalink
Merge pull request #125 from BaniHillabi/master
Browse files Browse the repository at this point in the history
feat : add link_berkas input
  • Loading branch information
BaniHillabi authored Sep 11, 2024
2 parents fc8d05c + 0ba07b0 commit 550eebe
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 132 deletions.
13 changes: 13 additions & 0 deletions prisma/migrations/20240910025053_add_link_berkas/migration.sql
Original file line number Diff line number Diff line change
@@ -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;
141 changes: 68 additions & 73 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -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"
}
Expand All @@ -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 {
Expand All @@ -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])
}
Expand All @@ -90,53 +38,100 @@ 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 {
id String @id @default(uuid())
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
}
22 changes: 19 additions & 3 deletions src/actions/Tim.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
27 changes: 22 additions & 5 deletions src/app/(admin)/admin/tim/[id]/components/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"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";
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,
Expand All @@ -34,14 +34,16 @@ 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 {
toast.success("Berhasil mengedit tim!", { id: toastId });
redirect("/admin/tim");
}
}


return (
<form action={Update}>
<H1>Profile Tim</H1>
Expand Down Expand Up @@ -85,6 +87,21 @@ export default function TimForm({
required={edit ? false : true}
disabled={true}
/>
<TextField
id="link_berkas"
type="url"
label="Link Berkas"
name="link_berkas"
placeholder="Link Berkas"
value={data?.link_berkas ?? ''}
required={edit ? false : true}
disabled={true}
/>

{data?.link_berkas ? (
<CopyLinkButton children="Copy Link" href={data.link_berkas ?? ''} />
) : null}

<div className="flex flex-col gap-2">
<label htmlFor={"jenjang"} className="text-[16px]">
Jenjang
Expand Down Expand Up @@ -124,7 +141,7 @@ export default function TimForm({
name="tipe_tim"
unstyled
defaultValue={{
label: data?.tipe_tim.toString() === "SMALL" ? "12 Anggota" : "15 Anggota" ,
label: data?.tipe_tim.toString() === "SMALL" ? "12 Anggota" : "15 Anggota",
value: data?.tipe_tim.toString(),
}}
isDisabled={false}
Expand Down
1 change: 1 addition & 0 deletions src/app/(admin)/admin/tim/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default async function TimEdit({ params }: { params: { id: string } }) {
updated_at: new Date(),
tipe_tim: "NORMAL",
foto_mascot: "",
link_berkas: ""
};

const trygetTim = await findTim({ id: params.id });
Expand Down
Loading

0 comments on commit 550eebe

Please sign in to comment.