Commit 4e9e2ee0 authored by Jiwon Yoon's avatar Jiwon Yoon
Browse files

copy clipboard, 버그 수정

parent 0f920a13
...@@ -75,13 +75,13 @@ export const SurveyForm = () => { ...@@ -75,13 +75,13 @@ export const SurveyForm = () => {
try { try {
const formData = new FormData(); const formData = new FormData();
formData.append("surveyId", answerSurvey.current._id); formData.append("surveyId", answerSurvey.current._id);
formData.append("guestId", ""); formData.append("guestId", "quest1");
formData.append("answers", JSON.stringify(answers)); formData.append("answers", JSON.stringify(answers));
files.map((f) => { files.map((f) => {
formData.append("uploadFiles", f.file); formData.append("uploadFiles", f.file);
}); });
const newAnswer: AnswerType = await answerApi.saveAnswers(formData); const newAnswer: AnswerType = await answerApi.saveAnswers(formData);
// console.log(newAnswer); console.log(newAnswer);
setSuccess(true); setSuccess(true);
setError(""); setError("");
} catch (error) { } catch (error) {
......
...@@ -3,6 +3,7 @@ import { useNavigate } from "react-router-dom"; ...@@ -3,6 +3,7 @@ import { useNavigate } from "react-router-dom";
import { surveyApi } from "../apis"; import { surveyApi } from "../apis";
import { SurveyType } from "../types"; import { SurveyType } from "../types";
import { catchErrors } from "../helpers"; import { catchErrors } from "../helpers";
import CopyImg from "../icons/copy.png";
type Props = { type Props = {
data: SurveyType; data: SurveyType;
...@@ -17,6 +18,7 @@ export const MySurveyCard = ({ data }: Props) => { ...@@ -17,6 +18,7 @@ export const MySurveyCard = ({ data }: Props) => {
const editSurvey = () => { const editSurvey = () => {
navigate(`/surveys/edit/${data._id}`, { navigate(`/surveys/edit/${data._id}`, {
replace: true, replace: true,
state: { save: true },
}); });
}; };
...@@ -26,6 +28,11 @@ export const MySurveyCard = ({ data }: Props) => { ...@@ -26,6 +28,11 @@ export const MySurveyCard = ({ data }: Props) => {
}); });
}; };
const copyLink = () => {
navigator.clipboard.writeText(`http://localhost:8080/surveys/${data._id}`);
alert("설문조사의 링크가 클립보드에 저장되었습니다.");
};
async function deleteSurvey() { async function deleteSurvey() {
try { try {
if (data._id) { if (data._id) {
...@@ -53,7 +60,7 @@ export const MySurveyCard = ({ data }: Props) => { ...@@ -53,7 +60,7 @@ export const MySurveyCard = ({ data }: Props) => {
</div> </div>
<div className="flex flex-col px-5 py-3"> <div className="flex flex-col px-5 py-3">
<div className="h-12"> <div className="h-12">
<button type="button" onClick={goSurvey}> <button type="button" onClick={editSurvey}>
<p className="font-bold"> <p className="font-bold">
{data.title ? data.title : "제목없는 설문조사"} {data.title ? data.title : "제목없는 설문조사"}
</p> </p>
...@@ -63,12 +70,9 @@ export const MySurveyCard = ({ data }: Props) => { ...@@ -63,12 +70,9 @@ export const MySurveyCard = ({ data }: Props) => {
</p> </p>
</div> </div>
<div className="flex justify-end pt-1"> <div className="flex justify-end pt-1">
<button <label className="pt-1">링크복사</label>
type="button" <button className="" onClick={copyLink}>
className="bg-themeColor rounded text-white py-1 px-1.5 mr-1" <img src={CopyImg} alt="copy"></img>
onClick={editSurvey}
>
수정
</button> </button>
<button <button
type="button" type="button"
......
...@@ -13,6 +13,7 @@ type Props = { ...@@ -13,6 +13,7 @@ type Props = {
element: BasicQuestionType; element: BasicQuestionType;
handleQuestion: (id: string) => void; handleQuestion: (id: string) => void;
deleteQuestion: (id: string) => void; deleteQuestion: (id: string) => void;
isSave: boolean;
}; };
const typeDropDown = new Map([ const typeDropDown = new Map([
...@@ -30,8 +31,9 @@ export const Question = ({ ...@@ -30,8 +31,9 @@ export const Question = ({
element, element,
handleQuestion, handleQuestion,
deleteQuestion, deleteQuestion,
isSave,
}: Props) => { }: Props) => {
const [save, setSave] = useState(true); const [save, setSave] = useState(isSave);
async function handleEditComplete() { async function handleEditComplete() {
try { try {
const newQuestion: BasicQuestionType = await questionApi.updateQuestion( const newQuestion: BasicQuestionType = await questionApi.updateQuestion(
......
import React, { FormEvent, useEffect, useState } from "react"; import React, { FormEvent, useEffect, useState } from "react";
import { useParams } from "react-router-dom"; import { useParams, useLocation } from "react-router-dom";
import { questionApi, surveyApi } from "../apis"; import { questionApi, surveyApi } from "../apis";
import { SpinnerIcon } from "../icons"; import { SpinnerIcon } from "../icons";
import { Question } from "../questions"; import { Question } from "../questions";
...@@ -8,6 +8,12 @@ import { catchErrors } from "../helpers"; ...@@ -8,6 +8,12 @@ import { catchErrors } from "../helpers";
export const EditSurvey = () => { export const EditSurvey = () => {
let { surveyId } = useParams<{ surveyId: string }>(); let { surveyId } = useParams<{ surveyId: string }>();
interface CustomizedState {
save: boolean;
}
const location = useLocation();
const state = location.state as CustomizedState;
useEffect(() => { useEffect(() => {
getSurvey(); getSurvey();
}, [surveyId]); }, [surveyId]);
...@@ -100,6 +106,7 @@ export const EditSurvey = () => { ...@@ -100,6 +106,7 @@ export const EditSurvey = () => {
const questions = survey.questions; const questions = survey.questions;
console.log(questions); console.log(questions);
console.log(state);
return ( return (
<> <>
{error ? alert(error) : <></>} {error ? alert(error) : <></>}
...@@ -130,6 +137,7 @@ export const EditSurvey = () => { ...@@ -130,6 +137,7 @@ export const EditSurvey = () => {
{questions.map((question) => ( {questions.map((question) => (
<Question <Question
element={question} element={question}
isSave={state ? true : false}
handleQuestion={handleQuestion} handleQuestion={handleQuestion}
deleteQuestion={deleteQuestion} deleteQuestion={deleteQuestion}
/> />
......
declare module "*.svg" {
const content: any;
export default content;
}
declare module "*.png" {
const value: any;
export = value;
}
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ "typeRoots": ["./src/types"], /* Specify multiple folders that act like './node_modules/@types'. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
......
...@@ -34,6 +34,7 @@ export const createAnswers = asyncWrap(async (reqExp, res) => { ...@@ -34,6 +34,7 @@ export const createAnswers = asyncWrap(async (reqExp, res) => {
} }
} }
// 3) Answer DB 만들기(map을 돌려서 하나씩 추가시켜야 함) // 3) Answer DB 만들기(map을 돌려서 하나씩 추가시켜야 함)
console.log("원래 answer", answer);
for (let index = 0; index < answer.answers.length; index++) { for (let index = 0; index < answer.answers.length; index++) {
const element = answer.answers[index]; const element = answer.answers[index];
const newAnswer = await answerDb.createAnswer({ const newAnswer = await answerDb.createAnswer({
...@@ -44,15 +45,14 @@ export const createAnswers = asyncWrap(async (reqExp, res) => { ...@@ -44,15 +45,14 @@ export const createAnswers = asyncWrap(async (reqExp, res) => {
}); });
console.log("DB에 넣은 answer", newAnswer); console.log("DB에 넣은 answer", newAnswer);
} }
// 주의: ref는 반드시 save를 해야 디비에 생성이 됩니다.
return res.json(); return res.json();
} catch (error: any) { } catch (error: any) {
console.log("error in create user:", error); console.log("error in create answer:", error);
// 오류 발생시 저장된 파일 제거 // 오류 발생시 저장된 파일 제거
if (files) { if (files) {
// uploadFiles && (await fileDb.deleteFileById(uploadFiles._id.toString())); // uploadFiles && (await fileDb.deleteFileById(uploadFiles._id.toString()));
// await fs.unlink(files.filepath); // await fs.unlink(files.filepath);
} }
res.status(422).send(error.message || "사용자 생성 오류"); res.status(422).send(error.message || "설문조사 응답 생성 오류");
} }
}); });
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment