From 904bb3d9987d1875284d8c1534bf8c6e2298f1fe Mon Sep 17 00:00:00 2001
From: Konrad Mohrfeldt <km@roko.li>
Date: Fri, 31 Jan 2025 02:07:01 +0100
Subject: [PATCH] feat: add error mapping support to attribution editor

---
 src/components/license/AAttributionEditor.vue | 27 ++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/src/components/license/AAttributionEditor.vue b/src/components/license/AAttributionEditor.vue
index edcd89a..75198e3 100644
--- a/src/components/license/AAttributionEditor.vue
+++ b/src/components/license/AAttributionEditor.vue
@@ -1,5 +1,9 @@
 <template>
-  <FormGroup v-slot="controlAttributes" :label="t('image.license')">
+  <FormGroup
+    v-slot="controlAttributes"
+    :label="t('image.license')"
+    :errors="errors.forField('licenseId')"
+  >
     <select v-model="licenseId" class="form-control" required v-bind="controlAttributes">
       <option v-for="license in licenseStore.items" :key="license.id" :value="license.id">
         {{ license.name }}
@@ -12,7 +16,11 @@
     </ADescription>
   </FormGroup>
 
-  <FormGroup v-slot="controlAttributes" :label="t('image.credits')" :errors="[needsAuthorError]">
+  <FormGroup
+    v-slot="controlAttributes"
+    :label="t('image.credits')"
+    :errors="[...errors.forField('credits'), needsAuthorError]"
+  >
     <input
       v-model="credits"
       class="form-control"
@@ -23,7 +31,10 @@
 
   <FormGroup
     v-slot="controlAttributes"
-    :errors="[isUseExplicitlyGrantedByAuthorError]"
+    :errors="[
+      ...errors.forField('isUseExplicitlyGrantedByAuthor'),
+      isUseExplicitlyGrantedByAuthorError,
+    ]"
     custom-control
   >
     <label class="tw-flex tw-gap-2 tw-items-center tw-mb-0">
@@ -47,8 +58,18 @@ import { Licensing } from '@/types'
 import { computed } from 'vue'
 import { useCopy } from '@/form'
 import { useI18n } from '@/i18n'
+import { MappedErrorDetail, ErrorDetailArray } from '@rokoli/bnb/drf'
 
 const _attribution = defineModel<Licensing | null>({ required: true })
+withDefaults(
+  defineProps<{
+    errors?: ErrorDetailArray<MappedErrorDetail>
+  }>(),
+  {
+    errors: () => new ErrorDetailArray<MappedErrorDetail>(),
+  },
+)
+
 const defaultAttribution: Licensing = {
   licenseId: null,
   credits: '',
-- 
GitLab