diff --git a/packages/desktop-client/src/components/modals/ImportTransactionsModal/CheckboxOption.jsx b/packages/desktop-client/src/components/modals/ImportTransactionsModal/CheckboxOption.jsx new file mode 100644 index 00000000000..76e1e7fb915 --- /dev/null +++ b/packages/desktop-client/src/components/modals/ImportTransactionsModal/CheckboxOption.jsx @@ -0,0 +1,43 @@ +import React from 'react'; + +import { theme } from '../../../style'; +import { View } from '../../common/View'; +import { Checkbox } from '../../forms'; + +export function CheckboxOption({ + id, + checked, + disabled, + onChange, + children, + style, +}) { + return ( + + + + + ); +} diff --git a/packages/desktop-client/src/components/modals/ImportTransactionsModal/DateFormatSelect.jsx b/packages/desktop-client/src/components/modals/ImportTransactionsModal/DateFormatSelect.jsx new file mode 100644 index 00000000000..c911ea36c66 --- /dev/null +++ b/packages/desktop-client/src/components/modals/ImportTransactionsModal/DateFormatSelect.jsx @@ -0,0 +1,39 @@ +import React from 'react'; + +import { Select } from '../../common/Select'; +import { View } from '../../common/View'; +import { SectionLabel } from '../../forms'; + +import { dateFormats } from './utils'; + +export function DateFormatSelect({ + transactions, + fieldMappings, + parseDateFormat, + onChange, +}) { + // We don't actually care about the delimiter, but we try to render + // it based on the data we have so far. Look in a transaction and + // try to figure out what delimiter the date is using, and default + // to space if we can't figure it out. + let delimiter = '-'; + if (transactions.length > 0 && fieldMappings && fieldMappings.date != null) { + const date = transactions[0][fieldMappings.date]; + const m = date && date.match(/[/.,-/\\]/); + delimiter = m ? m[0] : ' '; + } + + return ( + + + [ - option, - hasHeaderRow - ? option - : `Column ${parseInt(option) + 1} (${firstTransaction[option]})`, - ]), - ]} - value={value === null ? 'choose-field' : value} - onChange={onChange} - style={style} - /> - ); -} - -function DateFormatSelect({ - transactions, - fieldMappings, - parseDateFormat, - onChange, -}) { - // We don't actually care about the delimiter, but we try to render - // it based on the data we have so far. Look in a transaction and - // try to figure out what delimiter the date is using, and default - // to space if we can't figure it out. - let delimiter = '-'; - if (transactions.length > 0 && fieldMappings && fieldMappings.date != null) { - const date = transactions[0][fieldMappings.date]; - const m = date && date.match(/[/.,-/\\]/); - delimiter = m ? m[0] : ' '; - } - - return ( - - - - - ); -} - -function InOutOption({ - inOutMode, - outValue, - disabled, - onToggle, - onChangeText, -}) { - return ( - - - {inOutMode - ? 'in/out identifier' - : 'Select column to specify if amount goes in/out'} - - {inOutMode && ( - - )} - - ); -} - -function FieldMappings({ - transactions, - mappings, - onChange, - splitMode, - inOutMode, - hasHeaderRow, -}) { - if (transactions.length === 0) { - return null; - } - - const { existing, ignored, selected, selected_merge, trx_id, ...trans } = - transactions[0]; - const options = Object.keys(trans); - mappings = mappings || {}; - - return ( - - - - - - onChange('date', name)} - hasHeaderRow={hasHeaderRow} - firstTransaction={transactions[0]} - /> - - - - onChange('payee', name)} - hasHeaderRow={hasHeaderRow} - firstTransaction={transactions[0]} - /> - - - - onChange('notes', name)} - hasHeaderRow={hasHeaderRow} - firstTransaction={transactions[0]} - /> - - - - onChange('category', name)} - hasHeaderRow={hasHeaderRow} - firstTransaction={transactions[0]} - /> - - {splitMode ? ( - <> - - - onChange('outflow', name)} - hasHeaderRow={hasHeaderRow} - firstTransaction={transactions[0]} - /> - - - - onChange('inflow', name)} - hasHeaderRow={hasHeaderRow} - firstTransaction={transactions[0]} - /> - - - ) : ( - <> - {inOutMode && ( - - - onChange('inOut', name)} - hasHeaderRow={hasHeaderRow} - firstTransaction={transactions[0]} - /> - - )} - - - onChange('amount', name)} - hasHeaderRow={hasHeaderRow} - firstTransaction={transactions[0]} - /> - - - )} - - - ); -} - export function ImportTransactionsModal({ options }) { const dateFormat = useDateFormat() || 'MM/dd/yyyy'; const [prefs, savePrefs] = useSyncedPrefs(); diff --git a/packages/desktop-client/src/components/modals/ImportTransactionsModal/InOutOption.jsx b/packages/desktop-client/src/components/modals/ImportTransactionsModal/InOutOption.jsx new file mode 100644 index 00000000000..5bd36a8f42e --- /dev/null +++ b/packages/desktop-client/src/components/modals/ImportTransactionsModal/InOutOption.jsx @@ -0,0 +1,37 @@ +import React from 'react'; + +import { Input } from '../../common/Input'; +import { View } from '../../common/View'; + +import { CheckboxOption } from './CheckboxOption'; + +export function InOutOption({ + inOutMode, + outValue, + disabled, + onToggle, + onChangeText, +}) { + return ( + + + {inOutMode + ? 'in/out identifier' + : 'Select column to specify if amount goes in/out'} + + {inOutMode && ( + + )} + + ); +} diff --git a/packages/desktop-client/src/components/modals/ImportTransactionsModal/MultiplierOption.jsx b/packages/desktop-client/src/components/modals/ImportTransactionsModal/MultiplierOption.jsx new file mode 100644 index 00000000000..f5d922cf513 --- /dev/null +++ b/packages/desktop-client/src/components/modals/ImportTransactionsModal/MultiplierOption.jsx @@ -0,0 +1,32 @@ +import React from 'react'; + +import { Input } from '../../common/Input'; +import { View } from '../../common/View'; + +import { CheckboxOption } from './CheckboxOption'; + +export function MultiplierOption({ + multiplierEnabled, + multiplierAmount, + onToggle, + onChangeAmount, +}) { + return ( + + + Add multiplier + + + + ); +} diff --git a/packages/desktop-client/src/components/modals/ImportTransactionsModal/ParsedDate.jsx b/packages/desktop-client/src/components/modals/ImportTransactionsModal/ParsedDate.jsx new file mode 100644 index 00000000000..9abf5e340c0 --- /dev/null +++ b/packages/desktop-client/src/components/modals/ImportTransactionsModal/ParsedDate.jsx @@ -0,0 +1,30 @@ +import React from 'react'; + +import { theme } from '../../../style'; +import { Text } from '../../common/Text'; + +import { formatDate, parseDate } from './utils'; + +export function ParsedDate({ parseDateFormat, dateFormat, date }) { + const parsed = + date && + formatDate( + parseDateFormat ? parseDate(date, parseDateFormat) : date, + dateFormat, + ); + return ( + + + {date || ( + + Empty + + )}{' '} + →{' '} + + + {parsed || 'Invalid'} + + + ); +} diff --git a/packages/desktop-client/src/components/modals/ImportTransactionsModal/SelectField.jsx b/packages/desktop-client/src/components/modals/ImportTransactionsModal/SelectField.jsx new file mode 100644 index 00000000000..0626b8e6393 --- /dev/null +++ b/packages/desktop-client/src/components/modals/ImportTransactionsModal/SelectField.jsx @@ -0,0 +1,29 @@ +import React from 'react'; + +import { Select } from '../../common/Select'; + +export function SelectField({ + style, + options, + value, + onChange, + hasHeaderRow, + firstTransaction, +}) { + return ( +