Skip to content
Snippets Groups Projects
  • Jed Fox's avatar
    beef97d7
    Move the welcome modal to an interstitial, add import button (#762) · beef97d7
    Jed Fox authored
    I noticed that the first run flow is suboptimal for people who want to
    import an existing file from Actual/YNAB. I’ve moved the welcome modal
    into the management app and set it up to appear when there are no
    budgets available (which also has the benefit of allowing people to see
    the modal again!)
    
    I think there’s some weirdness around getting the modal to reappear when
    deleting a budget file which I want to work out before merging this.
    
    This PR also reorganizes the management app a bit to reduce usage of
    modals (currently, hitting escape while the budget list is open leaves
    you with a blank page).
    
    <img width="539" alt="Screenshot_2023-03-18 08 53 54"
    src="https://user-images.githubusercontent.com/25517624/226107462-b2b88791-1015-4397-b290-c64e7fcc0f41.png">
    
    - [x] Ensure modal consistently appears when needed (no longer a modal!)
    - [x] Fix e2e tests
    Move the welcome modal to an interstitial, add import button (#762)
    Jed Fox authored
    I noticed that the first run flow is suboptimal for people who want to
    import an existing file from Actual/YNAB. I’ve moved the welcome modal
    into the management app and set it up to appear when there are no
    budgets available (which also has the benefit of allowing people to see
    the modal again!)
    
    I think there’s some weirdness around getting the modal to reappear when
    deleting a budget file which I want to work out before merging this.
    
    This PR also reorganizes the management app a bit to reduce usage of
    modals (currently, hitting escape while the budget list is open leaves
    you with a blank page).
    
    <img width="539" alt="Screenshot_2023-03-18 08 53 54"
    src="https://user-images.githubusercontent.com/25517624/226107462-b2b88791-1015-4397-b290-c64e7fcc0f41.png">
    
    - [x] Ensure modal consistently appears when needed (no longer a modal!)
    - [x] Fix e2e tests
ImportYNAB4.js 2.39 KiB
import React, { useState } from 'react';
import { useDispatch } from 'react-redux';

import { importBudget } from 'loot-core/src/client/actions/budgets';

import { styles, colors } from '../../style';
import { View, Block, Modal, ButtonWithLoading, P } from '../common';

function getErrorMessage(error) {
  switch (error) {
    case 'not-ynab4':
      return 'This file is not valid. Please select a compressed ynab4 zip file.';
    default:
      return 'An unknown error occurred while importing. Sorry! We have been notified of this issue.';
  }
}

function Import({ modalProps, availableImports }) {
  const dispatch = useDispatch();
  const [error, setError] = useState(false);
  const [importing, setImporting] = useState(false);

  async function onImport() {
    const res = await window.Actual.openFileDialog({
      properties: ['openFile'],
      filters: [{ name: 'ynab', extensions: ['zip'] }],
    });
    if (res) {
      setImporting(true);
      setError(false);
      try {
        await dispatch(importBudget(res[0], 'ynab4'));
      } catch (err) {
        setError(err.message);
      } finally {
        setImporting(false);
      }
    }
  }

  return (
    <Modal {...modalProps} title="Import from YNAB4" style={{ width: 400 }}>
      {() => (
        <View style={[styles.smallText, { lineHeight: 1.5, marginTop: 20 }]}>
          {error && (
            <Block style={{ color: colors.r4, marginBottom: 15 }}>
              {getErrorMessage(error)}
            </Block>
          )}

          <View style={{ alignItems: 'center' }}>
            <P>
              To import data from YNAB4, locate where your YNAB4 data is stored.
              It is usually in your Documents folder under YNAB. Your data is a
              directory inside that with the ".ynab4" suffix.
            </P>
            <P>
              When you've located your data,{' '}
              <strong>compress it into a zip file</strong>. On macOS,
              right-click the folder and select "Compress". On Windows,
              right-click and select "Send to > Compressed (zipped) folder".
              Upload the zipped folder for importing.
            </P>
            <View>
              <ButtonWithLoading loading={importing} primary onClick={onImport}>
                Select zip file...
              </ButtonWithLoading>
            </View>
          </View>
        </View>
      )}
    </Modal>
  );
}

export default Import;