2626 data-cy-public-auth-prompt-dialog-name
2727 :label =" t (' files_sharing' , ' Name' )"
2828 :placeholder =" t (' files_sharing' , ' Enter your name' )"
29+ :required =" ! cancellable "
30+ :value .sync =" name "
2931 minlength="2"
30- name="name"
31- required
32- :value .sync =" name " />
32+ name="name" />
3333 </NcDialog >
3434</template >
3535
@@ -42,9 +42,11 @@ import { t } from '@nextcloud/l10n'
4242import NcDialog from ' @nextcloud/vue/components/NcDialog'
4343import NcNoteCard from ' @nextcloud/vue/components/NcNoteCard'
4444import NcTextField from ' @nextcloud/vue/components/NcTextField'
45+ import { showError } from ' @nextcloud/dialogs'
4546
4647const storage = getBuilder (' files_sharing' ).build ()
4748
49+ // TODO: move to @nextcloud/auth
4850export default defineComponent ({
4951 name: ' PublicAuthPrompt' ,
5052
@@ -89,6 +91,24 @@ export default defineComponent({
8991 type: String ,
9092 default: t (' files_sharing' , ' You are currently not identified.' ),
9193 },
94+
95+ /**
96+ * Dialog submit button label
97+ * @default ' Submit name'
98+ */
99+ submitLabel: {
100+ type: String ,
101+ default: t (' files_sharing' , ' Submit name' ),
102+ },
103+
104+ /**
105+ * Whether the dialog is cancellable
106+ * @default false
107+ */
108+ cancellable: {
109+ type: Boolean ,
110+ default: false ,
111+ },
92112 },
93113
94114 setup() {
@@ -105,11 +125,24 @@ export default defineComponent({
105125
106126 computed: {
107127 dialogButtons() {
108- return [{
109- label: t (' files_sharing' , ' Submit name' ),
128+ const cancelButton = {
129+ label: t (' files_sharing' , ' Cancel' ),
130+ type: ' tertiary' ,
131+ callback : () => this .$emit (' close' ),
132+ }
133+
134+ const submitButton = {
135+ label: this .submitLabel ,
110136 type: ' primary' ,
111137 nativeType: ' submit' ,
112- }]
138+ }
139+
140+ // If the dialog is cancellable, add a cancel button
141+ if (this .cancellable ) {
142+ return [cancelButton , submitButton ]
143+ }
144+
145+ return [submitButton ]
113146 },
114147 },
115148
@@ -127,8 +160,24 @@ export default defineComponent({
127160 onSubmit() {
128161 const nickname = this .name .trim ()
129162
130- // Set the nickname
131- setGuestNickname (nickname )
163+ if (nickname === ' ' ) {
164+ // Show error if the nickname is empty
165+ showError (t (' files_sharing' , ' You cannot leave the name empty.' ))
166+ return
167+ }
168+
169+ if (nickname .length < 2 ) {
170+ // Show error if the nickname is too short
171+ showError (t (' files_sharing' , ' Please enter a name with at least 2 characters.' ))
172+ return
173+ }
174+
175+ try {
176+ // Set the nickname
177+ setGuestNickname (nickname )
178+ } catch (e ) {
179+ showError (t (' files_sharing' , ' Failed to set nickname.' ))
180+ }
132181
133182 // Set the dialog as shown
134183 storage .setItem (' public-auth-prompt-shown' , ' true' )
0 commit comments