Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

database: change datetime into start and end time strings #53

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/app/actions/events/create/route.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { CREATE_EVENT } from "gql/mutations/events";
export async function POST(request) {
const response = { ok: false, data: null, error: null };
const { details } = await request.json();

const {
data: { createEvent },
error,
Expand Down
3 changes: 2 additions & 1 deletion src/app/actions/events/venues/route.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export async function POST(request) {
data: { availableRooms },
error,
} = await getClient().query(GET_AVAILABLE_LOCATIONS, {
timeslot: [startDate, endDate],
startTime: startDate,
endTime: endDate,
eventid: eventid,
});
if (error) {
Expand Down
5 changes: 3 additions & 2 deletions src/app/events/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Box, Divider, Typography } from "@mui/material";
import EventsFilter from "components/events/EventsFilter";

import EventsGrid from "components/events/EventsGrid";
import {getDateObj} from "utils/formatTime";

export const metadata = {
title: "Events",
Expand Down Expand Up @@ -44,7 +45,7 @@ export default async function Events({ searchParams }) {
if (!targetState) selectedState = true;
else {
const isUpcoming =
new Date(event?.datetimeperiod[1]) > new Date();
new getDateObj(event?.endTime) > new Date();
selectedState = isUpcoming;
}

Expand Down Expand Up @@ -84,7 +85,7 @@ export default async function Events({ searchParams }) {
if (!targetState) selectedState = true;
else {
const isUpcoming =
new Date(event?.datetimeperiod[1]) > new Date();
new getDateObj(event?.endTime) > new Date();
selectedState = !isUpcoming;
}

Expand Down
5 changes: 3 additions & 2 deletions src/app/manage/events/[id]/copy/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ function transformDateTime(datetimeperiod) {
}

function transformEvent(event) {
let newDatetime = transformDateTime([event?.startTime, event?.endTime]);
return {
...event,
// parse datetime strings to date objects
datetimeperiod: transformDateTime(event?.datetimeperiod),
startTime: newDatetime[0],
endTime: newDatetime[1],
budget: [],
location: [],
// parse population as int
Expand Down
9 changes: 4 additions & 5 deletions src/app/manage/events/[id]/edit/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ import { Container, Typography } from "@mui/material";

import EventForm from "components/events/EventForm";

import {getDateObj} from "utils/formatTime";

export const metadata = {
title: "Edit Event",
};

function transformEvent(event) {
return {
...event,
// parse datetime strings to date objects
datetimeperiod: [
new Date(event?.datetimeperiod[0]),
new Date(event?.datetimeperiod[1]),
],
startTime: getDateObj(event?.startTime),
endTime: getDateObj(event?.endTime),
// add mandatory ID field for DataGrid
budget:
event?.budget?.map((budget, key) => ({
Expand Down
5 changes: 4 additions & 1 deletion src/app/manage/events/[id]/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
import { locationLabel } from "utils/formatEvent";
import MemberListItem from "components/members/MemberListItem";

import {getDateObj} from "utils/formatTime"

export async function generateMetadata({ params }, parent) {
const { id } = params;

Expand Down Expand Up @@ -221,7 +223,8 @@ export default async function ManageEvent({ params }) {

// set conditional actions based on event datetime, current status and user role
function getActions(event, user) {
const upcoming = new Date(event?.datetimeperiod[0]) >= new Date();
const upcoming = getDateObj(event?.startTime) >= new Date();

/*
* Deleted Event
* CC/Club - copy
Expand Down
3 changes: 2 additions & 1 deletion src/app/manage/events/new/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export default function NewEvent() {
const defaultValues = {
clubid: "",
name: "",
datetimeperiod: [null, null],
startTime: "",
endTime: "",
description: "",
audience: [],
poster: "",
Expand Down
12 changes: 6 additions & 6 deletions src/components/Calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ function eventDataTransform(event, role, uid) {
return {
id: event._id,
title: event.name,
start: new Date(event.datetimeperiod[0]),
end: new Date(event.datetimeperiod[1]),
start: event.startTime,
end: event.endTime,
backgroundColor: stc(event.clubid),
url: `/events/${event._id}`,
display: "block",
Expand All @@ -22,8 +22,8 @@ function eventDataTransform(event, role, uid) {
return {
id: event._id,
title: event.name,
start: new Date(event.datetimeperiod[0]),
end: new Date(event.datetimeperiod[1]),
start: event.startTime,
end: event.endTime,
backgroundColor: stc(event.clubid),
url: `/manage/events/${event._id}`,
display: "block",
Expand All @@ -32,8 +32,8 @@ function eventDataTransform(event, role, uid) {
return {
id: event._id,
title: event.name,
start: new Date(event.datetimeperiod[0]),
end: new Date(event.datetimeperiod[1]),
start: event.startTime,
end: event.endTime,
backgroundColor: stc(event.clubid),
display: "block",
};
Expand Down
7 changes: 0 additions & 7 deletions src/components/DateTime.jsx

This file was deleted.

8 changes: 4 additions & 4 deletions src/components/events/EventCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { Box, Card, CardActionArea, Typography, Stack } from "@mui/material";

import EventPoster from "components/events/EventPoster";
import EventFallbackPoster from "components/events/EventFallbackPoster";

const DateTime = dynamic(() => import("components/DateTime"), { ssr: false });
import {appendWeekday} from "utils/formatTime"

export default function EventCard({
_id,
name,
datetimeperiod,
startTime,
endTime,
poster,
clubid,
}) {
Expand All @@ -31,7 +31,7 @@ export default function EventCard({
{name}
</Typography>
<Typography variant="caption" noWrap>
<DateTime dt={datetimeperiod?.[0]} showWeekDay={true} />
{appendWeekday(startTime)}
</Typography>
</Stack>
</CardActionArea>
Expand Down
7 changes: 3 additions & 4 deletions src/components/events/EventDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import dynamic from "next/dynamic";
import { Divider, Card, Stack, Box, Grid, Typography } from "@mui/material";

import { locationLabel } from "utils/formatEvent";
import { shortDateStr } from "utils/formatTime";

import ClubButton from "components/clubs/ClubButton";
import EventPoster from "components/events/EventPoster";
Expand All @@ -11,8 +12,6 @@ import EventFallbackPoster from "components/events/EventFallbackPoster";

import Icon from "components/Icon";

const DateTime = dynamic(() => import("components/DateTime"), { ssr: false });

export default function EventDetails({ event, showCode = false }) {
return (
<Grid container spacing={2}>
Expand Down Expand Up @@ -43,11 +42,11 @@ export default function EventDetails({ event, showCode = false }) {
<Box display="flex" alignItems="center">
<Icon variant="calendar-today" sx={{ mr: 2, width: 16 }} />
<Typography variant="body2">
<DateTime dt={event.datetimeperiod[0]} />
{shortDateStr(event?.startTime)}
</Typography>
<Box mx={1}>-</Box>
<Typography variant="body2">
<DateTime dt={event.datetimeperiod[1]} />
{shortDateStr(event?.endTime)} (IST)
</Typography>
</Box>

Expand Down
Loading