mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-28 14:50:08 +03:00
parent
9983b79a5c
commit
6fe6728da9
src/fireedge/src/client
containers
hooks
services
utils
@ -16,13 +16,13 @@ import useGeneral from 'client/hooks/useGeneral'
|
||||
function ProviderCreateForm () {
|
||||
const history = useHistory()
|
||||
const { id } = useParams()
|
||||
const { showError } = useGeneral()
|
||||
const isUpdate = id !== undefined
|
||||
|
||||
const {
|
||||
steps,
|
||||
defaultValues,
|
||||
resolvers
|
||||
} = Steps({ isUpdate: id !== undefined })
|
||||
} = Steps({ isUpdate })
|
||||
|
||||
const {
|
||||
getProvider,
|
||||
@ -31,6 +31,7 @@ function ProviderCreateForm () {
|
||||
updateProvider,
|
||||
providersTemplates
|
||||
} = useProvision()
|
||||
const { showError } = useGeneral()
|
||||
|
||||
const { data, fetchRequestAll, loading, error } = useFetchAll()
|
||||
|
||||
@ -41,7 +42,7 @@ function ProviderCreateForm () {
|
||||
})
|
||||
|
||||
const onSubmit = formData => {
|
||||
const { provider, location, connection } = formData
|
||||
const { provider, location, connection, registration_time: time } = formData
|
||||
const providerSelected = provider[0]
|
||||
const locationSelected = location[0]
|
||||
|
||||
@ -49,14 +50,16 @@ function ProviderCreateForm () {
|
||||
.find(({ name }) => name === providerSelected) ?? {}
|
||||
|
||||
const formatData = {
|
||||
name: `${providerSelected}_${locationSelected}`,
|
||||
...(!isUpdate && { name: `${providerSelected}_${locationSelected}` }),
|
||||
provider: providerSelected,
|
||||
connection: {
|
||||
...connection,
|
||||
[providerTemplate.location_key]: locationSelected
|
||||
}
|
||||
},
|
||||
registration_time: time
|
||||
}
|
||||
|
||||
if (id) {
|
||||
if (isUpdate) {
|
||||
updateProvider({ id, data: formatData })
|
||||
.then(() => history.push(PATH.PROVIDERS.LIST))
|
||||
} else {
|
||||
@ -66,15 +69,15 @@ function ProviderCreateForm () {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
id && fetchRequestAll([getProvider({ id }), getProvidersTemplates()])
|
||||
}, [id])
|
||||
isUpdate && fetchRequestAll([getProvider({ id }), getProvidersTemplates()])
|
||||
}, [isUpdate])
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
const [provider = {}, templates = []] = data
|
||||
|
||||
const { TEMPLATE: { PROVISION_BODY = {} } } = provider
|
||||
const { connection, provider: providerName } = PROVISION_BODY
|
||||
const { connection, provider: providerName, registration_time: time } = PROVISION_BODY
|
||||
|
||||
const {
|
||||
location_key: key
|
||||
@ -91,6 +94,7 @@ function ProviderCreateForm () {
|
||||
|
||||
methods.reset({
|
||||
provider: [providerName],
|
||||
registration_time: time,
|
||||
connection: connections,
|
||||
location: [location]
|
||||
}, { errors: false })
|
||||
@ -101,7 +105,7 @@ function ProviderCreateForm () {
|
||||
return <Redirect to={PATH.PROVIDERS.LIST} />
|
||||
}
|
||||
|
||||
return (id && !data) || loading ? (
|
||||
return (isUpdate && !data) || loading ? (
|
||||
<LinearProgress />
|
||||
) : (
|
||||
<Container style={{ display: 'flex', flexFlow: 'column' }} disableGutters>
|
||||
|
@ -22,6 +22,7 @@ function ProvisionCreateForm () {
|
||||
})
|
||||
|
||||
const onSubmit = data => {
|
||||
console.log(data)
|
||||
createProvision({ data })
|
||||
.then(() => history.push(PATH.PROVISIONS.LIST))
|
||||
}
|
||||
|
@ -77,39 +77,34 @@ export default function useOpennebula () {
|
||||
({ data }) =>
|
||||
serviceProvision
|
||||
.createProvider({ data })
|
||||
.then(doc => dispatch(
|
||||
enqueueSuccess(`Template created - ID: ${doc?.ID}`))
|
||||
.then(id => dispatch(
|
||||
enqueueSuccess(`Template created - ID: ${id}`))
|
||||
)
|
||||
.catch(err => dispatch(
|
||||
enqueueError(err?.message ?? 'Error CREATE provider')
|
||||
)),
|
||||
[dispatch, providers]
|
||||
.catch(err => dispatch(enqueueError(err ?? 'Error CREATE provider')))
|
||||
, [dispatch, providers]
|
||||
)
|
||||
|
||||
const updateProvider = useCallback(
|
||||
({ id, data }) =>
|
||||
serviceProvision
|
||||
.updateProvider({ id, data })
|
||||
.then(doc => dispatch(
|
||||
enqueueSuccess(`Template updated - ID: ${doc?.ID}`))
|
||||
.then(() => dispatch(
|
||||
enqueueSuccess(`Template updated - ID: ${id}`))
|
||||
)
|
||||
.catch(err => dispatch(
|
||||
enqueueError(err?.message ?? 'Error UPDATE provider')
|
||||
)),
|
||||
[dispatch, providers]
|
||||
.catch(err => dispatch(enqueueError(err ?? 'Error UPDATE provider')))
|
||||
, [dispatch, providers]
|
||||
)
|
||||
|
||||
const deleteProvider = useCallback(
|
||||
({ id }) =>
|
||||
serviceProvision
|
||||
.deleteProvider({ id })
|
||||
.then(doc => dispatch(
|
||||
enqueueSuccess(`Template deleted - ID: ${doc?.ID}`))
|
||||
)
|
||||
.catch(err => dispatch(
|
||||
enqueueError(err?.message ?? 'Error DELETE provider')
|
||||
)),
|
||||
[dispatch]
|
||||
.then(() => {
|
||||
dispatch(enqueueSuccess(`Template deleted - ID: ${id}`))
|
||||
dispatch(setProviders(providers.filter(({ ID }) => ID !== id)))
|
||||
})
|
||||
.catch(err => dispatch(enqueueError(err ?? 'Error DELETE provider')))
|
||||
, [dispatch, providers]
|
||||
)
|
||||
|
||||
// --------------------------------------------
|
||||
|
@ -52,7 +52,8 @@ export const getProviders = ({ filter }) =>
|
||||
export const createProvider = ({ data = {} }) =>
|
||||
requestData(`/api/${PROVIDER}/create`, {
|
||||
data,
|
||||
method: POST
|
||||
method: POST,
|
||||
error: err => err?.message
|
||||
}).then(res => {
|
||||
if (!res?.id || res?.id !== httpCodes.ok.id) throw res
|
||||
|
||||
@ -62,7 +63,8 @@ export const createProvider = ({ data = {} }) =>
|
||||
export const updateProvider = ({ id, data = {} }) =>
|
||||
requestData(`/api/${PROVIDER}/update/${id}`, {
|
||||
data,
|
||||
method: PUT
|
||||
method: PUT,
|
||||
error: err => err?.message
|
||||
}).then(res => {
|
||||
if (!res?.id || res?.id !== httpCodes.ok.id) throw res
|
||||
|
||||
@ -124,7 +126,8 @@ export const getProvision = ({ id }) =>
|
||||
export const getProvisions = ({ filter }) =>
|
||||
requestData(`/api/${PROVISION}/list`, {
|
||||
data: { filter },
|
||||
method: GET
|
||||
method: GET,
|
||||
error: err => err?.message
|
||||
}).then(res => {
|
||||
if (!res?.id || res?.id !== httpCodes.ok.id) throw res
|
||||
|
||||
|
@ -27,7 +27,7 @@ const defaultData = {
|
||||
method: 'GET',
|
||||
authenticate: true,
|
||||
onUploadProgress: null,
|
||||
error: e => e
|
||||
error: err => err
|
||||
}
|
||||
|
||||
export const storage = (name = '', data = '', keepData = false) => {
|
||||
@ -104,7 +104,7 @@ export const requestData = (url = '', data = {}) => {
|
||||
? response.data.json()
|
||||
: response.data
|
||||
}
|
||||
throw new Error(response.statusText)
|
||||
throw new Error(response?.data?.message ?? response?.statusText)
|
||||
})
|
||||
.catch(err => {
|
||||
const configErrorParser = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user