ahmedsaad3117 / survey-builder

0 stars 0 forks source link

Sweep: create a survey builder that build a html content with question #1

Open ahmedsaad3117 opened 1 year ago

ahmedsaad3117 commented 1 year ago
Checklist - [X] `components/Builder.tsx` > Modify the Builder component to create a form with input fields for each question and answer type. Add functionality to add or remove questions. Fetch the survey data from the JSON file and set the form fields with the data when the component is mounted. - [X] `helper/json-builder.ts` > Modify the JsonBuilder class to generate JSON from the form data. Iterate over the form fields and create a JSON object for each question and its answers.
sweep-ai[bot] commented 1 year ago

Here's the PR! https://github.com/ahmedsaad3117/survey-builder/pull/3.

⚡ Sweep Free Trial: I used GPT-4 to create this ticket. You have 5 GPT-4 tickets left for the month and 2 for the day. For more GPT-4 tickets, visit our payment portal.To get Sweep to recreate this ticket, leave a comment prefixed with "sweep:" or edit the issue.


Step 1: 🔍 Code Search

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/ahmedsaad3117/survey-builder/blob/d4b01972f59c6ceedd3329cd3d0cf8dc33fa2d4d/survaycate.example.json#L1-L295 https://github.com/ahmedsaad3117/survey-builder/blob/d4b01972f59c6ceedd3329cd3d0cf8dc33fa2d4d/survaycate.example.json#L1-L133 https://github.com/ahmedsaad3117/survey-builder/blob/d4b01972f59c6ceedd3329cd3d0cf8dc33fa2d4d/components/Builder.tsx#L1-L47 https://github.com/ahmedsaad3117/survey-builder/blob/d4b01972f59c6ceedd3329cd3d0cf8dc33fa2d4d/helper/json-builder.ts#L1-L32 https://github.com/ahmedsaad3117/survey-builder/blob/d4b01972f59c6ceedd3329cd3d0cf8dc33fa2d4d/package.json#L1-L25

Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
components/Builder.tsx Modify the Builder component to create a form with input fields for each question and answer type. Add functionality to add or remove questions. Fetch the survey data from the JSON file and set the form fields with the data when the component is mounted.
helper/json-builder.ts Modify the JsonBuilder class to generate JSON from the form data. Iterate over the form fields and create a JSON object for each question and its answers.

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

Create survey builder to generate HTML content with questions sweep/survey-builder

Description

This PR aims to enhance the existing Builder component in order to generate HTML content with questions. The current implementation only generates JSON from an input field. The modifications include creating a dynamic form with input fields for each question and answer type, allowing users to add or remove questions. Additionally, the JsonBuilder class is updated to generate JSON from the form data, iterating over the form fields to create JSON objects for each question and its answers. The survey data from the JSON file is also loaded into the form when the Builder component is mounted.

Summary of Changes

  • Modified components/Builder.tsx to create a dynamic form with input fields for questions and answer types.
  • Updated helper/json-builder.ts to generate JSON from the form data.
  • Fetched survey data from the JSON file and set the form fields with the data when the Builder component is mounted.

Step 4: ⌨️ Coding

File Instructions Progress
components/Builder.tsx Modify the Builder component to create a form with input fields for each question and answer type. Add functionality to add or remove questions. Fetch the survey data from the JSON file and set the form fields with the data when the component is mounted. ✅ Commit 26af622
helper/json-builder.ts Modify the JsonBuilder class to generate JSON from the form data. Iterate over the form fields and create a JSON object for each question and its answers. ✅ Commit 26af622 I have finished coding the issue. I am now reviewing it for completeness.

Step 5: 🔁 Code Review

Here are my self-reviews of my changes at sweep/survey-builder.

Here is the 1st review

Hello, great job on the changes you've made so far. However, there are a few areas that need some adjustments:

In components/Builder.tsx:

  • On lines 11-18, you've hardcoded the path to the JSON file as 'path_to_json_file'. Please replace this with the actual path to the JSON file.
  • Also on lines 11-18, there is no error handling for the fetch request. It would be good to add a .catch block to handle any potential errors that might occur during the fetch.

In helper/json-builder.ts:

  • The changes made are correct and no further adjustments are required.

Keep up the good work!

I finished incorporating these changes.


To recreate the pull request, or edit the issue title or description. Join Our Discord