forked from aws-samples/amplify-next-template
-
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.
Merge pull request #282 from cabcookie:restructure-paused-projects
Pausierte Projekte ausschlanken
- Loading branch information
Showing
4 changed files
with
98 additions
and
10 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,71 @@ | ||
import { Project, useProjectsContext } from "@/api/ContextProjects"; | ||
import { addProjectDayplan } from "@/api/dayplan/add-project-dayplan"; | ||
import { DailyPlan, DailyPlanProject } from "@/api/useDailyPlans"; | ||
import { ButtonPlayPause } from "@/components/ui/button-play-pause"; | ||
import { IconButton } from "@/components/ui/icon-button"; | ||
import { flow, get, identity } from "lodash/fp"; | ||
import { ExternalLink } from "lucide-react"; | ||
import { FC, useEffect, useState } from "react"; | ||
|
||
interface DailyPlanMaybeProjectProps { | ||
dayPlan: DailyPlan; | ||
dailyPlanProject: DailyPlanProject; | ||
mutateProject: (project: DailyPlanProject, refresh: boolean) => void; | ||
} | ||
|
||
const DailyPlanMaybeProject: FC<DailyPlanMaybeProjectProps> = ({ | ||
dayPlan, | ||
dailyPlanProject, | ||
mutateProject, | ||
}) => { | ||
const { getProjectById } = useProjectsContext(); | ||
const [project, setProject] = useState<Project | undefined>(); | ||
|
||
useEffect(() => { | ||
flow( | ||
identity<DailyPlanProject>, | ||
get("projectId"), | ||
getProjectById, | ||
setProject | ||
)(dailyPlanProject); | ||
}, [dailyPlanProject, getProjectById]); | ||
|
||
const addProject = (maybe: boolean) => | ||
addProjectDayplan({ | ||
data: { | ||
dayPlanId: dayPlan.id, | ||
projectId: dailyPlanProject.projectId, | ||
maybe, | ||
}, | ||
options: { | ||
mutate: (refresh) => | ||
mutateProject({ ...dailyPlanProject, maybe }, refresh), | ||
}, | ||
}); | ||
|
||
return ( | ||
project && ( | ||
<div className="space-y-2"> | ||
<div className="font-semibold">{project.project}</div> | ||
<div className="flex flex-wrap gap-1"> | ||
<ButtonPlayPause | ||
state={dailyPlanProject.maybe ? "PAUSE" : "PLAY"} | ||
className="h-7 p-1" | ||
onClick={() => addProject(!dailyPlanProject.maybe)} | ||
/> | ||
|
||
<IconButton | ||
tooltip="Details" | ||
label="Details" | ||
className="w-24 h-7 p-1" | ||
onClick={() => window.open(`/projects/${project.id}`, "_blank")} | ||
> | ||
<ExternalLink className="w-4 h-4" /> | ||
</IconButton> | ||
</div> | ||
</div> | ||
) | ||
); | ||
}; | ||
|
||
export default DailyPlanMaybeProject; |
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,23 @@ | ||
import { DailyPlan, DailyPlanProject } from "@/api/useDailyPlans"; | ||
import { FC } from "react"; | ||
import DailyPlanMaybeProject from "../planning/day/DailyPlanMaybeProject"; | ||
|
||
interface DayPlanMaybeProjectsProps { | ||
dayPlan: DailyPlan; | ||
dayPlanProjects: DailyPlanProject[] | undefined; | ||
mutateProject: (project: DailyPlanProject, refresh: boolean) => void; | ||
} | ||
|
||
const DayPlanMaybeProjects: FC<DayPlanMaybeProjectsProps> = ({ | ||
dayPlan, | ||
dayPlanProjects, | ||
mutateProject, | ||
}) => | ||
dayPlanProjects?.map((p) => ( | ||
<DailyPlanMaybeProject | ||
key={p.recordId} | ||
{...{ dayPlan, dailyPlanProject: p, mutateProject }} | ||
/> | ||
)); | ||
|
||
export default DayPlanMaybeProjects; |
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