mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
reset form fix
This commit is contained in:
parent
920d5c59fb
commit
f71eaa854e
@ -5,7 +5,7 @@ import Tags from '../../atoms/Tags'
|
|||||||
import MetaItem from '../../organisms/AssetContent/MetaItem'
|
import MetaItem from '../../organisms/AssetContent/MetaItem'
|
||||||
import styles from './Preview.module.css'
|
import styles from './Preview.module.css'
|
||||||
import File from '../../atoms/File'
|
import File from '../../atoms/File'
|
||||||
import { MetadataPublishForm } from '../../../@types/Metadata'
|
import { MetadataPublishForm } from '../../../@types/MetaData'
|
||||||
|
|
||||||
export default function Preview({
|
export default function Preview({
|
||||||
values
|
values
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { ReactElement, useEffect } from 'react'
|
import React, { ReactElement, useEffect, FormEvent } from 'react'
|
||||||
import styles from './PublishForm.module.css'
|
import styles from './PublishForm.module.css'
|
||||||
import { useOcean, usePublish } from '@oceanprotocol/react'
|
import { useOcean, usePublish } from '@oceanprotocol/react'
|
||||||
import { useFormikContext, Form, Field } from 'formik'
|
import { useFormikContext, Form, Field } from 'formik'
|
||||||
@ -22,9 +22,10 @@ export default function PublishForm({
|
|||||||
setErrors,
|
setErrors,
|
||||||
setTouched,
|
setTouched,
|
||||||
resetForm,
|
resetForm,
|
||||||
|
setValues,
|
||||||
initialValues
|
initialValues
|
||||||
} = useFormikContext()
|
} = useFormikContext()
|
||||||
|
const formName = 'ocean-publish-form'
|
||||||
// reset form validation on every mount
|
// reset form validation on every mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setErrors({})
|
setErrors({})
|
||||||
@ -32,6 +33,14 @@ export default function PublishForm({
|
|||||||
// setSubmitting(false)
|
// setSubmitting(false)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
const resetFormAndClearStorage = async (e: FormEvent<Element>) => {
|
||||||
|
e.preventDefault()
|
||||||
|
|
||||||
|
await resetForm({ values: initialValues, status: 'empty' })
|
||||||
|
|
||||||
|
setStatus('empty')
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form
|
<Form
|
||||||
className={styles.form}
|
className={styles.form}
|
||||||
@ -57,18 +66,14 @@ export default function PublishForm({
|
|||||||
<Button
|
<Button
|
||||||
style="text"
|
style="text"
|
||||||
size="small"
|
size="small"
|
||||||
onClick={(e) => {
|
onClick={resetFormAndClearStorage}
|
||||||
e.preventDefault()
|
|
||||||
resetForm(initialValues)
|
|
||||||
setStatus('empty')
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
Reset Form
|
Reset Form
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</footer>
|
</footer>
|
||||||
)}
|
)}
|
||||||
<Persist name="ocean-publish-form" />
|
<Persist name={formName} />
|
||||||
</Form>
|
</Form>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,12 @@ export default function PublishPage({
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
const metadata = transformPublishFormToMetadata(values)
|
const metadata = transformPublishFormToMetadata(values)
|
||||||
const { tokensToMint, type, weightOnDataToken, ownerFee } = values.price
|
const {
|
||||||
|
tokensToMint,
|
||||||
|
type,
|
||||||
|
weightOnDataToken,
|
||||||
|
liquidityProviderFee
|
||||||
|
} = values.price
|
||||||
const serviceType = values.access === 'Download' ? 'access' : 'compute'
|
const serviceType = values.access === 'Download' ? 'access' : 'compute'
|
||||||
|
|
||||||
console.log(`
|
console.log(`
|
||||||
@ -61,7 +66,7 @@ export default function PublishPage({
|
|||||||
ddo.dataToken,
|
ddo.dataToken,
|
||||||
tokensToMint.toString(),
|
tokensToMint.toString(),
|
||||||
weightOnDataToken,
|
weightOnDataToken,
|
||||||
ownerFee
|
liquidityProviderFee
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,20 +29,20 @@ export const validationSchema = Yup.object().shape<MetadataPublishForm>({
|
|||||||
})
|
})
|
||||||
|
|
||||||
export const initialValues: MetadataPublishForm = {
|
export const initialValues: MetadataPublishForm = {
|
||||||
name: undefined,
|
name: '',
|
||||||
author: undefined,
|
author: '',
|
||||||
price: {
|
price: {
|
||||||
type: 'simple',
|
type: 'simple',
|
||||||
tokensToMint: 1,
|
tokensToMint: 1,
|
||||||
weightOnDataToken: '9', // 90% on data token
|
weightOnDataToken: '9', // 90% on data token
|
||||||
liquidityProviderFee: '0.1' // in %
|
liquidityProviderFee: '0.1' // in %
|
||||||
},
|
},
|
||||||
files: undefined,
|
files: '',
|
||||||
description: undefined,
|
description: '',
|
||||||
license: undefined,
|
license: '',
|
||||||
access: undefined,
|
access: '',
|
||||||
termsAndConditions: false,
|
termsAndConditions: false,
|
||||||
copyrightHolder: undefined,
|
copyrightHolder: '',
|
||||||
tags: undefined,
|
tags: '',
|
||||||
links: undefined
|
links: ''
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user