Skip to content

Commit 748203a

Browse files
no reset for diff owner
1 parent 030146e commit 748203a

1 file changed

Lines changed: 32 additions & 17 deletions

File tree

  • src/app/clientApp/Devices/List/DevicesListPage/Tabs

src/app/clientApp/Devices/List/DevicesListPage/Tabs/Tab2.tsx

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { messages as d } from '../../../Devices.i18n'
1313
import FormSelect, { selectAligns } from '../../../../../../components/Atomic/FormSelect'
1414
import { DEVICE_AUTH_MODE } from '../../../../constants'
1515
import FormInput, { inputAligns } from '../../../../../../components/Atomic/FormInput'
16-
import { mergeConfig, useIsMounted } from '../../../../../../common/hooks'
16+
import { mergeConfig, useIsMounted, WellKnownConfigType } from '../../../../../../common/hooks'
1717
import AppContext from '../../../../../share/AppContext'
1818
import BottomPanel from '../../../../../../components/Layout/BottomPanel/BottomPanel'
1919
import Button from '../../../../../../components/Atomic/Button'
@@ -25,6 +25,7 @@ import Alert, { severities } from '../../../../../../components/Atomic/Alert'
2525
import { remoteClientStatuses } from '../../../../RemoteClients/constants'
2626
import { security } from '../../../../../../common/services'
2727
import { reset as resetApp } from '../../../../App/AppRest'
28+
import { hasDifferentOwner } from '../../../../../../common/services/api-utils'
2829

2930
interface RowsType {
3031
attribute: string
@@ -296,6 +297,21 @@ const Tab2: FC<Props> = (props) => {
296297
)
297298
}
298299

300+
const differentOwner = useCallback(
301+
(wellKnownConfig: WellKnownConfigType, userWellKnownConfig: any) => hasDifferentOwner(wellKnownConfig, userWellKnownConfig),
302+
[]
303+
)
304+
305+
const onFinish = useCallback(
306+
(dataForSave: any) => {
307+
isFunction(setLoading) && setLoading(false)
308+
isFunction(updateAppWellKnownConfig) && dispatch(updateAppWellKnownConfig(dataForSave))
309+
Notification.success({ title: _(d.configurationUpdate), message: _(d.configurationUpdateMessage) })
310+
},
311+
// eslint-disable-next-line react-hooks/exhaustive-deps
312+
[setLoading, updateAppWellKnownConfig]
313+
)
314+
299315
const onSubmit: SubmitHandler<Inputs> = () => {
300316
const values = getValues()
301317

@@ -313,24 +329,23 @@ const Tab2: FC<Props> = (props) => {
313329
values.audience = values.audience?.value as any
314330
}
315331

332+
const dataForSave = {
333+
...omit(values, getIgnoredFields(values.deviceAuthenticationMode.value)),
334+
deviceAuthenticationMode: values.deviceAuthenticationMode.value,
335+
}
336+
316337
isFunction(setLoading) && setLoading(true)
317338

318-
resetApp()
319-
.then(() => isFunction(setInitialize) && setInitialize(false))
320-
.catch(() => console.log('error'))
321-
.finally(() => {
322-
isFunction(setLoading) && setLoading(false)
323-
// authenticationMode -> deviceAuthenticationMode
324-
isFunction(updateAppWellKnownConfig) &&
325-
dispatch(
326-
updateAppWellKnownConfig({
327-
...omit(values, getIgnoredFields(values.deviceAuthenticationMode.value)),
328-
deviceAuthenticationMode: values.deviceAuthenticationMode.value,
329-
})
330-
)
331-
332-
Notification.success({ title: _(d.configurationUpdate), message: _(d.configurationUpdateMessage) })
333-
})
339+
if (differentOwner(wellKnownConfig, dataForSave)) {
340+
onFinish(dataForSave)
341+
} else {
342+
resetApp()
343+
.then(() => isFunction(setInitialize) && setInitialize(false))
344+
.catch(() => console.log('error'))
345+
.finally(() => {
346+
onFinish(dataForSave)
347+
})
348+
}
334349
}
335350
}
336351

0 commit comments

Comments
 (0)