From 705f0aacfc7ae2cf39a6db81d56bbc3380aaa9be Mon Sep 17 00:00:00 2001 From: harish Date: Sun, 22 Dec 2024 18:03:37 -0500 Subject: [PATCH 1/6] #3097 hook done --- src/frontend/src/apis/onboarding.api.ts | 7 +++++ src/frontend/src/hooks/onboarding.hook.ts | 26 ++++++++++++++-- .../OnboardingConfig/AdminTask.tsx | 30 ++++++++++++++++++- src/frontend/src/utils/urls.ts | 2 ++ 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/src/frontend/src/apis/onboarding.api.ts b/src/frontend/src/apis/onboarding.api.ts index dff34e17a3..8c726ea7c3 100644 --- a/src/frontend/src/apis/onboarding.api.ts +++ b/src/frontend/src/apis/onboarding.api.ts @@ -29,6 +29,13 @@ export const getUsersChecklists = () => { }); }; +/** + * API call to delete a checklist + */ +export const deleteChecklist = (checklistId: string) => { + return axios.post<{ message: string }>(apiUrls.checklistDelete(checklistId)); +}; + /** * API Call to download a google image * @param fileId file id to be downloaded diff --git a/src/frontend/src/hooks/onboarding.hook.ts b/src/frontend/src/hooks/onboarding.hook.ts index 2194afa9ba..83551a6993 100644 --- a/src/frontend/src/hooks/onboarding.hook.ts +++ b/src/frontend/src/hooks/onboarding.hook.ts @@ -1,6 +1,12 @@ -import { useQuery } from 'react-query'; +import { useMutation, useQuery, useQueryClient } from 'react-query'; import { Checklist } from 'shared'; -import { getAllChecklists, getGeneralChecklists, getUsersChecklists, downloadGoogleImage } from '../apis/onboarding.api'; +import { + getAllChecklists, + getGeneralChecklists, + getUsersChecklists, + downloadGoogleImage, + deleteChecklist +} from '../apis/onboarding.api'; export const useAllChecklists = () => { return useQuery(['checklists'], async () => { @@ -23,6 +29,22 @@ export const useUsersTeamTypeChecklists = () => { }); }; +export const useDeleteChecklist = () => { + const queryClient = useQueryClient(); + return useMutation<{ message: string }, Error, any>( + ['checklists', 'delete'], + async (checklistId: string) => { + const { data } = await deleteChecklist(checklistId); + return data; + }, + { + onSuccess: () => { + queryClient.invalidateQueries(['checklists']); + } + } + ); +}; + export const useGetImageUrl = (imageFileId: string | null) => { return useQuery( ['image', imageFileId], diff --git a/src/frontend/src/pages/AdminToolsPage/OnboardingConfig/AdminTask.tsx b/src/frontend/src/pages/AdminToolsPage/OnboardingConfig/AdminTask.tsx index 25b5a8bd73..777980a4f3 100644 --- a/src/frontend/src/pages/AdminToolsPage/OnboardingConfig/AdminTask.tsx +++ b/src/frontend/src/pages/AdminToolsPage/OnboardingConfig/AdminTask.tsx @@ -7,6 +7,9 @@ import SubtaskSection from '../../HomePage/components/SubtaskSection'; import { GridDragIcon } from '@mui/x-data-grid'; import RemoveCircleOutlineIcon from '@mui/icons-material/RemoveCircleOutline'; import EditIcon from '@mui/icons-material/Edit'; +import NERDeleteModal from '../../../components/NERDeleteModal'; +import { useDeleteChecklist } from '../../../hooks/onboarding.hook'; +import { useToast } from '../../../hooks/toasts.hooks'; interface AdminTaskProps { subtasks: Checklist[]; @@ -15,11 +18,27 @@ interface AdminTaskProps { const AdminTask: React.FC = ({ subtasks, parentTask }) => { const [showSubtasks, setShowSubtasks] = useState(false); + const [taskToDelete, setTaskToDelete] = useState(null); const toggleShowSubtasks = () => { setShowSubtasks((prev) => !prev); }; + const toast = useToast(); + const { mutateAsync: deleteChecklist } = useDeleteChecklist(); + + const handleDelete = async (taskId: string) => { + try { + await deleteChecklist(taskId); + toast.success('Task deleted successfully'); + } catch (error: unknown) { + if (error instanceof Error) { + toast.error(error.message); + } + } + setTaskToDelete(null); + }; + return ( @@ -29,7 +48,7 @@ const AdminTask: React.FC = ({ subtasks, parentTask }) => { {parentTask.name} - + setTaskToDelete(parentTask)}> @@ -42,6 +61,15 @@ const AdminTask: React.FC = ({ subtasks, parentTask }) => { {showSubtasks && } + {taskToDelete && ( + setTaskToDelete(null)} + formId="delete-task-form" + dataType="Task" + onFormSubmit={() => handleDelete(taskToDelete.checklistId)} + /> + )} ); }; diff --git a/src/frontend/src/utils/urls.ts b/src/frontend/src/utils/urls.ts index c1490279b1..a2d8813b83 100644 --- a/src/frontend/src/utils/urls.ts +++ b/src/frontend/src/utils/urls.ts @@ -199,6 +199,7 @@ const onboarding = () => `${API_URL}/onboarding`; const allChecklists = () => `${onboarding()}/checklists`; const generalChecklists = () => `${allChecklists()}/general`; const usersTeamTypeChecklists = () => `${allChecklists()}/usersChecklists`; +const checklistDelete = (id: string) => `${onboarding()}/checklist/delete/${id}`; const imageById = (imageId: string) => `${onboarding()}/image/${imageId}`; /**************** Other Endpoints ****************/ @@ -362,6 +363,7 @@ export const apiUrls = { allChecklists, generalChecklists, usersTeamTypeChecklists, + checklistDelete, imageById, version From 61a1f42256380275b0ad41b0dfc14d892c75b77f Mon Sep 17 00:00:00 2001 From: harish Date: Sun, 22 Dec 2024 18:16:21 -0500 Subject: [PATCH 2/6] Triggering CI tests From 8d7402e07b8e3461d9c7f8008b59686adc5e89c3 Mon Sep 17 00:00:00 2001 From: harish Date: Mon, 23 Dec 2024 13:24:50 -0500 Subject: [PATCH 3/6] #3097 alphabetical checklist groups except for general --- src/frontend/src/utils/onboarding.utils.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/utils/onboarding.utils.ts b/src/frontend/src/utils/onboarding.utils.ts index d22f6d4b51..5e00176035 100644 --- a/src/frontend/src/utils/onboarding.utils.ts +++ b/src/frontend/src/utils/onboarding.utils.ts @@ -18,5 +18,16 @@ export const groupChecklists = (checklists: Checklist[]) => { return groupedChecklists; }, {}); - return groupedChecklists; + const sortedGroupNames = Object.keys(groupedChecklists).sort((group1, group2) => { + if (group1 === 'General') return -1; + if (group2 === 'General') return 1; + return group1.localeCompare(group2); + }); + + const sortedGroupedChecklists: Record = {}; + sortedGroupNames.forEach((groupName) => { + sortedGroupedChecklists[groupName] = groupedChecklists[groupName]; + }); + + return sortedGroupedChecklists; }; From e3d0a530e7c28c9d2a3eef45de63423c8976f827 Mon Sep 17 00:00:00 2001 From: harish Date: Wed, 25 Dec 2024 17:35:12 -0500 Subject: [PATCH 4/6] #3097 merge conflicts --- src/frontend/src/apis/onboarding.api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/src/apis/onboarding.api.ts b/src/frontend/src/apis/onboarding.api.ts index ca15ff8f10..ec95c10adb 100644 --- a/src/frontend/src/apis/onboarding.api.ts +++ b/src/frontend/src/apis/onboarding.api.ts @@ -52,8 +52,8 @@ export const deleteChecklist = (checklistId: string) => { export const toggleChecklist = (payload: ToggleChecklistPayload) => { return axios.post(apiUrls.toggleChecklist(payload.checklistId), { ...payload + }); }; - /** * API Call to download a google image * @param fileId file id to be downloaded From ff476010089fdbda82ec540120ec164c2cda5ee4 Mon Sep 17 00:00:00 2001 From: harish Date: Thu, 26 Dec 2024 15:43:13 -0500 Subject: [PATCH 5/6] #3097 delete team type checklists --- .../OnboardingConfig/AdminChecklist.tsx | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/frontend/src/pages/AdminToolsPage/OnboardingConfig/AdminChecklist.tsx b/src/frontend/src/pages/AdminToolsPage/OnboardingConfig/AdminChecklist.tsx index 4c1c4751bf..1e32b955fe 100644 --- a/src/frontend/src/pages/AdminToolsPage/OnboardingConfig/AdminChecklist.tsx +++ b/src/frontend/src/pages/AdminToolsPage/OnboardingConfig/AdminChecklist.tsx @@ -5,17 +5,41 @@ import { useState } from 'react'; import { Checklist } from 'shared'; import AdminTask from './AdminTask'; import AddCircleOutlineIcon from '@mui/icons-material/AddCircleOutline'; +import { useDeleteChecklist } from '../../../hooks/onboarding.hook'; +import NERDeleteModal from '../../../components/NERDeleteModal'; +import RemoveCircleOutlineIcon from '@mui/icons-material/RemoveCircleOutline'; +import { useToast } from '../../../hooks/toasts.hooks'; export const AdminChecklist: React.FC<{ parentChecklists: Checklist[]; checklistName?: string }> = ({ parentChecklists, checklistName }) => { const [showTasks, setShowTasks] = useState(false); + const [tasksToDelete, setTasksToDelete] = useState(null); const toggleShowTasks = () => { setShowTasks((prev) => !prev); }; + const toast = useToast(); + const { mutateAsync: deleteChecklist } = useDeleteChecklist(); + + const handleDelete = async () => { + if (!tasksToDelete) return; + + try { + for (const task of tasksToDelete) { + await deleteChecklist(task.checklistId); + } + toast.success('All tasks deleted successfully'); + } catch (error: unknown) { + if (error instanceof Error) { + toast.error(error.message); + } + } + setTasksToDelete(null); + }; + return ( @@ -33,6 +57,9 @@ export const AdminChecklist: React.FC<{ parentChecklists: Checklist[]; checklist {checklistName} Checklist + setTasksToDelete(parentChecklists)}> + + {showTasks ? ( @@ -69,6 +96,15 @@ export const AdminChecklist: React.FC<{ parentChecklists: Checklist[]; checklist )} + {tasksToDelete && ( + setTasksToDelete(null)} + formId="delete-task-form" + dataType="Task" + onFormSubmit={() => handleDelete()} + /> + )} ); }; From 0c98536621b3f298e96602b3d0338241026f64f4 Mon Sep 17 00:00:00 2001 From: aaryan1203 Date: Thu, 2 Jan 2025 07:44:09 -0500 Subject: [PATCH 6/6] #3097 cleaned up modal --- .../pages/AdminToolsPage/OnboardingConfig/AdminChecklist.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/pages/AdminToolsPage/OnboardingConfig/AdminChecklist.tsx b/src/frontend/src/pages/AdminToolsPage/OnboardingConfig/AdminChecklist.tsx index 1e32b955fe..3a5e211d3b 100644 --- a/src/frontend/src/pages/AdminToolsPage/OnboardingConfig/AdminChecklist.tsx +++ b/src/frontend/src/pages/AdminToolsPage/OnboardingConfig/AdminChecklist.tsx @@ -56,7 +56,7 @@ export const AdminChecklist: React.FC<{ parentChecklists: Checklist[]; checklist {checklistName} Checklist - + setTasksToDelete(parentChecklists)}> @@ -101,7 +101,7 @@ export const AdminChecklist: React.FC<{ parentChecklists: Checklist[]; checklist open={!!tasksToDelete} onHide={() => setTasksToDelete(null)} formId="delete-task-form" - dataType="Task" + dataType="Checklist" onFormSubmit={() => handleDelete()} /> )}