Skip to content

Commit

Permalink
feat: time error 수정 in JDEDit
Browse files Browse the repository at this point in the history
  • Loading branch information
hyo-4 committed May 23, 2024
1 parent 0987a88 commit 8c88cf4
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions src/pages/JDEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import AirplaneToggle from "../components/JD/AirplaneToggle";
import BundleEditor from "../components/editor/BundleEditor";
import TimeSelector from "../components/common/TimePicker";
import OneDatePick from "../components/common/DatePicker";
import { useNavigate, useParams } from "react-router-dom";
import { useLocation, useNavigate, useParams } from "react-router-dom";
import Modal from "../components/JD/JDEditModal";
import ClockIcon from "../assets/icons/icon_clock_net600.svg";
import { jobdescriptionget, jobpatch, jobpost } from "../services/JD/jdApi";
import { JobAPI, JobDescriptionAPI } from "../types/type";
import { getCookie } from "../services/cookie";

const JDEditPage: React.FC = () => {
const [selectedTime, setSelectedTime] = useState<string>("10:00");
const [selectedTime, setSelectedTime] = useState<string | null>(null);
const [isModalOpen, setIsModalOpen] = useState(false);
const nav = useNavigate();
const location = useLocation();
const user = getCookie("user");
const [jdData, setJdData] = useState<JobDescriptionAPI>({
enterpriseName: "",
Expand All @@ -30,6 +31,18 @@ const JDEditPage: React.FC = () => {
const jdId = useParams().jdId;
const [isLoading, setIsLoading] = useState(true);

useEffect(() => {
const handleBackNavigation = () => {
openModal();
};

window.history.pushState(null, document.title, location.pathname);
window.addEventListener("popstate", handleBackNavigation);
return () => {
window.removeEventListener("popstate", handleBackNavigation);
};
}, [location.pathname]);

useEffect(() => {
window.scrollTo({
top: 0,
Expand All @@ -42,17 +55,21 @@ const JDEditPage: React.FC = () => {

// endTime 계산
const getEndTime = () => {
if (!jdData.endedAt) return null; // endDate가 null이면 null 반환

const hours = parseInt(selectedTime.split(":")[0]);
const minutes = parseInt(selectedTime.split(":")[1]);

const endTime = new Date(jdData.endedAt); // endDate를 기반으로 새 Date 객체 생성
endTime.setHours(hours, minutes, 0); // 시간과 분 설정
console.log("최종시간은", endTime);
return endTime;
if (!jdData.endedAt) return null;
if (selectedTime) {
const endTime = new Date(jdData.endedAt);
let [hours, minutes] = selectedTime.split(":");
endTime.setHours(parseInt(hours, 10) + 9, parseInt(minutes, 10), 0, 0);
setJdData({ ...jdData, endedAt: endTime });
}
};
const endTime = getEndTime();

useEffect(() => {
if (jdData.startAt && jdData.endedAt && selectedTime !== null) {
getEndTime();
}
console.log(selectedTime);
}, [selectedTime]);

const openModal = () => {
setIsModalOpen(true);
Expand Down Expand Up @@ -131,15 +148,14 @@ const JDEditPage: React.FC = () => {
enterpriseName: response.data.enterpriseName,
title: response.data.title,
remainingDate: response.data.remainingDate,
content: response.data.link,
content: response.data.content,
writeStatus: response.data.writeStatus,
link: response.data.link,
createdAt: response.data.createdAt,
startAt: response.data.startedAt,
endedAt: response.data.endedAt,
};
setJdData(jdApiData);
setSelectedTime(response.data.endedAt);
console.log(jdData);
} catch (error) {
console.error(error);
Expand Down

0 comments on commit 8c88cf4

Please sign in to comment.