import React, { useState } from 'react' import AppLoadingView from '../../common/app-loading' import AppPage from '../../common/app-page' import AppText from '../../common/app-text' import Button from '../../common/button' import Segment from '../../common/segment' import { openImportDialog, getFileContent, importData } from './import-dialog' import openShareDialogAndExport from './export-dialog' import DeleteData from './delete-data' import labels from '../../../i18n/en/settings' import { ACTION_DELETE, ACTION_EXPORT, ACTION_IMPORT } from '../../../config' const DataManagement = () => { const [isLoading, setIsLoading] = useState(false) const [currentAction, setCurrentAction] = useState(null) const startImportFlow = async (shouldDeleteExistingData) => { setIsLoading(true) const fileContent = await getFileContent() if (fileContent) { await importData(shouldDeleteExistingData, fileContent) } setIsLoading(false) } const startExport = () => { setCurrentAction(ACTION_EXPORT) openShareDialogAndExport() } const startImport = () => { setCurrentAction(ACTION_IMPORT) openImportDialog(startImportFlow) } if (isLoading) return const isDeletingData = currentAction === ACTION_DELETE return ( {labels.export.segmentExplainer} {labels.import.segmentExplainer} {labels.deleteSegment.explainer} setCurrentAction(ACTION_DELETE)} /> ) } export default DataManagement