Repository: payloadcms/payload
File: packages/ui/src/elements/UnpublishButton/index.tsx (TypeScript)

Code before:
      api,
      localeCode,
      id,
      i18n.language,
      incrementVersionCount,
      setHasPublishedDoc,
      setMostRecentVersionIsAutosaved,
      setUnpublishedVersionCount,
      t,
    ],
  )

  useEffect(() => {
    const hasLocalizedField = traverseForLocalizedFields(entityConfig?.fields)
    setHasLocalizedFields(hasLocalizedField)
  }, [entityConfig?.fields])

  const drafts = entityConfig?.versions?.drafts
  const hasDraftsEnabled = typeof drafts === 'object' && drafts !== null

  const canUnpublish = React.useMemo(() => {
    return hasPublishPermission && hasPublishedDoc && !isTrashed && hasDraftsEnabled
  }, [hasPublishPermission, hasPublishedDoc, isTrashed, hasDraftsEnabled])

  const canUnpublishCurrentLocale = React.useMemo(() => {
    if (!canUnpublish || !hasLocalizedFields || !hasDraftsEnabled) {
      return false
    }

    const isLocalizeStatusEnabled = drafts.localizeStatus === true
    const isExperimentalEnabled = config.experimental?.localizeStatus === true

    return isLocalizeStatusEnabled && isExperimentalEnabled
  }, [canUnpublish, hasLocalizedFields, hasDraftsEnabled, drafts, config.experimental?.localizeStatus])

  const label = getTranslation(localeLabel, i18n)

  if (!canUnpublish) {
    return null
  }

  return (
    <React.Fragment>
      <PopupList.Button
        id="action-unpublish"
        onClick={() => {
          setUnpublishAll(true)
          toggleModal(unPublishModalSlug)
        }}
      >
        {labelProp || t('version:unpublish')}

Review comment (suggestion):
The `!hasDraftsEnabled` here is duplicative since it is already checked in `canPublish`. But if you need this here for L137, its fine I would just move it to the front like the comment above.

Code after:
      api,
      localeCode,
      id,
      i18n.language,
      incrementVersionCount,
      setHasPublishedDoc,
      setMostRecentVersionIsAutosaved,
      setUnpublishedVersionCount,
      t,
    ],
  )

  useEffect(() => {
    const hasLocalizedField = traverseForLocalizedFields(entityConfig?.fields)
    setHasLocalizedFields(hasLocalizedField)
  }, [entityConfig?.fields])

  const drafts = entityConfig?.versions?.drafts
  const hasDraftsEnabled = typeof drafts === 'object' && drafts !== null

  const canUnpublish = React.useMemo(() => {
    return hasDraftsEnabled && hasPublishPermission && hasPublishedDoc && !isTrashed
  }, [hasPublishPermission, hasPublishedDoc, isTrashed, hasDraftsEnabled])

  const canUnpublishCurrentLocale = React.useMemo(() => {
    if (!canUnpublish || !hasLocalizedFields) {
      return false
    }

    const isLocalizeStatusEnabled = drafts && drafts.localizeStatus === true
    const isExperimentalEnabled = config.experimental?.localizeStatus === true

    return isLocalizeStatusEnabled && isExperimentalEnabled
  }, [canUnpublish, hasLocalizedFields, drafts, config.experimental?.localizeStatus])

  const label = getTranslation(localeLabel, i18n)

  if (!canUnpublish) {
    return null
  }

  return (
    <React.Fragment>
      <PopupList.Button
        id="action-unpublish"
        onClick={() => {
          setUnpublishAll(true)
          toggleModal(unPublishModalSlug)
        }}
      >
        {labelProp || t('version:unpublish')}