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

Project Survey Josefin R #444

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Survey form with React

Replace this readme with your own information about your project.

Start by briefly describing the assignment in a sentence or two. Keep it short and to the point.
The assignment was to use React to make a form with a few questions and a summary.

## The problem

Describe how you approached to problem, and what tools and techniques you used to solve it. How did you plan? What technologies did you use? If you had more time, what would be next?
I started with creating a lot of test components to get a better feel for React and useState, and then drawing up a flowchart on paper. When I had built some on that, I decided I wanted the answers to the questions to actually "matter", so I made an array of snacks to compare the answers to. That made the project way bigger and I had to go back and adapt to this array entering the stage so it got a bit out of hand, but I had fun. I will keep fixing errors like components not rendering properly if you don't make a choice (only had time to get a pre-set choice on the first question), and adding a few features, like the summary leading up to a randomized snack suggestion. And more styling.


## View it live

Every project should be deployed somewhere. Be sure to include the link to the deployed project so that the viewer can click around and see what it's all about.
The Snack survey:

https://illustrious-tapioca-2bd373.netlify.app/
4 changes: 3 additions & 1 deletion code/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Technigo React App</title>
<link href="https://fonts.googleapis.com/css2?family=Permanent+Marker&display=swap" rel="stylesheet">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the two fonts you picked looks really good together.

<link href="https://fonts.googleapis.com/css2?family=Cairo&family=Noto+Sans+Lepcha&family=Permanent+Marker&display=swap" rel="stylesheet">
<title>The Snack Survey</title>
</head>

<body>
Expand Down
139 changes: 135 additions & 4 deletions code/src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,140 @@
import React from 'react';
/* eslint-disable react/no-unescaped-entities */
import React, { useState } from 'react';
import Header from 'components/Header';
import ProgressButton from 'components/ProgressButton';
import TasteGroup from 'components/TasteGroup';
import TypeOfSnack from 'components/TypeOfSnack';
import Texture from 'components/Texture';
import Flavor from 'components/Flavor';
import PriceSlider from 'components/PriceSlider';
import CommentOption from 'components/CommentOption';
import ImportantOption from 'components/ImportantOption';
import Results from 'components/Results';
import FinishButton from 'FinishButton';

export const App = () => {
const [progress, setProgress] = useState(0);
const [isChoiceMade, setIsChoiceMade] = useState(false)
const [type, setType] = useState('');
const [tasteGroup, setTasteGroup] = useState('');
const [texture, setTexture] = useState('');
const [flavor, setFlavor] = useState('');
const [priceValue, setPriceValue] = useState(7);
const [comment, setComment] = useState('');
const [textInput, setTextInput] = useState('');
const [importantLabel, setImportantLabel] = useState([]);
const [screenRender, setScreenRender] = useState(null)
const [showProgressButton, setShowProgressButton] = useState(false);

const handleReset = () => {
setProgress(0);
window.location.reload();
}

console.log({ progress })
return (
<div>
Find me in src/app.js!
</div>
<>
<Header />
{progress < 1 && (
<div className="introMsg">
<h3>
You&apos;ve reached a survey made by your local convenient store.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to use this way to get '

We&apos;re about to stock our shelves with some new snacks and we&apos;d love to
get your opinion on what to put on them. Thank you for your time!
<p>-Here for you day & night, LocalMart</p>
</h3>
</div>
)}
{progress === 1 && <TasteGroup
tasteGroup={tasteGroup}
setTasteGroup={setTasteGroup}
progress={progress}
setProgress={setProgress}
showProgressButton={showProgressButton}
setShowProgressButton={setShowProgressButton} />}
{progress === 2 && <TypeOfSnack
isChoiceMade={isChoiceMade}
setIsChoiceMade={setIsChoiceMade}
tasteGroup={tasteGroup}
type={type}
setType={setType}
progress={progress}
setProgress={setProgress}
showProgressButton={showProgressButton}
setShowProgressButton={setShowProgressButton} />}
{progress === 3 && <Texture
tasteGroup={tasteGroup}
type={type}
texture={texture}
setTexture={setTexture}
progress={progress}
setProgress={setProgress}
setIsChoiceMade={setIsChoiceMade}
showProgressButton={showProgressButton}
setShowProgressButton={setShowProgressButton} />}
{progress === 4 && <Flavor
tasteGroup={tasteGroup}
type={type}
texture={texture}
flavor={flavor}
setFlavor={setFlavor}
progress={progress}
setProgress={setProgress}
showProgressButton={showProgressButton}
setShowProgressButton={setShowProgressButton} />}
{progress === 5 && <PriceSlider
priceValue={priceValue}
setPriceValue={setPriceValue} />}
{progress === 6 && <CommentOption
tasteGroup={tasteGroup}
type={type}
texture={texture}
flavor={flavor}
priceValue={priceValue}
comment={comment}
setComment={setComment}
textInput={textInput}
setTextInput={setTextInput}
progress={progress}
setProgress={setProgress}
showProgressButton={showProgressButton}
setShowProgressButton={setShowProgressButton} />}
{progress === 7 && <ImportantOption
importantLabel={importantLabel}
setImportantLabel={setImportantLabel}
progress={progress}
setProgress={setProgress}
showProgressButton={showProgressButton}
setShowProgressButton={setShowProgressButton} />}
{progress === 8 && <Results
tasteGroup={tasteGroup}
type={type}
texture={texture}
flavor={flavor}
priceValue={priceValue}
comment={comment}
setComment={setComment}
textInput={textInput}
setTextInput={setTextInput}
importantLabel={importantLabel} />}
{progress === 0 || progress === 5 ? (
console.log('ProgressButton mounted'),
<ProgressButton
progress={progress}
setProgress={setProgress}
isChoiceMade={isChoiceMade}
setIsChoiceMade={setIsChoiceMade}
tasteGroup={tasteGroup}
type={type}
texture={texture}
flavor={flavor}
priceValue={priceValue} />) : null}
{progress === 8 && <button type="button" onClick={handleReset}>Reset survey</button>}
{progress === 8 && <FinishButton
screenRender={screenRender}
setScreenRender={setScreenRender} />}
{progress > 0 && progress <= 7 && (<p>You are on step {progress} of 7 of the survey</p>)}
</>
);
}

20 changes: 20 additions & 0 deletions code/src/FinishButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import FinishScreen from 'components/FinishScreen.js';

const FinishButton = ({ screenRender, setScreenRender }) => {
const handleDoneClick = () => {
setScreenRender(<FinishScreen />);
};

return (
<div className="finishBtn">
{screenRender || (
<button type="button" onClick={handleDoneClick}>
Nope done
</button>
)}
</div>
);
};

export default FinishButton;
55 changes: 55 additions & 0 deletions code/src/components/CommentOption.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React, { useEffect } from 'react';
import ProgressButton from './ProgressButton';

const CommentOption = ({
comment, setComment, textInput, setTextInput, progress,
setProgress,
showProgressButton,
setShowProgressButton
}) => {
console.log({ textInput })

useEffect(() => {
if (!comment) {
setShowProgressButton(false);
console.log('IF', { showProgressButton });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
<>
<form className="commentForm">
<h3>Is there any specific snack you would like us to stock up on? </h3>
<select
onChange={(event) => {
setComment(event.target.value);
setShowProgressButton(true);
}}
value={comment}>
<option value="" disabled>Add a snack?</option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
{comment === 'yes' && (
<input
type="text"
onChange={(event) => setTextInput(event.target.value)}
value={textInput}
onKeyDown={(e) => {
if (e.key === 'Enter') {
e.preventDefault();
}
}} />
)}
</form>
{showProgressButton && (
<ProgressButton
progress={progress}
setProgress={setProgress} />
)}
</>
);
};

export default CommentOption;
12 changes: 12 additions & 0 deletions code/src/components/FinishScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';

const FinishScreen = () => {
return (
<>
<h1>Thanks a lot for your help!</h1>
<h2>Come see us soon</h2>
</>
)
}

export default FinishScreen;
Loading