-
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.
feature: Adds deletion check on a goal with multiple tasks, adds the …
…date picker, refactors the Goal component.
- Loading branch information
1 parent
b8f3408
commit aba1c61
Showing
10 changed files
with
234 additions
and
114 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
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
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
51 changes: 51 additions & 0 deletions
51
apps/private/src/components/GoalList/components/Goal/components/GoalActionGroup.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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react'; | ||
import {IconButton} from "koi-pool"; | ||
import checkAll from "../assets/confirm_check.svg"; | ||
import uncheckAll from "../assets/remove_check.svg"; | ||
import edit from "../assets/pencil.svg"; | ||
import copy from "../assets/copy.svg"; | ||
import trash from "../assets/archive.ico"; | ||
import {GoalType, TaskType} from "@repo/types"; | ||
import TaskActions from "../../../actions/TaskActions"; | ||
import {useGoalListContext} from "../../../../../contexts/GoalListProvider/GoalListProvider"; | ||
import GoalActions from "../../../actions/GoalActions"; | ||
|
||
type GoalActionGroupProps = GoalType & {id: string, taskListOfIds: string[], handleToggleGoalEditing: ()=> void} | ||
|
||
const GoalActionGroup = ({tasks, id, taskListOfIds, handleToggleGoalEditing}: GoalActionGroupProps) => { | ||
const {applyActionToGoalList} = useGoalListContext(); | ||
|
||
const handleToggleAllTasks = () => applyActionToGoalList(TaskActions.toggleAllTasks(id)); | ||
const handleDuplicateGoal = () => applyActionToGoalList(GoalActions.duplicate(id)); | ||
|
||
|
||
const isEveryTaskComplete = taskListOfIds.every((taskId) => { | ||
const taskBeingChecked = tasks[taskId] as TaskType; | ||
|
||
return taskBeingChecked.isCompleted | ||
}) | ||
|
||
return ( | ||
<div className='Subheader'> | ||
|
||
<IconButton className={'IconButton'} | ||
src={isEveryTaskComplete ? checkAll : uncheckAll} | ||
alt={'Reset Objectives'} | ||
isActive={isEveryTaskComplete} | ||
variant={'accept'} title={'Toggle goal tasks'} | ||
onClick={handleToggleAllTasks}/> | ||
<IconButton className={'IconButton'} src={edit} alt={'Edit'} | ||
variant={'accept'} title={'Edit goal'} | ||
onClick={handleToggleGoalEditing}/> | ||
|
||
<IconButton className={'IconButton'} src={copy} alt={'Duplicate'} | ||
variant={'accept'} title={'Duplicate goal'} | ||
onClick={handleDuplicateGoal}/> | ||
|
||
<IconButton className={'IconButton'} src={trash} alt={'Archive'} | ||
variant={'caution'} onClick={handleDuplicateGoal}/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GoalActionGroup; |
55 changes: 55 additions & 0 deletions
55
apps/private/src/components/GoalList/components/Goal/components/GoalDeleteModal.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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React, {useState} from 'react'; | ||
import {CloseButton, GenericAcceptanceModal} from "koi-pool"; | ||
import GoalActions from "../../../actions/GoalActions.js"; | ||
import {useGoalListContext} from "../../../../../contexts/GoalListProvider/GoalListProvider.js"; | ||
import {TaskType} from "@repo/types"; | ||
|
||
type GoalDeleteButtonProps = { id: string, name: string, taskListOfIds: string[] }; | ||
|
||
const GoalDeleteButton = ({id, name, taskListOfIds}: GoalDeleteButtonProps) => { | ||
const {applyActionToGoalList} = useGoalListContext(); | ||
const [showConfirmDeleteModal, setShowConfirmDeleteModal] = useState<boolean>(false) | ||
|
||
const handleClose = () => { | ||
setShowConfirmDeleteModal(false); | ||
} | ||
|
||
const handleDeleteGoal = () => applyActionToGoalList(GoalActions.remove(id)); | ||
|
||
const showDeleteModal = () => { | ||
if (taskListOfIds.length <= 1) { | ||
handleDeleteGoal(); | ||
} else { | ||
setShowConfirmDeleteModal(true) | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<CloseButton onClick={showDeleteModal}/> | ||
|
||
<GenericAcceptanceModal handleClose={handleClose} handleSubmit={handleDeleteGoal} | ||
isOpen={showConfirmDeleteModal} | ||
modalAttributes={{ | ||
style: { | ||
height: 'fit-content', | ||
fontSize: '1rem', | ||
minHeight: "200px" | ||
} | ||
}} | ||
isNegative | ||
cancelButtonText={'Keep it'} | ||
submitButtonText={'Delete it'} | ||
actionGroupAttributes={{style: {marginTop: '3rem', border: 'unset'}}} | ||
> | ||
<h2> | ||
Are you sure you want to delete the goal | ||
{Boolean(name) ? <i> ({name})</i> : ''}? | ||
</h2> | ||
</GenericAcceptanceModal> | ||
</> | ||
|
||
); | ||
}; | ||
|
||
export default GoalDeleteButton; |
68 changes: 68 additions & 0 deletions
68
apps/private/src/components/GoalList/components/Goal/components/GoalHeader.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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React, {ChangeEvent, KeyboardEvent} from 'react'; | ||
import {FloatingLabelInputWithButton} from "koi-pool"; | ||
import {GoalType} from "@repo/types"; | ||
import dayjs from "dayjs"; | ||
import GoalActions from "../../../actions/GoalActions"; | ||
import {useGoalListContext} from "../../../../../contexts/GoalListProvider/GoalListProvider"; | ||
import {handleSubmitEnter} from "@repo/shared"; | ||
import {findNextElementInListToFocusOn} from "../../../../../utils/utils"; | ||
|
||
type GoalHeaderProps = GoalType & { id: string, handleToggleGoalEditing: () => void, tasksListOfIds: string[] } | ||
|
||
const GoalHeader = ({ | ||
completionDate, | ||
isEditing, | ||
tasksCompleted, | ||
name, | ||
id, | ||
handleToggleGoalEditing, | ||
tasksListOfIds | ||
}: GoalHeaderProps) => { | ||
const {applyActionToGoalList} = useGoalListContext(); | ||
|
||
|
||
const handleGoalNameEnterPress = (event: KeyboardEvent) => handleSubmitEnter(event, () => { | ||
handleToggleGoalEditing() | ||
findNextElementInListToFocusOn(tasksListOfIds) | ||
}) | ||
|
||
const handleUpdateGoalName = (value: ChangeEvent<HTMLInputElement>) => applyActionToGoalList(GoalActions.updateName(id, value.target.value)) | ||
|
||
const handleUpdateGoalDate = (event: ChangeEvent<HTMLInputElement>) => { | ||
const userDate = event.target.value; | ||
const parsedDate = dayjs(userDate); | ||
if (parsedDate.isValid()) { | ||
applyActionToGoalList(GoalActions.updateDueDate(id, parsedDate.toDate())) | ||
} else { | ||
console.error('Invalid date:', userDate); | ||
} | ||
} | ||
|
||
const formattedDate = dayjs(completionDate).format('YYYY-MM-DD') | ||
|
||
return ( | ||
<div className='Header'> | ||
{ | ||
isEditing | ||
? | ||
<FloatingLabelInputWithButton label='' placeholder={'Goal Name'} value={name} | ||
onClick={handleToggleGoalEditing} | ||
onKeyDown={handleGoalNameEnterPress} | ||
width={300} onChange={handleUpdateGoalName} | ||
/> | ||
: | ||
<h2 onDoubleClick={handleToggleGoalEditing}> | ||
{name} | ||
</h2> | ||
} | ||
<div> | ||
|
||
<p>Due: <input type='date' value={formattedDate} onChange={handleUpdateGoalDate}/></p> | ||
<p>Completed: <b>{Math.round((tasksCompleted / tasksListOfIds.length) * 100)}%</b></p> | ||
</div> | ||
|
||
</div> | ||
); | ||
}; | ||
|
||
export default GoalHeader; |
Oops, something went wrong.