Skip to content

Commit

Permalink
Merge pull request #284 from cabcookie:weekly-plan-with-optional-steps
Browse files Browse the repository at this point in the history
feat: skip actions in weekly planning
  • Loading branch information
cabcookie authored Jan 9, 2025
2 parents b70137c + 50c80f7 commit 5c9b484
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 25 deletions.
3 changes: 3 additions & 0 deletions amplify/data/planning-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const planningSchema = {
startDate: a.date().required(),
status: a.ref("PlanningStatus").required(),
projects: a.hasMany("WeeklyPlanProject", "weekPlanId"),
inboxSkipped: a.boolean(),
financialUpdateSkipped: a.boolean(),
crmUpdateSkipped: a.boolean(),
})
.secondaryIndexes((index) => [index("status")])
.authorization((allow) => [allow.owner()]),
Expand Down
28 changes: 27 additions & 1 deletion api/useWeekPlan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ export type WeeklyPlan = {
startDate: Date;
status: TWeekPlanStatus;
projectIds: string[];
inboxSkipped: boolean;
financialUpdateSkipped: boolean;
crmUpdateSkipped: boolean;
};

const selectionSet = [
"id",
"startDate",
"status",
"projects.projectId",
"inboxSkipped",
"financialUpdateSkipped",
"crmUpdateSkipped",
] as const;

type WeeklyPlanData = SelectionSet<
Expand All @@ -35,11 +41,17 @@ const mapWeekPlan: (data: WeeklyPlanData) => WeeklyPlan = ({
startDate,
status,
projects,
inboxSkipped,
financialUpdateSkipped,
crmUpdateSkipped,
}) => ({
id,
startDate: new Date(startDate),
status,
projectIds: projects.map(({ projectId }) => projectId),
inboxSkipped: !!inboxSkipped,
financialUpdateSkipped: !!financialUpdateSkipped,
crmUpdateSkipped: !!crmUpdateSkipped,
});

const fetchWeekPlans = async () => {
Expand Down Expand Up @@ -71,7 +83,15 @@ const useWeekPlan = () => {

const createWeekPlan = async (startDate: Date) => {
const updated: WeeklyPlan[] = [
{ id: crypto.randomUUID(), startDate, status: "WIP", projectIds: [] },
{
id: crypto.randomUUID(),
startDate,
status: "WIP",
projectIds: [],
inboxSkipped: false,
financialUpdateSkipped: false,
crmUpdateSkipped: false,
},
];
mutate(updated, false);
if (weekPlans && weekPlans.length > 0) {
Expand Down Expand Up @@ -197,6 +217,12 @@ const useWeekPlan = () => {
makeProjectDecision,
isLoading,
error,
mutate: (weekPlan: WeeklyPlan | undefined, update?: boolean) =>
weekPlan &&
mutate(
weekPlans?.map((p) => (p.id !== weekPlan?.id ? p : weekPlan)),
update
),
};
};

Expand Down
2 changes: 1 addition & 1 deletion components/learnings/LearningComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const LearningComponent: FC<LearningComponentProps> = ({
<div className={cn(!editable && "-mx-2")}>
<NotesWriter
readonly={!editable}
placeholder="Document what you've learned about the person…"
placeholder="Document what you've learned…"
notes={learning.learning}
saveNotes={onChange}
/>
Expand Down
61 changes: 61 additions & 0 deletions components/planning/useWeekPlanContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { type Schema } from "@/amplify/data/resource";
import { handleApiErrors } from "@/api/globals";
import useWeekPlan, { WeeklyPlan } from "@/api/useWeekPlan";
import { generateClient } from "aws-amplify/data";
import { addDays } from "date-fns";
import {
ComponentType,
Expand All @@ -8,9 +11,17 @@ import {
useEffect,
useState,
} from "react";
import { toast } from "../ui/use-toast";
const client = generateClient<Schema>();

interface WeekPlanType {
weekPlan: WeeklyPlan | undefined;
inboxSkipped: boolean;
financialUpdateSkipped: boolean;
crmUpdateSkipped: boolean;
skipInbox?: () => void;
skipFinancialUpdate?: () => void;
skipCrmUpdate?: () => void;
createWeekPlan: (startDate: Date) => Promise<void>;
confirmProjectSelection: () => Promise<string | undefined>;
startDate: Date;
Expand Down Expand Up @@ -39,6 +50,7 @@ const WeekPlanProvider: FC<WeekPlanProviderProps> = ({ children }) => {
isLoading,
error,
confirmProjectSelection,
mutate,
} = useWeekPlan();
const [startDate, setStartDate] = useState(
weekPlan?.startDate || addDays(new Date(), 1)
Expand All @@ -49,10 +61,59 @@ const WeekPlanProvider: FC<WeekPlanProviderProps> = ({ children }) => {
setStartDate(weekPlan.startDate);
}, [weekPlan]);

const skipInbox = !weekPlan
? undefined
: async () => {
console.log("skipInbox");
if (!weekPlan) return;
const { data, errors } = await client.models.WeeklyPlan.update({
id: weekPlan.id,
inboxSkipped: true,
});
if (errors) handleApiErrors(errors, "Couldn't skip inbox");
mutate({ ...weekPlan, inboxSkipped: true }, true);
if (!data) return;
toast({ title: "Skipped inbox" });
};

const skipFinancialUpdate = !weekPlan
? undefined
: async () => {
if (!weekPlan) return;
const { data, errors } = await client.models.WeeklyPlan.update({
id: weekPlan.id,
financialUpdateSkipped: true,
});
if (errors) handleApiErrors(errors, "Couldn't skip financial update");
mutate({ ...weekPlan, financialUpdateSkipped: true }, true);
if (!data) return;
toast({ title: "Skipped financial update" });
};

const skipCrmUpdate = !weekPlan
? undefined
: async () => {
if (!weekPlan) return;
const { data, errors } = await client.models.WeeklyPlan.update({
id: weekPlan.id,
crmUpdateSkipped: true,
});
if (errors) handleApiErrors(errors, "Couldn't skip CRM update");
mutate({ ...weekPlan, crmUpdateSkipped: true }, true);
if (!data) return;
toast({ title: "Skipped CRM update" });
};

return (
<WeekPlan.Provider
value={{
weekPlan,
inboxSkipped: !!weekPlan?.inboxSkipped,
financialUpdateSkipped: !!weekPlan?.financialUpdateSkipped,
crmUpdateSkipped: !!weekPlan?.crmUpdateSkipped,
skipInbox,
skipFinancialUpdate,
skipCrmUpdate,
createWeekPlan,
confirmProjectSelection,
startDate,
Expand Down
42 changes: 36 additions & 6 deletions components/planning/week/PlanWeekAction.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
import { FC } from "react";
import { Button } from "@/components/ui/button";
import { Loader2 } from "lucide-react";
import { FC, useState } from "react";

type PlanWeekActionProps = {
label: string;
skip?: () => void;
};

const PlanWeekAction: FC<PlanWeekActionProps> = ({ label }) => (
<div className="border-2 border-[--context-color] rounded-md flex justify-center p-1 font-semibold">
Next Action: {label}
</div>
);
const PlanWeekAction: FC<PlanWeekActionProps> = ({ label, skip }) => {
const [skipping, setSkipping] = useState(false);

const handleSkip = () => {
setSkipping(true);
skip?.();
};

return (
<div className="border-2 border-[--context-color] rounded-md flex justify-center p-1 font-semibold flex-col items-center text-center">
<span>Next Action: {label}</span>
{skip && (
<Button
size="sm"
variant="link"
onClick={handleSkip}
className="text-muted-foreground hover:text-primary"
disabled={skipping}
>
{!skipping ? (
"Skip"
) : (
<div className="flex flex-row gap-1">
<Loader2 className="w-4 h-4 animate-spin" />
Skipping
</div>
)}
</Button>
)}
</div>
);
};

export default PlanWeekAction;
11 changes: 9 additions & 2 deletions components/planning/week/ProcessCrmUpdates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ import { FC } from "react";

interface ProcessCrmUpdatesProps {
mutateSfdc: ReturnType<typeof useMrrLatestUpload>["mutateSfdc"];
skipCrmUpdate?: () => void;
}

const ProcessCrmUpdates: FC<ProcessCrmUpdatesProps> = ({ mutateSfdc }) => (
const ProcessCrmUpdates: FC<ProcessCrmUpdatesProps> = ({
mutateSfdc,
skipCrmUpdate,
}) => (
<>
<PlanWeekAction label="Upload Salesforce Opportunities" />
<PlanWeekAction
label="Upload Salesforce Opportunities"
skip={skipCrmUpdate}
/>
<ImportProjectData reloader={mutateSfdc} />
</>
);
Expand Down
7 changes: 6 additions & 1 deletion components/planning/week/ProcessFinancialUpdates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ import { FC } from "react";

interface ProcessFinancialUpdatesProps {
mutateMrr: ReturnType<typeof useMrrLatestUpload>["mutateMrr"];
skipFinancialUpdate?: () => void;
}

const ProcessFinancialUpdates: FC<ProcessFinancialUpdatesProps> = ({
mutateMrr,
skipFinancialUpdate,
}) => (
<>
<PlanWeekAction label="Upload Customer Financials" />
<PlanWeekAction
label="Upload Customer Financials"
skip={skipFinancialUpdate}
/>
<MrrFilterProvider>
<Accordion type="single" collapsible>
<InstructionsUploadMrr reloader={mutateMrr} />
Expand Down
9 changes: 7 additions & 2 deletions components/planning/week/ProcessInbox.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import ProcessInboxItem from "@/components/inbox/ProcessInboxItem";
import PlanWeekAction from "@/components/planning/week/PlanWeekAction";
import { FC } from "react";

const ProcessInbox = () => (
interface ProcessInboxProps {
skipInbox?: () => void;
}

const ProcessInbox: FC<ProcessInboxProps> = ({ skipInbox }) => (
<>
<PlanWeekAction label="Process Inbox Items" />
<PlanWeekAction label="Process Inbox Items" skip={skipInbox} />
<ProcessInboxItem />
</>
);
Expand Down
3 changes: 2 additions & 1 deletion components/ui-elements/notes-writer/NotesWriter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ const NotesWriter: FC<NotesWriterProps> = ({
},
attributes: {
class: cn(
"prose w-full max-w-full text-notesEditor rounded-md p-2 bg-inherit transition duration-1000 ease",
"prose w-full max-w-full text-notesEditor bg-inherit transition duration-1000 ease p-2",
!readonly && "rounded-md border pt-16",
showSaveStatus &&
!readonly &&
!isUpToDate(notes, editor.getJSON()) &&
Expand Down
10 changes: 8 additions & 2 deletions docs/releases/next.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Notizen Menü überall zeigen (Version :VERSION)
# Optionale Schritte in der Wochenplanung (Version :VERSION)

- Das Menü zum Formatieren für Notizen wird nun überall angezeigt.
- Das Leeren der Inbox kann nun in der Wochenplanung übersprungen werden.
- Das Aktualisieren der Finanzdaten kann nun in der Wochenplanung übersprungen werden.
- Das Aktualisieren der CRM Projekte kann nun in der Wochenplanung übersprungen werden.

## Fehlerbehebungen

- Bei Gelerntem zu Kunden und Personen erscheint die erste Zeile nun unter der Menüleiste und ist nicht mehr von dieser abgedeckt.

## Bekannte Fehler

Expand Down
27 changes: 18 additions & 9 deletions pages/planweek.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,25 @@ import {
} from "@/components/planning/useWeekPlanContext";
import PlanWeekForm from "@/components/planning/week/PlanWeekForm";
import ProcessCrmUpdates from "@/components/planning/week/ProcessCrmUpdates";
import ProcessFinancialUpdates from "@/components/planning/week/ProcessFinancialUpdates";
import ProcessInbox from "@/components/planning/week/ProcessInbox";
import ProcessProjects from "@/components/planning/week/ProcessProjects";
import { useContextContext } from "@/contexts/ContextContext";

const WeeklyPlanningPage = () => {
const { context } = useContextContext();
const { error } = useWeekPlanContext();
const {
error,
inboxSkipped,
financialUpdateSkipped,
crmUpdateSkipped,
skipCrmUpdate,
skipFinancialUpdate,
skipInbox,
} = useWeekPlanContext();
const { inbox } = useInbox();
const { sfdcUploadTooOld, mutateSfdc } = useMrrLatestUpload();
const { sfdcUploadTooOld, mutateSfdc, mrrUploadTooOld, mutateMrr } =
useMrrLatestUpload();

return (
<MainLayout title="Weekly Planning" sectionName="Weekly Planning">
Expand All @@ -30,10 +40,12 @@ const WeeklyPlanningPage = () => {
<ContextSwitcher />
</div>

{inbox && inbox.length > 0 ? (
<ProcessInbox />
) : context === "work" && sfdcUploadTooOld ? (
<ProcessCrmUpdates {...{ mutateSfdc }} />
{!inboxSkipped && inbox && inbox.length > 0 ? (
<ProcessInbox {...{ skipInbox }} />
) : context === "work" && !financialUpdateSkipped && mrrUploadTooOld ? (
<ProcessFinancialUpdates {...{ mutateMrr, skipFinancialUpdate }} />
) : context === "work" && !crmUpdateSkipped && sfdcUploadTooOld ? (
<ProcessCrmUpdates {...{ mutateSfdc, skipCrmUpdate }} />
) : (
<ProcessProjects />
)}
Expand All @@ -43,6 +55,3 @@ const WeeklyPlanningPage = () => {
};

export default withWeekPlan(WeeklyPlanningPage);

// ) : context === "work" && mrrUploadTooOld ? (
// <ProcessFinancialUpdates {...{ mutateMrr }} />

0 comments on commit 5c9b484

Please sign in to comment.