import React, { useState } from "react"; import PropTypes from "prop-types"; import copyToClipboard, { copySupported } from "../../lib/copyToClipboard"; import ModalStore from "../../stores/ModalStore"; import ToastStore from "../../stores/ToastStore"; import { putJson } from "../../lib/request"; export default function AttachmentEditor(props) { const { attachment } = props; const [locale, setLocale] = useState(props.locale); const [localizations, setLocalizations] = useState({ name: attachment.name || {}, description: attachment.description || {}, }); const updateLocalization = (name) => (evt) => { setLocalizations({ ...localizations, [name]: { ...localizations[name], [locale]: evt.target.value } }); }; const copyEmbedCode = (evt) => { evt.preventDefault(); copyToClipboard(`[attachment:${attachment.id}]`); ToastStore.dispatch({ type: "NOTICE", message: "Embed code copied to clipboard" }); }; const save = (evt) => { evt.preventDefault(); evt.stopPropagation(); let data = { ...localizations }; putJson(`/admin/attachments/${attachment.id}`, { attachment: data }); if (props.onUpdate) { props.onUpdate(data); } ModalStore.dispatch({ type: "CLOSE" }); }; return (
{props.locales && Object.keys(props.locales).length > 1 && (
)}