Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ellipsis] Prevent form submissions when is_open is false #91

Closed
wants to merge 1 commit into from

Conversation

ellipsis-dev[bot]
Copy link

@ellipsis-dev ellipsis-dev bot commented Jan 23, 2024

Summary:

Issue: #90

Implementation:

  1. Add a state variable for is_open
    • In the NewFormPage component, add a new state variable isOpen with its setter function setIsOpen. Initialize it with true. This will be used to control whether the form is open for submissions or not. The code should look like this: const [isOpen, setIsOpen] = useState(true);
  2. Update form submission function
    • Update the onFormSubmit function in the NewFormPage component to check the isOpen state before accepting submissions. If isOpen is false, prevent form submission and display the specified message. The updated function should look like this:
async function onFormSubmit(event: React.FormEvent<HTMLFormElement>) {
  if (user === null || !isOpen) {
    // Display the message and return
    alert('This form is no longer accepting responses. If you believe this is an error please reach out to the form sender.');
    return;
  }
  event.preventDefault();
  setIsLoading(true);
  const formId = v4();
  await supabase.from('forms').insert([
    {
      description: formTopic, // we're deleting the intermediate description
      raw_instructions: formTopic,
      fields_guidance: fieldsGuidance,
      fields_schema: fieldsSchema,
      id: formId,
      is_open: true,
      name: title,
      user_id: user.id,
    },
  ]);
  setIsLoading(false);
  push(`/forms/${formId}`);
}

Report:

Step Result Details
1
Add a state variable for is_openI have successfully added a state variable for is_open and updated the form submission function to check the is_open state before accepting submissions. If is_open is false, the function prevents form submission and displays the specified message.
2
Update form submission functionUpdated the onFormSubmit function in the NewFormPage component to check the isOpen state before accepting submissions. If isOpen is false, the function prevents form submission and displays the specified message.

Something look wrong?: If this Pull Request doesn't contain the expected changes, add more information to #90. Then, add the ellipsis:create label to try again. For more information, check the documentation.

Generated with ❤️ by ellipsis.dev

@hbrooks hbrooks closed this Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant