import React from 'react' import { __ } from '@wordpress/i18n' import { useSnippetsAPI } from '../../../../hooks/useSnippetsAPI' import { Tooltip } from '../../../common/Tooltip' import { useSnippetForm } from '../../SnippetForm/WithSnippetFormContext' export const LockControl: React.FC = () => { const { snippet, setSnippet, isWorking, setIsWorking, setCurrentNotice } = useSnippetForm() const { update } = useSnippetsAPI() const handleToggle = () => { setSnippet(previous => ({ ...previous, locked: !previous.locked })) setIsWorking(true) update({ id: snippet.id, network: snippet.network, locked: !snippet.locked }) .then(result => { setSnippet(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 (