55 data-test =" open-tag-edit"
66 @click =" open"
77 >
8- <div class =" d-flex align-center" >
9- <div class =" mr-2" >
10- <v-icon > mdi-pencil </v-icon >
11- </div >
12-
8+ <div class =" d-flex align-center ga-2" >
9+ <v-icon icon =" mdi-pencil" > mdi-pencil </v-icon >
1310 <v-list-item-title data-test =" mdi-information-list-item" >
1411 Edit
1512 </v-list-item-title >
3027 @cancel =" close"
3128 @confirm =" edit"
3229 >
33- <div class =" px-6 pt-4 " >
30+ <div class =" pa-6 " >
3431 <v-text-field
35- v-model =" inputTags "
32+ v-model =" tagInput "
3633 label =" Tag name"
37- :error-messages =" tagsError"
34+ hide-details =" auto"
35+ :error-messages =" tagError"
3836 required
3937 data-test =" tag-field"
38+ @update:model-value =" validateTagInput"
4039 />
4140 </div >
4241 </FormDialog >
4342</template >
4443
4544<script setup lang="ts">
46- import { ref , computed , watch } from " vue" ;
45+ import { ref , computed } from " vue" ;
4746import FormDialog from " @/components/Dialogs/FormDialog.vue" ;
4847import handleError from " @/utils/handleError" ;
4948import useSnackbar from " @/helpers/snackbar" ;
5049import useTagsStore from " @/store/modules/tags" ;
5150
52- const props = defineProps ( {
53- tagName: { type: String , required: true },
54- hasAuthorization: { type: Boolean , default: false },
55- });
51+ const props = defineProps < {
52+ tagName: string ;
53+ hasAuthorization? : boolean ;
54+ }>( );
5655
5756const emit = defineEmits ([" update" ]);
5857const tagsStore = useTagsStore ();
5958const snackbar = useSnackbar ();
6059
6160const showDialog = ref (false );
62- const inputTags = ref <string >(" " );
63- const tagsError = ref (" " );
64-
65- const tenant = computed (() => localStorage .getItem (" tenant" ));
66-
67- const tagsHasLessThan3Characters = computed (() => inputTags .value .length < 3 );
68-
69- watch (inputTags , () => {
70- if (inputTags .value .length > 255 ) {
71- tagsError .value = " The maximum length is 255 characters" ;
72- } else if (tagsHasLessThan3Characters .value ) {
73- tagsError .value = " The minimum length is 3 characters" ;
74- } else {
75- tagsError .value = " " ;
76- }
77- });
78-
79- const confirmDisabled = computed (() => ! inputTags .value || !! tagsError .value );
61+ const tagInput = ref <string >(" " );
62+ const tagError = ref (" " );
63+ const confirmDisabled = computed (() => ! tagInput .value || !! tagError .value );
64+
65+ const validateTagInput = () => {
66+ const inputLength = tagInput .value .length ;
67+ if (inputLength > 255 ) tagError .value = " The maximum length is 255 characters" ;
68+ else if (inputLength < 3 ) tagError .value = " The minimum length is 3 characters" ;
69+ else tagError .value = " " ;
70+ };
8071
8172const open = () => {
8273 showDialog .value = true ;
83- inputTags .value = props .tagName ;
74+ tagInput .value = props .tagName ;
8475};
8576
8677const close = () => {
8778 showDialog .value = false ;
88- inputTags .value = " " ;
79+ tagInput .value = " " ;
8980};
9081
9182const update = () => {
@@ -94,14 +85,13 @@ const update = () => {
9485};
9586
9687const edit = async () => {
97- if (tagsError .value ) return ;
88+ if (tagError .value ) return ;
9889
9990 try {
100- await tagsStore .editTag ({
101- tenant: tenant .value || " " ,
102- currentName: props .tagName ,
103- newName: { name: inputTags .value },
104- });
91+ await tagsStore .updateTag (
92+ props .tagName ,
93+ { name: tagInput .value },
94+ );
10595
10696 snackbar .showSuccess (" Tag updated successfully." );
10797 update ();
@@ -110,6 +100,4 @@ const edit = async () => {
110100 handleError (error );
111101 }
112102};
113-
114- defineExpose ({ inputTags });
115103 </script >
0 commit comments