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

Feature/#99 - refactor use survey #102

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
3 changes: 1 addition & 2 deletions .vscode/typescriptreact.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
"body": [
"import React from 'react'",
"",

"interface ${1:${TM_FILENAME_BASE}}Props {",
" $2",
"};",
"",
"const ${1:${TM_FILENAME_BASE}}: React.FC<${1:${TM_FILENAME_BASE}}Props> = ({ $2 } ) => {",
"const ${1:${TM_FILENAME_BASE}} = ({ $2 }: ${1:${TM_FILENAME_BASE}}Props) => {",
" return (",
" <div>",
" ${1:${TM_FILENAME_BASE}}",
Expand Down
79 changes: 48 additions & 31 deletions src/components/survey/steps/Step1.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
import React, { useCallback, useMemo, useState } from 'react';
import React, { useMemo, useState } from 'react';
import SurveyTitle from '@/components/survey/SurveyTitle/SurveyTitle';
import MenuSelect from '@/components/survey/MenuSelect/MenuSelect';
import { motion } from 'framer-motion';
import { Button } from '@/components/common/ui/button';

interface Step1Props {
title: string;
questions: string[];
handleAnswer: (text: string) => void;
handleNextStep: (selectedItem?: string) => void;
}

const Step1 = ({ title, questions, handleAnswer }: Step1Props) => {
const Step1 = ({ title, questions, handleNextStep }: Step1Props) => {
const [activeItem, setActiveItem] = useState('');
const memoizedTitle = useMemo(() => title, [title]);

const handleSelect = useCallback(
(content: string) => {
const handleSelect = (content: string) => {
if (activeItem === content) {
setActiveItem('');
} else {
setActiveItem(content);
handleAnswer(content);
},
[handleAnswer]
);
}
};

const onNext = () => {
handleNextStep(activeItem);
};

const container = {
hidden: { opacity: 0, y: -20 },
Expand All @@ -34,28 +39,40 @@ const Step1 = ({ title, questions, handleAnswer }: Step1Props) => {
};

return (
<motion.div
className='flex flex-1 flex-col gap-3'
variants={container}
initial='hidden'
animate='show'
>
<div className='mb-5'>
<SurveyTitle title={memoizedTitle} />
</div>

<div className='flex flex-wrap gap-4'>
{questions.map(question => (
<MenuSelect
key={question}
type='large'
status={activeItem === question ? 'active' : 'inActive'}
content={question}
handleSelect={() => handleSelect(question)}
/>
))}
</div>
</motion.div>
<>
<motion.div
className='flex flex-1 flex-col gap-3 px-5'
variants={container}
initial='hidden'
animate='show'
>
<div className='mb-5'>
<SurveyTitle title={memoizedTitle} />
</div>

<div className='flex flex-wrap gap-4'>
{questions.map(question => (
<MenuSelect
key={question}
type='large'
status={activeItem === question ? 'active' : 'inActive'}
content={question}
handleSelect={() => handleSelect(question)}
/>
))}
</div>
</motion.div>
<motion.div className='sticky bottom-6 bg-white px-5'>
<Button
size={'large'}
variant={!activeItem ? 'disabled' : 'full'}
disabled={!activeItem}
onClick={onNext}
>
๋‹ค์Œ
</Button>
</motion.div>
</>
);
};

Expand Down
72 changes: 46 additions & 26 deletions src/components/survey/steps/Step2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,29 @@ import React, { useMemo, useState } from 'react';
import SurveyTitle from '@/components/survey/SurveyTitle/SurveyTitle';
import MenuSelect from '@/components/survey/MenuSelect/MenuSelect';
import { motion } from 'framer-motion';
import { Button } from '@/components/common/ui/button';

interface Step2Props {
title: string;
questions: string[];
handleAnswer: (text: string) => void;
handleNextStep: (selectedItem?: string) => void;
}

const Step2: React.FC<Step2Props> = ({ title, questions, handleAnswer }) => {
const Step2: React.FC<Step2Props> = ({ title, questions, handleNextStep }) => {
const [activeItem, setActiveItem] = useState('');

const memoizedTitle = useMemo(() => title, [title]);

const handleSelect = (content: string) => {
setActiveItem(content);
handleAnswer(content);
if (activeItem === content) {
setActiveItem('');
} else {
setActiveItem(content);
}
};

const onNext = () => {
handleNextStep(activeItem);
};

const container = {
Expand All @@ -32,28 +40,40 @@ const Step2: React.FC<Step2Props> = ({ title, questions, handleAnswer }) => {
};

return (
<motion.div
className='flex flex-1 flex-col gap-3'
variants={container}
initial='hidden'
animate='show'
>
<div className='mb-5'>
<SurveyTitle title={memoizedTitle} />
</div>

<div className='flex flex-wrap gap-3'>
{questions.map(question => (
<MenuSelect
key={question}
type='large'
status={activeItem === question ? 'active' : 'inActive'}
content={question}
handleSelect={() => handleSelect(question)}
/>
))}
</div>
</motion.div>
<>
<motion.div
className='flex flex-1 flex-col gap-3 px-5'
variants={container}
initial='hidden'
animate='show'
>
<div className='mb-5'>
<SurveyTitle title={memoizedTitle} />
</div>

<div className='flex flex-wrap gap-3'>
{questions.map(question => (
<MenuSelect
key={question}
type='large'
status={activeItem === question ? 'active' : 'inActive'}
content={question}
handleSelect={() => handleSelect(question)}
/>
))}
</div>
</motion.div>
<motion.div className='sticky bottom-6 bg-white px-5'>
<Button
size={'large'}
variant={!activeItem ? 'disabled' : 'full'}
disabled={!activeItem}
onClick={onNext}
>
๋‹ค์Œ
</Button>
</motion.div>
</>
);
};

Expand Down
72 changes: 46 additions & 26 deletions src/components/survey/steps/Step3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,29 @@ import React, { useMemo, useState } from 'react';
import SurveyTitle from '@/components/survey/SurveyTitle/SurveyTitle';
import MenuSelect from '@/components/survey/MenuSelect/MenuSelect';
import { motion } from 'framer-motion';
import { Button } from '@/components/common/ui/button';

interface Step3Props {
title: string;
questions: string[];
handleAnswer: (text: string) => void;
handleNextStep: (selectedItem?: string) => void;
}

const Step3: React.FC<Step3Props> = ({ title, questions, handleAnswer }) => {
const Step3: React.FC<Step3Props> = ({ title, questions, handleNextStep }) => {
const [activeItem, setActiveItem] = useState('');

const memoizedTitle = useMemo(() => title, [title]);

const handleSelect = (content: string) => {
setActiveItem(content);
handleAnswer(content);
if (activeItem === content) {
setActiveItem('');
} else {
setActiveItem(content);
}
};

const onNext = () => {
handleNextStep(activeItem);
};

const container = {
Expand All @@ -32,28 +40,40 @@ const Step3: React.FC<Step3Props> = ({ title, questions, handleAnswer }) => {
};

return (
<motion.div
className='flex flex-1 flex-col gap-3'
variants={container}
initial='hidden'
animate='show'
>
<div className='mb-5'>
<SurveyTitle title={memoizedTitle} />
</div>

<div className='flex flex-wrap gap-3'>
{questions.map(question => (
<MenuSelect
key={question}
type='large'
status={activeItem === question ? 'active' : 'inActive'}
content={question}
handleSelect={() => handleSelect(question)}
/>
))}
</div>
</motion.div>
<>
<motion.div
className='flex flex-1 flex-col gap-3 px-5'
variants={container}
initial='hidden'
animate='show'
>
<div className='mb-5'>
<SurveyTitle title={memoizedTitle} />
</div>

<div className='flex flex-wrap gap-3'>
{questions.map(question => (
<MenuSelect
key={question}
type='large'
status={activeItem === question ? 'active' : 'inActive'}
content={question}
handleSelect={() => handleSelect(question)}
/>
))}
</div>
</motion.div>
<motion.div className='sticky bottom-6 bg-white px-5'>
<Button
size={'large'}
variant={!activeItem ? 'disabled' : 'full'}
disabled={!activeItem}
onClick={onNext}
>
๋‹ค์Œ
</Button>
</motion.div>
</>
);
};

Expand Down
Loading