From 1ae28c9b9c4af8deff4e5268bf30f0d105c57089 Mon Sep 17 00:00:00 2001 From: AlexisG Date: Tue, 25 Apr 2023 16:39:06 +0200 Subject: [PATCH 1/2] docs: Add import service documentation --- docs/services.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/services.md b/docs/services.md index 53ff442b7f..4ab6ab5f62 100644 --- a/docs/services.md +++ b/docs/services.md @@ -122,6 +122,16 @@ The service also determines if a delayed notification schedule at D+3 and D+7 is ℹ️ This service can be run via CLI via `yarn service konnectorAlerts` +### Import + +slug: `import` + +Allows you to import bank data into Cozy, from the Cozy bank export file (.csv format) +This service is launched manually once the import of the file has been successful on the cozy. +It also saves the number of imported transactions in the doctype `io.cozy.bank.settings` (`lastImportSuccess.savedTransactionsCount`) + +ℹ️ This service can be run via CLI via `yarn service import` + ## I am writing a banking konnector, what should I do? If you want to benefit from all the features of these services, the most From 864eb06779ca22b0d4fa2fe20f30e432cada0ae9 Mon Sep 17 00:00:00 2001 From: AlexisG Date: Tue, 25 Apr 2023 16:44:59 +0200 Subject: [PATCH 2/2] feat: Update text to specify number of successfully imported operations --- .../ImportContents/ImportContentSuccess.jsx | 27 +++++++++++++++---- src/ducks/settings/queries.js | 10 ++++++- src/locales/en.json | 2 +- src/locales/fr.json | 4 +-- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/ducks/settings/Import/ImportContents/ImportContentSuccess.jsx b/src/ducks/settings/Import/ImportContents/ImportContentSuccess.jsx index 3379db6b8f..6d5ec2ef69 100644 --- a/src/ducks/settings/Import/ImportContents/ImportContentSuccess.jsx +++ b/src/ducks/settings/Import/ImportContents/ImportContentSuccess.jsx @@ -1,24 +1,41 @@ import React from 'react' +import { isQueryLoading, useQuery } from 'cozy-client' import { Empty } from 'cozy-ui/transpiled/react' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import Typography from 'cozy-ui/transpiled/react/Typography' import successIllu from 'assets/icons/success-illu.svg' +import { buildAppSettingsQuery } from 'ducks/settings/queries' const ImportContentSuccess = () => { const { t } = useI18n() + const appSettingsQuery = buildAppSettingsQuery() + const { data: appSettings, ...appSettingsQueryResult } = useQuery( + appSettingsQuery.definition, + appSettingsQuery.options + ) + const isLoadingAppSettings = + isQueryLoading(appSettingsQueryResult) || appSettingsQueryResult.hasMore + + const savedTransactionsCount = + !isLoadingAppSettings && + appSettings?.[0]?.lastImportSuccess?.savedTransactionsCount + + const text = savedTransactionsCount ? ( + + {t('Settings.import.description.success', { + smart_count: savedTransactionsCount + })} + + ) : null return ( - {t('Settings.import.description.success')} - - } + text={text} data-testid="ImportContentSuccess" /> ) diff --git a/src/ducks/settings/queries.js b/src/ducks/settings/queries.js index b30881b118..32324611dd 100644 --- a/src/ducks/settings/queries.js +++ b/src/ducks/settings/queries.js @@ -1,6 +1,6 @@ import { Q, fetchPolicies } from 'cozy-client' -import { FILES_DOCTYPE } from 'src/doctypes' +import { FILES_DOCTYPE, SETTINGS_DOCTYPE } from 'src/doctypes' const defaultFetchPolicy = fetchPolicies.olderThan(30 * 1000) @@ -19,3 +19,11 @@ export const buildFilesQueryByNameAndDirId = (name, dirId) => ({ fetchPolicy: defaultFetchPolicy } }) + +export const buildAppSettingsQuery = () => ({ + definition: () => Q(SETTINGS_DOCTYPE), + options: { + as: `${SETTINGS_DOCTYPE}`, + fetchPolicy: defaultFetchPolicy + } +}) diff --git a/src/locales/en.json b/src/locales/en.json index 2deb17edeb..9040045ecf 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -639,7 +639,7 @@ "description": { "text": "Select the data to import\n(File format: .csv)", "serviceInProgress": "Please wait a few moments, your data is being processed.", - "success": "Your data has been successfully imported.", + "success": "%{smart_count} operation imported. |||| %{smart_count} operations imported.", "action": "Data to import" }, "action": { diff --git a/src/locales/fr.json b/src/locales/fr.json index 4a62001277..564cd53bf1 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -635,12 +635,12 @@ "title": { "text": "Importer mes données", "serviceInProgress": "Traitement des données", - "success": "Import réussi" + "success": "Import terminé" }, "description": { "text": "Sélectionnez les données à importer\n(Format du fichier : .csv)", "serviceInProgress": "Merci de patientez quelques instants, vos données sont en cours de traitement.", - "success": "Vos données ont été correctement importées.", + "success": "%{smart_count} opération importée. |||| %{smart_count} opérations importées.", "action": "Données à importer" }, "action": {