-
Notifications
You must be signed in to change notification settings - Fork 2
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 #95 from fac30/feature/create-and-delete-actions
Create Next Actions & Allow Their Immediate Selection
- Loading branch information
Showing
6 changed files
with
168 additions
and
139 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
70 changes: 53 additions & 17 deletions
70
src/app/needs/next-actions/components/NextActionsSection.tsx
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 |
---|---|---|
@@ -1,38 +1,74 @@ | ||
"use client"; | ||
|
||
import React from "react"; | ||
import React, { useState } from "react"; | ||
import Button from "@/ui/shared/Button"; | ||
import Modal from "@/ui/shared/Modal"; | ||
import { NeedDocument } from "./NextActionsDisplay"; | ||
import { NextActionDocument } from "./NextActionsDisplay"; | ||
import { PlusCircleIcon } from "@heroicons/react/24/outline"; | ||
|
||
interface NextActionsSectionProps { | ||
interface SectionProps { | ||
need: NeedDocument; | ||
actions: NextActionDocument[]; | ||
onToggleAction: (action: NextActionDocument) => Promise<void>; | ||
handleAddAction: (newAction: string, need: NeedDocument) => Promise<void>; | ||
} | ||
|
||
export default function NextActionsSection({ | ||
need, | ||
actions, | ||
onToggleAction, | ||
}: NextActionsSectionProps) { | ||
return ( | ||
handleAddAction, | ||
}: SectionProps) { | ||
const [modalOpen, setModalOpen] = useState(false); | ||
const [newAction, setNewAction] = useState<string>(""); | ||
|
||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setNewAction(e.target.value) | ||
}; | ||
|
||
const handleSubmitAction = async () => { | ||
await handleAddAction(newAction, need); | ||
setModalOpen(false); | ||
} | ||
|
||
return ( <> | ||
<div className="ml-4 mb-6"> | ||
{actions.map((action) => { | ||
const highlighted = new Date(action.selectedExpiry) > new Date(); | ||
|
||
return ( | ||
<Button | ||
key={action.id} | ||
label={action.name} | ||
className={ | ||
highlighted | ||
? "bg-twd-primary-purple text-black" | ||
: "bg-gray-600 text-white" | ||
} | ||
onClick={() => onToggleAction(action)} | ||
/> | ||
); | ||
return (<Button key={action.id} | ||
label={action.name} | ||
className={ highlighted ? | ||
"bg-twd-primary-purple text-black" : | ||
"bg-gray-600 text-white" | ||
} | ||
onClick={() => onToggleAction(action)} | ||
/>); | ||
})} | ||
|
||
<button onClick={() => setModalOpen(true)} | ||
className="flex justify-center items-center" | ||
aria-label="Add Action" | ||
> | ||
<PlusCircleIcon className="w-7 m-auto" /> | ||
</button> | ||
</div> | ||
); | ||
|
||
<Modal title="Add a New Action" | ||
inputModal={true} | ||
modalOpen={modalOpen} | ||
placeholder="What action might help meet this need?" | ||
handleInputChange={handleInputChange} | ||
forwardButton={{ label: "Add", | ||
action: handleSubmitAction, | ||
}} | ||
backButton={{ label: "Cancel", | ||
action: () => { | ||
setNewAction(""); | ||
setModalOpen(false); | ||
}, | ||
}} | ||
/> | ||
</> ); | ||
} |
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
Oops, something went wrong.