From 51afb159b0737b1ac3b6739d94e37ae044be93eb Mon Sep 17 00:00:00 2001 From: meriadec Date: Wed, 27 Jun 2018 12:32:55 +0200 Subject: [PATCH] Refacto ManagerPage to use GenuineCheck component --- src/components/GenuineCheck.js | 11 ++- .../ManagerPage/ManagerGenuineCheck.js | 53 ++++++++++++++ src/components/ManagerPage/index.js | 70 +++++++++---------- 3 files changed, 90 insertions(+), 44 deletions(-) create mode 100644 src/components/ManagerPage/ManagerGenuineCheck.js diff --git a/src/components/GenuineCheck.js b/src/components/GenuineCheck.js index 56442003..44a307cf 100644 --- a/src/components/GenuineCheck.js +++ b/src/components/GenuineCheck.js @@ -63,16 +63,13 @@ class GenuineCheck extends PureComponent { checkGenuineInteractionHandler = async ({ device, - infos, + deviceInfo, }: { device: Device, - infos: DeviceInfo, + deviceInfo: DeviceInfo, }) => { const res = await getIsGenuine - .send({ - devicePath: device.path, - deviceInfo: infos, - }) + .send({ devicePath: device.path, deviceInfo }) .pipe(timeout(GENUINE_TIMEOUT)) .toPromise() const isGenuine = res === '0000' @@ -106,7 +103,7 @@ class GenuineCheck extends PureComponent { run: this.connectInteractionHandler, }, { - id: 'infos', + id: 'deviceInfo', title: ( {'Navigate to the '} diff --git a/src/components/ManagerPage/ManagerGenuineCheck.js b/src/components/ManagerPage/ManagerGenuineCheck.js new file mode 100644 index 00000000..d637db48 --- /dev/null +++ b/src/components/ManagerPage/ManagerGenuineCheck.js @@ -0,0 +1,53 @@ +// @flow + +import React, { PureComponent } from 'react' +import { translate } from 'react-i18next' + +import type { T } from 'types/common' + +import { i } from 'helpers/staticPath' + +import GenuineCheck from 'components/GenuineCheck' +import Box from 'components/base/Box' +import Space from 'components/base/Space' +import Text from 'components/base/Text' + +type Props = { + t: T, + onSuccess: void => void, +} + +class ManagerGenuineCheck extends PureComponent { + render() { + const { t, onSuccess } = this.props + return ( + + + connect your device + + {t('app:manager.device.title')} + + + {t('app:manager.device.desc')} + + + + { + console.log(`fail`) + }} + onUnavailable={() => { + console.log(`unavailable`) + }} + /> + + ) + } +} + +export default translate()(ManagerGenuineCheck) diff --git a/src/components/ManagerPage/index.js b/src/components/ManagerPage/index.js index 49a7312b..a8e3ca65 100644 --- a/src/components/ManagerPage/index.js +++ b/src/components/ManagerPage/index.js @@ -1,52 +1,48 @@ // @flow -/* eslint-disable react/jsx-no-literals */ // FIXME: remove import React, { PureComponent } from 'react' +import invariant from 'invariant' import type { Device } from 'types/common' import type { DeviceInfo } from 'helpers/devices/getDeviceInfo' -import Workflow from 'components/Workflow' -import WorkflowWithIcon from 'components/Workflow/WorkflowWithIcon' import Dashboard from './Dashboard' -import FlashMcu from './FlashMcu' +// import FlashMcu from './FlashMcu' -type Error = { - message: string, - stack: string, +import ManagerGenuineCheck from './ManagerGenuineCheck' + +type Props = {} + +type State = { + isGenuine: ?boolean, + device: ?Device, + deviceInfo: ?DeviceInfo, } -class ManagerPage extends PureComponent<*, *> { +class ManagerPage extends PureComponent { + state = { + isGenuine: null, + } + + handleSuccessGenuine = ({ device, deviceInfo }) => { + this.setState({ isGenuine: true, device, deviceInfo }) + } + render() { - return ( - ( -

UPDATE FINAL FIRMARE (TEMPLATE + ACTION WIP) {deviceInfo.isOSU}

- )} - renderMcuUpdate={(device: Device, deviceInfo: DeviceInfo) => ( - - )} - renderDashboard={(device: Device, deviceInfo: DeviceInfo) => ( - - )} - renderDefault={( - device: ?Device, - deviceInfo: ?DeviceInfo, - isGenuine: ?boolean, - errors: { - dashboardError: ?Error, - genuineError: ?Error, - }, - ) => ( - - )} - /> - ) + const { isGenuine, device, deviceInfo } = this.state + + if (!isGenuine) { + return + } + + invariant(device, 'Inexistant device considered genuine') + invariant(deviceInfo, 'Inexistant device infos for genuine device') + + // TODO + // renderFinalUpdate + // renderMcuUpdate + + return } }