-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Custom Fields in Unterveranstaltung
- Loading branch information
Showing
23 changed files
with
519 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
api/src/services/customFields/customFieldsUnterveranstaltungCreate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Role } from '@prisma/client' | ||
import { z } from 'zod' | ||
|
||
import prisma from '../../prisma' | ||
import { defineProcedure } from '../../types/defineProcedure' | ||
|
||
import { customFieldSchema } from './schema/customField.schema' | ||
|
||
export const customFieldsUnterveranstaltungCreate = defineProcedure({ | ||
key: 'unterveranstaltungCreate', | ||
method: 'mutation', | ||
protection: { type: 'restrictToRoleIds', roleIds: [Role.ADMIN, Role.GLIEDERUNG_ADMIN] }, | ||
inputSchema: z.strictObject({ | ||
unterveranstaltungId: z.number(), | ||
data: customFieldSchema, | ||
}), | ||
handler: ({ input }) => | ||
prisma.customField.create({ | ||
data: { | ||
...input.data, | ||
unterveranstaltungId: input.unterveranstaltungId, | ||
}, | ||
}), | ||
}) |
15 changes: 5 additions & 10 deletions
15
api/src/services/customFields/customFieldsVeranstaltungCreate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 5 additions & 10 deletions
15
api/src/services/customFields/customFieldsVeranstaltungUpdate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
api/src/services/customFields/schema/customField.schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { CustomFieldPosition, CustomFieldType } from '@prisma/client' | ||
import { z } from 'zod' | ||
|
||
export const customFieldSchema = z.strictObject({ | ||
name: z.string().min(1), | ||
description: z.string().nullable(), | ||
type: z.nativeEnum(CustomFieldType), | ||
required: z.boolean(), | ||
options: z.array(z.string()), | ||
positions: z.nativeEnum(CustomFieldPosition).array(), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
frontend/src/components/CustomFields/CustomFieldsFormCreate.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<script setup lang="ts"> | ||
import { useAsyncState } from '@vueuse/core' | ||
import { ref } from 'vue' | ||
import { apiClient } from '@/api' | ||
import CustomFieldsFormGeneral, { type ICustomFieldData } from '@/components/CustomFields/CustomFieldsFormGeneral.vue' | ||
import Button from '@/components/UIComponents/Button.vue' | ||
import router from '@/router' | ||
import { type CustomFieldType, type RouterInput } from '@codeanker/api' | ||
import { ValidateForm } from '@codeanker/validation' | ||
type Query = RouterInput['customFields']['list'] | ||
/* @vue-ignore */ | ||
const props = defineProps<{ | ||
entity: Query['entity'] | ||
entityId: Query['entityId'] | ||
}>() | ||
const form = ref<ICustomFieldData>({ | ||
name: '', | ||
description: '', | ||
required: false, | ||
type: 'BASIC_INPUT' as CustomFieldType, | ||
options: [], | ||
positions: [], | ||
}) | ||
const validationErrors = ref([]) | ||
const { execute, error, isLoading } = useAsyncState( | ||
async () => { | ||
const data = form.value | ||
try { | ||
if (props.entity === 'veranstaltung') { | ||
await apiClient.customFields.veranstaltungCreate.mutate({ | ||
veranstaltungId: props.entityId, | ||
data: { | ||
name: data.name, | ||
description: data.description || null, | ||
required: data.required, | ||
type: data.type, | ||
options: data.options || [], | ||
positions: data.positions || [], | ||
}, | ||
}) | ||
} else if (props.entity === 'unterveranstaltung') { | ||
await apiClient.customFields.unterveranstaltungCreate.mutate({ | ||
unterveranstaltungId: props.entityId, | ||
data: { | ||
name: data.name, | ||
description: data.description || null, | ||
required: data.required, | ||
type: data.type, | ||
options: data.options || [], | ||
positions: data.positions || [], | ||
}, | ||
}) | ||
} | ||
router.back() | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} catch (error: any) { | ||
if (error.shape) { | ||
validationErrors.value = JSON.parse(error.shape?.message) | ||
} | ||
} | ||
}, | ||
null, | ||
{ immediate: false } | ||
) | ||
</script> | ||
|
||
<template> | ||
<h5>Benutzerdefiniertes Feld erstellen</h5> | ||
|
||
<ValidateForm @submit="execute"> | ||
<CustomFieldsFormGeneral v-model="form" /> | ||
|
||
<div class="mt-4 flex gap-4 items-center"> | ||
<Button | ||
type="submit" | ||
color="primary" | ||
> | ||
<span v-if="!isLoading">Speichern</span> | ||
<span v-else>Loading...</span> | ||
</Button> | ||
<Button | ||
type="button" | ||
color="warning" | ||
@click="() => router.back()" | ||
> | ||
Abbrechen | ||
</Button> | ||
</div> | ||
</ValidateForm> | ||
|
||
<div class="mt-8"> | ||
<div v-if="validationErrors.length > 0"> | ||
<pre>{{ validationErrors }}</pre> | ||
</div> | ||
<div | ||
v-else-if="error" | ||
class="bg-danger-400 mb-2 mt-5 rounded p-3 text-white" | ||
> | ||
{{ error }} | ||
</div> | ||
</div> | ||
</template> |
Oops, something went wrong.