|
| 1 | +<template> |
| 2 | + <Screen :back="back" :class="$style.screen" :title="t('navigation.tools.import.thirdParty.import')"> |
| 3 | + <Alert :text="t('navigation.tools.import.thirdParty.instructions')" type="info" /> |
| 4 | + |
| 5 | + <div :class="$style.content"> |
| 6 | + <Button |
| 7 | + color="success" |
| 8 | + size="s" |
| 9 | + :text="t('navigation.tools.import.thirdParty.downloadTemplate')" |
| 10 | + :icon="RiFileDownloadLine" |
| 11 | + @click="downloadTemplate" |
| 12 | + /> |
| 13 | + |
| 14 | + <FilePicker |
| 15 | + v-model="incomeFile" |
| 16 | + :placeholder="t('navigation.tools.import.thirdParty.income')" |
| 17 | + :accept="['.csv']" |
| 18 | + /> |
| 19 | + <FilePicker |
| 20 | + v-model="expensesFile" |
| 21 | + :placeholder="t('navigation.tools.import.thirdParty.expenses')" |
| 22 | + :accept="['.csv']" |
| 23 | + /> |
| 24 | + <Button |
| 25 | + v-if="expensesFile && incomeFile" |
| 26 | + :icon="RiUploadCloud2Line" |
| 27 | + :text="t('navigation.tools.import.thirdParty.import')" |
| 28 | + @click="load" |
| 29 | + /> |
| 30 | + </div> |
| 31 | + </Screen> |
| 32 | +</template> |
| 33 | + |
| 34 | +<script lang="ts" setup> |
| 35 | +import Screen from './Screen.vue'; |
| 36 | +import Alert from '@components/base/alert/Alert.vue'; |
| 37 | +import Button from '@components/base/button/Button.vue'; |
| 38 | +import FilePicker from '@components/base/file-picker/FilePicker.vue'; |
| 39 | +import { RiFileDownloadLine, RiUploadCloud2Line } from '@remixicon/vue'; |
| 40 | +import { useDataStore } from '@store/state'; |
| 41 | +import { convertGoogleAnnualBudgetCSVToBudgetGroups } from '@store/state/parser/googleAnnualBudgetSheet'; |
| 42 | +import { readFile } from '@utils/readFile.ts'; |
| 43 | +import { ref } from 'vue'; |
| 44 | +import { useI18n } from 'vue-i18n'; |
| 45 | +
|
| 46 | +const emit = defineEmits<{ |
| 47 | + (e: 'loaded'): void; |
| 48 | +}>(); |
| 49 | +
|
| 50 | +defineProps<{ |
| 51 | + back: () => void; |
| 52 | +}>(); |
| 53 | +
|
| 54 | +const { setBudgetGroups } = useDataStore(); |
| 55 | +const expensesFile = ref<File>(); |
| 56 | +const incomeFile = ref<File>(); |
| 57 | +const { t } = useI18n(); |
| 58 | +
|
| 59 | +const load = async () => { |
| 60 | + if (expensesFile.value && incomeFile.value) { |
| 61 | + const expenses = convertGoogleAnnualBudgetCSVToBudgetGroups(await readFile(expensesFile.value)); |
| 62 | + const income = convertGoogleAnnualBudgetCSVToBudgetGroups(await readFile(incomeFile.value)); |
| 63 | + setBudgetGroups('expenses', expenses); |
| 64 | + setBudgetGroups('income', income); |
| 65 | + emit('loaded'); |
| 66 | + } |
| 67 | +}; |
| 68 | +
|
| 69 | +const downloadTemplate = () => { |
| 70 | + // TODO: Download template and implement the logic to import the file |
| 71 | +}; |
| 72 | +</script> |
| 73 | + |
| 74 | +<style lang="scss" module> |
| 75 | +.screen { |
| 76 | + width: 400px; |
| 77 | +} |
| 78 | +
|
| 79 | +.content { |
| 80 | + display: flex; |
| 81 | + flex-direction: column; |
| 82 | + gap: 10px; |
| 83 | + width: 100%; |
| 84 | +} |
| 85 | +</style> |
0 commit comments