diff --git a/src/app/needs/next-actions/components/NextActionsDisplay.tsx b/src/app/needs/next-actions/components/NextActionsDisplay.tsx index a33774bd..6aa467da 100644 --- a/src/app/needs/next-actions/components/NextActionsDisplay.tsx +++ b/src/app/needs/next-actions/components/NextActionsDisplay.tsx @@ -5,8 +5,8 @@ import { useDatabase } from "@/context/DatabaseContext"; import clsx from "clsx"; import changeCase from "@/lib/utils/changeCase"; import NextActionsSection from "./NextActionsSection"; -import Button from "@/ui/shared/Button"; import Modal from "@/ui/shared/Modal"; +import { TrashIcon } from "@heroicons/react/24/outline"; export interface NeedDocument { id: string; @@ -34,15 +34,18 @@ export interface NextActionDocument { export default function NextActionsDisplay() { const database = useDatabase(); const [highlightedNeeds, setHighlightedNeeds] = useState([]); - const [relatedNextActions, setRelatedNextActions] = useState([]); + const [relatedNextActions, setRelatedNextActions] = useState< + NextActionDocument[] + >([]); const [chainEnd, setChainEnd] = useState(0); const [actionState, setActionState] = useState(0); const [mode, setMode] = useState<"create" | "destroy">("create"); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); - const [choppingBlock, setChoppingBlock] = useState(null); - + const [choppingBlock, setChoppingBlock] = useState( + null + ); - useEffect(() => { /* Fetch Data */ + useEffect(() => { async function fetchData() { const needsDocs = await database.getFromDb("needs"); const allNeeds = needsDocs.map((doc) => doc.toJSON() as NeedDocument); @@ -73,9 +76,9 @@ export default function NextActionsDisplay() { fetchData(); }, [database, chainEnd, actionState]); - useEffect(() => { /* Log Mode Change */ + useEffect(() => { console.log(`...to ${mode}.`); - }, [mode]) + }, [mode]); const priorityGroups = useMemo(() => { if (highlightedNeeds.length === 0) return []; @@ -126,7 +129,7 @@ export default function NextActionsDisplay() { if (highlighted) { const updatedTimestamps = [...action.selectedTimestamps]; updatedTimestamps.pop(); - + await database.updateDocument( collectionName, action.id, @@ -141,9 +144,14 @@ export default function NextActionsDisplay() { action.timestamp ); } else { - const updatedTimestamps = [...action.selectedTimestamps, new Date().toISOString()]; + const updatedTimestamps = [ + ...action.selectedTimestamps, + new Date().toISOString(), + ]; - const parentNeed = highlightedNeeds.find((need) => need.id === action.need); + const parentNeed = highlightedNeeds.find( + (need) => need.id === action.need + ); if (!parentNeed) { console.error("Parent need not found for action:", action); return; @@ -164,7 +172,7 @@ export default function NextActionsDisplay() { ); } - setChainEnd(prev => prev + 1); + setChainEnd((prev) => prev + 1); }; const onDeleteAction = async (action: NextActionDocument) => { @@ -176,11 +184,11 @@ export default function NextActionsDisplay() { await database.deleteFromDb("next_actions", action.id); setChoppingBlock(null); - setChainEnd(prev => prev + 1); + setChainEnd((prev) => prev + 1); }; const onToggleMode = () => { - switch(mode) { + switch (mode) { case "create": setMode("destroy"); break; @@ -211,35 +219,41 @@ export default function NextActionsDisplay() { console.log(`Action State: ${actionState}`); } }; - + return (
- {priorityGroups.length === 0 - ? (

- You have no unmet needs selected. Review which needs might be unmet before we can recommend next actions to meet them. -

) - : (priorityGroups.map((group, i) => ( + {priorityGroups.length === 0 ? ( +

+ You have no unmet needs selected. Review which needs might be unmet + before we can recommend next actions to meet them. +

+ ) : ( + priorityGroups.map((group, i) => (
-

+

{changeCase(group.priority.name, "sentence")}

- + {group.needs.map((need) => { const actions = getActionsForNeed(need.id); return (

- To meet a need for {changeCase(need.name, "lower")}, which actions can you take next? + To meet a need for {changeCase(need.name, "lower")}, which + actions can you take next?

- - ))) - } - - + + { @@ -279,10 +297,12 @@ export default function NextActionsDisplay() { label: "Yes", }} backButton={{ - action: () => { setIsDeleteModalOpen(false) }, + action: () => { + setIsDeleteModalOpen(false); + }, label: "No", }} />
); -} \ No newline at end of file +} diff --git a/src/app/needs/next-actions/components/NextActionsSection.tsx b/src/app/needs/next-actions/components/NextActionsSection.tsx index 6746b69f..2cc0aa09 100644 --- a/src/app/needs/next-actions/components/NextActionsSection.tsx +++ b/src/app/needs/next-actions/components/NextActionsSection.tsx @@ -22,7 +22,7 @@ export default function NextActionsSection({ onToggleAction, handleAddAction, onDeleteAction, - mode + mode, }: SectionProps) { const [modalOpen, setModalOpen] = useState(false); const [newAction, setNewAction] = useState(""); @@ -38,60 +38,64 @@ export default function NextActionsSection({ return ( <> - { actions.length > 0 - ?
+ {actions.length > 0 ? ( +
{actions.map((action) => { const highlighted = new Date(action.selectedExpiry) > new Date(); return ( -
- : ( -
-

- No next actions available for this need. -

+ ) : ( +
+

+ No next actions available for this need. +

- -
- ) - } + +
+ )} - { setNewAction(""); setModalOpen(false); @@ -100,4 +104,4 @@ export default function NextActionsSection({ /> ); -} \ No newline at end of file +}