Skip to content

Commit

Permalink
Merge pull request #48796 from nextcloud/backport/48696/stable28
Browse files Browse the repository at this point in the history
[stable28] fix(files_sharing): Add proper user facing messages on success
  • Loading branch information
susnux authored Oct 23, 2024
2 parents 7df57c2 + 38eef3d commit 0977b7d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 28 deletions.
65 changes: 43 additions & 22 deletions apps/files_sharing/src/mixins/SharesMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
*
*/

import { getCurrentUser } from '@nextcloud/auth'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import { fetchNode } from '../services/WebdavClient.ts'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { getCurrentUser } from '@nextcloud/auth'
// eslint-disable-next-line import/no-unresolved, n/no-missing-import

import PQueue from 'p-queue'
import debounce from 'debounce'

Expand Down Expand Up @@ -114,10 +114,10 @@ export default {
// Datepicker language
lang() {
const weekdaysShort = window.dayNamesShort
? window.dayNamesShort // provided by nextcloud
? window.dayNamesShort // provided by Nextcloud
: ['Sun.', 'Mon.', 'Tue.', 'Wed.', 'Thu.', 'Fri.', 'Sat.']
const monthsShort = window.monthNamesShort
? window.monthNamesShort // provided by nextcloud
? window.monthNamesShort // provided by Nextcloud
: ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May.', 'Jun.', 'Jul.', 'Aug.', 'Sep.', 'Oct.', 'Nov.', 'Dec.']
const firstDayOfWeek = window.firstDay ? window.firstDay : 0

Expand Down Expand Up @@ -178,7 +178,7 @@ export default {

methods: {
/**
* Fetch webdav node
* Fetch WebDAV node
*
* @return {Node}
*/
Expand All @@ -191,6 +191,7 @@ export default {
logger.error('Error:', error)
}
},

/**
* Check if a share is valid before
* firing the request
Expand All @@ -214,19 +215,7 @@ export default {
},

/**
* @param {string} date a date with YYYY-MM-DD format
* @return {Date} date
*/
parseDateString(date) {
if (!date) {
return
}
const regex = /([0-9]{4}-[0-9]{2}-[0-9]{2})/i
return new Date(date.match(regex)?.pop())
},

/**
* @param {Date} date
* @param {Date} date the date to format
* @return {string} date a date with YYYY-MM-DD format
*/
formatDateToString(date) {
Expand Down Expand Up @@ -338,11 +327,17 @@ export default {

// clear any previous errors
this.$delete(this.errors, propertyNames[0])
showSuccess(t('files_sharing', 'Share {propertyName} saved', { propertyName: propertyNames[0] }))
} catch ({ message }) {
showSuccess(this.updateSuccessMessage(propertyNames))
} catch (error) {
logger.error('Could not update share', { error, share: this.share, propertyNames })

const { message } = error
if (message && message !== '') {
this.onSyncError(propertyNames[0], message)
showError(t('files_sharing', message))
showError(message)
} else {
// We do not have information what happened, but we should still inform the user
showError(t('files_sharing', 'Could not update share'))
}
} finally {
this.saving = false
Expand All @@ -355,6 +350,32 @@ export default {
console.debug('Updated local share', this.share)
},

/**
* @param {string[]} names Properties changed
*/
updateSuccessMessage(names) {
if (names.length !== 1) {
return t('files_sharing', 'Share saved')
}

switch (names[0]) {
case 'expireDate':
return t('files_sharing', 'Share expire date saved')
case 'hideDownload':
return t('files_sharing', 'Share hide-download state saved')
case 'label':
return t('files_sharing', 'Share label saved')
case 'note':
return t('files_sharing', 'Share note for recipient saved')
case 'password':
return t('files_sharing', 'Share password saved')
case 'permissions':
return t('files_sharing', 'Share permissions saved')
default:
return t('files_sharing', 'Share saved')
}
},

/**
* Manage sync errors
*
Expand Down
4 changes: 2 additions & 2 deletions dist/8325-8325.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/8325-8325.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files_sharing-files_sharing_tab.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/files_sharing-files_sharing_tab.js.map

Large diffs are not rendered by default.

0 comments on commit 0977b7d

Please sign in to comment.