This repository has been archived by the owner on Jan 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WDY-369
- Loading branch information
Showing
32 changed files
with
807 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Response } from 'express'; | ||
import { AuthRequest } from '../types'; | ||
import { ScheduleModel } from '../../models/Schedule'; | ||
|
||
interface Request extends AuthRequest {} | ||
|
||
/** | ||
* Gets the user's schedule | ||
* | ||
* endpoint ➜ GET /api/schedule | ||
*/ | ||
export const getSchedule = async (req: Request, res: Response) => { | ||
const schedule = await ScheduleModel.findOne({ | ||
owner: req.userId, | ||
}).populate('tasks.scope'); | ||
|
||
if (!schedule) { | ||
return res.status(404).json({ error: 'Schedule not found' }); | ||
} | ||
|
||
res.json(schedule); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { getSchedule } from './getSchedule'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { getSchedule } from '../controllers/schedule'; | ||
import { catchErrors } from '../middlewares/catchErrors'; | ||
import requireLogin from '../middlewares/requireLogin'; | ||
|
||
const router = require('express').Router(); | ||
|
||
router.get('/', requireLogin, catchErrors(getSchedule)); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from 'react'; | ||
import { useParams } from 'react-router'; | ||
import { Button, IconButton, theme, Tooltip } from '@binarycapsule/ui-capsules'; | ||
import { TaskDto, useDay } from '../api/useDay'; | ||
import { useMoveTask } from '../api/useMoveTask'; | ||
import { useSchedule } from '../api/useSchedule'; | ||
|
||
const colors = [theme.neutral200, theme.neutral400, '#CFBCF2', '#653CAD']; | ||
|
||
interface Props { | ||
isButton?: boolean; | ||
task: TaskDto; | ||
} | ||
|
||
export const AddToPlan: React.FC<Props> = ({ isButton, task }) => { | ||
const { dayId } = useParams(); | ||
const { data: day } = useDay(dayId); | ||
const [moveTask] = useMoveTask(); | ||
const { data: schedule } = useSchedule(); | ||
|
||
if (!schedule) return null; | ||
|
||
const taskIndex = schedule.tasks.findIndex(({ id }) => id === task.id); | ||
|
||
const moveToPlan = () => { | ||
if (day) { | ||
const toSectionId = day.sections.find(({ isPlan }) => isPlan)?.id; | ||
|
||
if (!toSectionId) return; | ||
|
||
moveTask({ | ||
taskId: task.id, | ||
body: { | ||
dayId, | ||
fromIndex: taskIndex, | ||
fromSectionId: 'schedule', | ||
toSectionId, | ||
toIndex: null, | ||
}, | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<Tooltip tooltip="Add task to Plan" delayShow={1000}> | ||
{isButton ? ( | ||
<Button appearance="minimal" iconBefore="plus_c" onClick={moveToPlan}> | ||
Add to Plan | ||
</Button> | ||
) : ( | ||
<IconButton colors={colors} icon="circle_add" onClick={moveToPlan} /> | ||
)} | ||
</Tooltip> | ||
); | ||
}; |
Oops, something went wrong.