1515import React , { useCallback } from 'react'
1616import { defineMessages } from 'react-intl'
1717
18- import { IconCamera , IconPlus } from '@ttn-lw/components/icon'
18+ import { IconCamera } from '@ttn-lw/components/icon'
1919import Link from '@ttn-lw/components/link'
2020import ModalButton from '@ttn-lw/components/button/modal-button'
21- import Button from '@ttn-lw/components/button'
22- import Input from '@ttn-lw/components/input'
2321
2422import Message from '@ttn-lw/lib/components/message'
2523import ErrorMessage from '@ttn-lw/lib/components/error-message'
2624
2725import PropTypes from '@ttn-lw/lib/prop-types'
2826import sharedMessages from '@ttn-lw/lib/shared-messages'
29- import { selectPluginTTSCloud } from '@ttn-lw/lib/selectors/env'
3027
3128import DataSheet from '../data-sheet'
3229import QR from '../qr'
3330
34- const smUrl = selectPluginTTSCloud ( ) . subscription_management_url
35-
3631const QrScanDoc = (
3732 < Link . Anchor external secondary href = "https://www.thethingsindustries.com/docs/" >
3833 Having trouble?
@@ -42,40 +37,10 @@ const QrScanDoc = (
4237const m = defineMessages ( {
4338 scanContinue : 'Please scan the QR code to continue. {qrScanDoc}' ,
4439 apply : 'Apply' ,
45- fleetToken : 'Fleet owner token' ,
46- addFleet : 'Add to Fleet' ,
47- addToFleetTooltip :
48- 'You are registering a Managed gateway. If you want to add it to an existing fleet, click here.' ,
4940} )
5041
5142const QRModalButton = props => {
52- const { message, onApprove, onCancel, onRead, qrData, setQrData, invalidMessage } = props
53- const [ isAddToFleet , setIsAddToFleet ] = React . useState ( undefined )
54- const [ fleetOwnerToken , setFleetOwnerToken ] = React . useState ( '' )
55-
56- const handleAddToFleet = useCallback ( ( ) => {
57- setIsAddToFleet ( true )
58- } , [ ] )
59-
60- const handleRemoveFleet = useCallback ( ( ) => {
61- setIsAddToFleet ( false )
62- setFleetOwnerToken ( '' )
63- setQrData ( {
64- ...qrData ,
65- gateway : { ...qrData . gateway , _fleet_owner_token : undefined } ,
66- } )
67- } , [ qrData , setQrData ] )
68-
69- const handleFleetTokenChange = useCallback (
70- value => {
71- setFleetOwnerToken ( value )
72- setQrData ( {
73- ...qrData ,
74- gateway : { ...qrData . gateway , _fleet_owner_token : value } ,
75- } )
76- } ,
77- [ qrData , setQrData ] ,
78- )
43+ const { message, onApprove, onCancel, onRead, qrData, invalidMessage, modalDataChildren } = props
7944
8045 const handleRead = useCallback (
8146 val => {
@@ -90,57 +55,7 @@ const QRModalButton = props => {
9055 qrData . valid ? (
9156 < >
9257 < DataSheet data = { qrData . data } />
93- { qrData . gateway . is_managed && (
94- < >
95- { isAddToFleet ? (
96- < div className = "w-full mt-cs-xs" >
97- < div className = "d-flex j-between" >
98- < Message content = { m . fleetToken } className = "c-text-neutral-semilight" />
99- < Button
100- message = { sharedMessages . remove }
101- onClick = { handleRemoveFleet }
102- className = "c-text-neutral-light fw-bold hover-underline"
103- />
104- </ div >
105- < Message
106- content = { sharedMessages . fleetTokenInfo }
107- values = { {
108- Link : val => (
109- < Link . Anchor secondary href = { `${ smUrl } /dashboard` } external >
110- { val }
111- </ Link . Anchor >
112- ) ,
113- } }
114- className = "mb-cs-xs mt-cs-xxs c-text-neutral-light fs-s"
115- component = "div"
116- />
117- < Input
118- type = "code"
119- sensitive
120- className = "w-full"
121- inputWidth = "full"
122- value = { fleetOwnerToken }
123- onChange = { handleFleetTokenChange }
124- />
125- < Message
126- content = { sharedMessages . fleetInfo }
127- className = "mt-cs-xs c-text-neutral-light fs-s"
128- component = "div"
129- />
130- </ div >
131- ) : (
132- < Button
133- tertiary
134- message = { m . addFleet }
135- icon = { IconPlus }
136- onClick = { handleAddToFleet }
137- className = "mt-cs-xs"
138- tooltip = { m . addToFleetTooltip }
139- tooltipPlacement = "bottom"
140- />
141- ) }
142- </ >
143- ) }
58+ { modalDataChildren }
14459 </ >
14560 ) : (
14661 < ErrorMessage content = { invalidMessage } />
@@ -185,6 +100,7 @@ const QRModalButton = props => {
185100QRModalButton . propTypes = {
186101 invalidMessage : PropTypes . message . isRequired ,
187102 message : PropTypes . message . isRequired ,
103+ modalDataChildren : PropTypes . node ,
188104 onApprove : PropTypes . func . isRequired ,
189105 onCancel : PropTypes . func . isRequired ,
190106 onRead : PropTypes . func . isRequired ,
@@ -195,11 +111,11 @@ QRModalButton.propTypes = {
195111 is_managed : PropTypes . bool ,
196112 } ) ,
197113 } ) ,
198- setQrData : PropTypes . func . isRequired ,
199114}
200115
201116QRModalButton . defaultProps = {
202117 qrData : undefined ,
118+ modalDataChildren : null ,
203119}
204120
205121export default QRModalButton
0 commit comments