diff --git a/src/lib/components/MyProfile/LinkForm.svelte b/src/lib/components/MyProfile/LinkForm.svelte index 4ad020c..94e792f 100644 --- a/src/lib/components/MyProfile/LinkForm.svelte +++ b/src/lib/components/MyProfile/LinkForm.svelte @@ -4,15 +4,19 @@ import { linksSchema, type LinksSchema } from '$lib/schemas/links'; import { type SuperValidated, type Infer, superForm } from 'sveltekit-superforms'; import { zodClient } from 'sveltekit-superforms/adapters'; + import type { Link } from '@prisma/client'; export let data: SuperValidated>; export let linksLength: number; + export let links: Link[] = []; + let isLimitReached = false; + $: isLimitReached = links.length >= 15; const form = superForm(data, { validators: zodClient(linksSchema) }); - const { form: formData, enhance } = form; + const { form: formData, enhance, message } = form; $: $formData.order = linksLength; @@ -49,5 +53,11 @@ - Add + Add + +{#if isLimitReached} +

You have reached the maximum limit of 15 links.

+{:else if $message} +

{$message}

+{/if} \ No newline at end of file diff --git a/src/lib/components/MyProfile/SkillsForm.svelte b/src/lib/components/MyProfile/SkillsForm.svelte index 20d1ce8..ed4c651 100644 --- a/src/lib/components/MyProfile/SkillsForm.svelte +++ b/src/lib/components/MyProfile/SkillsForm.svelte @@ -5,10 +5,13 @@ import { Select } from 'bits-ui'; import { type SuperValidated, type Infer, superForm } from 'sveltekit-superforms'; import { zodClient } from 'sveltekit-superforms/adapters'; + import type { Skill } from '@prisma/client'; export let data: SuperValidated>; export let skillsLength: number; - + export let skills: Skill[] = []; + let isLimitReached = false; + $: isLimitReached = skills.length >= 15; const form = superForm(data, { validators: zodClient(skillsSchema), resetForm: false, @@ -20,7 +23,7 @@ } }); - const { form: formData, enhance } = form; + const { form: formData, enhance ,message} = form; $: $formData.order = skillsLength; $: selectedLevel = $formData.level @@ -81,5 +84,11 @@ - Add + Add + +{#if isLimitReached} +

You have reached the maximum limit of 15 skills.

+{:else if $message} +

{$message}

+{/if} \ No newline at end of file diff --git a/src/routes/profile/+page.server.ts b/src/routes/profile/+page.server.ts index 9557183..b69fa72 100644 --- a/src/routes/profile/+page.server.ts +++ b/src/routes/profile/+page.server.ts @@ -89,6 +89,10 @@ export const actions: Actions = { if (user) { try { + const linkCount = await prisma.link.count({where: { userId: user.githubId }}); + if (linkCount >= 15) { + return fail(400, {form, message: 'You have reached the maximum limit of 15 links.'}); + } await prisma.link.create({ data: { title, @@ -144,6 +148,10 @@ export const actions: Actions = { if (user) { try { + const skillCount = await prisma.skill.count({where :{userId:user.githubId}}); + if (skillCount >= 15) { + return fail(400, {form,message:'You have reached the maximum limit of 15 skills'}) + } await prisma.skill.create({ data: { title, diff --git a/src/routes/profile/+page.svelte b/src/routes/profile/+page.svelte index 8bcf97c..631f559 100644 --- a/src/routes/profile/+page.svelte +++ b/src/routes/profile/+page.svelte @@ -70,7 +70,7 @@ The links visible on your profile. You can drag links around to modify the order - + @@ -82,7 +82,7 @@ Tech Stack You can drag skills around to modify the order - +