UNPKG

@sanity/scheduled-publishing

Version:

> [!IMPORTANT] > As of [v3.39.0](https://www.sanity.io/changelog/e6013ee5-8214-4e03-9593-f7b19124b8a3) of Sanity Studio, this plugin has been deprecated and the Scheduled Publishing functionality has been moved into the core studio package. > Read more an

44 lines (37 loc) 1.19 kB
import {useMemo} from 'react' import {isValidationErrorMarker, isValidationWarningMarker} from 'sanity' import {ButtonTone} from '@sanity/ui' import {ValidationMarker} from 'sanity' import {ValidationStatus} from '../types' export const EMPTY_VALIDATION_STATUS: ValidationStatus = { validation: [], isValidating: false, } interface ValidationState { markers: ValidationMarker[] validationTone: ButtonTone hasError: boolean hasWarning: boolean } export function getValidationState( validationMarkers: ValidationMarker[] = EMPTY_VALIDATION_STATUS.validation ): ValidationState { const hasError = validationMarkers.filter(isValidationErrorMarker).length > 0 const hasWarning = validationMarkers.filter(isValidationWarningMarker).length > 0 let validationTone: ButtonTone = 'default' if (hasWarning) { validationTone = 'default' //not using 'caution' for now } if (hasError) { validationTone = 'critical' } return { markers: validationMarkers, validationTone, hasError, hasWarning, } } export function useValidationState(markers: ValidationMarker[]): ValidationState { return useMemo(() => getValidationState(markers), [markers]) }