Skip to content

Commit

Permalink
add : 이전 외출
Browse files Browse the repository at this point in the history
add : 이전 외출
  • Loading branch information
phyuna0525 authored Mar 20, 2024
2 parents f3f429e + 885a405 commit aa3ddab
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 56 deletions.
6 changes: 3 additions & 3 deletions src/apis/outList/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ interface schedulesdata {
}

interface addSchedule {
name: string;
eventName: string;
date: string;
}

Expand Down Expand Up @@ -482,8 +482,8 @@ export const AddSchedule = () => {
const response = await instance.post(
"/schedule/create",
{
name: param.name,
date: param.date,
eventName: param.eventName,
date: "2024-05-25",
},
{
headers: {
Expand Down
47 changes: 3 additions & 44 deletions src/app/Schedule/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use client";
import React, { useState } from "react";
import Modal from "../components/common/modal/page";
import Header from "../components/common/Header";
import Link from "next/link";
import ScheduleCalendar from "../components/common/calendar/schedule/page";
Expand All @@ -13,56 +12,16 @@ interface ScheduleData {
}

const Schedule = () => {
const [modal, setModal] = useState<boolean>(false);
const [selectedDate, setSelectedDate] = useState<Date | null>(null);
const [scheduleData, setScheduleData] = useState<ScheduleData>({
name: "",
date: "",
});
const { mutate: addScheduleMutate } = AddSchedule();

const handleChangeTeacher = (date: Date) => {
setSelectedDate(date);
setModal(true);
};

const handleModalCancel = () => {
setModal(false);
};

const formetDate = selectedDate
? moment(selectedDate).format("YYYY-MM-DD")
: null;

const handleModalConfirm = async () => {
try {
const newScheduleData: ScheduleData = {
name: "",
date: formetDate || "",
};
setScheduleData(newScheduleData);

const result = await addScheduleMutate(newScheduleData, {
onSuccess: () => {
alert("일정이 추가되었습니다");
},
onError: (error) => {
console.log(error);
},
});
} catch (error) {
console.log(error);
}
};

return (
<div className=" min-w-fit">
<div className=" flex flex-col">
<Header />
<div className=" min-w-max flex flex-col 3xl:px-100 px-30 py-12 gap-7">
<div className=" self-center flex flex-col py-12 gap-7">
<div className="text-neutral-200 text-sub-title3-B">
<Link href="/main"></Link> &gt; 일정 관리
</div>
<ScheduleCalendar onClick={handleChangeTeacher} onChange={() => {}} />
<ScheduleCalendar onClick={()=>{}} onChange={() => {}} />
<div className=" min-w-max absolute top-40 text-heading4">
일정 관리
</div>
Expand Down
44 changes: 44 additions & 0 deletions src/app/components/common/calendar/schedule/fix/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { useState, useRef, useEffect } from "react";

const ScheduleFix = () => {
const [isOptionsVisible, setOptionsVisible] = useState(false);
const dropdownRef = useRef<HTMLDivElement>(null);

const toggleOptions = () => {
setOptionsVisible(!isOptionsVisible);
};

useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (
dropdownRef.current &&
!dropdownRef.current.contains(event.target as Node)
) {
setOptionsVisible(false);
}
};

document.addEventListener("mousedown", handleClickOutside);
return () => {
document.removeEventListener("mousedown", handleClickOutside);
};
}, []);

return (
<div className="relative group cursor-grab" onClick={toggleOptions}>
<div className="group flex flex-col gap-0.5">
<div className="rounded-full w-1 h-1 bg-neutral-400"></div>
<div className="rounded-full w-1 h-1 bg-neutral-400"></div>
<div className="rounded-full w-1 h-1 bg-neutral-400"></div>
</div>
{isOptionsVisible && (
<div className="bg-white rounded w-16 shadow-lg text-caption3 absolute right-0 text-nowrap">
<div className=" flex p-1">수정하기</div>
<div className="flex p-1">삭제하기</div>
</div>
)}
</div>
);
};

export default ScheduleFix;
19 changes: 12 additions & 7 deletions src/app/components/common/calendar/schedule/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import "../style/style.css";
import Calendar from "react-calendar";
import { GetSchdule } from "@/apis/outList/list";
import Modal from "../../modal/page";
import ScheduleFix from "./fix";
import PostSchedule from "../../modal/schdule/page";

interface CalendarProps {
onClick: (date: Date) => void;
Expand All @@ -15,7 +17,7 @@ interface Schedule {
id: string;
event_name: string;
month: number;
day: number; // day 필드를 문자열로 변경
day: number;
}

const ScheduleCalendar: React.FC<CalendarProps> = ({ onClick, onChange }) => {
Expand Down Expand Up @@ -64,7 +66,7 @@ const ScheduleCalendar: React.FC<CalendarProps> = ({ onClick, onChange }) => {

const handleModalConfirm = () => {
setModal(false);
scheduleData(selectDate); // 모달에서 일정이 추가되었으므로 스케줄 데이터를 다시 불러옴
scheduleData(selectDate);
};

return (
Expand Down Expand Up @@ -101,12 +103,15 @@ const ScheduleCalendar: React.FC<CalendarProps> = ({ onClick, onChange }) => {
{dateData.map((item, index) => (
<div
key={index}
className="bg-white flex px-2 py-1 shadow-md rounded gap-2 w-full"
className="bg-white flex justify-between px-2 py-1 shadow-md rounded w-full"
>
<div className="h-auto rounded w-0.5 bg-primary-200"></div>
<div className="text-black text-Button-ES">
{item.event_name}
<div className=" flex gap-2">
<div className="h-auto rounded w-0.5 bg-primary-200"></div>
<div className="text-black text-Button-ES">
{item.event_name}
</div>
</div>
<ScheduleFix />
</div>
))}
</>
Expand All @@ -116,7 +121,7 @@ const ScheduleCalendar: React.FC<CalendarProps> = ({ onClick, onChange }) => {
}}
/>
{modal && (
<Modal
<PostSchedule
date={selectDate}
type="addSchedule"
heading1="새로운 일정"
Expand Down
27 changes: 27 additions & 0 deletions src/app/components/common/list/before/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use client";

import Image from "next/image";
import { useState } from "react";
import arrow from "@/assets/img/Icon/chevron-right.svg";
import downarrow from "@/assets/img/Icon/downarrow.svg";

const PreviousList = () => {
const [isDropdownVisible, setIsDropdownVisible] = useState<boolean>(false);

return (
<>
<div className="group bg-white left-5 top-5 rounded-lg p-4 text-label1 w-77 flex justify-between">
<div>{"이름"}</div>
<Image
src={isDropdownVisible ? `${arrow.src}` : `${downarrow.src}`}
width={24}
height={24}
alt=""
/>
</div>
<BeforeList />
</>
);
};

export default PreviousList;
2 changes: 1 addition & 1 deletion src/app/components/common/modal/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const Modal: React.FC<ModalProps> = ({
const formetDate = date ? moment(date).format("M월 DD일") : null;

return (
<div className=" inset-0 flex items-center justify-center bg-gray-800 bg-opacity-30">
<div className=" inset-0 fixed flex items-center justify-center bg-gray-800 bg-opacity-30">
{type === "button" || type === "error" ? (
<div className=" z-10 bg-white rounded-xl px-24 py-13 w-155">
<div className="flex flex-col gap-8 items-center">
Expand Down
118 changes: 118 additions & 0 deletions src/app/components/common/modal/schdule/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
"use client";
import React, { useState } from "react";
import moment from "moment";
import Button from "../../Button";
import Input from "../../input";
import { AddSchedule } from "@/apis/outList/list";

export interface ChangeProps {
text: string;
name: string;
}

interface ModalProps {
heading1?: string;
onCancel: () => void;
onSuccess: () => void;
initialDate: Date | null;
}

interface ScheduleData {
eventName: string;
date: string;
}

const PostSchedule: React.FC<ModalProps> = ({
heading1,
onCancel,
initialDate,
onSuccess,
}) => {
const [selectedDate, setSelectedDate] = useState<Date | null>(null);
const [scheduleData, setScheduleData] = useState<ScheduleData>({
eventName: "",
date: "",
});
const { mutate: addScheduleMutate } = AddSchedule();

const handleChangeDate = (date: Date) => {
setSelectedDate(date);
};

const handleModalCancel = () => {
onCancel();
};

const handleModalConfirm = async () => {
try {
const formattedDate = selectedDate
? moment(selectedDate).format("YYYY-MM-DD")
: null;
const newScheduleData: ScheduleData = {
eventName: scheduleData.eventName,
date: formattedDate || "",
};
setScheduleData(newScheduleData);
await addScheduleMutate(newScheduleData, {
onSuccess: () => {
alert("일정이 추가되었습니다");
},
onError: (error) => {
console.log(error);
},
});
} catch (error) {
console.log(error);
}
};

const changeSchedule = ({ text, name }: ChangeProps) => {
setScheduleData({ ...scheduleData, [name]: text });
};

return (
<div className=" z-10 fixed inset-0 flex items-center justify-center bg-gray-800 bg-opacity-30">
<div className=" bg-white rounded-xl px-24 py-13 w-155">
<div className="flex flex-col gap-8 items-center">
<div className="text-neutral-50 text-center">
{heading1 && (
<div className="flex gap-1 text-heading6-M max-w-none">
<div className="text-primary-400">
{initialDate && moment(initialDate).format("M월 DD일")}
</div>
<div>{heading1}</div>
</div>
)}
</div>
<Input
type="text"
label="제목*"
onChange={changeSchedule}
value={scheduleData.eventName}
name="eventName"
placeholder="일정 제목"
width="92"
/>
</div>
<div className="flex gap-6">
<Button
colorType="ghost"
buttonSize="large"
onClick={handleModalCancel}
>
취소
</Button>
<Button
colorType="primary"
buttonSize="large"
onClick={handleModalConfirm}
>
확인
</Button>
</div>
</div>
</div>
);
};

export default PostSchedule;
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const SelfStudyModal: React.FC<ModalProps> = ({
heading1,
onCancel,
initialDate,
onSuccess,
}) => {
const [secondData, setSecondData] = useState({ floor: 2, teacher: "" });
const [thirdData, setThirdData] = useState({ floor: 3, teacher: "" });
Expand Down
38 changes: 38 additions & 0 deletions src/app/outAccept/previous/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use client";
import Header from "@/app/components/common/Header";
import Dropdown from "@/app/components/common/dropdown";
import PreviousList from "@/app/components/common/list/before";
import Link from "next/link";

const Previous = () => {
return (
<div className="flex flex-col">
<Header />
<div className=" self-center flex flex-col gap-7 py-16 h-90dvh w-3/5">
<div className="text-neutral-200 text-sub-title3-B text-nowrap">
<Link href="/main"></Link> &gt;
<Link href="/outAccept"> 외출 수락</Link> &gt; 외출 기록 보기
</div>
<div className=" flex justify-between items-center gap-3 flex-wrap">
<div className=" text-nowrap flex justify-center items-center font-sans text-heading4 text-gray-900">
외출 기록 보기
</div>
<div className=" flex items-center gap-3">
<Dropdown type="grade" />
<Dropdown type="class" />
</div>
</div>
<div className="w-full gap-4 rounded-xl bg-primary-1200 h-full px-10 py-10 overflow-y-scroll scrollbar-hide ">
<div className="flex gap-4 flex-wrap justify-between">
<PreviousList />
<PreviousList />
<PreviousList />
<PreviousList />
</div>
</div>
</div>
</div>
);
};

export default Previous;
1 change: 1 addition & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ const config: Config = {
"90dvh": "90dvh",
},
gap: {
"0.5": "0.125rem",
"29": "7.25rem",
17: "4.5rem",
13: "3.875rem",
Expand Down

0 comments on commit aa3ddab

Please sign in to comment.