Skip to content

Commit

Permalink
feat(core): add banner when the user doesn't have permissions to publ…
Browse files Browse the repository at this point in the history
…ish or schedule
  • Loading branch information
RitaDias committed Feb 11, 2025
1 parent d298eae commit 1a5d1d9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
5 changes: 5 additions & 0 deletions packages/sanity/src/core/releases/i18n/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ const releasesLocaleStrings = {
/** Title for the release tool */
'overview.title': 'Releases',

/** Text for when a user doesn't have publish or schedule releases */
'permission-missing-title': 'Limited access',
/** Description for when a user doesn't have publish or schedule releases */
'permission-missing-description':
'This release is not yet published. Only users with access to this release can view it.',
/** Title for the dialog confirming the publish of a release */
'publish-dialog.confirm-publish.title':
'Are you sure you want to publish the release and all document versions?',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ErrorOutlineIcon, PinFilledIcon, PinIcon} from '@sanity/icons'
import {ErrorOutlineIcon, PinFilledIcon, PinIcon, WarningOutlineIcon} from '@sanity/icons'
import {
Box,
// Custom button with full radius used here
Expand All @@ -10,7 +10,7 @@ import {
Stack,
Text,
} from '@sanity/ui'
import {useCallback} from 'react'
import {useCallback, useEffect, useState} from 'react'

import {ToneIcon} from '../../../../ui-components/toneIcon/ToneIcon'
import {TextWithTone} from '../../../components/textWithTone/TextWithTone'
Expand All @@ -19,6 +19,7 @@ import {useTranslation} from '../../../i18n'
import {usePerspective} from '../../../perspective/usePerspective'
import {useSetPerspective} from '../../../perspective/useSetPerspective'
import {releasesLocaleNamespace} from '../../i18n'
import {useReleaseOperations} from '../../store'
import {type ReleaseDocument} from '../../store/types'
import {getReleaseIdFromReleaseDocumentId} from '../../util/getReleaseIdFromReleaseDocumentId'
import {getReleaseTone} from '../../util/getReleaseTone'
Expand All @@ -28,12 +29,31 @@ import {ReleaseTypePicker} from './ReleaseTypePicker'
export function ReleaseDashboardDetails({release}: {release: ReleaseDocument}) {
const {state} = release
const releaseId = getReleaseIdFromReleaseDocumentId(release._id)
const {canSchedule, canPublish} = useReleaseOperations()

const {t: tRelease} = useTranslation(releasesLocaleNamespace)
const {selectedReleaseId} = usePerspective()
const setPerspective = useSetPerspective()
const isSelected = releaseId === selectedReleaseId
const shouldDisplayError = release.state === 'active' && typeof release.error !== 'undefined'
const isActive = release.state === 'active'
const shouldDisplayError = isActive && typeof release.error !== 'undefined'
const [shouldDisplayPermissionWarning, setShouldDisplayPermissionWarning] = useState(false)

useEffect(() => {
// only run if the release is active
if (isActive) {
canPublish(release._id).then((response) => {
setShouldDisplayPermissionWarning(!response)
})

// if it's a release that can be scheduled, check if it can be scheduled
if (release.metadata.intendedPublishAt && release.metadata.releaseType === 'scheduled') {
canSchedule(release._id, new Date(release.metadata.intendedPublishAt)).then((response) => {
setShouldDisplayPermissionWarning(!response)
})
}
}
})

const handlePinRelease = useCallback(() => {
if (isSelected) {
Expand Down Expand Up @@ -80,8 +100,8 @@ export function ReleaseDashboardDetails({release}: {release: ReleaseDocument}) {
<Text size={1}>
<ErrorOutlineIcon />
</Text>
<Stack space={4}>
<Text>{tRelease('failed-publish-title')}</Text>
<Stack space={3}>
<Text size={1}>{tRelease('failed-publish-title')}</Text>
<Details title={tRelease('error-details-title')}>
<Text>
<code>{release.error?.message}</code>
Expand All @@ -91,6 +111,22 @@ export function ReleaseDashboardDetails({release}: {release: ReleaseDocument}) {
</Flex>
</Card>
)}

{isActive && shouldDisplayPermissionWarning && (
<Card padding={4} radius={4} tone="caution">
<Flex gap={3}>
<Text size={1}>
<WarningOutlineIcon />
</Text>
<Stack space={3}>
<Text size={1}>{tRelease('permission-missing-title')}</Text>
<Text size={1} muted>
{tRelease('permission-missing-description')}
</Text>
</Stack>
</Flex>
</Card>
)}
</Stack>
</Container>
)
Expand Down

0 comments on commit 1a5d1d9

Please sign in to comment.