diff --git a/src/components/Timer/TimerApp.tsx b/src/components/Timer/TimerApp.tsx new file mode 100644 index 00000000..2f89cabf --- /dev/null +++ b/src/components/Timer/TimerApp.tsx @@ -0,0 +1,219 @@ +import React from "react"; +import { useState, useEffect } from "react"; +import { styled } from "styled-components"; +import { Button, Alert } from "antd"; +import { + ClockCircleOutlined, + CheckOutlined, + PoweroffOutlined, +} from "@ant-design/icons"; + +// 타이머 스타일링 +interface TimerProps { + fontSize?: string; +} +const TimerText = styled.div` + font-size: ${(props) => props.fontSize || "1.5rem"}; +`; + +const TimerAlign = styled.div` + style={ + display: "flex", + flexDirection: "column", + justifyContent: "right", + alignItems: "center"}`; + +const GreetingText = styled.div` + font-size: "1.5rem"; +`; + +const TimerApp = () => { + const nowDate = new Date().toLocaleDateString("ko-KR", { + year: "2-digit", + month: "2-digit", + day: "2-digit", + weekday: "narrow", + }); + + const [nowTime, setNowTime] = useState( + new Date().toLocaleTimeString(), + ); // 현재 시간 표시 + const [startWorkTime, setStartWorkTime] = useState(null); // 출근 시간 기록 + const [finishWorkTime, setFinishWorkTime] = useState(null); // 퇴근 시간 기록 + const [startWorkBtnClicked, setStartWorkBtnClicked] = + useState(false); // 출근 버튼 클릭 가능 상태로 시작 + const [finishWorkBtnClicked, setFinishWorkBtnClicked] = + useState(false); // 퇴근 버튼 클릭 가능 상태로 시작 + const [clickedStartBtnText, setClickedStartBtnText] = useState(""); // 출근 버튼이 클릭됐을 때 해당 시각을 버튼에 표시 + const [clickedFinishBtnText, setClickedFinishBtnText] = useState(""); // 퇴근 버튼이 클릭됐을 때 해당 시각을 버튼에 표시 + const [userName, setUserName] = useState(""); + + const UpdateTime = () => { + let nowTime = new Date().toLocaleTimeString(); + setNowTime(nowTime); + }; + + useEffect(() => { + const interval = setInterval(UpdateTime, 1000); + + return () => { + clearInterval(interval); + }; + }, []); + + const recordStartWork = (e: React.MouseEvent) => { + e.preventDefault(); + // 현재 시간을 출근 시간으로 기록 + const startWorkTime = new Date(); + const hours = startWorkTime.getHours().toString().padStart(2, "0"); + const minutes = startWorkTime.getMinutes().toString().padStart(2, "0"); + const seconds = startWorkTime.getSeconds().toString().padStart(2, "0"); + setStartWorkTime(`${hours}:${minutes}:${seconds}`); + setStartWorkBtnClicked(true); // 출근 시간 기록 후 버튼 비활성화 + setClickedStartBtnText(nowTime); + }; + + const recordFinishWork = (e: React.MouseEvent) => { + e.preventDefault(); + // 현재 시간을 퇴근 시간으로 기록 + + if (!startWorkBtnClicked) { + return alert("출근한 상태일 때만 퇴근 기록이 가능합니다!"); + } + + const finishWorkTime = new Date(); + const hours = finishWorkTime.getHours().toString().padStart(2, "0"); + const minutes = finishWorkTime.getMinutes().toString().padStart(2, "0"); + const seconds = finishWorkTime.getSeconds().toString().padStart(2, "0"); + setFinishWorkTime(`${hours}:${minutes}:${seconds}`); + setFinishWorkBtnClicked(true); // 퇴근 시간 기록 후 버튼 비활성화 + setClickedFinishBtnText(nowTime); + }; + + const calcWorkTime = () => { + if (startWorkTime && finishWorkTime) { + const startTime = startWorkTime.split(":"); + const finishTime = finishWorkTime.split(":"); + const startHours = parseInt(startTime[0], 10); + const startMinutes = parseInt(startTime[1], 10); + const finishHours = parseInt(finishTime[0], 10); + const finishMinutes = parseInt(finishTime[1], 10); + + let hours = finishHours - startHours; + let minutes = finishMinutes - startMinutes; + + if (minutes < 0) { + hours -= 1; + minutes += 60; + } + + return `오늘 총 근무 시간은 ${hours}시간 ${minutes}분 입니다.`; + } + }; + + return ( +
+ +
+
+ TODAY {nowDate} +
+
+ + +   + {nowTime} + +
+
+
+
+
+ +  |  + +
+ {startWorkBtnClicked && !finishWorkBtnClicked && ( + +
좋은 하루 보내세요😊
+
+ )} + {startWorkBtnClicked && finishWorkBtnClicked && ( + +
오늘도 수고하셨습니다!👍
+
+ )} + {startWorkTime && finishWorkTime &&
{calcWorkTime()}
} +
+ ); +}; + +export default TimerApp; diff --git a/src/pages/Timer.tsx b/src/pages/Timer.tsx index 9941ca8d..031ddbca 100644 --- a/src/pages/Timer.tsx +++ b/src/pages/Timer.tsx @@ -1,7 +1,51 @@ -import React from "react"; +import React, { useState } from "react"; +import { styled } from "styled-components"; +import TimerApp from "../components/Timer/TimerApp"; + +const TimerContainer = styled.div` + width: 320px; + height: 260px; + border: 2px solid #3956a3; + border-radius: 40px; + padding: 15px 25px; + box-sizing: border-box; + white-space: pre-line; + display: flex; + justify-content: flex-end; + font-size: 1rem; + z-index: 999; + position: absolute; + top: 10%; + right: 5%; +`; + +const TextAlign = styled.div` + text-align: right; +`; + +const CloseModalBtn = styled.div` + width: 5px; + height: 5px; + cursor: pointer; + color: #535353; +`; +// const [closeModal, setCloseModal] = useState(false); const Timer = () => { - return
Timer
; + // const closeModal = () => { + // setCloseModal(true); + // }; + + return ( + + X + +
+ 환영합니다. OOO 님! + +
+
+ ); }; export default Timer;