Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
151 additions
and
85 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
packages/cozy-harvest-lib/src/components/cards/TriggerAlert.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React from 'react' | ||
|
||
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n' | ||
|
||
import { ErrorAlert } from './ErrorAlert' | ||
import { MaintenanceAlert } from './MaintenanceAlert' | ||
import { RunnableAlert } from './RunnableAlert' | ||
import { makeLabel } from './helpers' | ||
|
||
const TriggerAlert = ({ | ||
trigger, | ||
isInMaintenance, | ||
isInError, | ||
isRunning, | ||
isRunnable, | ||
withMaintenanceDescription, | ||
error, | ||
maintenanceMessages, | ||
account, | ||
konnectorRoot, | ||
historyAction, | ||
intentsApi, | ||
flow | ||
}) => { | ||
const { t } = useI18n() | ||
const { konnector } = flow | ||
|
||
const label = makeLabel({ | ||
t, | ||
konnector, | ||
trigger, | ||
isRunning, | ||
isInMaintenance | ||
}) | ||
|
||
if (isInMaintenance) { | ||
return ( | ||
<MaintenanceAlert | ||
label={label} | ||
withDescription={withMaintenanceDescription} | ||
messages={maintenanceMessages} | ||
isRunnable={isRunnable} | ||
historyAction={historyAction} | ||
konnectorRoot={konnectorRoot} | ||
trigger={trigger} | ||
konnector={konnector} | ||
/> | ||
) | ||
} | ||
|
||
if (isInError) { | ||
return ( | ||
<ErrorAlert | ||
label={label} | ||
error={error} | ||
konnectorRoot={konnectorRoot} | ||
trigger={trigger} | ||
isRunning={isRunning} | ||
isRunnable={isRunnable} | ||
historyAction={historyAction} | ||
flow={flow} | ||
account={account} | ||
intentsApi={intentsApi} | ||
/> | ||
) | ||
} | ||
|
||
return ( | ||
<RunnableAlert | ||
label={label} | ||
isRunning={isRunning} | ||
konnectorSlug={konnector.slug} | ||
konnectorRoot={konnectorRoot} | ||
trigger={trigger} | ||
error={error} | ||
historyAction={historyAction} | ||
flow={flow} | ||
account={account} | ||
intentsApi={intentsApi} | ||
isRunnable={isRunnable} | ||
/> | ||
) | ||
} | ||
|
||
export { TriggerAlert } |
52 changes: 52 additions & 0 deletions
52
packages/cozy-harvest-lib/src/components/cards/TriggerAlert.stories.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { TriggerAlert } from './TriggerAlert' | ||
import { KonnectorJobError } from '../../helpers/konnectors' | ||
|
||
const meta = { | ||
component: TriggerAlert, | ||
args: { | ||
trigger: {}, | ||
isInMaintenance: false, | ||
isInError: false, | ||
isRunnable: true, | ||
isRunning: false, | ||
expectingTriggerLaunch: false, | ||
withMaintenanceDescription: false, | ||
error: new KonnectorJobError('LOGIN_FAILED'), | ||
maintenanceMessages: { | ||
en: { | ||
long_message: | ||
"We're currently working on this service. Please try again later." | ||
} | ||
}, | ||
account: {}, | ||
konnectorRoot: '/konnector/dummy', | ||
historyAction: () => {}, | ||
intentsApi: {}, | ||
flow: { | ||
konnector: { | ||
name: 'Dummy', | ||
type: 'konnector', | ||
slug: 'dummy', | ||
locales: { | ||
en: { | ||
description: 'Konnector used for debug purpose', | ||
fields: { | ||
date: { | ||
label: 'Date' | ||
}, | ||
error: { | ||
label: 'Intended error' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default meta | ||
|
||
export const Default = { | ||
name: 'Default' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters