; +export type UserSurvey = SurveyDetail & { + qitems: (Question & { + articles: Article[]; + })[]; +}; export interface SurveyService { getSurveyList(params: SurveyParams): Promise; @@ -108,4 +113,5 @@ export interface SurveyService { deleteQuestion(srvyQitemNo: number): Promise; getArticleList(params: ArticleParams): Promise; saveArticleList(data: Article[]): Promise; + getUserSurvey(srvySn: number): Promise; } diff --git a/apps/cs/src/pages/survey/model/survey-table-columns.tsx b/apps/cs/src/pages/survey/model/survey-table-columns.tsx index 14710edf2..08213020b 100644 --- a/apps/cs/src/pages/survey/model/survey-table-columns.tsx +++ b/apps/cs/src/pages/survey/model/survey-table-columns.tsx @@ -65,7 +65,7 @@ export const columns: ColumnDef[] = [ const left = window.screen.width / 2 - width / 2 + window.screenX; const top = window.screen.height / 2 - height / 2 + window.screenY; window.open( - `/survey-article/${row.original.srvySn}`, + `/user-survey-article/${row.original.srvySn}`, "", `width=${width},height=${height},left=${left},top=${top}`, ); diff --git a/apps/cs/src/pages/survey/ui/question-form.tsx b/apps/cs/src/pages/survey/ui/question-form.tsx index b722a4802..cb321fbe7 100644 --- a/apps/cs/src/pages/survey/ui/question-form.tsx +++ b/apps/cs/src/pages/survey/ui/question-form.tsx @@ -107,7 +107,7 @@ function QuestionForm({ form, actionSlot, handleSave }: QuestionFormProps) { /> - {qstnTypeCd === "CHECK" && ( + {qstnTypeCd === "CHECKBOX" && ( 최대선택갯수 @@ -134,7 +134,7 @@ function QuestionForm({ form, actionSlot, handleSave }: QuestionFormProps) { )} - {(qstnTypeCd === "RADIO" || qstnTypeCd === "CHECK") && ( + {(qstnTypeCd === "RADIO" || qstnTypeCd === "CHECKBOX") && ( 기타답변여부 diff --git a/apps/cs/src/pages/survey/ui/survey-article.tsx b/apps/cs/src/pages/survey/ui/survey-article.tsx deleted file mode 100644 index 768e0b182..000000000 --- a/apps/cs/src/pages/survey/ui/survey-article.tsx +++ /dev/null @@ -1,146 +0,0 @@ -"use client"; - -import { CodeSelect } from "@/entities/code"; -import { - Button, - Checkbox, - Input, - Label, - RadioGroup, - RadioGroupItem, - Textarea, -} from "@common/components"; - -function SurveyArticle() { - return ( - - - - 설문 제목 - - 제출 - 닫기 - - - - - - 설문 참여자 정보 - - - - 응답자명 - - - - 직업 - - - - 생년월일 - - - - 성별 - - - - 남자 - - - - 여자 - - - - - - - - 답변 설명 - - - - - 1 - - - - - - 2 - - - - - - 3 - - - - - - - - ); -} - -function RadioArticle() { - return ( - - 질문 1 - - - - - - 답변1 - - - - - - 답변2 - - - - - - ); -} - -function CheckboxArticle() { - return ( - - 질문 2 - - - - - 답변1 - - - - - - 답변2 - - - - - ); -} - -function TextareaArticle() { - return ( - - 질문 3 - - - ); -} - -export { SurveyArticle }; diff --git a/apps/cs/src/pages/survey/ui/user-survey-article.tsx b/apps/cs/src/pages/survey/ui/user-survey-article.tsx new file mode 100644 index 000000000..2b3e8ad8a --- /dev/null +++ b/apps/cs/src/pages/survey/ui/user-survey-article.tsx @@ -0,0 +1,211 @@ +"use client"; + +import { useQuery } from "@tanstack/react-query"; +import { + Button, + Checkbox, + Input, + Label, + RadioGroup, + RadioGroupItem, + Textarea, +} from "@common/components"; +import { ENDPOINT } from "@/shared/config"; +import { CodeSelect } from "@/entities/code"; +import { SurveyApi } from "../api/survey-service"; +import type { Article } from "../model/survey-interface"; +import { useState } from "react"; +import { useAlertStore } from "@/shared/lib"; + +function UserSurveyArticle({ srvySn }: { srvySn: string }) { + const { data: userSurvey } = useQuery({ + queryKey: [ENDPOINT.CMS_SERVICE.SURVEY, srvySn], + queryFn: () => SurveyApi.getUserSurvey(parseInt(srvySn)), + }); + + return ( + + + + + {userSurvey?.srvyTtl} + + + 제출 + window.close()}> + 닫기 + + + + + + + 설문 참여자 정보 + + + + 응답자명 + + + + 직업 + + + + 생년월일 + + + + 성별 + + + + 남자 + + + + 여자 + + + + + + + + {userSurvey?.srvyWrtGdCn} + + + {userSurvey?.qitems.map((item) => ( + + + {item.qstnSeq} + + {item.qstnTypeCd === "RADIO" && ( + + )} + {item.qstnTypeCd === "CHECKBOX" && ( + + )} + {item.qstnTypeCd === "INPUT" && ( + + )} + + ))} + + + + + ); +} + +function RadioArticle({ + name, + qstnCn, + articles, +}: { + name: string; + qstnCn: string; + articles: Article[]; +}) { + return ( + + {qstnCn} + + + {articles.map((article, index) => ( + + + + {article.artclCn} + + + ))} + + + + ); +} + +function CheckboxArticle({ + name, + qstnCn, + maxChcCnt, + articles, +}: { + name: string; + qstnCn: string; + maxChcCnt: number; + articles: Article[]; +}) { + const [selectedValues, setSelectedValues] = useState([]); + const alert = useAlertStore((state) => state.setMessage); + + const handleCheckboxChange = (value: number) => (checked: boolean) => { + if (checked && selectedValues.length >= maxChcCnt) { + alert("최대 선택 개수를 초과했습니다."); + return; + } + if (selectedValues.includes(value)) { + setSelectedValues((prev) => prev.filter((item) => item !== value)); + return; + } + setSelectedValues((prev) => [...prev, value]); + }; + + return ( + + + {qstnCn} (최대 {maxChcCnt}개 선택) + + + {articles.map((article, index) => ( + + + + {article.artclCn} + + + ))} + + + ); +} + +function TextareaArticle({ qstnCn }: { qstnCn: string; article?: Article }) { + return ( + + {qstnCn} + + + ); +} + +export { UserSurveyArticle };