import React, { useState } from 'react'; import { View, Block, Modal, Button, Link } from '../common'; import { styles, colors } from '../../style'; function getErrorMessage(error) { switch (error) { case 'not-ynab4': return 'This file is not valid. Please select a .ynab4 file'; default: return 'An unknown error occurred while importing. Sorry! We have been notified of this issue.'; } } // const res = await window.Actual.openFileDialog({ // // Windows treats the ynab4 file as a directroy, while Mac // // treats it like a normal file // properties: ['openDirectory', 'openFile'], // filters: [{ name: 'ynab', extensions: ['ynab4'] }] // }); // if (res) { // this.doImport(res[0]); // } // this.props.actions.importBudget(filepath).catch(err => { // this.setState({ error: err.message, importing: false }); // }); function Import({ modalProps, actions, availableImports }) { const [error, setError] = useState(false); const [importing, setImporting] = useState(false); const [type, setType] = useState(null); function onSelectType(type) { switch (type) { case 'ynab4': actions.pushModal('import-ynab4'); break; case 'ynab5': actions.pushModal('import-ynab5'); break; case 'actual': actions.pushModal('import-actual'); break; default: } } let itemStyle = { padding: 10, border: '1px solid ' + colors.border, borderRadius: 6, marginBottom: 10, display: 'block' }; return ( {() => ( {error && ( {getErrorMessage(error)} )} Import from: )} ); } export default Import;