Skip to content

Commit

Permalink
Merge pull request #155 from U2DJ2/frontend-main
Browse files Browse the repository at this point in the history
[FEAT] 모임 생성 및 메인 기능 개발
  • Loading branch information
urimeee authored May 19, 2024
2 parents 68fe532 + 13bbaaf commit d3ab96d
Show file tree
Hide file tree
Showing 56 changed files with 3,441 additions and 1,529 deletions.
13 changes: 9 additions & 4 deletions frontend/moim_front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,27 @@
"@fullcalendar/timegrid": "^6.1.11",
"@headlessui/react": "^1.7.19",
"@heroicons/react": "^2.1.3",
"@material-ui/core": "^4.12.4",
"@material-ui/lab": "^4.0.0-alpha.61",
"@mui/icons-material": "^5.15.15",
"@mui/material": "^5.15.15",
"@mui/icons-material": "^5.15.17",
"@mui/lab": "^5.0.0-alpha.170",
"@mui/material": "^5.15.17",
"@mui/x-date-pickers": "^7.3.2",
"axios": "^1.6.8",
"date-fns": "^3.6.0",
"dayjs": "^1.11.11",
"flowbite-react": "^0.9.0",
"little-state-machine": "^4.8.0",
"npm": "^10.6.0",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-awesome-calendar": "^1.0.14",
"react-cookie": "^7.1.4",
"react-custom-scroll": "^7.0.0",
"react-datepicker": "^6.9.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.51.3",
"react-router": "^6.23.0",
"react-router-dom": "^6.23.0",
"react-tailwindcss-datepicker": "^1.6.6",
"tailwindcss": "^3.4.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion frontend/moim_front/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ function App() {
);
}

export default App;
export default App;
44 changes: 44 additions & 0 deletions frontend/moim_front/src/api/moim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import axios from "axios";
import { POST } from "../utils/axios";

export const fetchNotices = async (moimId) => {
const result = await axios.get(
"https://api.moim.today/api/moims/notices/simple",
{
params: {
moimId: moimId,
},
}
);
return result;
};

export const fetchMoimInfo = async (moimId) => {
const result = await axios.get(
`https://api.moim.today/api/moims/detail/${moimId}`
);
return result;
};

export const fetchMeetings = async (moimId, meetingStatus) => {
const result = await axios.get(
`https://api.moim.today/api/meetings/${moimId}`,
{
params: {
meetingStatus: meetingStatus,
},
}
);
return result;
};

export const fetchMembers = async (moimId) => {
const result = await axios.get(
`https://api.moim.today/api/moims/members/${moimId}`
);
return result;
};

export const postMeeting = async (data) => {
const response = await POST("api/meetings", data);
};
7 changes: 7 additions & 0 deletions frontend/moim_front/src/api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ export const checkEmailValid = async (data) =>
baseURL: properties.baseURL,
},
});

export const checkWriter = async (moimId) => {
const result = await axios.get(
`https://api.moim.today/api/members/${moimId}/hosts`
);
return result;
};
Binary file added frontend/moim_front/src/assets/images/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions frontend/moim_front/src/assets/svg/profileImg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion frontend/moim_front/src/components/AuthLeft/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function AuthLeft({
const passwordHandler = (e) => setPassword(e.target.value);
const memoryHandler = (e) => !setMemory;
const navigation = useNavigate();

const onClick = () => {
const data = {
email: email,
Expand All @@ -37,7 +38,7 @@ function AuthLeft({
console.log("clicked");
POST("api/login", data)
.then((res) => {
console.log(res.data);
console.log(res);
navigation("/");
})
.catch((error) => {
Expand All @@ -50,6 +51,7 @@ function AuthLeft({
}
});
};

return (
<div className="flex-1 flex flex-col justify-center justify-items-center">
<div className="w-96 ">
Expand Down
275 changes: 275 additions & 0 deletions frontend/moim_front/src/components/Calendar/PersonalCalendar.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
// React
import { useState, useEffect, useRef } from "react";

// Axios
import axios from "axios";

// Full Calendar
import FullCalendar from "@fullcalendar/react";
import dayGridPlugin from "@fullcalendar/daygrid";
import timeGridPlugin from "@fullcalendar/timegrid";
import interactionPlugin from "@fullcalendar/interaction";

// Modal for Meeting Creation
import CreationModal from "../../components/CreationModal";

// Temporary event ID generator
// let eventGuid = 0;

export default function Calendar({
selectedDate,
isPersonal,
isMeeting,
moimId,
title,
setShowModal,
endDateTime,
setEndDateTime,
startDateTime,
setStartDateTime,
}) {
const calendarRef = useRef(null); // 1. useRef를 사용하여 ref 생성
const [events, setEvents] = useState([]);

useEffect(() => {
// Get current year
const currentYear = new Date().getFullYear();

// Fetch all events on component mount
// fetchAllEvents(currentYear).catch(console.error);

if (isPersonal) {
fetchAllEvents(currentYear).catch(console.error);
} else if (isMeeting) {
//isMeeting이 true일 경우
fetchAvailables();
fetchMeetings();
}
}, []);

useEffect(() => {
if (calendarRef.current && selectedDate) {
calendarRef.current.getApi().gotoDate(selectedDate);
}
}, [selectedDate]);

async function fetchAllEvents(year) {
try {
let allEvents = [];
for (let month = 1; month <= 8; month++) {
const response = await axios.get(
`https://api.moim.today/api/schedules/monthly?yearMonth=${year}-${
month < 10 ? "0" + month : month
}`,
{
headers: {
"Content-Type": "application/json",
},
// Add any other necessary headers or configurations
}
);
allEvents = [
...allEvents,
...response.data.data.map((event) => mapEventData(event, false)),
];
}
setEvents(allEvents);
console.log(events);
} catch (error) {
console.error("Error fetching events:", error);
}
}

async function fetchMeetings() {
try {
const response = await axios.get(
`https://api.moim.today/api/meetings/${moimId}`,
{
params: {
meetingStatus: "ALL",
},
}
);
console.log(response);
} catch (e) {
console.log(e);
}
}

async function fetchAvailables() {
try {
let allEvents = [];
const response = await axios.get(
`https://api.moim.today/api/schedules/weekly/available-time/moims/${moimId}`,
{
params: {
startDate: "2024-05-19",
},
}
);
allEvents = [
...allEvents,
...response.data.data.map((event) => mapEventData(event, true)),
];
setEvents(allEvents);
} catch (e) {
console.log(e);
}
}

// Function to map event data
function mapEventData(event, backgroundEvent) {
const formattedEvent = {
id: event.scheduleId || event.calendarId,
title: event.scheduleName || "",
start: event.startDateTime.replace(" ", "T"),
end: event.endDateTime.replace(" ", "T"),
allDay: false, // Assuming all events fetched are not all-day events
backgroundColor: event.colorHex,
};
// display: "background" 속성을 추가
if (backgroundEvent) {
formattedEvent.display = "background";
}
return formattedEvent;
}

// Function to handle date selection
function handleDateSelect(selectInfo) {
setShowModal(true);

let calendarApi = selectInfo.view.calendar;
console.log(selectInfo.endStr.replace("T", " "));
console.log(selectInfo.startStr);
console.log(selectInfo.endStr);
setStartDateTime(selectInfo.startStr);
setEndDateTime(selectInfo.endStr);

calendarApi.unselect(); // clear date selection

if (title) {
calendarApi.addEvent({
id: createEventId(),
title,
start: selectInfo.startStr,
end: selectInfo.endStr,
allDay: selectInfo.allDay,
});
}
}

// // Function to handle event click
// function handleEventClick(clickInfo) {
// if (
// confirm(
// `Are you sure you want to delete the event '${clickInfo.event.title}'`
// )
// ) {
// // clickInfo.event.remove();
// }
// }

// Function to handle event add
async function handleEventAdd(info) {
try {
const eventData = {
scheduleName: info.event.title,
startDateTime: info.event.start,
endDateTime: info.event.end,
};

const result = await axios.post(
"https://api.moim.today/api/schedules",
eventData
);

console.log(
"Event added and sent to the backend:",
info.event.start,
info.event.end
);
} catch (error) {
console.error("Error adding event:", error);
}
}

// Function to handle event change
function handleEventChange(info) {
console.log("Event changed:", info.event);
}

// Function to handle event remove
function handleEventRemove(info) {
console.log("Event removed:", info.event);
}

// Function to create unique event ID
// function createEventId() {
// return String(eventGuid++);
// }

return (
<div className="demo-app">
<div className="demo-app-main">
<FullCalendar
ref={calendarRef} // 2. FullCalendar 컴포넌트에 ref 추가
plugins={[dayGridPlugin, timeGridPlugin, interactionPlugin]}
headerToolbar={{
left: "prev,next today",
center: "title",
right: "",
// right: "dayGridMonth,timeGridWeek",
}}
initialView="timeGridWeek"
editable={true}
selectable={true}
selectMirror={true}
dayMaxEvents={true}
events={events}
select={handleDateSelect}
eventContent={renderEventContent} // custom render function
// eventClick={handleEventClick}
// you can update a remote database when these fire:
/*
eventAdd={function(){}}
eventChange={function(){}}
eventRemove={function(){}}
*/
eventAdd={handleEventAdd}
eventChange={handleEventChange}
eventRemove={handleEventRemove}
/>
</div>
{/* {isMeeting ? (
<CreationModal
showModal={showModal}
setShowModal={setShowModal}
closeHandler={() => calendarRef.current.getApi().unselect()}
>
<div>
<h2>새 이벤트 추가</h2>
<input
type="text"
value={agenda}
onChange={(e) => setAgenda(e.target.value)}
placeholder="Event Title"
/>
</div>
</CreationModal>
) : null} */}
</div>
);
}

function renderEventContent(eventInfo) {
return (
<div className="flex flex-col">
<b className="text-white font-Pretendard_SemiBold">
{eventInfo.timeText}
</b>
<i className="text-white font-Pretendard_Normal">
{eventInfo.event.title}
</i>
</div>
);
}
Loading

0 comments on commit d3ab96d

Please sign in to comment.