import Input from '@shared/FormInput' import { Field, useFormikContext } from 'formik' import React, { ReactElement, useEffect } from 'react' import IconDownload from '@images/download.svg' import IconCompute from '@images/compute.svg' import content from '../../../../content/publish/form.json' import consumerParametersContent from '../../../../content/publish/consumerParameters.json' import { getFieldContent } from '@utils/form' import { FormPublishData } from '../_types' import Alert from '@shared/atoms/Alert' import { useMarketMetadata } from '@context/MarketMetadata' import styles from '../index.module.css' const accessTypeOptionsTitles = getFieldContent( 'access', content.services.fields ).options export default function ServicesFields(): ReactElement { const { siteContent } = useMarketMetadata() // connect with Form state, use for conditional field rendering const { values, setFieldValue } = useFormikContext() // name and title should be download, but option value should be access, probably the best way would be to change the component so that option is an object like {name,value} const accessTypeOptions = [ { name: 'download', value: accessTypeOptionsTitles[0].toLowerCase(), title: 'Download', icon: , // BoxSelection component is not a Formik component // so we need to handle checked state manually. checked: values.services[0].access === accessTypeOptionsTitles[0].toLowerCase() }, { name: accessTypeOptionsTitles[1].toLowerCase(), value: accessTypeOptionsTitles[1].toLowerCase(), title: accessTypeOptionsTitles[1], icon: , checked: values.services[0].access === accessTypeOptionsTitles[1].toLowerCase() } ] // Auto-change access type based on algo privacy boolean. // Could be also done later in transformPublishFormToDdo(). useEffect(() => { if ( values.services[0].algorithmPrivacy === null || values.services[0].algorithmPrivacy === undefined ) return setFieldValue( 'services[0].access', values.services[0].algorithmPrivacy === true ? 'compute' : 'access' ) }, [values.services[0].algorithmPrivacy, setFieldValue]) return ( <> {values.metadata.type === 'algorithm' ? ( ) : ( <> )} {values.services[0].usesConsumerParameters && ( )} ) }