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

result 관련 페이지 타입 분리 #178

Merged
merged 4 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions client/src/component/molecules/QuestionRespond/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import React from 'react';
import { Answers } from 'types/type';
import * as S from './style';

export interface IAnswers {
title: string;
answers: string[];
}
export interface IQuestionRespond extends IAnswers {
export interface QuestionRespondProps extends Answers {
className?: string;
}

function QuestionRespond({ title, answers, className }: IQuestionRespond) {
function QuestionRespond({ title, answers, className }: QuestionRespondProps) {
const QuestionRespondComponents = answers.map((questionRespond: string) => (
<span className="questionRespond">{questionRespond}</span>
));
Expand Down
25 changes: 15 additions & 10 deletions client/src/component/orgamisms/QuestionResult/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { useHistory } from 'react-router-dom';
import { IAnswers } from 'component/molecules/QuestionRespond';
import { Answers } from 'types/type';
import { gql, useMutation, useQuery } from '@apollo/client';
import { updateUser } from 'graphql/mutations';
import { getUser } from 'graphql/queries';
Expand All @@ -10,7 +10,7 @@ import * as S from './style';

interface IQuestionResult {
className?: string;
answerRespond: IAnswers[];
answerRespond: Answers[];
userId: string;
surveyCompleted: boolean;
onCloseResult: () => void;
Expand All @@ -30,7 +30,7 @@ function QuestionResult({

const openModal = () => {
const filterArray: number[] = [];
answerRespond.forEach((answer: IAnswers, index: number) => {
answerRespond.forEach((answer: Answers, index: number) => {
if (answer.answers.length < 1 || answer.answers[0].length < 1) {
filterArray.push(index + 1);
}
Expand Down Expand Up @@ -66,13 +66,18 @@ function QuestionResult({
`,
);

const QuestionRespondList = answerRespond.map((answer: IAnswers) => (
answer.title.length > 0 && <S.QuestionRespond
key={answer.title}
title={answer.title}
answers={answer.answers.length > 0 ? answer.answers : ['응답 하지 않음']}
/>
));
const QuestionRespondList = answerRespond.map(
(answer: Answers) =>
answer.title.length > 0 && (
<S.QuestionRespond
key={answer.title}
title={answer.title}
answers={
answer.answers.length > 0 ? answer.answers : ['응답 하지 않음']
}
/>
),
);

const confirmSubmit = async () => {
if (!surveyCompleted) {
Expand Down
13 changes: 8 additions & 5 deletions client/src/page/Result/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import React from 'react';
import { IAnswers } from 'component/molecules/QuestionRespond';
import { Answers } from 'types/type';
import * as S from './style';

interface IResult {
export interface ResultProps {
userId: string;
surveyCompleted: boolean;
answerRespond: IAnswers[];
answerRespond: Answers[];
onCloseResult: () => void;
}

const Result = ({
userId, surveyCompleted, answerRespond, onCloseResult,
}: IResult) => (
userId,
surveyCompleted,
answerRespond,
onCloseResult,
}: ResultProps) => (
<S.ResultPage>
<S.Title>설문 결과</S.Title>
<S.QuestionResult
Expand Down
6 changes: 3 additions & 3 deletions client/src/page/Survey/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { listQuestionnaires, getUser } from 'graphql/queries';
import { createUser } from 'graphql/mutations';
import BaseTemplate from 'page/BaseTemplate';
import LoadingPage from 'page/Loading';
import { IAnswers } from 'component/molecules/QuestionRespond';
import { Answers } from 'types/type';
import Questionnaire from 'component/orgamisms/Questionnaire';
import ResultComponent from '../Result';
import * as S from './style';

const firstInput: IAnswers[] = Array(12).fill({ title: '', answers: [] });
const firstInput: Answers[] = Array(12).fill({ title: '', answers: [] });
const Survey = ({ className, isLoggedIn }: any) => {
const { loading, error, data } = useQuery(
gql`
Expand Down Expand Up @@ -44,7 +44,7 @@ const Survey = ({ className, isLoggedIn }: any) => {

const bUserUpdating = useRef<boolean>(false);
const [page, setPage] = useState<number>(0);
const [answerRespond, setanswerRespond] = useState<IAnswers[]>(
const [answerRespond, setanswerRespond] = useState<Answers[]>(
userData?.getUser.items[0]
? userData.getUser.items[0].question
: firstInput,
Expand Down
4 changes: 4 additions & 0 deletions client/src/types/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Answers {
Copy link
Contributor

Choose a reason for hiding this comment

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

여기는 이름 뒤에 Props가 빠져있는 이유가 있을까요?

Copy link
Contributor

Choose a reason for hiding this comment

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

컴포넌트 props 아니고서는 얘기를 안 나눴던 것 같긴 합니다!

Copy link
Contributor Author

@lhk3337 lhk3337 Sep 14, 2021

Choose a reason for hiding this comment

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

Answers가 props로 쓰이기도 하고 변수의 타입으로 사용되어 일단 선언하지 않았습니다.

Copy link
Member

Choose a reason for hiding this comment

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

props가 아닌건 types로 빼자고 했었던 것 같습니다.
그냥 Answers라는 이름이 적절하진 않은 것 같은데 딱히 좋은게 생각안나니 이대로 가도 좋을 것 같아요

Copy link
Member

@pkiop pkiop Sep 15, 2021

Choose a reason for hiding this comment

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

파일이름 type.ts 로 하지말고 우선 index.ts 로 합시다
import 할 때 'types' 로 쓸 수 있게요.

title: string;
answers: string[];
}