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

wrapping publish in permissions wrapper

This commit is contained in:
Jamie Hewitt 2021-05-20 17:18:23 +03:00
parent f74ec8dce5
commit 440afbdc05
3 changed files with 87 additions and 80 deletions

View File

@ -94,8 +94,8 @@ function SectionQueryResult({
export default function HomePage(): ReactElement { export default function HomePage(): ReactElement {
return ( return (
<> <Permission eventType="browse">
<Permission eventType="browse"> <>
<Container narrow className={styles.searchWrap}> <Container narrow className={styles.searchWrap}>
<SearchBar size="large" /> <SearchBar size="large" />
</Container> </Container>
@ -127,7 +127,7 @@ export default function HomePage(): ReactElement {
</Button> </Button>
} }
/> />
</Permission> </>
</> </Permission>
) )
} }

View File

@ -1,4 +1,5 @@
import React, { ReactElement, useState, useEffect } from 'react' import React, { ReactElement, useState, useEffect } from 'react'
import Permission from '../../organisms/Permission'
import { Formik, FormikState } from 'formik' import { Formik, FormikState } from 'formik'
import { usePublish } from '../../../hooks/usePublish' import { usePublish } from '../../../hooks/usePublish'
import styles from './index.module.css' import styles from './index.module.css'
@ -216,86 +217,92 @@ export default function PublishPage({
} }
return isInPurgatory && purgatoryData ? null : ( return isInPurgatory && purgatoryData ? null : (
<Formik <Permission eventType="publish">
initialValues={ <Formik
publishType === 'dataset' ? datasetInitialValues : algoInitialValues initialValues={
} publishType === 'dataset' ? datasetInitialValues : algoInitialValues
initialStatus="empty" }
validationSchema={ initialStatus="empty"
publishType === 'dataset' ? validationSchema : validationSchemaAlgorithm validationSchema={
} publishType === 'dataset'
onSubmit={async (values, { resetForm }) => { ? validationSchema
// move user's focus to top of screen : validationSchemaAlgorithm
window.scrollTo({ top: 0, left: 0, behavior: 'smooth' }) }
// kick off publishing onSubmit={async (values, { resetForm }) => {
publishType === 'dataset' // move user's focus to top of screen
? await handleSubmit(values, resetForm) window.scrollTo({ top: 0, left: 0, behavior: 'smooth' })
: await handleAlgorithmSubmit(values, resetForm) // kick off publishing
}} publishType === 'dataset'
enableReinitialize ? await handleSubmit(values, resetForm)
> : await handleAlgorithmSubmit(values, resetForm)
{({ values }) => { }}
const tabs = [ enableReinitialize
{ >
title: 'Data Set', {({ values }) => {
content: <TabContent values={values} publishType={publishType} /> const tabs = [
}, {
{ title: 'Data Set',
title: 'Algorithm', content: <TabContent values={values} publishType={publishType} />
content: <TabContent values={values} publishType={publishType} /> },
} {
] title: 'Algorithm',
content: <TabContent values={values} publishType={publishType} />
}
]
return ( return (
<> <>
<Persist <Persist
name={ name={
publishType === 'dataset' publishType === 'dataset'
? formNameDatasets ? formNameDatasets
: formNameAlgorithms : formNameAlgorithms
} }
ignoreFields={['isSubmitting']} ignoreFields={['isSubmitting']}
/>
{hasFeedback ? (
<MetadataFeedback
title={title}
error={error}
success={success}
loading={publishStepText}
setError={setError}
successAction={{
name: `Go to ${
publishType === 'dataset' ? 'data set' : 'algorithm'
} `,
to: `/asset/${did}`
}}
/> />
) : (
<>
<Alert
text={content.warning}
state="info"
className={styles.alert}
/>
<Tabs {hasFeedback ? (
className={styles.tabs} <MetadataFeedback
items={tabs} title={title}
handleTabChange={(title) => { error={error}
setPublishType(title.toLowerCase().replace(' ', '') as any) success={success}
title === 'Algorithm' loading={publishStepText}
? setdatasetInitialValues(values) setError={setError}
: setAlgoInitialValues(values) successAction={{
name: `Go to ${
publishType === 'dataset' ? 'data set' : 'algorithm'
} `,
to: `/asset/${did}`
}} }}
/> />
</> ) : (
)} <>
<Alert
text={content.warning}
state="info"
className={styles.alert}
/>
{debug === true && <Debug values={values} />} <Tabs
</> className={styles.tabs}
) items={tabs}
}} handleTabChange={(title) => {
</Formik> setPublishType(
title.toLowerCase().replace(' ', '') as any
)
title === 'Algorithm'
? setdatasetInitialValues(values)
: setAlgoInitialValues(values)
}}
/>
</>
)}
{debug === true && <Debug values={values} />}
</>
)
}}
</Formik>
</Permission>
) )
} }

View File

@ -12,7 +12,7 @@ export default async function rbacRequest(eventType: string): Promise<boolean> {
eventType, eventType,
credentials: { credentials: {
token: token:
'1e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