1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

change content flow

This commit is contained in:
Matthias Kretschmann 2020-10-20 17:41:50 +02:00
parent 9b55934994
commit efcf65813d
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 65 additions and 46 deletions

View File

@ -1,5 +1,10 @@
{ {
"create": { "create": {
"empty": {
"title": "No Price Created",
"info": "This data set has no price yet. As the publisher you can create a fixed price, or a dynamic price for it. Onwards!",
"action": "Create Pricing"
},
"fixed": { "fixed": {
"title": "Fixed", "title": "Fixed",
"info": "Set your price for accessing this data set. The datatoken for this data set will be worth the entered amount of OCEAN." "info": "Set your price for accessing this data set. The datatoken for this data set will be worth the entered amount of OCEAN."

View File

@ -1,5 +1,4 @@
import React, { ReactElement, useEffect } from 'react' import React, { ReactElement, useEffect } from 'react'
import { graphql, useStaticQuery } from 'gatsby'
import styles from './index.module.css' import styles from './index.module.css'
import Tabs from '../../../../atoms/Tabs' import Tabs from '../../../../atoms/Tabs'
import Fixed from './Fixed' import Fixed from './Fixed'
@ -10,46 +9,16 @@ import { PriceOptionsMarket } from '../../../../../@types/MetaData'
import Button from '../../../../atoms/Button' import Button from '../../../../atoms/Button'
import { DDO } from '@oceanprotocol/lib' import { DDO } from '@oceanprotocol/lib'
const query = graphql`
query PriceFieldQuery {
content: allFile(filter: { relativePath: { eq: "price.json" } }) {
edges {
node {
childContentJson {
create {
fixed {
title
info
}
dynamic {
title
info
tooltips {
poolInfo
swapFee
communityFee
marketplaceFee
}
}
}
}
}
}
}
}
`
export default function FormPricing({ export default function FormPricing({
ddo, ddo,
setShowPricing setShowPricing,
content
}: { }: {
ddo: DDO ddo: DDO
setShowPricing: (value: boolean) => void setShowPricing: (value: boolean) => void
content: any
}): ReactElement { }): ReactElement {
const { debug } = useUserPreferences() const { debug } = useUserPreferences()
// Get content
const data = useStaticQuery(query)
const content = data.content.edges[0].node.childContentJson.create
// Connect with form // Connect with form
const { values, setFieldValue, submitForm } = useFormikContext() const { values, setFieldValue, submitForm } = useFormikContext()
@ -88,7 +57,7 @@ export default function FormPricing({
<div className={styles.actions}> <div className={styles.actions}>
<Button style="primary" onClick={() => submitForm()}> <Button style="primary" onClick={() => submitForm()}>
Create Pricing {content.empty.action}
</Button> </Button>
<Button style="text" size="small" onClick={() => setShowPricing(false)}> <Button style="text" size="small" onClick={() => setShowPricing(false)}>
Cancel Cancel

View File

@ -9,8 +9,47 @@ import styles from './index.module.css'
import FormPricing from './FormPricing' import FormPricing from './FormPricing'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import Feedback from './Feedback' import Feedback from './Feedback'
import { graphql, useStaticQuery } from 'gatsby'
const query = graphql`
query PricingQuery {
content: allFile(filter: { relativePath: { eq: "price.json" } }) {
edges {
node {
childContentJson {
create {
empty {
title
info
action
}
fixed {
title
info
}
dynamic {
title
info
tooltips {
poolInfo
swapFee
communityFee
marketplaceFee
}
}
}
}
}
}
}
}
`
export default function Pricing({ ddo }: { ddo: DDO }): ReactElement { export default function Pricing({ ddo }: { ddo: DDO }): ReactElement {
// Get content
const data = useStaticQuery(query)
const content = data.content.edges[0].node.childContentJson.create
const { const {
createPricing, createPricing,
pricingIsLoading, pricingIsLoading,
@ -33,19 +72,24 @@ export default function Pricing({ ddo }: { ddo: DDO }): ReactElement {
// Pricing failed // Pricing failed
if (!tx || pricingError) { if (!tx || pricingError) {
toast.error(pricingError) toast.error(pricingError || 'Price creation failed.')
Logger.error(pricingError) Logger.error(pricingError || 'Price creation failed.')
return return
} }
// Pricing succeeded // Pricing succeeded
tx && setSuccess(`🎉 Successfully created a ${values.type} price. 🎉`) setSuccess(`🎉 Successfully created a ${values.type} price. 🎉`)
} catch (error) { } catch (error) {
toast.error(error.message) toast.error(error.message)
Logger.error(error.message) Logger.error(error.message)
} }
} }
function handleShowPricingForm(e: FormEvent<HTMLButtonElement>) {
e.preventDefault()
setShowPricing(true)
}
return ( return (
<div className={styles.pricing}> <div className={styles.pricing}>
<Formik <Formik
@ -64,18 +108,19 @@ export default function Pricing({ ddo }: { ddo: DDO }): ReactElement {
hasFeedback ? ( hasFeedback ? (
<Feedback success={success} pricingStepText={pricingStepText} /> <Feedback success={success} pricingStepText={pricingStepText} />
) : showPricing ? ( ) : showPricing ? (
<FormPricing ddo={ddo} setShowPricing={setShowPricing} /> <FormPricing
ddo={ddo}
setShowPricing={setShowPricing}
content={content}
/>
) : ( ) : (
<Alert <Alert
state="info" state="info"
title="No Price Created" title={content.empty.title}
text="This data set has no price yet. As the publisher you can create a fixed price, or a dynamic price for it. Onwards!" text={content.empty.info}
action={{ action={{
name: 'Create Pricing', name: content.empty.action,
handleAction: (e: FormEvent<HTMLButtonElement>) => { handleAction: handleShowPricingForm
e.preventDefault()
setShowPricing(true)
}
}} }}
/> />
) )