Skip to content
This repository was archived by the owner on Jul 2, 2023. It is now read-only.

Commit 5b95cf3

Browse files
Merge pull request #13 from AndresMorelos/fix-import-export
Fixing import function when no file is added.
2 parents 262c13f + 255289a commit 5b95cf3

File tree

4 files changed

+37
-95
lines changed

4 files changed

+37
-95
lines changed

app/components/settings/ImportExport.jsx

Lines changed: 0 additions & 72 deletions
This file was deleted.

app/containers/Settings.jsx

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,14 @@ import {
3232
getSavedSettings,
3333
} from '../reducers/SettingsReducer';
3434

35-
import {
36-
getSecretKey
37-
} from '../reducers/exportImportReducer'
35+
import { getSecretKey } from '../reducers/exportImportReducer';
3836

3937
// Actions
4038
import * as SettingsActions from '../actions/settings';
4139
import * as ExportImportActions from '../actions/exportImport';
4240

4341
import { bindActionCreators } from 'redux';
4442

45-
4643
// Component
4744
class Settings extends Component {
4845
constructor(props) {
@@ -55,12 +52,14 @@ class Settings extends Component {
5552

5653
componentDidMount() {
5754
ipc.on('import-file-selected', (event, filePath) => {
58-
this.handleFileUpload(filePath);
59-
})
55+
if (filePath) {
56+
this.handleFileUpload(filePath);
57+
}
58+
});
6059
}
6160

6261
componentWillUnmount() {
63-
ipc.removeAllListeners(['import-file-selected'])
62+
ipc.removeAllListeners(['import-file-selected']);
6463
}
6564

6665
// Check if settings have been saved
@@ -86,22 +85,24 @@ class Settings extends Component {
8685
}
8786

8887
handleFileUpload(filePath) {
89-
const { secretKey } = this.props
88+
const { secretKey } = this.props;
9089
parseImportFile(filePath, secretKey, (err, fileData) => {
9190
if (err) {
9291
return;
9392
}
94-
this.importData(fileData)
95-
})
93+
this.importData(fileData);
94+
});
9695
}
9796

9897
importData(fileData) {
99-
const { importData } = this.props.boundExportImportActionsCreators;
100-
importData(fileData)
98+
if (fileData) {
99+
const { importData } = this.props.boundExportImportActionsCreators;
100+
importData(fileData);
101+
}
101102
}
102103

103104
selectImportFile(fileData) {
104-
ipc.send('open-import-file-dialog')
105+
ipc.send('open-import-file-dialog');
105106
}
106107

107108
// Render Main Content
@@ -148,10 +149,20 @@ class Settings extends Component {
148149
</Tabs>
149150
<TabContent>
150151
{this.state.visibleTab === 1 && (
151-
<Profile t={t} profile={profile} updateSettings={updateSettings} setSavable={this.setSavable} />
152+
<Profile
153+
t={t}
154+
profile={profile}
155+
updateSettings={updateSettings}
156+
setSavable={this.setSavable}
157+
/>
152158
)}
153159
{this.state.visibleTab === 2 && (
154-
<Invoice t={t} invoice={invoice} updateSettings={updateSettings} setSavable={this.setSavable} />
160+
<Invoice
161+
t={t}
162+
invoice={invoice}
163+
updateSettings={updateSettings}
164+
setSavable={this.setSavable}
165+
/>
155166
)}
156167
{this.state.visibleTab === 3 && (
157168
<General
@@ -183,23 +194,26 @@ Settings.propTypes = {
183194
}).isRequired,
184195
boundExportImportActionsCreators: PropTypes.shape({
185196
exportData: PropTypes.func.isRequired,
186-
importData: PropTypes.func.isRequired
197+
importData: PropTypes.func.isRequired,
187198
}),
188199
currentSettings: PropTypes.object.isRequired,
189200
savedSettings: PropTypes.object.isRequired,
190201
secretKey: PropTypes.string.isRequired,
191202
};
192203

193204
// Map State & Dispatch to Props & Export
194-
const mapDispatchToProps = dispatch => ({
205+
const mapDispatchToProps = (dispatch) => ({
195206
boundActionCreators: bindActionCreators(SettingsActions, dispatch),
196-
boundExportImportActionsCreators: bindActionCreators(ExportImportActions, dispatch)
207+
boundExportImportActionsCreators: bindActionCreators(
208+
ExportImportActions,
209+
dispatch
210+
),
197211
});
198212

199-
const mapStateToProps = state => ({
213+
const mapStateToProps = (state) => ({
200214
currentSettings: getCurrentSettings(state),
201215
savedSettings: getSavedSettings(state),
202-
secretKey: getSecretKey(state)
216+
secretKey: getSecretKey(state),
203217
});
204218

205219
export default compose(

main/select-import-file.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ const ipc = require('electron').ipcMain;
33
const dialog = require('electron').dialog;
44

55
ipc.on('open-import-file-dialog', event => {
6-
const [file] = dialog.showOpenDialogSync(
6+
const result = dialog.showOpenDialogSync(
77
{
88
properties: ['openFile'],
99
filters: [{ name: 'Import Data', extensions: ['json'] }],
1010
}
1111
)
1212

13-
if (file) { event.sender.send('import-file-selected', file); }
13+
if (result && result.file) { event.sender.send('import-file-selected', result.file); }
1414
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "invoncify",
33
"homepage": "https://invoncify.andresmorelos.me",
44
"productName": "Invoncify",
5-
"version": "1.4.2",
5+
"version": "1.4.3",
66
"license": "GPL-3.0",
77
"description": "Flexible invoicing desktop app with beautiful & customizable templates",
88
"author": {

0 commit comments

Comments
 (0)