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

copy clipboard, 버그 수정

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