Skip to content
Snippets Groups Projects
Commit ebf84d85 authored by Min Dong Hyeun's avatar Min Dong Hyeun
Browse files

Make LinkPage.js

parent 939919be
No related branches found
No related tags found
No related merge requests found
function Button({type,text}){ function Button({type,text,onClick}){
return( return(
<button <button
type = {type} type = {type}
onClick={onClick}
> >
{text} {text}
</button> </button>
......
...@@ -40,7 +40,7 @@ function HomeMake() { ...@@ -40,7 +40,7 @@ function HomeMake() {
/> />
<br /> <br />
<Input <Input
type="text" type="password"
value={password} value={password}
onChange={onPasswordChange} onChange={onPasswordChange}
placeholder="관리용 Password" placeholder="관리용 Password"
......
function LinkPage(){ import {useState, useEffect} from "react";
return( import "../styles/HomeMake.css"
<h1>LinkPage</h1> import Input from "../components/Input";
); import Button from "../components/Button";
} import { useNavigate } from "react-router-dom";
export default LinkPage; function LinkPage() {
\ No newline at end of file const [link, setLink] = useState("");
const navigate = useNavigate();
const generateLink = () => {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const linkLength = 10;
let randomLink = '';
for (let i = 0; i < linkLength; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
randomLink += characters[randomIndex];
}
setLink(randomLink);
};
const copyToClipboard = () => {
const textField = document.createElement('textarea');
textField.innerText = `localhost:3000/UserTimeInfo/${link}`;
document.body.appendChild(textField);
textField.select();
document.execCommand('copy');
document.body.removeChild(textField);
alert('링크가 복사되었습니다.');
};
const handleSubmit = (event)=>{
event.preventDefault();
navigate(`/UserTimeInfo/${link}`);
}
useEffect(()=>{
generateLink();
},[])
return (
<div className="center-container">
<form onSubmit={handleSubmit}>
<Input
value={`localhost:3000/UserTimeInfo/${link}`}
/>
<Button
type= "button"
onClick={copyToClipboard}
text= "링크 복사"
/>
<Button
type= "submit"
text = "투표 페이지로 이동"
/>
</form>
</div>
);
}
export default LinkPage;
\ No newline at end of file
...@@ -11,7 +11,7 @@ function MeetingInfo() { ...@@ -11,7 +11,7 @@ function MeetingInfo() {
const [endTime, setEndTime] = useState(""); const [endTime, setEndTime] = useState("");
const navigate = useNavigate(); const navigate = useNavigate();
const handleOnClick = (event) => { const handleOnChange = (event) => {
setMeetingPurpose(event.target.value); setMeetingPurpose(event.target.value);
} }
const handleCalendar = (value) => { const handleCalendar = (value) => {
...@@ -25,7 +25,7 @@ function MeetingInfo() { ...@@ -25,7 +25,7 @@ function MeetingInfo() {
} }
const handleSubmit = (event) => { const handleSubmit = (event) => {
event.preventDefault(); event.preventDefault();
if (meetingPurpose === "") { if (meetingPurpose === "" || meetingPurpose === "선택") {
return alert("목적을 선택하세요");; return alert("목적을 선택하세요");;
} }
else { else {
...@@ -38,7 +38,8 @@ function MeetingInfo() { ...@@ -38,7 +38,8 @@ function MeetingInfo() {
<h1>약속 일정 만들기</h1> <h1>약속 일정 만들기</h1>
<label> <label>
목적: 목적:
<select value={meetingPurpose} onClick={handleOnClick}> <select value={meetingPurpose} onChange={handleOnChange}>
<option>선택</option>
<option>식사</option> <option>식사</option>
<option>공부</option> <option>공부</option>
<option>놀기</option> <option>놀기</option>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment