cozy-harvest-lib 11.2.0 → 11.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [11.4.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@11.3.0...cozy-harvest-lib@11.4.0) (2023-01-10)
7
+
8
+
9
+ ### Features
10
+
11
+ * **harvest:** Add success snackbar after successful synchronization ([242544e](https://github.com/cozy/cozy-libs/commit/242544ef5717062c76ae2a23b8326739bce57369))
12
+
13
+
14
+
15
+
16
+
17
+ # [11.3.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@11.2.0...cozy-harvest-lib@11.3.0) (2023-01-04)
18
+
19
+
20
+ ### Features
21
+
22
+ * **harvest:** Add onSuccess in Routes API ([5f41164](https://github.com/cozy/cozy-libs/commit/5f411642d0ac325375925cad157f66275e64db67))
23
+
24
+
25
+
26
+
27
+
6
28
  # [11.2.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@11.1.0...cozy-harvest-lib@11.2.0) (2023-01-02)
7
29
 
8
30
 
@@ -2,19 +2,19 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import React, { useContext } from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import cx from 'classnames';
5
- import { useClient } from 'cozy-client';
5
+ import DialogContent from '@material-ui/core/DialogContent';
6
6
  import flag from 'cozy-flags';
7
+ import { useClient } from 'cozy-client';
7
8
  import { useI18n } from 'cozy-ui/transpiled/react/I18n';
8
9
  import Spinner from 'cozy-ui/transpiled/react/Spinner';
9
10
  import Typography from 'cozy-ui/transpiled/react/Typography';
11
+ import { DialogTitle } from 'cozy-ui/transpiled/react/Dialog';
10
12
  import TriggerManager from './TriggerManager';
11
13
  import KonnectorIcon from './KonnectorIcon';
12
14
  import * as triggersModel from '../helpers/triggers';
13
15
  import KonnectorMaintenance from './Maintenance';
14
16
  import useMaintenanceStatus from './hooks/useMaintenanceStatus';
15
17
  import { MountPointContext } from './MountPointContext';
16
- import DialogContent from '@material-ui/core/DialogContent';
17
- import { DialogTitle } from 'cozy-ui/transpiled/react/Dialog';
18
18
  import { useDialogContext } from './DialogContext';
19
19
  /**
20
20
  * We need to deal with `onLoginSuccess` and `onSucess` because we
@@ -25,6 +25,7 @@ import { useDialogContext } from './DialogContext';
25
25
 
26
26
  var NewAccountModal = function NewAccountModal(_ref) {
27
27
  var konnector = _ref.konnector,
28
+ onSuccess = _ref.onSuccess,
28
29
  onDismiss = _ref.onDismiss;
29
30
 
30
31
  var _useI18n = useI18n(),
@@ -49,6 +50,21 @@ var NewAccountModal = function NewAccountModal(_ref) {
49
50
  var fieldOptions = {
50
51
  displaySecretPlaceholder: false
51
52
  };
53
+
54
+ var handleSuccess = function handleSuccess(trigger) {
55
+ if (onSuccess) {
56
+ return onSuccess();
57
+ }
58
+
59
+ var accountId = triggersModel.getAccountId(trigger);
60
+
61
+ if (!flag('harvest.inappconnectors.enabled') && trigger.worker !== 'client') {
62
+ replaceHistory("/accounts/".concat(accountId, "/success"));
63
+ }
64
+
65
+ replaceHistory("/accounts/".concat(accountId));
66
+ };
67
+
52
68
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DialogTitle, _extends({}, dialogTitleProps, {
53
69
  className: cx(dialogTitleProps.className, 'u-ta-center u-flex-column u-stack-m u-pb-1'),
54
70
  disableTypography: true
@@ -71,26 +87,8 @@ var NewAccountModal = function NewAccountModal(_ref) {
71
87
  className: "u-pt-0"
72
88
  }, /*#__PURE__*/React.createElement(TriggerManager, {
73
89
  konnector: konnector,
74
- onLoginSuccess: function onLoginSuccess(trigger) {
75
- var accountId = triggersModel.getAccountId(trigger);
76
- var path = "/accounts/".concat(accountId);
77
-
78
- if (!flag('harvest.inappconnectors.enabled') && trigger.worker !== 'client') {
79
- path += '/success';
80
- }
81
-
82
- replaceHistory(path);
83
- },
84
- onSuccess: function onSuccess(trigger) {
85
- var accountId = triggersModel.getAccountId(trigger);
86
- var path = "/accounts/".concat(accountId);
87
-
88
- if (!flag('harvest.inappconnectors.enabled') && trigger.worker !== 'client') {
89
- path += '/success';
90
- }
91
-
92
- replaceHistory(path);
93
- },
90
+ onLoginSuccess: handleSuccess,
91
+ onSuccess: handleSuccess,
94
92
  onVaultDismiss: onDismiss,
95
93
  fieldOptions: fieldOptions
96
94
  }), /*#__PURE__*/React.createElement("div", {
@@ -12,6 +12,7 @@ var RoutesV4 = function RoutesV4(_ref) {
12
12
  var konnectorRoot = _ref.konnectorRoot,
13
13
  konnectorWithTriggers = _ref.konnectorWithTriggers,
14
14
  accountsAndTriggers = _ref.accountsAndTriggers,
15
+ onSuccess = _ref.onSuccess,
15
16
  onDismiss = _ref.onDismiss;
16
17
  return /*#__PURE__*/React.createElement(Switch, null, /*#__PURE__*/React.createElement(Route, {
17
18
  path: "".concat(konnectorRoot, "/"),
@@ -59,6 +60,7 @@ var RoutesV4 = function RoutesV4(_ref) {
59
60
  render: function render() {
60
61
  return /*#__PURE__*/React.createElement(NewAccountModal, {
61
62
  konnector: konnectorWithTriggers,
63
+ onSuccess: onSuccess,
62
64
  onDismiss: onDismiss
63
65
  });
64
66
  }
@@ -16,6 +16,7 @@ var HarvestParamsWrapper = function HarvestParamsWrapper(props) {
16
16
  var RoutesV6 = function RoutesV6(_ref) {
17
17
  var konnectorWithTriggers = _ref.konnectorWithTriggers,
18
18
  accountsAndTriggers = _ref.accountsAndTriggers,
19
+ onSuccess = _ref.onSuccess,
19
20
  onDismiss = _ref.onDismiss;
20
21
  return /*#__PURE__*/React.createElement(Routes, null, /*#__PURE__*/React.createElement(Route, {
21
22
  path: "/",
@@ -27,6 +28,7 @@ var RoutesV6 = function RoutesV6(_ref) {
27
28
  path: "new",
28
29
  element: /*#__PURE__*/React.createElement(NewAccountModal, {
29
30
  konnector: konnectorWithTriggers,
31
+ onSuccess: onSuccess,
30
32
  onDismiss: onDismiss
31
33
  })
32
34
  }), /*#__PURE__*/React.createElement(Route, {
@@ -48,6 +48,7 @@ var Routes = function Routes(_ref) {
48
48
  var konnectorRoot = _ref.konnectorRoot,
49
49
  konnector = _ref.konnector,
50
50
  konnectorSlug = _ref.konnectorSlug,
51
+ onSuccess = _ref.onSuccess,
51
52
  onDismiss = _ref.onDismiss,
52
53
  datacardOptions = _ref.datacardOptions,
53
54
  ComponentsProps = _ref.ComponentsProps;
@@ -96,6 +97,7 @@ var Routes = function Routes(_ref) {
96
97
  konnectorRoot: konnectorRoot,
97
98
  konnectorWithTriggers: konnectorWithTriggers,
98
99
  accountsAndTriggers: accountsAndTriggers,
100
+ onSuccess: onSuccess,
99
101
  onDismiss: onDismiss
100
102
  });
101
103
  }))), /*#__PURE__*/React.createElement(VaultUnlockPlaceholder, null))))));
@@ -1,12 +1,15 @@
1
- import React from 'react';
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import React, { useState, useEffect } from 'react';
2
3
  import Alert from 'cozy-ui/transpiled/react/Alert';
3
4
  import Button from 'cozy-ui/transpiled/react/Buttons';
4
5
  import Typography from 'cozy-ui/transpiled/react/Typography';
5
6
  import Spinner from 'cozy-ui/transpiled/react/Spinner';
6
- import KonnectorIcon from '../KonnectorIcon';
7
+ import Snackbar from 'cozy-ui/transpiled/react/Snackbar';
7
8
  import { getLastSuccessDate, getKonnectorSlug } from '../../helpers/triggers';
8
9
  import { isRunnable } from '../../helpers/konnectors';
9
10
  import { useFlowState } from '../../models/withConnectionFlow';
11
+ import { SUCCESS } from '../../models/flowEvents';
12
+ import KonnectorIcon from '../KonnectorIcon';
10
13
  import { makeLabel } from './helpers';
11
14
  export var LaunchTriggerAlert = function LaunchTriggerAlert(_ref) {
12
15
  var flow = _ref.flow,
@@ -14,10 +17,16 @@ export var LaunchTriggerAlert = function LaunchTriggerAlert(_ref) {
14
17
  t = _ref.t,
15
18
  disabled = _ref.disabled;
16
19
 
20
+ var _useState = useState(false),
21
+ _useState2 = _slicedToArray(_useState, 2),
22
+ showSuccessSnackbar = _useState2[0],
23
+ setShowSuccessSnackbar = _useState2[1];
24
+
17
25
  var _useFlowState = useFlowState(flow),
18
26
  trigger = _useFlowState.trigger,
19
27
  running = _useFlowState.running,
20
- expectingTriggerLaunch = _useFlowState.expectingTriggerLaunch;
28
+ expectingTriggerLaunch = _useFlowState.expectingTriggerLaunch,
29
+ status = _useFlowState.status;
21
30
 
22
31
  var launch = flow.launch,
23
32
  konnector = flow.konnector;
@@ -26,7 +35,12 @@ export var LaunchTriggerAlert = function LaunchTriggerAlert(_ref) {
26
35
  win: window,
27
36
  konnector: konnector
28
37
  });
29
- return /*#__PURE__*/React.createElement(Alert, {
38
+ useEffect(function () {
39
+ if (status === SUCCESS) {
40
+ setShowSuccessSnackbar(true);
41
+ }
42
+ }, [status]);
43
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Alert, {
30
44
  color: "var(--paperBackground)",
31
45
  icon: running ? /*#__PURE__*/React.createElement(Spinner, {
32
46
  className: "u-flex",
@@ -54,6 +68,18 @@ export var LaunchTriggerAlert = function LaunchTriggerAlert(_ref) {
54
68
  running: running,
55
69
  expectingTriggerLaunch: expectingTriggerLaunch,
56
70
  lastSuccessDate: lastSuccessDate
57
- })));
71
+ }))), /*#__PURE__*/React.createElement(Snackbar, {
72
+ open: showSuccessSnackbar,
73
+ onClose: function onClose() {
74
+ return setShowSuccessSnackbar(false);
75
+ }
76
+ }, /*#__PURE__*/React.createElement(Alert, {
77
+ variant: "filled",
78
+ elevation: 6,
79
+ severity: "success",
80
+ onClose: function onClose() {
81
+ return setShowSuccessSnackbar(false);
82
+ }
83
+ }, t('card.launchTrigger.success'))));
58
84
  };
59
85
  export default LaunchTriggerAlert;
@@ -77,6 +77,7 @@
77
77
  "button": {
78
78
  "label": "Run again now"
79
79
  },
80
+ "success": "Successful synchronization",
80
81
  "error": "An error occured.",
81
82
  "frequency": {
82
83
  "label": "Frequency:",
@@ -77,6 +77,7 @@
77
77
  "button": {
78
78
  "label": "Mettre à jour"
79
79
  },
80
+ "success": "Synchronisation réussie",
80
81
  "error": "Une erreur est survenue.",
81
82
  "frequency": {
82
83
  "label": "Fréquence :",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-harvest-lib",
3
- "version": "11.2.0",
3
+ "version": "11.4.0",
4
4
  "description": "Provides logic, modules and components for Cozy's harvest applications.",
5
5
  "main": "dist/index.js",
6
6
  "author": "Cozy",
@@ -90,5 +90,5 @@
90
90
  "react-router-dom": ">=4.3.1"
91
91
  },
92
92
  "sideEffects": false,
93
- "gitHead": "034e1cbcf44130b8ad3e697001e017a1a610698b"
93
+ "gitHead": "c2606cb995dfb001340033281f78008aa47cd55f"
94
94
  }
@@ -1,12 +1,14 @@
1
1
  import React, { useContext } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import cx from 'classnames'
4
- import { useClient } from 'cozy-client'
5
- import flag from 'cozy-flags'
4
+ import DialogContent from '@material-ui/core/DialogContent'
6
5
 
6
+ import flag from 'cozy-flags'
7
+ import { useClient } from 'cozy-client'
7
8
  import { useI18n } from 'cozy-ui/transpiled/react/I18n'
8
9
  import Spinner from 'cozy-ui/transpiled/react/Spinner'
9
10
  import Typography from 'cozy-ui/transpiled/react/Typography'
11
+ import { DialogTitle } from 'cozy-ui/transpiled/react/Dialog'
10
12
 
11
13
  import TriggerManager from './TriggerManager'
12
14
  import KonnectorIcon from './KonnectorIcon'
@@ -14,8 +16,6 @@ import * as triggersModel from '../helpers/triggers'
14
16
  import KonnectorMaintenance from './Maintenance'
15
17
  import useMaintenanceStatus from './hooks/useMaintenanceStatus'
16
18
  import { MountPointContext } from './MountPointContext'
17
- import DialogContent from '@material-ui/core/DialogContent'
18
- import { DialogTitle } from 'cozy-ui/transpiled/react/Dialog'
19
19
  import { useDialogContext } from './DialogContext'
20
20
 
21
21
  /**
@@ -24,7 +24,7 @@ import { useDialogContext } from './DialogContext'
24
24
  * few konnectors know if the login is success or not.
25
25
  *
26
26
  */
27
- const NewAccountModal = ({ konnector, onDismiss }) => {
27
+ const NewAccountModal = ({ konnector, onSuccess, onDismiss }) => {
28
28
  const { t } = useI18n()
29
29
  const client = useClient()
30
30
  const { replaceHistory } = useContext(MountPointContext)
@@ -40,6 +40,21 @@ const NewAccountModal = ({ konnector, onDismiss }) => {
40
40
  displaySecretPlaceholder: false
41
41
  }
42
42
 
43
+ const handleSuccess = trigger => {
44
+ if (onSuccess) {
45
+ return onSuccess()
46
+ }
47
+
48
+ const accountId = triggersModel.getAccountId(trigger)
49
+ if (
50
+ !flag('harvest.inappconnectors.enabled') &&
51
+ trigger.worker !== 'client'
52
+ ) {
53
+ replaceHistory(`/accounts/${accountId}/success`)
54
+ }
55
+ replaceHistory(`/accounts/${accountId}`)
56
+ }
57
+
43
58
  return (
44
59
  <>
45
60
  <DialogTitle
@@ -69,28 +84,8 @@ const NewAccountModal = ({ konnector, onDismiss }) => {
69
84
  <DialogContent className="u-pt-0">
70
85
  <TriggerManager
71
86
  konnector={konnector}
72
- onLoginSuccess={trigger => {
73
- const accountId = triggersModel.getAccountId(trigger)
74
- let path = `/accounts/${accountId}`
75
- if (
76
- !flag('harvest.inappconnectors.enabled') &&
77
- trigger.worker !== 'client'
78
- ) {
79
- path += '/success'
80
- }
81
- replaceHistory(path)
82
- }}
83
- onSuccess={trigger => {
84
- const accountId = triggersModel.getAccountId(trigger)
85
- let path = `/accounts/${accountId}`
86
- if (
87
- !flag('harvest.inappconnectors.enabled') &&
88
- trigger.worker !== 'client'
89
- ) {
90
- path += '/success'
91
- }
92
- replaceHistory(path)
93
- }}
87
+ onLoginSuccess={handleSuccess}
88
+ onSuccess={handleSuccess}
94
89
  onVaultDismiss={onDismiss}
95
90
  fieldOptions={fieldOptions}
96
91
  />
@@ -14,6 +14,7 @@ const RoutesV4 = ({
14
14
  konnectorRoot,
15
15
  konnectorWithTriggers,
16
16
  accountsAndTriggers,
17
+ onSuccess,
17
18
  onDismiss
18
19
  }) => {
19
20
  return (
@@ -64,6 +65,7 @@ const RoutesV4 = ({
64
65
  render={() => (
65
66
  <NewAccountModal
66
67
  konnector={konnectorWithTriggers}
68
+ onSuccess={onSuccess}
67
69
  onDismiss={onDismiss}
68
70
  />
69
71
  )}
@@ -18,6 +18,7 @@ const HarvestParamsWrapper = props => {
18
18
  const RoutesV6 = ({
19
19
  konnectorWithTriggers,
20
20
  accountsAndTriggers,
21
+ onSuccess,
21
22
  onDismiss
22
23
  }) => {
23
24
  return (
@@ -37,6 +38,7 @@ const RoutesV6 = ({
37
38
  element={
38
39
  <NewAccountModal
39
40
  konnector={konnectorWithTriggers}
41
+ onSuccess={onSuccess}
40
42
  onDismiss={onDismiss}
41
43
  />
42
44
  }
@@ -49,6 +49,7 @@ const Routes = ({
49
49
  konnectorRoot,
50
50
  konnector,
51
51
  konnectorSlug,
52
+ onSuccess,
52
53
  onDismiss,
53
54
  datacardOptions,
54
55
  ComponentsProps
@@ -95,6 +96,7 @@ const Routes = ({
95
96
  konnectorRoot={konnectorRoot}
96
97
  konnectorWithTriggers={konnectorWithTriggers}
97
98
  accountsAndTriggers={accountsAndTriggers}
99
+ onSuccess={onSuccess}
98
100
  onDismiss={onDismiss}
99
101
  />
100
102
  )}
@@ -1,57 +1,83 @@
1
- import React from 'react'
1
+ import React, { useState, useEffect } from 'react'
2
2
 
3
3
  import Alert from 'cozy-ui/transpiled/react/Alert'
4
4
  import Button from 'cozy-ui/transpiled/react/Buttons'
5
5
  import Typography from 'cozy-ui/transpiled/react/Typography'
6
6
  import Spinner from 'cozy-ui/transpiled/react/Spinner'
7
+ import Snackbar from 'cozy-ui/transpiled/react/Snackbar'
7
8
 
8
- import KonnectorIcon from '../KonnectorIcon'
9
9
  import { getLastSuccessDate, getKonnectorSlug } from '../../helpers/triggers'
10
10
  import { isRunnable } from '../../helpers/konnectors'
11
11
  import { useFlowState } from '../../models/withConnectionFlow'
12
+ import { SUCCESS } from '../../models/flowEvents'
13
+ import KonnectorIcon from '../KonnectorIcon'
12
14
  import { makeLabel } from './helpers'
13
15
 
14
16
  export const LaunchTriggerAlert = ({ flow, f, t, disabled }) => {
15
- const { trigger, running, expectingTriggerLaunch } = useFlowState(flow)
17
+ const [showSuccessSnackbar, setShowSuccessSnackbar] = useState(false)
18
+ const { trigger, running, expectingTriggerLaunch, status } =
19
+ useFlowState(flow)
16
20
  const { launch, konnector } = flow
21
+
17
22
  const lastSuccessDate = getLastSuccessDate(trigger)
18
23
  const isKonnectorRunnable = isRunnable({ win: window, konnector })
19
24
 
25
+ useEffect(() => {
26
+ if (status === SUCCESS) {
27
+ setShowSuccessSnackbar(true)
28
+ }
29
+ }, [status])
30
+
20
31
  return (
21
- <Alert
22
- color="var(--paperBackground)"
23
- icon={
24
- running ? (
25
- <Spinner className="u-flex" noMargin />
26
- ) : (
27
- <KonnectorIcon
28
- className="u-w-1 u-h-1"
29
- konnectorSlug={getKonnectorSlug(trigger)}
30
- />
31
- )
32
- }
33
- action={
34
- isKonnectorRunnable && (
35
- <Button
36
- variant="text"
37
- size="small"
38
- disabled={running || disabled}
39
- label={t('card.launchTrigger.button.label')}
40
- onClick={() => launch({ autoSuccessTimer: false })}
41
- />
42
- )
43
- }
44
- >
45
- <Typography variant="caption">
46
- {makeLabel({
47
- t,
48
- f,
49
- running,
50
- expectingTriggerLaunch,
51
- lastSuccessDate
52
- })}
53
- </Typography>
54
- </Alert>
32
+ <>
33
+ <Alert
34
+ color="var(--paperBackground)"
35
+ icon={
36
+ running ? (
37
+ <Spinner className="u-flex" noMargin />
38
+ ) : (
39
+ <KonnectorIcon
40
+ className="u-w-1 u-h-1"
41
+ konnectorSlug={getKonnectorSlug(trigger)}
42
+ />
43
+ )
44
+ }
45
+ action={
46
+ isKonnectorRunnable && (
47
+ <Button
48
+ variant="text"
49
+ size="small"
50
+ disabled={running || disabled}
51
+ label={t('card.launchTrigger.button.label')}
52
+ onClick={() => launch({ autoSuccessTimer: false })}
53
+ />
54
+ )
55
+ }
56
+ >
57
+ <Typography variant="caption">
58
+ {makeLabel({
59
+ t,
60
+ f,
61
+ running,
62
+ expectingTriggerLaunch,
63
+ lastSuccessDate
64
+ })}
65
+ </Typography>
66
+ </Alert>
67
+ <Snackbar
68
+ open={showSuccessSnackbar}
69
+ onClose={() => setShowSuccessSnackbar(false)}
70
+ >
71
+ <Alert
72
+ variant="filled"
73
+ elevation={6}
74
+ severity="success"
75
+ onClose={() => setShowSuccessSnackbar(false)}
76
+ >
77
+ {t('card.launchTrigger.success')}
78
+ </Alert>
79
+ </Snackbar>
80
+ </>
55
81
  )
56
82
  }
57
83
 
@@ -77,6 +77,7 @@
77
77
  "button": {
78
78
  "label": "Run again now"
79
79
  },
80
+ "success": "Successful synchronization",
80
81
  "error": "An error occured.",
81
82
  "frequency": {
82
83
  "label": "Frequency:",
@@ -77,6 +77,7 @@
77
77
  "button": {
78
78
  "label": "Mettre à jour"
79
79
  },
80
+ "success": "Synchronisation réussie",
80
81
  "error": "Une erreur est survenue.",
81
82
  "frequency": {
82
83
  "label": "Fréquence :",