Skip to content

Commit

Permalink
https://www.youtube.com/watch?v=My2FRPA3Gf8
Browse files Browse the repository at this point in the history
  • Loading branch information
marcfranquesa committed Mar 16, 2024
1 parent dd3c389 commit 39d7634
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/app/[slug]/submit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ const page = async ({ params }: PageProps) => {
<ProfileForm
PreselectedSubject={slug}
isAdmin={isAdmin}
session={session}
semester={
subject.semester[0] === "Q" ? parseInt(subject.semester[1]) : 8
}
generacio={session ? Number(session.user.generacio) : 2017}
/>
</>
)
Expand Down
28 changes: 15 additions & 13 deletions src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ 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(),
Expand All @@ -47,13 +46,13 @@ const formSchema = z.object({
export function ProfileForm({
PreselectedSubject,
isAdmin,
session,
semester,
generacio = 2017,
}: {
PreselectedSubject: string
isAdmin: boolean
session: Session
semester: number
semester?: number
generacio?: number
}) {
const router = useRouter()

Expand Down Expand Up @@ -278,17 +277,20 @@ export function ProfileForm({

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++) {
interface Year {
value: string
label: string
}
let tipus_any: Year[] = []
for (let i = generacio; 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
const default_year = semester
? (generacio + Math.floor((semester - 1) / 2)).toString()
: undefined

// ------------------------------
return (
Expand All @@ -301,9 +303,9 @@ export function ProfileForm({
control={form.control}
name="year"
render={({ field }) => {
if (!field.value) {
field.value = default_year.toString()
field.onChange(default_year.toString())
if (!field.value && default_year) {
field.value = default_year
field.onChange(default_year)
}

return (
Expand Down

0 comments on commit 39d7634

Please sign in to comment.