| 1 |
import { Spinner, ToggleControl } from '@wordpress/components' |
| 2 |
import { useState } from '@wordpress/element' |
| 3 |
import { __ } from '@wordpress/i18n' |
| 4 |
import { updateOptions } from '@chat/api/Data' |
| 5 |
|
| 6 |
export const ChatSettings = ({ showChat, setShowChat }) => { |
| 7 |
const [loading, setLoading] = useState(false) |
| 8 |
|
| 9 |
const toggleChat = () => { |
| 10 |
setLoading(true) |
| 11 |
updateOptions({ showChat: !showChat }).then(() => { |
| 12 |
setShowChat(!showChat) |
| 13 |
setLoading(false) |
| 14 |
}) |
| 15 |
} |
| 16 |
|
| 17 |
return ( |
| 18 |
<div className="flex items-center mt-4"> |
| 19 |
<ToggleControl |
| 20 |
label={__('Enable the AI Chatbot', 'extendify')} |
| 21 |
checked={showChat} |
| 22 |
onChange={toggleChat} |
| 23 |
className="m-0 focus:ring-2 focus:ring-design-main focus:border-design-main" |
| 24 |
/> |
| 25 |
{loading && <Spinner className="mt-0 text-design-main" />} |
| 26 |
</div> |
| 27 |
) |
| 28 |
} |
| 29 |
|