import Card, { CardContent, CardFooter, CardHeader } from "@/components/Card"; import FileControl from "@/pages/settings/controls/FileControl"; import { __ } from "@wordpress/i18n"; import { Upload } from "lucide-react"; import { useEffect, useState } from "@wordpress/element"; import { useAppStore } from "@/store/store"; import { spcApi } from "@/lib/api"; import { toast } from "sonner"; import Notice from "@/components/Notice"; import Button from "@/components/Button"; const ImportCard = () => { const [importContent, setImportContent] = useState(''); const [valid, setValid] = useState(true); const [isImporting, setIsImporting] = useState(false); const { lockAsync, asyncLocked } = useAppStore(); const handleFileChange = (content: string | null) => { setImportContent(content || ''); } const handleImport = async () => { lockAsync(true) setIsImporting(true); const response = await spcApi.importConfig(JSON.parse(importContent)); if (!response.success) { setIsImporting(false); toast.error(response.message); return; } toast.success(response.message, { description: __('Please wait, the page will reload soon.', 'wp-cloudflare-page-cache'), }); setTimeout(() => { window.location.href = window.SPCDash.mainPageURL; }, 3000); } useEffect(() => { if (!importContent.trim()) { setValid(true); return; } try { JSON.parse(importContent); setValid(true); } catch { setValid(false); } }, [importContent]) return

{__('Import Settings', 'wp-cloudflare-page-cache')}

{__('Restore configuration from backup', 'wp-cloudflare-page-cache')}

{__('Import your settings from a previously exported file to quickly restore your configuration.', 'wp-cloudflare-page-cache')}

{__('Import the options of the previously exported configuration file.')} {' '} {__('After importing, you\'ll need to reconnect to Cloudflare by entering your login details again and turning the cache back on.', 'wp-cloudflare-page-cache')} } > {!valid && ( {__('Invalid JSON format', 'wp-cloudflare-page-cache')} )} {__('Important', 'wp-cloudflare-page-cache')}: {' '} {__('Importing will overwrite your current settings. Consider exporting your current configuration first as a backup.', 'wp-cloudflare-page-cache')}
; }; export default ImportCard;