fix results page

This commit is contained in:
Tatiana Nikolaeva 2025-06-10 08:42:07 +05:00
parent 3c466a98d3
commit 1e60984d64
9 changed files with 267 additions and 136 deletions

View file

@ -1,8 +1,7 @@
import React from 'react';
import React, {useRef, useState} from 'react';
import SurveyInfo from "../SurveyInfo/SurveyInfo.tsx";
import styles from "./SettingSurvey.module.css";
import TimeEvent from "../TimeEvent/TimeEvent.tsx";
import SaveButton from "../SaveButton/SaveButton.tsx";
import {ISurvey} from "../../api/SurveyApi.ts";
import {useLocation, useOutletContext} from "react-router-dom";
import {useSurveyContext} from "../../context/SurveyContext.tsx";
@ -16,13 +15,17 @@ const SettingSurvey: React.FC = () => {
setSurvey: (survey: ISurvey) => void;
}>();
const { tempSurvey, setTempSurvey } = useSurveyContext();
const [showPopup, setShowPopup] = useState(false);
const buttonRef = useRef<HTMLButtonElement>(null);
const handleCopyLink = () => {
if (!survey?.id)
return;
if (!survey?.id) return;
const link = `${window.location.origin}/complete-survey/${survey.id}`;
navigator.clipboard.writeText(link)
.then(() => console.log('Copied!'))
.then(() => {
setShowPopup(true);
setTimeout(() => setShowPopup(false), 2000);
})
.catch(error => console.error(`Не удалось скопировать ссылку: ${error}`));
}
@ -50,8 +53,22 @@ const SettingSurvey: React.FC = () => {
<div className={styles.param}>
<h2>Параметры видимости</h2>
</div>
<SaveButton onClick={() => {}}/>
{!isSettingCreatePage ? <button onClick={handleCopyLink} className={styles.copyButton}>Копировать ссылку</button> : ''}
{!isSettingCreatePage && (
<div className={styles.buttonContainer}>
<button
ref={buttonRef}
onClick={handleCopyLink}
className={styles.copyButton}
>
Копировать ссылку
</button>
{showPopup && (
<div className={styles.popup}>
Ссылка скопирована
</div>
)}
</div>
)}
</div>
)
}