From 99a0253946a581bf587340901b76c83c1e788e8b Mon Sep 17 00:00:00 2001 From: EETagent Date: Fri, 30 Dec 2022 22:49:55 +0100 Subject: [PATCH 1/5] feat: add delete to api definitions --- frontend/src/lib/@api/admin.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/frontend/src/lib/@api/admin.ts b/frontend/src/lib/@api/admin.ts index 6ae2c9b..5fd7321 100644 --- a/frontend/src/lib/@api/admin.ts +++ b/frontend/src/lib/@api/admin.ts @@ -29,6 +29,16 @@ export const apiCreateCandidate = async (data: CreateCandidate): Promise => { + try { + const res = await axios.delete(API_URL + `/admin/candidate/${id}`, { withCredentials: true }); + return res.data; + } catch (e) { + throw errorHandler(e, 'Candidate creation failed'); + } +}; + // Reset candidate password /admin/candidate/{id}/reset_password export const apiResetCandidatePassword = async (id: number): Promise => { try { From 07ccd44d56ccdcfc9fc3cd3431b0f52284ff1a2f Mon Sep 17 00:00:00 2001 From: EETagent Date: Fri, 30 Dec 2022 23:10:17 +0100 Subject: [PATCH 2/5] feat: add delete button --- .../src/lib/components/button/Delete.svelte | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 frontend/src/lib/components/button/Delete.svelte diff --git a/frontend/src/lib/components/button/Delete.svelte b/frontend/src/lib/components/button/Delete.svelte new file mode 100644 index 0000000..1e49128 --- /dev/null +++ b/frontend/src/lib/components/button/Delete.svelte @@ -0,0 +1,61 @@ + + + + + From 233da205f3d13ba1c243f7d0086db9ea9c490725 Mon Sep 17 00:00:00 2001 From: EETagent Date: Fri, 30 Dec 2022 23:15:26 +0100 Subject: [PATCH 3/5] feat: initial dashboard user delete --- .../admin/(authenticated)/dashboard/+page.svelte | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte b/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte index 6f07102..21c5c21 100644 --- a/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte +++ b/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte @@ -1,11 +1,12 @@ {#if createCandidateModal} @@ -118,6 +124,7 @@ Příjmení Obor + @@ -140,6 +147,9 @@ {candidate.study} + + await deleteCandidate(candidate.applicationId)} value="Odstranit" /> + {/each} From 5c78b1136be5ec033d4181b766a3e4732c2ba896 Mon Sep 17 00:00:00 2001 From: EETagent Date: Fri, 30 Dec 2022 23:19:58 +0100 Subject: [PATCH 4/5] fix: refetch --- .../admin/(authenticated)/dashboard/+page.svelte | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte b/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte index 21c5c21..f2e18b4 100644 --- a/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte +++ b/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte @@ -14,7 +14,10 @@ const getCandidates = async (field?: string) => { try { - candidates = await apiListCandidates(undefined, field); + candidates = await apiListCandidates( + undefined, + field ?? activeFilter !== 'Vše' ? activeFilter : '' + ); } catch { console.log('error'); } @@ -24,7 +27,7 @@ let filters: Array = ['Vše', 'KBB', 'IT', 'GYM']; - let activeFilter: Filter = 'Vše'; + let activeFilter: Filter = filters[0]; const changeFilter = (filter: Filter) => { activeFilter = filter; @@ -69,7 +72,7 @@ const deleteCandidate = async (id: number | undefined) => { if (id) await apiDeleteCandidate(id); getCandidates(); - } + }; {#if createCandidateModal} @@ -148,7 +151,10 @@ {candidate.study} - await deleteCandidate(candidate.applicationId)} value="Odstranit" /> + await deleteCandidate(candidate.applicationId)} + value="Odstranit" + /> {/each} From b8d79e8cd9d6dcfe052831671ea6fa31fb846b9b Mon Sep 17 00:00:00 2001 From: EETagent Date: Sun, 1 Jan 2023 13:59:44 +0100 Subject: [PATCH 5/5] feat: move table to seperate component --- .../lib/components/admin/table/Table.svelte | 60 +++++++++++++++++++ .../src/lib/components/button/Delete.svelte | 14 +++-- .../(authenticated)/dashboard/+page.svelte | 54 +---------------- 3 files changed, 71 insertions(+), 57 deletions(-) create mode 100644 frontend/src/lib/components/admin/table/Table.svelte diff --git a/frontend/src/lib/components/admin/table/Table.svelte b/frontend/src/lib/components/admin/table/Table.svelte new file mode 100644 index 0000000..97755b7 --- /dev/null +++ b/frontend/src/lib/components/admin/table/Table.svelte @@ -0,0 +1,60 @@ + + +
+
+
+
+ + + + + + + + + + + {#each candidates as candidate} + + + + + + + + {/each} + +
Ev. č. přihlásky Jméno Příjmení Obor +
{candidate.applicationId} + {candidate.name} + + {candidate.surname} + + {candidate.study} + + +
+
+
+
+
+ + diff --git a/frontend/src/lib/components/button/Delete.svelte b/frontend/src/lib/components/button/Delete.svelte index 1e49128..ae1f330 100644 --- a/frontend/src/lib/components/button/Delete.svelte +++ b/frontend/src/lib/components/button/Delete.svelte @@ -5,14 +5,19 @@ export let value: string; - let isPrepared = false; + export let id: number | undefined; + let isPrepared = false; const buttonLogic = () => { if (isPrepared) { - dispatch('delete'); + dispatch('delete', { + id: id + }); } else { - dispatch('prepared'); + dispatch('prepared', { + id: id + }); isPrepared = true; setTimeout(() => { isPrepared = false; @@ -44,9 +49,8 @@ button { @apply inline-flex items-center; @apply bg-red-700; - @apply @apply rounded-lg p-3 text-xl font-semibold + @apply @apply rounded-lg p-3 font-semibold text-white transition-colors duration-300; - @apply w-full; animation: none !important; } diff --git a/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte b/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte index f2e18b4..c50249c 100644 --- a/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte +++ b/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte @@ -7,6 +7,7 @@ import Fuse from 'fuse.js'; import type { PageServerData } from './$types'; import Delete from '$lib/components/button/Delete.svelte'; + import Table from '$lib/components/admin/table/Table.svelte'; export let data: PageServerData; @@ -112,58 +113,7 @@ {/if} -
-
-
-
- - - - - - - - - - - {#each candidatesTable as candidate} - - - - - - - - {/each} - -
- Ev. č. přihlásky - Jméno - Příjmení - Obor -
{candidate.applicationId} - {candidate.name} - - {candidate.surname} - - {candidate.study} - - await deleteCandidate(candidate.applicationId)} - value="Odstranit" - /> -
-
-
-
-
+ deleteCandidate(event.detail.id)} />