From eea2852cb70764cd73e0390e9ef78892f5915521 Mon Sep 17 00:00:00 2001 From: suvarnakale Date: Fri, 11 Oct 2024 12:13:23 +0530 Subject: [PATCH 1/2] Issue #PS-2172 feat:Implementation of delete functionality --- src/components/CourseCard.tsx | 19 +++++++++++++-- src/components/SideBar.tsx | 6 ++--- src/pages/workspace/content/draft/index.tsx | 8 +++++-- src/services/ContentService.ts | 23 ++++++++++++++++++- src/services/RestClient.ts | 8 +++++++ .../{CustomTheme.tsx => CustomTheme.ts} | 0 6 files changed, 56 insertions(+), 8 deletions(-) rename src/styles/{CustomTheme.tsx => CustomTheme.ts} (100%) diff --git a/src/components/CourseCard.tsx b/src/components/CourseCard.tsx index e2e1e5c..9a0dabd 100644 --- a/src/components/CourseCard.tsx +++ b/src/components/CourseCard.tsx @@ -15,6 +15,7 @@ import ImageIcon from "@mui/icons-material/Image"; import { Status } from "@/utils/app.constant"; import { MIME_TYPE } from "@/utils/app.config"; import router from "next/router"; +import { deleteContent } from "@/services/ContentService"; interface ContentCardProps { title: string; @@ -24,7 +25,7 @@ interface ContentCardProps { status: string; identifier?: string; mimeType?: string; - mode?:string; + mode?: string; onDelete?: () => void; } @@ -49,6 +50,20 @@ const CourseCard: React.FC = ({ } }; + const handleDeleteClick = async () => { + if (identifier && mimeType) { + try { + await deleteContent(identifier, mimeType); + console.log(`Deleted item with identifier - ${identifier}`); + if (onDelete) { + onDelete(); + } + } catch (error) { + console.error("Failed to delete content:", error); + } + } + }; + return ( = ({ {(status === Status.DRAFT || status === Status.LIVE) && ( - + diff --git a/src/components/SideBar.tsx b/src/components/SideBar.tsx index 08b890f..b669523 100644 --- a/src/components/SideBar.tsx +++ b/src/components/SideBar.tsx @@ -87,8 +87,8 @@ const Sidebar: React.FC = ({ selectedKey, onSelect }) => { borderRadius: "4rem", backgroundColor: selectedKey === item.key - ? theme.palette.primary.main - : "transparent", // Background for selected item + ? "var(--mui-palette-primary-main)" + : "transparent", color: selectedKey === item.key ? "#2E1500" @@ -97,7 +97,7 @@ const Sidebar: React.FC = ({ selectedKey, onSelect }) => { "&:hover": { background: selectedKey === item.key - ? theme.palette.primary.main + ? "var(--mui-palette-primary-main)" : "transparent", }, }} diff --git a/src/pages/workspace/content/draft/index.tsx b/src/pages/workspace/content/draft/index.tsx index dd64f3a..bcae7e2 100644 --- a/src/pages/workspace/content/draft/index.tsx +++ b/src/pages/workspace/content/draft/index.tsx @@ -15,6 +15,7 @@ const DraftPage = () => { const [filter, setFilter] = useState("all"); const [sortBy, setSortBy] = useState("updated"); const [contentList, setContentList] = React.useState([]); + const [contentDeleted, setContentDeleted] = React.useState(false); const [loading, setLoading] = useState(false); const [debouncedSearchTerm, setDebouncedSearchTerm] = useState(searchTerm); @@ -67,6 +68,7 @@ const DraftPage = () => { const handleDelete = (index: number) => { console.log(`Deleting item at index ${index}`); + setContentDeleted((prev) => !prev); }; useEffect(() => { @@ -75,7 +77,9 @@ const DraftPage = () => { setLoading(true); const query = debouncedSearchTerm || ""; const response = await getContent(["Draft", "FlagDraft"], query); - const contentList = (response?.content || []).concat(response?.QuestionSet || []); + const contentList = (response?.content || []).concat( + response?.QuestionSet || [] + ); setContentList(contentList); setLoading(false); } catch (error) { @@ -83,7 +87,7 @@ const DraftPage = () => { } }; getDraftContentList(); - }, [debouncedSearchTerm]); + }, [debouncedSearchTerm, contentDeleted]); return ( diff --git a/src/services/ContentService.ts b/src/services/ContentService.ts index 6dd0f0f..f4af7c0 100644 --- a/src/services/ContentService.ts +++ b/src/services/ContentService.ts @@ -1,7 +1,8 @@ import { stringify } from "json5"; import { getLocalStoredUserData } from "./LocalStorageService"; -import { post } from "./RestClient"; +import { delApi, deleteApi, post } from "./RestClient"; import axios from "axios"; +import { MIME_TYPE } from "@/utils/app.config"; const authToken = process.env.NEXT_PUBLIC_AUTH_API_TOKEN; const baseUrl = process.env.NEXT_PUBLIC_BASE_URL; @@ -85,3 +86,23 @@ export const createQuestionSet = async () => { throw error; } }; + +export const deleteContent = async (identifier: string, mimeType: string) => { + const questionsetRetireURL = `/action/questionset/v2/retire/${identifier}`; + const contentRetireURL = `/action/content/v3/retire/${identifier}`; + let apiURL = ""; + if (mimeType === MIME_TYPE.QUESTIONSET_MIME_TYPE) { + apiURL = questionsetRetireURL; + } else if ( + mimeType !== MIME_TYPE.QUESTIONSET_MIME_TYPE && + mimeType !== MIME_TYPE.COLLECTION_MIME_TYPE + ) { + apiURL = contentRetireURL; + } + try { + const response = await delApi(apiURL); // Assuming you have a 'del' method that handles DELETE + return response?.data?.result; + } catch (error) { + throw error; + } +}; diff --git a/src/services/RestClient.ts b/src/services/RestClient.ts index 15160be..e92ca61 100644 --- a/src/services/RestClient.ts +++ b/src/services/RestClient.ts @@ -40,3 +40,11 @@ export async function deleteApi( ): Promise { return axiosInstance.delete(url, { data: body, headers }); } + +export async function delApi( + url: string, + body?: T, + headers: AxiosRequestConfig["headers"] = {} +): Promise { + return axiosInstance.delete(url, { data: body, headers }); +} diff --git a/src/styles/CustomTheme.tsx b/src/styles/CustomTheme.ts similarity index 100% rename from src/styles/CustomTheme.tsx rename to src/styles/CustomTheme.ts From dfe3cfcb1d227798ebc41a1208de0122ab9e200e Mon Sep 17 00:00:00 2001 From: suvarnakale Date: Fri, 11 Oct 2024 12:17:46 +0530 Subject: [PATCH 2/2] Issue #PS-2172 feat:Implementation of delete functionality on publish and review page --- src/pages/workspace/content/publish/index.tsx | 10 +++++++--- src/pages/workspace/content/submitted/index.tsx | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/pages/workspace/content/publish/index.tsx b/src/pages/workspace/content/publish/index.tsx index b7306c8..7556fee 100644 --- a/src/pages/workspace/content/publish/index.tsx +++ b/src/pages/workspace/content/publish/index.tsx @@ -14,6 +14,7 @@ const PublishPage = () => { const [sortBy, setSortBy] = useState("updated"); const [contentList, setContentList] = React.useState([]); const [loading, setLoading] = useState(false); + const [contentDeleted, setContentDeleted] = React.useState(false); const [debouncedSearchTerm, setDebouncedSearchTerm] = useState(searchTerm); @@ -55,6 +56,7 @@ const PublishPage = () => { const handleDelete = (index: number) => { console.log(`Deleting item at index ${index}`); + setContentDeleted((prev) => !prev); }; useEffect(() => { @@ -63,7 +65,9 @@ const PublishPage = () => { setLoading(true); const query = debouncedSearchTerm || ""; const response = await getContent(["Live"], query); - const contentList = (response?.content || []).concat(response?.QuestionSet || []); + const contentList = (response?.content || []).concat( + response?.QuestionSet || [] + ); setContentList(contentList); setLoading(false); } catch (error) { @@ -71,7 +75,7 @@ const PublishPage = () => { } }; getPublishContentList(); - }, [debouncedSearchTerm]); + }, [debouncedSearchTerm, contentDeleted]); return ( @@ -110,7 +114,7 @@ const PublishPage = () => { status={content.status} identifier={content?.identifier} mimeType={content?.mimeType} - mode={'read'} + mode={"read"} onDelete={() => handleDelete(index)} /> diff --git a/src/pages/workspace/content/submitted/index.tsx b/src/pages/workspace/content/submitted/index.tsx index 871f5e6..cc6f149 100644 --- a/src/pages/workspace/content/submitted/index.tsx +++ b/src/pages/workspace/content/submitted/index.tsx @@ -14,6 +14,7 @@ const SubmittedForReviewPage = () => { const [searchTerm, setSearchTerm] = useState(""); const [contentList, setContentList] = React.useState([]); const [loading, setLoading] = useState(false); + const [contentDeleted, setContentDeleted] = React.useState(false); const [debouncedSearchTerm, setDebouncedSearchTerm] = useState(searchTerm); @@ -54,6 +55,7 @@ const SubmittedForReviewPage = () => { const handleDelete = (index: number) => { console.log(`Deleting item at index ${index}`); + setContentDeleted((prev) => !prev); }; useEffect(() => { @@ -62,7 +64,9 @@ const SubmittedForReviewPage = () => { setLoading(true); const query = debouncedSearchTerm || ""; const response = await getContent(["Review", "FlagReview"], query); - const contentList = (response?.content || []).concat(response?.QuestionSet || []); + const contentList = (response?.content || []).concat( + response?.QuestionSet || [] + ); setContentList(contentList); setLoading(false); } catch (error) { @@ -70,7 +74,7 @@ const SubmittedForReviewPage = () => { } }; getReviewContentList(); - }, [debouncedSearchTerm]); + }, [debouncedSearchTerm, contentDeleted]); return ( @@ -111,7 +115,7 @@ const SubmittedForReviewPage = () => { status={content.status} identifier={content?.identifier} mimeType={content?.mimeType} - mode={'review'} + mode={"review"} onDelete={() => handleDelete(index)} />