feat(frontend): Add DeleteModal
This commit is contained in:
25
legalconsenthub/components/DeleteModal.vue
Normal file
25
legalconsenthub/components/DeleteModal.vue
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<template>
|
||||||
|
<UModal :open="isOpen" title="Mitbestimmungsantrag löschen" @update:open="$emit('update:isOpen', $event)">
|
||||||
|
<template #body>
|
||||||
|
Möchten Sie wirklich den Mitbestimmungsantrag <strong>{{ applicationFormToDelete.name }}</strong> löschen?
|
||||||
|
</template>
|
||||||
|
<template #footer>
|
||||||
|
<UButton label="Abbrechen" color="neutral" variant="outline" @click="$emit('update:isOpen', false)" />
|
||||||
|
<UButton label="Löschen" color="neutral" @click="$emit('delete', applicationFormToDelete.id)" />
|
||||||
|
</template>
|
||||||
|
</UModal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import type { ApplicationFormDto } from '~/.api-client'
|
||||||
|
|
||||||
|
defineEmits<{
|
||||||
|
(e: 'delete', id: string): void
|
||||||
|
(e: 'update:isOpen', value: boolean): void
|
||||||
|
}>()
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
applicationFormToDelete: ApplicationFormDto
|
||||||
|
isOpen: boolean
|
||||||
|
}>()
|
||||||
|
</script>
|
||||||
@@ -4,12 +4,12 @@
|
|||||||
<form @submit.prevent="handleLogin">
|
<form @submit.prevent="handleLogin">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="email-login">Email:</label>
|
<label for="email-login">Email:</label>
|
||||||
<input type="email" id="email-login" v-model="email" required />
|
<input id="email-login" v-model="email" type="email" required />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="password-login">Passwort:</label>
|
<label for="password-login">Passwort:</label>
|
||||||
<input type="password" id="password-login" v-model="password" required />
|
<input id="password-login" v-model="password" type="password" required />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit">Login</button>
|
<button type="submit">Login</button>
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
|
||||||
const email = ref('')
|
const email = ref('')
|
||||||
|
|||||||
@@ -4,22 +4,22 @@
|
|||||||
<form @submit.prevent="handleRegister">
|
<form @submit.prevent="handleRegister">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="username">Benutzername:</label>
|
<label for="username">Benutzername:</label>
|
||||||
<input type="text" id="username" v-model="username" required />
|
<input id="username" v-model="username" type="text" required />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="email">Email:</label>
|
<label for="email">Email:</label>
|
||||||
<input type="email" id="email" v-model="email" required />
|
<input id="email" v-model="email" type="email" required />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="password">Passwort:</label>
|
<label for="password">Passwort:</label>
|
||||||
<input type="password" id="password" v-model="password" required />
|
<input id="password" v-model="password" type="password" required />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="confirmPassword">Passwort bestätigen:</label>
|
<label for="confirmPassword">Passwort bestätigen:</label>
|
||||||
<input type="password" id="confirmPassword" v-model="confirmPassword" required />
|
<input id="confirmPassword" v-model="confirmPassword" type="password" required />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit">Registrieren</button>
|
<button type="submit">Registrieren</button>
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
|
||||||
const username = ref('')
|
const username = ref('')
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #body>
|
<template #body>
|
||||||
<div class="flex flex-col gap-4 sm:gap-6 lg:gap-12 w-full lg:max-w-2xl mx-auto">
|
<div class="flex flex-col gap-4 sm:gap-6 lg:gap-12 w-full lg:max-w-4xl mx-auto">
|
||||||
<UPageCard variant="subtle">
|
<UPageCard variant="subtle">
|
||||||
<UForm class="space-y-4" :state="{}" @submit="onSubmit">
|
<UForm class="space-y-4" :state="{}" @submit="onSubmit">
|
||||||
<FormEngine v-if="applicationForm" v-model="applicationForm.formElements" />
|
<FormEngine v-if="applicationForm" v-model="applicationForm.formElements" />
|
||||||
@@ -62,6 +62,7 @@ const applicationForm = computed({
|
|||||||
async function onSubmit() {
|
async function onSubmit() {
|
||||||
if (data?.value) {
|
if (data?.value) {
|
||||||
await updateApplicationForm(data.value.id, data.value)
|
await updateApplicationForm(data.value.id, data.value)
|
||||||
|
await navigateTo('/')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #body>
|
<template #body>
|
||||||
<div class="flex flex-col gap-4 sm:gap-6 lg:gap-12 w-full lg:max-w-2xl mx-auto">
|
<div class="flex flex-col gap-4 sm:gap-6 lg:gap-12 w-full lg:max-w-4xl mx-auto">
|
||||||
<UPageCard title="Ampelstatus" variant="naked" orientation="horizontal" class="mb-4">
|
<UPageCard title="Ampelstatus" variant="naked" orientation="horizontal" class="mb-4">
|
||||||
{{ ampelStatusEmoji }}
|
{{ ampelStatusEmoji }}
|
||||||
</UPageCard>
|
</UPageCard>
|
||||||
|
|||||||
@@ -19,33 +19,57 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #body>
|
<template #body>
|
||||||
<UPageList>
|
<div class="flex flex-col gap-4 sm:gap-6 lg:gap-12 w-full lg:max-w-4xl mx-auto">
|
||||||
<UPageCard
|
<div
|
||||||
v-for="(applicationFormElem, index) in applicationForms"
|
v-for="(applicationFormElem, index) in applicationForms"
|
||||||
:key="index"
|
:key="applicationFormElem.id"
|
||||||
variant="ghost"
|
class="flex justify-between items-center p-4 bg-white rounded-lg shadow-md"
|
||||||
:to="`application-forms/${applicationFormElem.id}`"
|
@click="navigateTo(`application-forms/${applicationFormElem.id}`)"
|
||||||
>
|
>
|
||||||
<template #body>
|
<div>
|
||||||
<div>
|
<p class="font-medium text-(--ui-text-highlighted) text-base">
|
||||||
<p class="font-medium text-(--ui-text-highlighted) text-base">
|
#{{ index }} {{ applicationFormElem.name }}
|
||||||
#{{ index }} {{ applicationFormElem.name }}
|
</p>
|
||||||
</p>
|
<p class="text-(--ui-text-muted) text-sm">
|
||||||
<p class="text-(--ui-text-muted) text-sm">
|
Zuletzt bearbeitet: {{ formatDate(applicationFormElem.modifiedAt) }}
|
||||||
Zuletzt bearbeitet: {{ formatDate(applicationFormElem.modifiedAt) }}
|
</p>
|
||||||
</p>
|
<p class="text-(--ui-text-muted) text-sm">Erstellt: {{ formatDate(applicationFormElem.createdAt) }}</p>
|
||||||
<p class="text-(--ui-text-muted) text-sm">Erstellt: {{ formatDate(applicationFormElem.createdAt) }}</p>
|
</div>
|
||||||
</div>
|
<div>
|
||||||
</template>
|
<UPageLinks :links="getLinksForApplicationForm(applicationFormElem)" />
|
||||||
</UPageCard>
|
</div>
|
||||||
</UPageList>
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
<DeleteModal
|
||||||
|
v-if="isDeleteModalOpen && applicationFormNameToDelete"
|
||||||
|
v-model:is-open="isDeleteModalOpen"
|
||||||
|
:application-form-to-delete="applicationFormNameToDelete"
|
||||||
|
@delete="deleteApplicationForm($event)"
|
||||||
|
/>
|
||||||
</UDashboardPanel>
|
</UDashboardPanel>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { PagedApplicationFormDto } from '~/.api-client'
|
import type { ApplicationFormDto, PagedApplicationFormDto } from '~/.api-client'
|
||||||
const { getAllApplicationForms } = useApplicationForm()
|
const { getAllApplicationForms, deleteApplicationFormById } = useApplicationForm()
|
||||||
|
const route = useRoute()
|
||||||
|
|
||||||
|
const { data } = await useAsyncData<PagedApplicationFormDto>(async () => {
|
||||||
|
return await getAllApplicationForms()
|
||||||
|
})
|
||||||
|
|
||||||
|
const isDeleteModalOpen = computed<boolean>({
|
||||||
|
get: () => 'delete' in route.query,
|
||||||
|
set: (isOpen: boolean) => {
|
||||||
|
if (isOpen) return
|
||||||
|
navigateTo({ path: route.path, query: {} })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const applicationFormNameToDelete = computed(() => {
|
||||||
|
return data?.value?.content.find((appForm) => appForm.id === route.query.id)
|
||||||
|
})
|
||||||
|
|
||||||
const items = [
|
const items = [
|
||||||
[
|
[
|
||||||
@@ -57,10 +81,6 @@ const items = [
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
const { data } = await useAsyncData<PagedApplicationFormDto>(async () => {
|
|
||||||
return await getAllApplicationForms()
|
|
||||||
})
|
|
||||||
|
|
||||||
const applicationForms = computed({
|
const applicationForms = computed({
|
||||||
get: () => data?.value?.content ?? [],
|
get: () => data?.value?.content ?? [],
|
||||||
set: (val) => {
|
set: (val) => {
|
||||||
@@ -69,4 +89,28 @@ const applicationForms = computed({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function getLinksForApplicationForm(applicationForm: ApplicationFormDto) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
label: 'Bearbeiten',
|
||||||
|
icon: 'i-lucide-file-pen',
|
||||||
|
to: `/application-forms/${applicationForm.id}`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Löschen',
|
||||||
|
icon: 'i-lucide-trash',
|
||||||
|
to: `?delete&id=${applicationForm.id}`
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteApplicationForm(applicationFormId: string) {
|
||||||
|
await deleteApplicationFormById(applicationFormId)
|
||||||
|
data.value?.content.splice(
|
||||||
|
data.value?.content.findIndex((appForm) => appForm.id === applicationFormId),
|
||||||
|
1
|
||||||
|
)
|
||||||
|
isDeleteModalOpen.value = false
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
10
legalconsenthub/utils/date.ts
Normal file
10
legalconsenthub/utils/date.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
export function formatDate(date: Date): string {
|
||||||
|
return date.toLocaleString('de-DE', {
|
||||||
|
weekday: 'short',
|
||||||
|
day: '2-digit',
|
||||||
|
month: '2-digit',
|
||||||
|
year: '2-digit',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit'
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user