1
1
<template >
2
- <v-row v-bind =" $attrs" >
3
- <v-col data-test =" namespace-title" >
4
- <h3 >Namespace</h3 >
5
- </v-col >
6
-
7
- <v-spacer />
8
-
9
- <v-col md =" auto" class =" ml-auto" >
10
- <v-tooltip
11
- location =" bottom"
12
- class =" text-center"
13
- :disabled =" hasAuthorizationRenameNamespace()"
14
- >
15
- <template v-slot :activator =" { props } " >
16
- <div v-bind =" props" >
17
- <v-btn
18
- v-if =" editBtn"
19
- :disabled =" !hasAuthorizationRenameNamespace() || (!!nameError || !!connectionAnnouncementError)"
20
- color =" primary"
21
- @click =" editBtn = false;"
22
- data-test =" edit-btn"
23
- >
24
- Edit Namespace
25
- </v-btn >
26
- <v-btn
27
- v-else
28
- :disabled =" !!nameError || !!connectionAnnouncementError"
29
- color =" primary"
30
- @click =" editNamespace"
31
- data-test =" save-btn"
32
- >
33
- Save Namespace
34
- </v-btn >
35
- </div >
36
- </template >
37
- <span > You don't have this kind of authorization. </span >
38
- </v-tooltip >
39
- </v-col >
40
- </v-row >
41
-
42
- <div class =" mt-4 mb-2" >
43
- <v-text-field
44
- :disabled =" validateInput"
45
- v-model =" name"
46
- class =" ml-3"
47
- label =" Name"
48
- :error-messages =" nameError"
49
- variant =" underlined"
50
- required
51
- data-test =" name-text"
52
- />
53
- </div >
54
-
55
- <div class =" mb-2" >
56
- <v-textarea
57
- :disabled =" validateInput"
58
- v-model =" connectionAnnouncement"
59
- label =" Connection Announcement"
60
- :error-messages =" connectionAnnouncementError"
61
- data-test =" connectionAnnouncement-text"
62
- variant =" underlined"
63
- hint =" A connection announcement is a custom message written
2
+ <v-dialog v-model =" show" max-width =" 700" @click:outside =" close" >
3
+ <v-card data-test =" password-change-card" class =" bg-v-theme-surface" >
4
+ <v-card-title class =" text-h5 pa-4 bg-primary" data-test =" title" >
5
+ Change Connection Announcement
6
+ </v-card-title >
7
+
8
+ <v-card-text class =" mt-4 mb-3 pb-1" >
9
+ <div class =" mt-4 pl-4 pr-4" >
10
+ <v-textarea
11
+ v-model =" connectionAnnouncement"
12
+ label =" Connection Announcement"
13
+ :error-messages =" connectionAnnouncementError"
14
+ data-test =" connectionAnnouncement-text"
15
+ variant =" underlined"
16
+ hint =" A connection announcement is a custom message written
64
17
during a session when a connection is established on a device
65
18
within the namespace."
66
- persistent-hint
67
- required
68
- />
69
- </div >
19
+ persistent-hint
20
+ required
21
+ auto-grow
22
+ max-rows =" 25"
23
+ />
24
+ </div >
25
+ </v-card-text >
26
+
27
+ <v-card-actions >
28
+ <v-spacer />
29
+
30
+ <v-btn variant =" text" data-test =" close-btn" @click =" close" >
31
+ Cancel
32
+ </v-btn >
70
33
34
+ <v-btn
35
+ color =" primary"
36
+ variant =" text"
37
+ data-test =" change-connection-btn"
38
+ :disabled =" connectionAnnouncementError"
39
+ @click =" updateAnnouncement()"
40
+ >
41
+ Save Announcement
42
+ </v-btn >
43
+ </v-card-actions >
44
+ </v-card >
45
+ </v-dialog >
71
46
</template >
72
47
73
48
<script setup lang="ts">
74
- import { computed , onMounted , ref , watch } from " vue" ;
49
+ import { computed , onMounted , watch } from " vue" ;
75
50
import { useField } from " vee-validate" ;
76
- import axios , { AxiosError } from " axios" ;
51
+ import axios from " axios" ;
77
52
import * as yup from " yup" ;
78
53
import { useStore } from " ../../store" ;
79
- import hasPermission from " ../../utils/permission" ;
80
- import { actions , authorizer } from " ../../authorizer" ;
81
54
import {
82
55
INotificationsError ,
83
56
INotificationsSuccess ,
@@ -87,24 +60,8 @@ import handleError from "@/utils/handleError";
87
60
const store = useStore ();
88
61
const namespace = computed (() => store .getters [" namespaces/get" ]);
89
62
const tenant = computed (() => store .getters [" auth/tenant" ]);
90
- const editBtn = ref (true );
91
- const validateInput = computed (() => editBtn .value === true );
92
- const {
93
- value : name,
94
- errorMessage : nameError,
95
- setErrors : setNameError,
96
- } = useField <string >(
97
- " name" ,
98
- yup
99
- .string ()
100
- .min (3 , " Your namespace should be 3-30 characters long" )
101
- .max (30 , " Your namespace should be 3-30 characters long" )
102
- .required ()
103
- .matches (/ ^ [^ . ] * $ / , " The name must not contain dots" ),
104
- {
105
- initialValue: " " ,
106
- },
107
- );
63
+ const show = defineModel ({ default: false });
64
+ const emit = defineEmits ([" update" ]);
108
65
109
66
const {
110
67
value : connectionAnnouncement,
@@ -120,8 +77,12 @@ const {
120
77
},
121
78
);
122
79
80
+ const close = () => {
81
+ connectionAnnouncement .value = namespace .value .settings .connection_announcement ;
82
+ show .value = false ;
83
+ };
84
+
123
85
watch (namespace , (ns ) => {
124
- name .value = ns .name ;
125
86
connectionAnnouncement .value = ns .settings .connection_announcement ;
126
87
});
127
88
@@ -130,59 +91,53 @@ onMounted(() => {
130
91
store .dispatch (" namespaces/get" , tenant .value );
131
92
});
132
93
133
- const hasAuthorizationRenameNamespace = () => {
134
- const role = store .getters [" auth/role" ];
135
- if (role !== " " ) {
136
- return hasPermission (authorizer .role [role ], actions .namespace .rename );
137
- }
138
-
139
- return false ;
140
- };
141
-
142
- const editNamespace = async () => {
143
- if (! nameError .value ) {
144
- try {
145
- await store .dispatch (" namespaces/put" , {
146
- id: tenant .value ,
147
- name: name .value ,
148
- settings: {
149
- connection_announcement: connectionAnnouncement .value ,
150
- },
151
- });
152
- await store .dispatch (" namespaces/fetch" , {
153
- page: 1 ,
154
- perPage: 10 ,
155
- filter: " " ,
156
- });
157
- await store .dispatch (" namespaces/get" , tenant .value );
158
- store .dispatch (
159
- " snackbar/showSnackbarSuccessAction" ,
160
- INotificationsSuccess .namespaceEdit ,
161
- );
162
- editBtn .value = true ;
163
- } catch (error : unknown ) {
164
- if (axios .isAxiosError (error )) {
165
- const axiosError = error as AxiosError ;
166
- if (axiosError .response ?.status === 400 ) {
167
- setNameError (" This name is not valid" );
168
- setConnectionAnnouncementError (" This message is not valid" );
169
- } else if (axiosError .response ?.status === 409 ) {
170
- setNameError (" name used already" );
171
- } else {
172
- store .dispatch (
173
- " snackbar/showSnackbarErrorAction" ,
174
- INotificationsError .namespaceEdit ,
175
- );
176
- handleError (error );
177
- }
178
- } else {
94
+ const handleUpdateNameError = (error : unknown ): void => {
95
+ if (axios .isAxiosError (error )) {
96
+ switch (error .response ?.status ) {
97
+ case 400 :
98
+ setConnectionAnnouncementError (" This message is not valid" );
99
+ break ;
100
+ default :
179
101
store .dispatch (
180
102
" snackbar/showSnackbarErrorAction" ,
181
103
INotificationsError .namespaceEdit ,
182
104
);
183
105
handleError (error );
184
- }
185
106
}
186
107
}
108
+
109
+ store .dispatch (
110
+ " snackbar/showSnackbarErrorAction" ,
111
+ INotificationsError .namespaceEdit ,
112
+ );
113
+ handleError (error );
114
+ };
115
+
116
+ const updateAnnouncement = async () => {
117
+ try {
118
+ await store .dispatch (" namespaces/put" , {
119
+ id: tenant .value ,
120
+ settings: {
121
+ connection_announcement: connectionAnnouncement .value ,
122
+ },
123
+ });
124
+
125
+ await store .dispatch (" namespaces/fetch" , {
126
+ page: 1 ,
127
+ perPage: 10 ,
128
+ filter: " " ,
129
+ });
130
+
131
+ emit (" update" );
132
+ store .dispatch (
133
+ " snackbar/showSnackbarSuccessAction" ,
134
+ INotificationsSuccess .namespaceEdit ,
135
+ );
136
+ show .value = false ;
137
+ } catch (error ) {
138
+ handleUpdateNameError (error );
139
+ }
187
140
};
141
+
142
+ defineExpose ({ show });
188
143
</script >
0 commit comments