diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml new file mode 100644 index 0000000..7c3fd94 --- /dev/null +++ b/.github/workflows/deploy-dev.yml @@ -0,0 +1,50 @@ +name: Deploy Dev App +#deploy dev branch +on: + push: + branches: + - dev + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Copy repository to SFTP + uses: appleboy/scp-action@master + with: + host: ${{ secrets.SFTP_HOST }} + username: ${{ secrets.SFTP_USER }} + password: ${{ secrets.SFTP_PASSWORD }} + port: ${{ secrets.SFTP_PORT }} + source: '.' + target: '/opt/route-dev' + + - name: Build and deploy Docker container + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SFTP_HOST }} + username: ${{ secrets.SFTP_USER }} + password: ${{ secrets.SFTP_PASSWORD }} + port: ${{ secrets.SFTP_PORT }} + script: | + cd '/opt/route-dev' + + # Overwrite the .env file to recreate it during each deployment + rm -f .env + echo "AUTH_SECRET=${{ secrets.AUTH_SECRET_TESTING }}" >> .env + echo "CLIENT_ID=${{ secrets.CLIENT_ID_TESTING }}" >> .env + echo "CLIENT_SECRET=${{ secrets.CLIENT_SECRET_TESTING }}" >> .env + echo "DATABASE_URL=${{ secrets.DATABASE_URL_TESTING }}" >> .env + echo "AUTH_TRUST_HOST=${{ secrets.AUTH_TRUST_HOST }}" >> .env + + #Prisma + npx prisma generate + + docker build -t route-dev . + docker stop route-dev || true + docker rm route-dev || true + docker run -d --name route-dev --restart always --env-file .env -p 3003:3000 route-dev 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..e701993 100644 --- a/src/lib/components/MyProfile/SkillsForm.svelte +++ b/src/lib/components/MyProfile/SkillsForm.svelte @@ -2,12 +2,18 @@ import * as Form from '$lib/components/ui/form'; import { Input } from '$lib/components/ui/input'; import { skillsSchema, type SkillsSchema } from '$lib/schemas/skills'; - import { Select } from 'bits-ui'; + import { Select, type Selected } from 'bits-ui'; import { type SuperValidated, type Infer, superForm } from 'sveltekit-superforms'; import { zodClient } from 'sveltekit-superforms/adapters'; + import type { Skill } from '@prisma/client'; + import { masteryLevels } from '$lib/constants/masteryLevel'; + import { getMasteryLevelFromLabel, getMasteryLevelFromLevel } from '$lib/utils/getMasteryLevel'; 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), @@ -20,15 +26,28 @@ } }); - const { form: formData, enhance } = form; + const { form: formData, enhance, message } = form; $: $formData.order = skillsLength; - $: selectedLevel = $formData.level - ? { - label: $formData.level, - value: $formData.level + $: selectedLevel = { + value: '', + label: '' + }; + + const onSelectedChange = (selected: Selected | undefined) => { + if (selected) { + const level = getMasteryLevelFromLabel(selected.value); + if (level) { + $formData.level = level.value; } - : undefined; + } + }; + + formData.subscribe((current) => { + if (!selectedLevel) selectedLevel = { label: '', value: '' }; + selectedLevel.label = getMasteryLevelFromLevel(current.level)?.label ?? ''; + selectedLevel.value = current.level; + });
-
+
Title @@ -45,41 +64,38 @@ -
-
Level of mastery - { - v && ($formData.level = v.value); - }} - > + - - - - - + {#each masteryLevels as mastery} + + {/each} - -
- - - - - + + + + + - Add + Add +
+ +{#if isLimitReached} +

You have reached the maximum limit of 15 skills.

+{:else if $message} +

{$message}

+{/if} + diff --git a/src/lib/components/MyProfile/UserSkills.svelte b/src/lib/components/MyProfile/UserSkills.svelte index ac79694..a131ab6 100644 --- a/src/lib/components/MyProfile/UserSkills.svelte +++ b/src/lib/components/MyProfile/UserSkills.svelte @@ -1,6 +1,6 @@ - {#each skills as skill(skill.id)} + {#each skills as skill (skill.id)}

{skill.title}

- {masteryLevels.find((level) => level.value === String(skill.level))?.label} + {getMasteryLevelFromLevel(skill.level)?.label}

diff --git a/src/lib/constants/masteryLevel.ts b/src/lib/constants/masteryLevel.ts index 961c656..05b43ec 100644 --- a/src/lib/constants/masteryLevel.ts +++ b/src/lib/constants/masteryLevel.ts @@ -1,4 +1,6 @@ -export const masteryLevels = [ +import type { MasteryLevel } from '$lib/types/MasteryLevel'; + +export const masteryLevels: MasteryLevel[] = [ { value: '1', label: 'Novice' }, { value: '2', label: 'Intermediate' }, { value: '3', label: 'Competent' }, diff --git a/src/lib/types/MasteryLevel.ts b/src/lib/types/MasteryLevel.ts new file mode 100644 index 0000000..d97a082 --- /dev/null +++ b/src/lib/types/MasteryLevel.ts @@ -0,0 +1,4 @@ +export interface MasteryLevel { + value: string; + label: string; +} diff --git a/src/lib/utils/getMasteryLevel.ts b/src/lib/utils/getMasteryLevel.ts new file mode 100644 index 0000000..a03c92a --- /dev/null +++ b/src/lib/utils/getMasteryLevel.ts @@ -0,0 +1,10 @@ +import { masteryLevels } from '$lib/constants/masteryLevel'; +import type { MasteryLevel } from '$lib/types/MasteryLevel'; + +export const getMasteryLevelFromLabel = (label: string): MasteryLevel | undefined => { + return masteryLevels.find((masteryLevel) => masteryLevel.label == label); +}; + +export const getMasteryLevelFromLevel = (level: string): MasteryLevel | undefined => { + return masteryLevels.find((masteryLevel) => masteryLevel.value == level); +}; 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 - +