Skip to content

Commit

Permalink
Merge pull request #173 from cabcookie:improve-person-mention
Browse files Browse the repository at this point in the history
Projekte schnell verlegen
  • Loading branch information
cabcookie authored Aug 7, 2024
2 parents f6ee2b1 + 2f7982d commit f300800
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 47 deletions.
55 changes: 16 additions & 39 deletions api/ContextProjects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ interface ProjectsContextType {
projectId: string,
notes?: EditorJsonContent
) => Promise<string | undefined>;
saveNextActions: (
projectId: string,
myNextActions: EditorJsonContent | string,
othersNextActions: EditorJsonContent | string
) => Promise<string | undefined>;
saveProjectName: (
projectId: string,
projectName: string
Expand Down Expand Up @@ -325,26 +320,26 @@ export const ProjectsContextProvider: FC<ProjectsContextProviderProps> = ({
return data?.activityId;
};

type UpdateProjectProps = {
id: string;
project?: string;
dueOn?: Date;
doneOn?: Date | null;
type UpdateProjectDates = {
onHoldTill?: Date | null;
myNextActions?: EditorJsonContent | string;
othersNextActions?: EditorJsonContent | string;
done?: boolean;
doneOn?: Date | null;
dueOn?: Date | null;
};

type UpdateProjectProps = Partial<
Omit<Project, "id" | "onHoldTill" | "doneOn" | "dueOn">
> &
UpdateProjectDates & {
id: string;
};

const updateProject = async ({
id,
project,
done,
doneOn,
dueOn,
onHoldTill,
myNextActions,
othersNextActions,
}: UpdateProjectProps) => {
const updProject: Project | undefined = projects?.find((p) => p.id === id);
if (!updProject) return;
Expand All @@ -355,8 +350,6 @@ export const ProjectsContextProvider: FC<ProjectsContextProviderProps> = ({
...(doneOn && { doneOn }),
...(dueOn && { dueOn }),
...(onHoldTill && { onHoldTill }),
...(myNextActions && { myNextActions }),
...(othersNextActions && { othersNextActions }),
});

const updated: Project[] =
Expand All @@ -367,15 +360,6 @@ export const ProjectsContextProvider: FC<ProjectsContextProviderProps> = ({
id,
project,
done,
...(myNextActions || othersNextActions
? {
myNextActions: null,
othersNextActions: null,
formatVersion: 2,
myNextActionsJson: JSON.stringify(updProject.myNextActions),
othersNextActionsJson: JSON.stringify(updProject.othersNextActions),
}
: {}),
dueOn: dueOn ? toISODateString(dueOn) : undefined,
doneOn:
done === undefined
Expand All @@ -391,26 +375,20 @@ export const ProjectsContextProvider: FC<ProjectsContextProviderProps> = ({
return data?.id;
};

const saveNextActions = (
projectId: string,
myNextActions: EditorJsonContent | string,
othersNextActions: EditorJsonContent | string
) => updateProject({ id: projectId, myNextActions, othersNextActions });

const saveProjectName = (projectId: string, projectName: string) =>
updateProject({ id: projectId, project: projectName });

type SaveProjectDatesProps = UpdateProjectDates & {
projectId: string;
};

const saveProjectDates = ({
projectId,
dueOn,
doneOn,
onHoldTill,
}: {
projectId: string;
dueOn?: Date;
doneOn?: Date;
onHoldTill?: Date | null;
}) => updateProject({ id: projectId, dueOn, onHoldTill, doneOn });
}: SaveProjectDatesProps) =>
updateProject({ id: projectId, dueOn, onHoldTill, doneOn });

const updateProjectState = (projectId: string, done: boolean) =>
updateProject({ id: projectId, done, doneOn: done ? new Date() : null });
Expand Down Expand Up @@ -550,7 +528,6 @@ export const ProjectsContextProvider: FC<ProjectsContextProviderProps> = ({
createProject,
getProjectById,
createProjectActivity,
saveNextActions,
saveProjectName,
saveProjectDates,
updateProjectState,
Expand Down
11 changes: 9 additions & 2 deletions components/accounts/ProjectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ type ProjectsByFilter = {
accountId?: never;
filter: ProjectFilters;
};
type ProjectListProps = ProjectsByAccount | ProjectsByFilter;
type ProjectListProps = (ProjectsByAccount | ProjectsByFilter) & {
allowPushToNextDay?: boolean;
};

const ProjectList: FC<ProjectListProps> = ({
accountId,
filter: projectFilter,
allowPushToNextDay,
}) => {
const { projects, loadingProjects, errorProjects } = useProjectsContext();
const { accounts } = useAccountsContext();
Expand Down Expand Up @@ -65,7 +68,11 @@ const ProjectList: FC<ProjectListProps> = ({
)(10)}

{filteredProjects.map((project) => (
<ProjectAccordionItem key={project.id} project={project} />
<ProjectAccordionItem
key={project.id}
project={project}
allowPushToNextDay={allowPushToNextDay}
/>
))}
</Accordion>
</div>
Expand Down
40 changes: 37 additions & 3 deletions components/projects/ProjectAccordionItem.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
import { useAccountsContext } from "@/api/ContextAccounts";
import { useOpenTasksContext } from "@/api/ContextOpenTasks";
import { Project } from "@/api/ContextProjects";
import { Project, useProjectsContext } from "@/api/ContextProjects";
import { calcRevenueTwoYears, make2YearsRevenueText } from "@/helpers/projects";
import { format } from "date-fns";
import { addDays, format } from "date-fns";
import { flow, map, sum } from "lodash/fp";
import { FC } from "react";
import { ArrowRightCircle, Loader2 } from "lucide-react";
import { FC, useState } from "react";
import HygieneIssueBadge from "../crm/hygiene-issue-badge";
import { hasHygieneIssues } from "../crm/pipeline-hygiene";
import TaskBadge from "../task/TaskBadge";
import DefaultAccordionItem from "../ui-elements/accordion/DefaultAccordionItem";
import ProjectDetails from "../ui-elements/project-details/project-details";
import { Button } from "../ui/button";

type ProjectAccordionItemProps = {
project?: Project;
showNotes?: boolean;
onDelete?: () => void;
disabled?: boolean;
allowPushToNextDay?: boolean;
};

const ProjectAccordionItem: FC<ProjectAccordionItemProps> = ({
project,
onDelete,
disabled,
allowPushToNextDay,
showNotes = true,
}) => {
const [pushingInProgress, setPushingInProgress] = useState(false);
const { saveProjectDates } = useProjectsContext();
const { getAccountNamesByIds } = useAccountsContext();
const { openTasksByProjectId } = useOpenTasksContext();

const handlePushToNextDay = async () => {
if (!project) return;
setPushingInProgress(true);
const result = await saveProjectDates({
projectId: project.id,
onHoldTill: addDays(new Date(), 1),
});
if (result) return;
setPushingInProgress(false);
};

return (
project && (
<DefaultAccordionItem
Expand Down Expand Up @@ -64,6 +81,23 @@ const ProjectAccordionItem: FC<ProjectAccordionItemProps> = ({
]}
disabled={disabled}
>
{allowPushToNextDay && (
<Button
variant="outline"
size="sm"
onClick={handlePushToNextDay}
disabled={pushingInProgress}
>
{!pushingInProgress && (
<ArrowRightCircle className="w-4 h-4 mr-1" />
)}
{pushingInProgress && (
<Loader2 className="w-4 h-4 mr-1 animate-spin" />
)}
Push to next day
</Button>
)}

<ProjectDetails
projectId={project.id}
showCrmDetails
Expand Down
4 changes: 2 additions & 2 deletions docs/releases/next.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Bessere Visualisierung von Akkordions (Version :VERSION)
# Projekte schnell verlegen (Version :VERSION)

- Wenn Akkordions aufgeklappt werden, erhalten sie jetzt einen leichten transparenten Hintergrund. Wenn darüber weitere Akkordions geöffnet werden, wird die Transparenz immer weniger und somit sollte sich leichter unterscheiden lassen, welcher Akkordion Kopf zu welchem Inhalt gehört.
- In der Projekt-Listenansicht kann ich ein einzelnes Projekt schnell auf den nächsten Tag verlegen (On Hold Till), um davon nicht ständig abgelenkt zu werden.
2 changes: 1 addition & 1 deletion pages/projects/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ProjectListPage = () => {
/>
</div>

<ProjectList filter={filter} />
<ProjectList filter={filter} allowPushToNextDay />
</div>
</MainLayout>
);
Expand Down

0 comments on commit f300800

Please sign in to comment.