import React from 'react' import classnames from 'classnames' import { __ } from '@wordpress/i18n' import { useSnippetsAPI } from '../../../../hooks/useSnippetsAPI' import { TooltipButton } from '../../../common/TooltipButton' import { useSnippetForm } from '../../SnippetForm/WithSnippetFormContext' export const LockControl: React.FC = () => { const { update } = useSnippetsAPI() const { acceptSnippet, snippet, setSnippet, isWorking, setIsWorking, setCurrentNotice } = useSnippetForm() const handleToggle = () => { setIsWorking(true) setSnippet(previous => ({ ...previous, locked: !previous.locked })) update({ id: snippet.id, network: snippet.network, locked: !snippet.locked }) .then(result => { acceptSnippet(result) setCurrentNotice(['updated', result.locked ? __('Snippet locked.', 'code-snippets') : __('Snippet unlocked.', 'code-snippets')]) }) .catch(() => setCurrentNotice(['error', __('Unable to lock snippet.', 'code-snippets')])) .finally(() => setIsWorking(false)) } return (