-1

I am new to contentful. I am trying to develop an UI extension on Contentful using Contentful SDK.

I followed all the steps mentioned in this article.

This is the code I have in index.js.

import React from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
import { TextInput , Button } from '@contentful/forma-36-react-components';
import { init } from 'contentful-ui-extensions-sdk';
import '@contentful/forma-36-react-components/dist/styles.css';
import './index.css';

export class App extends React.Component {
  static propTypes = {
    sdk: PropTypes.object.isRequired
  };

  detachExternalChangeHandler = null;

  constructor(props) {
    super(props);
    this.state = {
      value: props.sdk.field.getValue() || ''
    };
  }

  componentDidMount() {
    this.props.sdk.window.startAutoResizer();

    // Handler for external field value changes (e.g. when multiple authors are working on the same entry).
    this.detachExternalChangeHandler = this.props.sdk.field.onValueChanged(this.onExternalChange);
  }

  componentWillUnmount() {
    if (this.detachExternalChangeHandler) {
      this.detachExternalChangeHandler();
    }
  }

  onExternalChange = value => {
    this.setState({ value });
  };

  onChange = e => {
    const value = e.currentTarget.value;
    this.setState({ value });
    if (value) {
      this.props.sdk.field.setValue(value);
    } else {
      this.props.sdk.field.removeValue();
    }
  };
  onButtonClick = async () => {
   console.log('hurray');
  };

  render() {
    return (
      <Button buttonType="primary" isFullWidth={false}
      onClick={this.onButtonClick}>
      Add Content from AEM DAM
      </Button>
    );
  }
}

Ideally i am trying to create an UI extension to be used in contentful space. I downloaded the contentful SDK and i have put in a button. But I receive this error on the console and it doesn't work Screenshot:

enter image description here

VHaarish
  • 81
  • 9

1 Answers1

0

https://github.com/contentful/create-contentful-extension

Go to the content of this Content Type and enable mixed content at your browser so that development version that is served from your local machine could be rendered within https://app.contentful.com.

Better yet:

I'm not the biggest fan of disabling the mixed content setting in browsers. Can I use HTTPS in development mode? Yes, you can serve your extension using HTTPS. Add --https to start command.

"start": "contentful-extension-scripts start --https", It uses Parcel HTTPS under the hood , which generates a self-signed certificate, you might have to configure your browser to allow self-signed certificates for localhost.

I think that will fix the 404 error and get things working.

Please follow the readme carefully and post a separate question if you still have problems.

Michael Ribbons
  • 1,753
  • 1
  • 16
  • 26
  • Thank you.. I tried enabling the mixed content. and I am still getting this 404 error on ui_config. I don't see the Mixed content error on my browsr. but I see the 404 error on the UI config – VHaarish Feb 12 '20 at 16:48
  • I can see a mixed content warning in your screen shot. Try using the https method. – Michael Ribbons Feb 12 '20 at 21:58