diff --git a/src/app/[slug]/submit/page.tsx b/src/app/[slug]/submit/page.tsx
index dbf59c4..85585b1 100644
--- a/src/app/[slug]/submit/page.tsx
+++ b/src/app/[slug]/submit/page.tsx
@@ -31,7 +31,14 @@ const page = async ({ params }: PageProps) => {
Penja apunts {subjectNameArticle}
{subject.name}
-
+
>
)
}
diff --git a/src/app/api/subject/post/create/route.ts b/src/app/api/subject/post/create/route.ts
index fffec0b..ab5350d 100644
--- a/src/app/api/subject/post/create/route.ts
+++ b/src/app/api/subject/post/create/route.ts
@@ -14,7 +14,7 @@ export async function POST(req: Request) {
const body = await req.json()
- const { pdf, title, assignatura, tipus, anonim, authorEmail } =
+ const { pdf, title, year, assignatura, tipus, anonim, authorEmail } =
ApuntsPostValidator.parse(body)
const subject = await db.subject.findFirst({
@@ -27,14 +27,6 @@ export async function POST(req: Request) {
return new Response("Subject not found", { status: 404 })
}
- const semester = subject.semester
- const semesterNumber = semester[0] === "Q" ? parseInt(semester[1]) : 8
- if (typeof session.user.generacio !== "number") {
- return new Response("Invalid generacio", { status: 409 })
- }
- const year: number =
- session.user.generacio + Math.floor((semesterNumber - 1) / 2)
-
if (
!["apunts", "examens", "exercicis", "diapositives", "altres"].includes(
tipus,
diff --git a/src/components/Form.tsx b/src/components/Form.tsx
index d6c89de..91546ab 100644
--- a/src/components/Form.tsx
+++ b/src/components/Form.tsx
@@ -22,12 +22,16 @@ import { Combobox } from "@/components/Combobox"
import { Checkbox } from "@/components/ui/checkbox"
import { ApuntsPostCreationRequest } from "@/lib/validators/post"
import { uploadFiles } from "@/lib/uploadthing"
+import { Session } from "next-auth"
const formSchema = z.object({
pdf: z.any(),
title: z.string({
required_error: "Selecciona un tÃtol",
}),
+ year: z.string({
+ required_error: "Selecciona un any",
+ }),
assignatura: z.string({
required_error: "Selecciona una assignatura.",
}),
@@ -43,9 +47,13 @@ const formSchema = z.object({
export function ProfileForm({
PreselectedSubject,
isAdmin,
+ session,
+ semester,
}: {
PreselectedSubject: string
isAdmin: boolean
+ session: Session
+ semester: number
}) {
const router = useRouter()
@@ -53,6 +61,7 @@ export function ProfileForm({
mutationFn: async ({
pdf,
title,
+ year,
assignatura,
tipus,
anonim,
@@ -61,6 +70,7 @@ export function ProfileForm({
const payload: ApuntsPostCreationRequest = {
pdf,
title,
+ year,
assignatura,
tipus,
anonim,
@@ -115,6 +125,7 @@ export function ProfileForm({
const payload: ApuntsPostCreationRequest = {
pdf: res.fileUrl,
title: data.title,
+ year: Number(data.year),
assignatura: data.assignatura,
tipus: data.tipus,
anonim: data.anonim,
@@ -264,6 +275,21 @@ export function ProfileForm({
label: "Altres",
},
]
+
+ const date = new Date()
+ const end = date.getFullYear()
+ const begin = session ? Number(session.user.generacio) : 2017 // primera promoció
+ let tipus_any = []
+ for (let i = begin; i <= end; i++) {
+ tipus_any.push({
+ value: i.toString(),
+ label: i.toString(),
+ })
+ }
+ const default_year = session
+ ? session.user.generacio + Math.floor((semester - 1) / 2)
+ : end
+
// ------------------------------
return (