Skip to content

Commit

Permalink
refactor(sanity): Add toast when discarding version and for deleting …
Browse files Browse the repository at this point in the history
…releases (#7419)

* refactor(sanity): add toast when deleting a release

* refactor(sanity): update translation for toast delete

* refactor(sanity): update translation and add toast for version discarding

* refactor(sanity): move toast from finally

* test(sanity): fix test (relative imports)
  • Loading branch information
RitaDias committed Aug 26, 2024
1 parent fe4563a commit c4614de
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
} from '@sanity/icons'
import {Menu, Spinner, Text, useToast} from '@sanity/ui'
import {useState} from 'react'
import {useTranslation} from 'sanity'
import {useRouter} from 'sanity/router'

import {Button, Dialog, MenuButton, MenuItem} from '../../../../ui-components'
import {BundleDetailsDialog} from '../../../bundles/components/dialog/BundleDetailsDialog'
import {Translate, useTranslation} from '../../../i18n'
import {type BundleDocument} from '../../../store/bundles/types'
import {useBundleOperations} from '../../../store/bundles/useBundleOperations'
import {releasesLocaleNamespace} from '../../i18n'
Expand Down Expand Up @@ -41,6 +41,13 @@ export const BundleMenuButton = ({disabled, bundle, documentCount}: BundleMenuBu
try {
setDiscardStatus('discarding')
await deleteBundle(bundle)
toast.push({
closable: true,
status: 'success',
description: (
<Translate t={t} i18nKey={'action.delete.success'} values={{title: bundle.title}} />
),
})
setDiscardStatus('idle')
if (router.state.bundleSlug) {
// navigate back to bundle overview
Expand All @@ -51,7 +58,7 @@ export const BundleMenuButton = ({disabled, bundle, documentCount}: BundleMenuBu
toast.push({
closable: true,
status: 'error',
title: 'Failed to delete bundle',
title: t('action.delete.failure'),
description: e.message,
})
} finally {
Expand Down
8 changes: 8 additions & 0 deletions packages/sanity/src/core/releases/i18n/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ const releasesLocaleStrings = {
'action.archived': 'Archived',
/** Action text for deleting a release */
'action.delete': 'Delete',
/** Description for toast when release deletion failed */
'action.delete.failure': 'Failed to delete release',
/** Description for toast when release is successfully deleted */
'action.delete.success': '<strong>{{title}}</strong> release was successfully deleted',
/** Action text for discarding a document version */
'action.discard-version': 'Discard version',
/** Description for toast when version discarding failed */
'action.discard-version.failure': 'Failed to discard version',
/** Description for toast when version deletion is successfully discarded */
'action.discard-version.success': '<strong>{{title}}</strong> version was successfully discarded',
/** Action text for editing a release */
'action.edit': 'Edit',
/** Action text for opening a release */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,31 @@ export const DocumentActions = memo(
try {
setDiscardStatus('discarding')
await client.delete(document.document._id)

toast.push({
closable: true,
status: 'success',
description: (
<Translate
t={t}
i18nKey={'action.discard-version.success'}
values={{title: document.document.title as string}}
/>
),
})
setDiscardStatus('idle')
} catch (e) {
setDiscardStatus('error')
toast.push({
closable: true,
status: 'error',
title: 'Failed to discard version',
title: t('action.discard-version.failure'),
})
} finally {
setShowDiscardDialog(false)
}
}

return (
<>
<Card tone="default" display="flex">
Expand Down

0 comments on commit c4614de

Please sign in to comment.