Browse Source

fallback to default screen when error happens with device in manager page

master
Valentin D. Pinkman 7 years ago
parent
commit
2bfabbc30d
No known key found for this signature in database GPG Key ID: E7D110669FFB8D3E
  1. 26
      src/components/ManagerPage/Workflow.js
  2. 24
      src/components/ManagerPage/WorkflowDefault.js
  3. 12
      src/components/ManagerPage/index.js

26
src/components/ManagerPage/Workflow.js

@ -25,13 +25,16 @@ type Props = {
renderDefault: ( renderDefault: (
device: ?Device, device: ?Device,
deviceInfo: ?DeviceInfo, deviceInfo: ?DeviceInfo,
dashboardError: ?Error,
isGenuine: ?boolean, isGenuine: ?boolean,
error: {
dashboardError: ?Error,
genuineError: ?Error,
},
) => Node, ) => Node,
renderMcuUpdate: (deviceInfo: DeviceInfo) => Node, renderMcuUpdate: (deviceInfo: DeviceInfo) => Node,
renderFinalUpdate: (deviceInfo: DeviceInfo) => Node, renderFinalUpdate: (deviceInfo: DeviceInfo) => Node,
renderDashboard: (device: Device, deviceInfo: DeviceInfo) => Node, renderDashboard: (device: Device, deviceInfo: DeviceInfo) => Node,
renderError: (dashboardError: ?Error, genuineError: ?Error) => Node, renderError?: (dashboardError: ?Error, genuineError: ?Error) => Node,
} }
type State = {} type State = {}
@ -52,14 +55,12 @@ class Workflow extends PureComponent<Props, State> {
<EnsureGenuine device={device}> <EnsureGenuine device={device}>
{(isGenuine: ?boolean, genuineError: ?Error) => { {(isGenuine: ?boolean, genuineError: ?Error) => {
if (dashboardError || genuineError) { if (dashboardError || genuineError) {
return renderError ? ( return renderError
renderError(dashboardError, genuineError) ? renderError(dashboardError, genuineError)
) : ( : renderDefault(device, deviceInfo, isGenuine, {
<div> genuineError,
{dashboardError && <span>{dashboardError.message}</span>} dashboardError,
{genuineError && <span>{genuineError.message}</span>} })
</div>
)
} }
if (deviceInfo && deviceInfo.mcu) { if (deviceInfo && deviceInfo.mcu) {
@ -74,7 +75,10 @@ class Workflow extends PureComponent<Props, State> {
return renderDashboard(device, deviceInfo) return renderDashboard(device, deviceInfo)
} }
return renderDefault(device, deviceInfo, dashboardError, isGenuine) return renderDefault(device, deviceInfo, isGenuine, {
genuineError,
dashboardError,
})
}} }}
</EnsureGenuine> </EnsureGenuine>
)} )}

24
src/components/ManagerPage/WorkflowDefault.js

@ -8,7 +8,6 @@ import type { Device, T } from 'types/common'
import { i } from 'helpers/staticPath' import { i } from 'helpers/staticPath'
import Box from 'components/base/Box' import Box from 'components/base/Box'
import Space from 'components/base/Space'
import Text from 'components/base/Text' import Text from 'components/base/Text'
import Spinner from 'components/base/Spinner' import Spinner from 'components/base/Spinner'
@ -97,13 +96,15 @@ type Props = {
t: T, t: T,
device: ?Device, device: ?Device,
deviceInfo: ?DeviceInfo, deviceInfo: ?DeviceInfo,
errors: {
dashboardError: ?Error, dashboardError: ?Error,
genuineError: ?Error,
},
isGenuine: boolean, isGenuine: boolean,
} }
const WorkflowDefault = ({ device, deviceInfo, dashboardError, isGenuine, t }: Props) => ( const WorkflowDefault = ({ device, deviceInfo, errors, isGenuine, t }: Props) => (
<Box align="center"> <Box align="center" justify="center" sticky>
<Space of={152} />
<Box align="center" style={{ maxWidth: 460, padding: '0 10px' }}> <Box align="center" style={{ maxWidth: 460, padding: '0 10px' }}>
<img <img
src={i('logos/connectDevice.png')} src={i('logos/connectDevice.png')}
@ -138,7 +139,7 @@ const WorkflowDefault = ({ device, deviceInfo, dashboardError, isGenuine, t }: P
</Step> </Step>
{/* DASHBOARD CHECK */} {/* DASHBOARD CHECK */}
<Step validated={!!device && !!deviceInfo} hasErrors={!!device && !!dashboardError}> <Step validated={!!device && !!deviceInfo} hasErrors={!!device && !!errors.dashboardError}>
<StepContent> <StepContent>
<StepIcon> <StepIcon>
<WrapperIconCurrency> <WrapperIconCurrency>
@ -152,14 +153,21 @@ const WorkflowDefault = ({ device, deviceInfo, dashboardError, isGenuine, t }: P
{' on your device'} {' on your device'}
</Trans> </Trans>
</Box> </Box>
<StepCheck checked={!!device && !!deviceInfo} hasErrors={!!device && !!dashboardError} /> <StepCheck
checked={!!device && !!deviceInfo}
hasErrors={!!device && !!errors.dashboardError}
/>
</StepContent> </StepContent>
</Step> </Step>
{/* GENUINE CHECK */} {/* GENUINE CHECK */}
<Step <Step
validated={(!!device && !isNull(isGenuine) && isGenuine) || undefined} validated={
hasErrors={(!!device && !isNull(isGenuine) && !isGenuine) || undefined} (!!device && !isNull(isGenuine) && isGenuine && !errors.genuineError) || undefined
}
hasErrors={
(!!device && !isNull(isGenuine) && !isGenuine) || errors.genuineError || undefined
}
> >
<StepContent> <StepContent>
<StepIcon> <StepIcon>

12
src/components/ManagerPage/index.js

@ -24,11 +24,6 @@ type Error = {
function ManagerPage(): Node { function ManagerPage(): Node {
return ( return (
<Workflow <Workflow
renderError={(dashboardError: ?Error, genuineError: ?Error) => {
if (dashboardError) return <span>Dashboard Error: {dashboardError.message}</span>
if (genuineError) return <span>Genuine Error: {genuineError.message}</span>
return <span>Error</span>
}}
renderFinalUpdate={(deviceInfo: DeviceInfo) => ( renderFinalUpdate={(deviceInfo: DeviceInfo) => (
<p>UPDATE FINAL FIRMARE (TEMPLATE + ACTION WIP) {deviceInfo.final}</p> <p>UPDATE FINAL FIRMARE (TEMPLATE + ACTION WIP) {deviceInfo.final}</p>
)} )}
@ -41,13 +36,16 @@ function ManagerPage(): Node {
renderDefault={( renderDefault={(
device: ?Device, device: ?Device,
deviceInfo: ?DeviceInfo, deviceInfo: ?DeviceInfo,
dashboardError: ?Error,
isGenuine: ?boolean, isGenuine: ?boolean,
errors: {
dashboardError: ?Error,
genuineError: ?Error,
},
) => ( ) => (
<WorkflowDefault <WorkflowDefault
device={device} device={device}
deviceInfo={deviceInfo} deviceInfo={deviceInfo}
dashboardError={dashboardError} errors={errors}
isGenuine={isGenuine} isGenuine={isGenuine}
/> />
)} )}

Loading…
Cancel
Save