The form doesn't post the data

I’m unable to post the data from my local dev server to 8base. I’m not getting any errors: it simply doesn’t post the data. The form redirects successfully to the confirmation page.

I’m running Gatsby with Carbon Design System theme. Here is the source code for the mdx page and the component

________________________________ ArticleDetailsForm.js

import React, { useState } from ‘react’;
import gql from ‘graphql-tag’;
import { graphql } from ‘react-apollo’;
import { toast } from ‘react-toastify’;
import ‘carbon-components/css/carbon-components.min.css’;
import { Form, Button, TextInput, TextArea } from ‘carbon-components-react’;
import TagsInput from ‘react-tagsinput’; // yarn add react-tagsinput - it didn’t work
import subject from ‘…/./subject.js’;
import genre from ‘…/./genre.js’;
import { MultiSelect } from ‘carbon-components-react’;
import { FileUploader } from ‘carbon-components-react’;
// import { FileInput } from ‘@8base/file-input’; // do I meed this?

const ArticleDetailsForm = ( { articleCreate }) => {
const [ shortTitle, setTitle ] = useState(“My First Draft”);
const [ longTitle, setTitleLong ] = useState("");
const [ articleText, setArticleText ] = useState("");
const [ coAuthor, setCoauthor ] = useState("");
const [ editor, setEditor ] = useState("");
const [ filmTitle, setFilmTitle ] = useState("");
const [ filmDirector, setFilmDirector ] = useState("");
const [ filmProductionStudio, setFilmProductionStudio ] = useState("");
const [ tags, setTags ] = useState([]);
// set value for default selection
const [selectedSubjectValue, setSelectedSubjectValue] = useState([]);
const [selectedGenreValue, setSelectedGenreValue] = useState([]);

// set value for file uploader
// https://www.educative.io/edpresso/file-upload-in-react
const [selectedFile, setSelectedFile] = useState(null);
const [file, setFile] = useState("");

// handle onChange event for file upload
const handleUpload = (event) => {
  setFile(event.target.files[0]);

  // Add code here to upload file to server
  // ...
}


// handle onChange event of the dropdowns
// https://www.telerik.com/kendo-react-ui/components/dropdowns/multiselect/binding/
const handleSubjectChange = (e) => {
setSelectedSubjectValue(Array.isArray(e) ? e.map(x => x.value) : []);
}

const handleGenreChange = (e) => {
  setSelectedGenreValue(Array.isArray(e) ? e.map(x => x.value) : []);
}

const handleTitleChange = (e) => {
  setTitle(e.nativeEvent.target.value);
}


const handleTitleLongChange = (e) => {
  setTitleLong(e.nativeEvent.target.value);
}

const handleTextChange = (e) => {
  setArticleText(e.nativeEvent.target.value);
}

const handleCoauthorChange = (e) => {
  setCoauthor(e.nativeEvent.target.value);
}

const handleEditorChange = (e) => {
  setEditor(e.nativeEvent.target.value);
}

const handleFilmTitleChange = (e) => {
  setFilmTitle(e.nativeEvent.target.value);
}

const handleFilmDirectorChange = (e) => {
  setFilmDirector(e.nativeEvent.target.value);
}

const handleFilmProductionStudioChange = (e) => {
  setFilmProductionStudio(e.nativeEvent.target.value);
}

const handleTagsChange = (e) => {
  setTags(e.nativeEvent.target.value);
}

const handleSubmit = async (e) => {
  e.preventDefault();
  await articleCreate({ variables: { data: { shortTitle: shortTitle, longTitle: longTitle  } } });
  // toast('Your question has been added successfully');

};

return (
  <Form className="form" id="new-article-form" onSubmit={handleSubmit}>
    <TextInput
      helperText=""
      id="short-title"
      invalidText="Special characters or numbers are not allowed"
      labelText="Short Title"
      placeholder=""
      value={shortTitle}
      onChange={handleTitleChange}
    />
    <TextInput
      helperText=""
      id="long-title"
      invalidText="Special characters or numbers are not allowed"
      labelText="Long Title"
      placeholder=""
      value={longTitle}
      onChange={handleTitleLongChange}
    />
    <FileUploader
      accept={[
        '.jpg',
        '.png'
      ]}
      buttonKind="secondary"
      buttonLabel="Add file"
      filenameStatus="edit"
      iconDescription="Clear file"
      labelDescription="only .jpg or .png files at 500mb or less"
      labelTitle="Thumbnail Image"
      onChange={handleUpload}
    />

    <FileUploader
      accept={[
        '.jpg',
        '.png'
      ]}
      buttonKind="secondary"
      buttonLabel="Add file"
      filenameStatus="edit"
      iconDescription="Clear file"
      labelDescription="only .jpg or .png files at 500mb or less"
      labelTitle="Cover Image"
    />
    <TextArea
      cols={50}
      helperText=""
      id="articleText"
      invalidText="Invalid error message."
      labelText="Text"
      placeholder="Enter Your Article text"
      rows={4}
      value={articleText}
      onChange={handleTextChange}
    />
    <TextInput
      helperText=""
      id="coauthor"
      invalidText="Special characters or numbers are not allowed"
      labelText="Co-Author"
      placeholder=""
      value={coAuthor}
      onChange={handleCoauthorChange}
    />

    <TextInput
      helperText=""
      id="editor"
      invalidText="Special characters or numbers are not allowed"
      labelText="Editor"
      placeholder=""
      value={editor}
      onChange={handleEditorChange}
    />

    <MultiSelect
      data={subject}
      items={subject}
      value={selectedSubjectValue} 
      //items={subject.filter(obj => selectedValue.includes(obj.value))} // set selected values
      ariaLabel="MultiSelect"
      id="carbon-multiselect-example"
      label="Please select all that apply"
      titleText="Subject"
      onChange={handleSubjectChange} // assign onChange function
    />

    <MultiSelect
      data={genre}
      items={genre}
      value={selectedGenreValue} 
      ariaLabel="MultiSelect"
      id="carbon-multiselect-example"
      label="Please select all that apply"
      titleText="Genre"
      onChange={handleGenreChange} // assign onChange function
    />

    <TextInput
      helperText=""
      id="film"
      invalidText="Special characters or numbers are not allowed"
      labelText="Film Title"
      placeholder=""
      value={filmTitle}
      onChange={handleFilmTitleChange}
    />

    <TextInput
      helperText=""
      id="director"
      invalidText="Special characters or numbers are not allowed"
      labelText="Director"
      placeholder=""
      value={filmDirector}
      onChange={handleFilmDirectorChange}
    />

    <TextInput
      helperText=""
      id="studio"
      invalidText="Special characters or numbers are not allowed"
      labelText="Production Studio"
      placeholder=""
      value={filmProductionStudio}
      onChange={handleFilmProductionStudioChange}
    />

    <TextInput
      helperText=""
      id="tags"
      invalidText="Special characters or numbers are not allowed"
      labelText="Tags"
      placeholder=""
      value={tags}
      onChange={handleTagsChange}
    />

    <div className="centered">
      <Button
        kind="tertiary"
        tabIndex={0}
        type="submit"
        onSubmit={handleSubmit} // assign onChange function
        // I need a code to return to the previous location
      >
        Cancel  
      </Button>  
      <Button
        kind="tertiary"
        tabIndex={0}
        type="submit"
        // I need a code to add the article to the database
      >
        Save  
      </Button>
      <Button
        kind="primary"
        tabIndex={0}
        type="submit"
        href="/articles/thankyou"
        // I need a code to change the status from draft to pending
      >
        Publish    
      </Button>
    </div>

  </Form>

);

}

// 8base tutorial code

const ARTICLE_CREATE_MUTATION = gqlmutation ArticleCreate($data: ArticleCreateInput!) { articleCreate(data: $data) { id } };
export default graphql(ARTICLE_CREATE_MUTATION, {
name: ‘articleCreate’,
})(ArticleDetailsForm);

________________________________. new.mdx page


title: Article Draft
description: Publish your article

import ArticleDetailsForm from ‘…/…/components/ArticleDetailsForm’;
import { ApolloProvider, Query } from “react-apollo”;
import { client } from “…/…/…/8base.config.js”;
import { ARTICLES_QUERY } from “…/…/queries/index”;

Draft: Let’s Get Started!

Hello!

I’ve got your problem. I’ll let you know soon.

Lada Kokotova | Technical Support Engineer

Hello!

Firstly, you should check that mutation send from your side. Open browser and open the network tab. If it was sent you need to check that record was created in the 8base table(app.8base.com). Please let us know about your results

Lada Kokotova | Technical Support Engineer

Lada, here is the network tab before and after the form submission (I did not observe any changes)

And here is my 8base config file:


Please let me know what I’m missing…

Hello!

Please can you check that the handleSubmit method has been called?

const handleSubmit = async (e) => {
e.preventDefault();
console.log(‘handleSubmit’, e);
console.log(‘articleCreate’, articleCreate);
await articleCreate({ variables: { data: { shortTitle: shortTitle, longTitle: longTitle } } })
.then((res) => console.log(‘res’, res))
.catch(err => console.log(‘err’, err));
// toast(‘Your question has been added successfully’);
}

Lada Kokotova | Technical Support Engineer

Lada, I tested it, but I didn’t get any messages in console.
I also noticed a warning message that references Apollo

Try to delete ‘href="/articles/thankyou"’

Lada Kokotova | Technical Support Engineer

I commented out // href="/articles/thankyou"

Here is the console network test before and after the submission

Hello Anna!

Please check the console. Maybe it showed an error. And click on the red line and check what the error is.

Lada Kokotova | Technical Support Engineer

Lada, here is the console error:

https://api.8base.com/cknkou6vh008o0cme2pup9glz 400
(anonymous) @ bundle.esm.js:69
Subscription @ Observable.js:197
subscribe @ Observable.js:279
(anonymous) @ bundle.esm.js:864
Subscription @ Observable.js:197
subscribe @ Observable.js:279
(anonymous) @ bundle.esm.js:1001
(anonymous) @ bundle.esm.js:998
step @ tslib.es6.js:100
(anonymous) @ tslib.es6.js:81
(anonymous) @ tslib.es6.js:74
__awaiter @ tslib.es6.js:70
./node_modules/apollo-client/bundle.esm.js.QueryManager.mutate @ bundle.esm.js:950
./node_modules/apollo-client/bundle.esm.js.ApolloClient.mutate @ bundle.esm.js:2016
Mutation._this.mutate @ react-apollo.esm.js:457
Mutation._this.runMutation @ react-apollo.esm.js:432
_callee$ @ ArticleDetailsForm.js:98
tryCatch @ runtime.js:63
invoke @ runtime.js:293
(anonymous) @ runtime.js:118
asyncGeneratorStep @ asyncToGenerator.js:3
_next @ asyncToGenerator.js:25
(anonymous) @ asyncToGenerator.js:32
(anonymous) @ asyncToGenerator.js:21
handleSubmit @ ArticleDetailsForm.js:98
callCallback @ react-dom.development.js:189
invokeGuardedCallbackDev @ react-dom.development.js:238
invokeGuardedCallback @ react-dom.development.js:293
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:307
executeDispatch @ react-dom.development.js:390
executeDispatchesInOrder @ react-dom.development.js:415
executeDispatchesAndRelease @ react-dom.development.js:3279
executeDispatchesAndReleaseTopLevel @ react-dom.development.js:3288
forEachAccumulated @ react-dom.development.js:3260
runEventsInBatch @ react-dom.development.js:3305
runExtractedPluginEventsInBatch @ react-dom.development.js:3515
handleTopLevel @ react-dom.development.js:3559
batchedEventUpdates$1 @ react-dom.development.js:21872
batchedEventUpdates @ react-dom.development.js:796
dispatchEventForLegacyPluginEventSystem @ react-dom.development.js:3569
attemptToDispatchEvent @ react-dom.development.js:4268
dispatchEvent @ react-dom.development.js:4190
unstable_runWithPriority @ scheduler.development.js:653
runWithPriority$1 @ react-dom.development.js:11040
discreteUpdates$1 @ react-dom.development.js:21888
discreteUpdates @ react-dom.development.js:807
dispatchDiscreteEvent @ react-dom.development.js:4169

ArticleDetailsForm.js:104 err Error: Network error: Response not successful: Received status code 400
at new ApolloError (bundle.esm.js:63)
at Object.error (bundle.esm.js:1030)
at notifySubscription (Observable.js:140)
at onNotify (Observable.js:179)
at SubscriptionObserver.error (Observable.js:240)
at bundle.esm.js:869
at Set.forEach ()
at Object.error (bundle.esm.js:869)
at notifySubscription (Observable.js:140)
at onNotify (Observable.js:179)
at SubscriptionObserver.error (Observable.js:240)
at bundle.esm.js:86

and here is the Network error:
https://api.8base.com/cknkou6vh008o0cme2pup9glz

I also noticed this error in console on page load:

Warning: Failed prop type: Invalid prop `value` supplied to `ForwardRef(TextInput)`.
in ForwardRef(TextInput) (at ArticleDetailsForm.js:238)
in ArticleDetailsForm (created by Mutation)
in Mutation (created by Apollo(ArticleDetailsForm))
in Apollo(ArticleDetailsForm) (created by MDXCreateElement)
in MDXCreateElement (at new.mdx:38)
in ApolloProvider (created by MDXCreateElement)
in MDXCreateElement (at new.mdx:37)
in div (at Grid.js:85)
in Column (created by MDXCreateElement)
in MDXCreateElement (at new.mdx:35)
in div (at Grid.js:23)
in Row (created by MDXCreateElement)
in MDXCreateElement (at new.mdx:34)
in div (at Grid.js:10)
in Grid (at Main.js:7)
in Main (at Default.js:79)
in main (at Container.js:58)
in Container (at Layout.js:49)
in Layout (at Default.js:57)
in Default (created by MDXCreateElement)
in MDXCreateElement (at new.mdx:30)
in MDXContent (created by HotExportedMDXContent)
in AppContainer (created by HotExportedMDXContent)
in HotExportedMDXContent (created by PageRenderer)
in PageRenderer (at query-result-store.js:90)
in PageQueryStore (at root.js:57)
in RouteHandler (at root.js:79)
in div (created by FocusHandlerImpl)
in FocusHandlerImpl (created by Context.Consumer)
in FocusHandler (created by RouterImpl)
in RouterImpl (created by Context.Consumer)
in Location (created by Context.Consumer)
in Router (at root.js:74)
in ScrollHandler (at root.js:70)
in RouteUpdates (at root.js:69)
in EnsureResources (at root.js:67)
in LocationHandler (at root.js:125)
in LocationProvider (created by Context.Consumer)
in Location (at root.js:124)
in Root (at root.js:132)
in MDXProvider (at wrap-root-element.js:65)
in MDXScopeProvider (at wrap-root-element.js:64)
in Unknown
in Unknown (at wrap-root-element.js:72)
in MDXProvider (at MDXProvider.js:6)
in MDXProvider (at wrap-root-element.js:9)
in ThemeProvider (at ThemeProvider.js:6)
in ThemeProvider (at wrap-root-element.js:8)
in NavContextProvider (at wrap-root-element.js:7)
in StaticQueryStore (at root.js:149)
in ConditionalFastRefreshOverlay (at root.js:148)
in _default (at app.js:165)

stack_frame_overlay_proxy_console @ index.js:2177

I commented out the value line, and the error doesn’t show anymore. However, the form still doesn’t post.

Here is the error code after form. submission:

err Error: Network error: Response not successful: Received status code 400
at new ApolloError (bundle.esm.js:63)
at Object.error (bundle.esm.js:1030)
at notifySubscription (Observable.js:140)
at onNotify (Observable.js:179)
at SubscriptionObserver.error (Observable.js:240)
at bundle.esm.js:869
at Set.forEach ()
at Object.error (bundle.esm.js:869)
at notifySubscription (Observable.js:140)
at onNotify (Observable.js:179)
at SubscriptionObserver.error (Observable.js:240)
at bundle.esm.js:86

Hello Anna!

You don’t have the same mutation (fields or variables) that is sent from the client-side with the one that is accepted by your workspace. Take a closer look at the errors that came from the server. Try to go to your workspace in the api explorer and run the same mutation. In the api explorer you will see highlight what is wrong with mutation and suggest a fix to you.

Lada Kokotova | Technical Support Engineer

1 Like

Lada, I was able to find the mismatch in the field names, and I fixed it.

However, I’m still getting an error when I submit the form, but it’s a different one:

err Error: GraphQL error: You don't have permission to perform this operation
    at new ApolloError (bundle.esm.js:63)
    at Object.next (bundle.esm.js:1004)
    at notifySubscription (Observable.js:135)
    at onNotify (Observable.js:179)
    at SubscriptionObserver.next (Observable.js:235)
    at bundle.esm.js:866
    at Set.forEach (<anonymous>)
    at Object.next (bundle.esm.js:866)
    at notifySubscription (Observable.js:135)
    at onNotify (Observable.js:179)
    at SubscriptionObserver.next (Observable.js:235)
    at bundle.esm.js:76

Hi, just checking in if you have any updates? This is somewhat time-sensitive since this is my school. project.

@anyav77 you need to run your mutation in API Explorer and see what’s wrong. Also check your permissions settings.

Hey there. Login to your 8base account through the 8base console, Select your workspace then click on “API Explorer” as you can see in this picture. From there, drop in your query and you can test and debug it to solve this problem. Good luck!!