diff --git a/client/src/Pages/Settings/index.tsx b/client/src/Pages/Settings/index.tsx index b9d3e1f3c..55e08234d 100644 --- a/client/src/Pages/Settings/index.tsx +++ b/client/src/Pages/Settings/index.tsx @@ -202,6 +202,37 @@ export const SettingsPage = () => { URL.revokeObjectURL(url); }; + const handleFileSelect = async (event: React.ChangeEvent) => { + const file = event.target.files?.[0]; + if (!file) { + return; + } + + if (file.type !== "application/json") { + alert("Please select a valid JSON file"); + event.target.value = ""; // Reset input + return; + } + + // Log the file contents + try { + const text = await file.text(); + const monitors = JSON.parse(text); + + if (!Array.isArray(monitors)) { + alert("Invalid file format: expected an array of monitors"); + event.target.value = ""; + return; + } + console.log(monitors); + event.target.value = ""; // Reset input + } catch (error) { + console.error("Import error:", error); + alert("Error importing monitors. Please check the file format."); + event.target.value = ""; + } + }; + const onSubmit = async (data: SettingsFormData) => { // Don't send pagespeedApiKey if it's already set and user hasn't clicked reset const dataToSend = { ...data }; @@ -866,17 +897,33 @@ export const SettingsPage = () => { {/* Export Monitors - Admin Only */} {isAdmin && ( + + + - + } /> )} diff --git a/client/src/locales/en.json b/client/src/locales/en.json index e47ab64cc..8c20121f1 100644 --- a/client/src/locales/en.json +++ b/client/src/locales/en.json @@ -44,7 +44,9 @@ "addDemo": "Add demo monitors", "removeMonitors": "Remove monitors", "sendTestEmail": "Send test email", - "exportToJSON": "Export to JSON" + "exportToJSON": "Export to JSON", + "importFromJSON": "Import from JSON", + "selectFile": "Select file" }, "charts": { "labels": { @@ -1086,8 +1088,11 @@ } }, "exportMonitors": { - "title": "Export monitors", - "description": "Export your monitors data as a JSON file for backup or transfer." + "title": "Export monitors" + }, + "importExportMonitors": { + "title": "Import / Export monitors", + "description": "Import or export your monitors data as a JSON file for backup or transfer." }, "about": { "title": "About",