Skip to content

Commit

Permalink
F #3951: Fix provider form with hide credentials (#1092)
Browse files Browse the repository at this point in the history
(cherry picked from commit cefab36)
  • Loading branch information
Sergio Betanzos authored and rsmontero committed Apr 26, 2021
1 parent b44d880 commit 2384d48
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
36 changes: 20 additions & 16 deletions src/fireedge/src/client/containers/Providers/Form/Create/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { yupResolver } from '@hookform/resolvers'
import FormStepper from 'client/components/FormStepper'
import Steps from 'client/containers/Providers/Form/Create/Steps'

import { useFetch, useProvision, useGeneral } from 'client/hooks'
import { useFetchAll, useGeneral, useProvision } from 'client/hooks'
import * as ProviderTemplateModel from 'client/models/ProviderTemplate'
import { PATH } from 'client/router/provision'

Expand All @@ -19,11 +19,12 @@ function ProviderCreateForm () {

const {
getProvider,
getProviderConnection,
createProvider,
updateProvider
} = useProvision()

const { data, fetchRequest, loading, error } = useFetch(getProvider)
const { data, fetchRequestAll, loading, error } = useFetchAll()
const { steps, defaultValues, resolvers } = Steps({ isUpdate })
const { showError, changeLoading } = useGeneral()

Expand Down Expand Up @@ -72,19 +73,19 @@ function ProviderCreateForm () {
const callUpdateProvider = formData => {
const { configuration, connection: connectionEditable } = formData
const { description } = configuration
const [provider = {}, connection = []] = data

const {
PLAIN: { location_key: locationKey } = {},
PROVISION_BODY: {
connection: { [locationKey]: connectionFixed },
registration_time: registrationTime
}
} = data?.TEMPLATE
PROVISION_BODY: currentBodyTemplate
} = provider?.TEMPLATE

const { [locationKey]: connectionFixed } = connection

const formatData = {
...currentBodyTemplate,
description,
connection: { ...connectionEditable, [locationKey]: connectionFixed },
registration_time: registrationTime
connection: { ...connectionEditable, [locationKey]: connectionFixed }
}

updateProvider({ id, data: formatData })
Expand All @@ -97,19 +98,22 @@ function ProviderCreateForm () {
}

useEffect(() => {
isUpdate && fetchRequest({ id })
isUpdate && fetchRequestAll([
getProvider({ id }),
getProviderConnection({ id })
])
}, [isUpdate])

useEffect(() => {
if (data) {
const [provider = {}, connection = []] = data

const {
PLAIN: { location_key: locationKey } = {},
PROVISION_BODY: {
connection: { [locationKey]: _, ...connectionEditable },
description,
name
}
} = data?.TEMPLATE
PROVISION_BODY: { description, name }
} = provider?.TEMPLATE

const { [locationKey]: _, ...connectionEditable } = connection

methods.reset({
connection: connectionEditable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Info = memo(({ data }) => {
icon={<Visibility />}
cy='provider-connection'
handleClick={() => getProviderConnection({ id: ID })
.then(connection => setShowConnection(connection))}
.then(setShowConnection)}
/>
)

Expand Down

0 comments on commit 2384d48

Please sign in to comment.