Skip to content

Commit

Permalink
load all fields
Browse files Browse the repository at this point in the history
  • Loading branch information
axelrindle committed Sep 8, 2024
1 parent 8f51536 commit 436b139
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
1 change: 1 addition & 0 deletions api/src/services/anmeldung/anmeldungVerwaltungGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const anmeldungVerwaltungGetProcedure = defineProcedure({
},
unterveranstaltung: {
select: {
id: true,
veranstaltung: {
select: {
id: true,
Expand Down
9 changes: 3 additions & 6 deletions api/src/services/customFields/customFieldsList.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { CustomField } from '@prisma/client'
import { z } from 'zod'

import prisma from '../../prisma'
Expand All @@ -13,8 +12,6 @@ export const customFieldsList = defineProcedure({
entityId: z.number(),
}),
async handler({ input }) {
let fields: CustomField[] = []

if (input.entity === 'veranstaltung') {
const veranstaltung = await prisma.veranstaltung.findUniqueOrThrow({
where: {
Expand All @@ -25,7 +22,7 @@ export const customFieldsList = defineProcedure({
},
})

fields = veranstaltung.customFields
return veranstaltung.customFields
} else if (input.entity === 'unterveranstaltung') {
const ausschreibung = await prisma.unterveranstaltung.findUniqueOrThrow({
where: {
Expand All @@ -41,9 +38,9 @@ export const customFieldsList = defineProcedure({
},
})

fields = fields.concat(...ausschreibung.veranstaltung.customFields, ...ausschreibung.customFields)
return [...ausschreibung.veranstaltung.customFields, ...ausschreibung.customFields]
}

return fields
return []
},
})
32 changes: 26 additions & 6 deletions frontend/src/components/AnmeldungenTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ const { state: countAnmeldungen } = useAsyncState(async () => {
const selectedAnmeldungId = ref()
const showDrawer = ref(false)
function toggleDrawer($event) {
selectedAnmeldungId.value = $event.id
showDrawer.value = true
getSingleAnmeldung()
}
const {
state: currentAnmeldung,
execute: getSingleAnmeldung,
Expand All @@ -128,6 +122,31 @@ const {
{ immediate: false }
)
const { state: customFields, execute: loadCustomFields } = useAsyncState(
async () => {
if (!currentAnmeldung.value) {
return []
}
return await apiClient.customFields.list.query({
entity: 'unterveranstaltung',
entityId: currentAnmeldung.value.unterveranstaltung.id,
})
},
[],
{
immediate: false,
}
)
async function toggleDrawer($event) {
selectedAnmeldungId.value = $event.id
showDrawer.value = true
await getSingleAnmeldung()
await loadCustomFields()
}
const { execute: update } = useAsyncState(
async (anmeldung: FormPersonGeneralSubmit) => {
const nahrungsmittelIntoleranzen = Object.entries(anmeldung.essgewohnheiten.intoleranzen)
Expand Down Expand Up @@ -460,6 +479,7 @@ const showNotification = ref(false)
v-if="currentAnmeldung?.customFieldValues && entityId"
class="mt-8"
:entry-id="currentAnmeldung.id"
:custom-fields="customFields"
:custom-field-values="currentAnmeldung?.customFieldValues"
@update:success="showNotification = true"
/>
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/CustomFields/CustomFieldsFormUser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import Button from '@/components/UIComponents/Button.vue'
import type { RouterOutput } from '@codeanker/api'
import { ValidateForm } from '@codeanker/validation'
type Field = Awaited<RouterOutput['customFields']['list']>[number]
type Value = Awaited<RouterOutput['anmeldung']['verwaltungGet']>[number]['customFieldValues'][number]
const props = defineProps<{
// eslint-disable-next-line @typescript-eslint/no-explicit-any
customFields: Array<Field>
customFieldValues: Array<Value>
entryId: number
}>()
Expand Down Expand Up @@ -55,7 +56,7 @@ const { execute: submit, isLoading: isLoading } = useAsyncState(async () => {
<ValidateForm @submit="submit">
<div class="grid grid-flow-row lg:grid-cols-2 gap-5">
<template
v-for="customField in props.customFieldValues.map((f) => f.field)"
v-for="customField in customFields"
:key="customField.id"
>
<div class="flex flex-col gap-y-2">
Expand Down

0 comments on commit 436b139

Please sign in to comment.