Skip to content

Commit

Permalink
Merge pull request #31 from suvarnakale/main
Browse files Browse the repository at this point in the history
Issue #PS-2172 feat:Implementation of delete functionality
  • Loading branch information
itsvick authored Oct 11, 2024
2 parents a5d6222 + dfe3cfc commit 368d316
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 14 deletions.
19 changes: 17 additions & 2 deletions src/components/CourseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,7 +25,7 @@ interface ContentCardProps {
status: string;
identifier?: string;
mimeType?: string;
mode?:string;
mode?: string;
onDelete?: () => void;
}

Expand All @@ -49,6 +50,20 @@ const CourseCard: React.FC<ContentCardProps> = ({
}
};

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 (
<Card
sx={{
Expand Down Expand Up @@ -96,7 +111,7 @@ const CourseCard: React.FC<ContentCardProps> = ({
{(status === Status.DRAFT || status === Status.LIVE) && (
<CardActions disableSpacing>
<Box display="flex" justifyContent="flex-end" width="100%">
<IconButton aria-label="delete" onClick={onDelete}>
<IconButton aria-label="delete" onClick={handleDeleteClick}>
<DeleteIcon />
</IconButton>
</Box>
Expand Down
6 changes: 3 additions & 3 deletions src/components/SideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ const Sidebar: React.FC<SidebarProps> = ({ 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"
Expand All @@ -97,7 +97,7 @@ const Sidebar: React.FC<SidebarProps> = ({ selectedKey, onSelect }) => {
"&:hover": {
background:
selectedKey === item.key
? theme.palette.primary.main
? "var(--mui-palette-primary-main)"
: "transparent",
},
}}
Expand Down
8 changes: 6 additions & 2 deletions src/pages/workspace/content/draft/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const DraftPage = () => {
const [filter, setFilter] = useState("all");
const [sortBy, setSortBy] = useState("updated");
const [contentList, setContentList] = React.useState<content[]>([]);
const [contentDeleted, setContentDeleted] = React.useState(false);
const [loading, setLoading] = useState(false);
const [debouncedSearchTerm, setDebouncedSearchTerm] =
useState<string>(searchTerm);
Expand Down Expand Up @@ -67,6 +68,7 @@ const DraftPage = () => {

const handleDelete = (index: number) => {
console.log(`Deleting item at index ${index}`);
setContentDeleted((prev) => !prev);
};

useEffect(() => {
Expand All @@ -75,15 +77,17 @@ 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) {
console.log(error);
}
};
getDraftContentList();
}, [debouncedSearchTerm]);
}, [debouncedSearchTerm, contentDeleted]);

return (
<Layout selectedKey={selectedKey} onSelect={setSelectedKey}>
Expand Down
10 changes: 7 additions & 3 deletions src/pages/workspace/content/publish/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const PublishPage = () => {
const [sortBy, setSortBy] = useState("updated");
const [contentList, setContentList] = React.useState<content[]>([]);
const [loading, setLoading] = useState(false);
const [contentDeleted, setContentDeleted] = React.useState(false);
const [debouncedSearchTerm, setDebouncedSearchTerm] =
useState<string>(searchTerm);

Expand Down Expand Up @@ -55,6 +56,7 @@ const PublishPage = () => {

const handleDelete = (index: number) => {
console.log(`Deleting item at index ${index}`);
setContentDeleted((prev) => !prev);
};

useEffect(() => {
Expand All @@ -63,15 +65,17 @@ 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) {
console.log(error);
}
};
getPublishContentList();
}, [debouncedSearchTerm]);
}, [debouncedSearchTerm, contentDeleted]);

return (
<Layout selectedKey={selectedKey} onSelect={setSelectedKey}>
Expand Down Expand Up @@ -110,7 +114,7 @@ const PublishPage = () => {
status={content.status}
identifier={content?.identifier}
mimeType={content?.mimeType}
mode={'read'}
mode={"read"}
onDelete={() => handleDelete(index)}
/>
</Box>
Expand Down
10 changes: 7 additions & 3 deletions src/pages/workspace/content/submitted/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const SubmittedForReviewPage = () => {
const [searchTerm, setSearchTerm] = useState("");
const [contentList, setContentList] = React.useState<content[]>([]);
const [loading, setLoading] = useState(false);
const [contentDeleted, setContentDeleted] = React.useState(false);
const [debouncedSearchTerm, setDebouncedSearchTerm] =
useState<string>(searchTerm);

Expand Down Expand Up @@ -54,6 +55,7 @@ const SubmittedForReviewPage = () => {

const handleDelete = (index: number) => {
console.log(`Deleting item at index ${index}`);
setContentDeleted((prev) => !prev);
};

useEffect(() => {
Expand All @@ -62,15 +64,17 @@ 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) {
console.log(error);
}
};
getReviewContentList();
}, [debouncedSearchTerm]);
}, [debouncedSearchTerm, contentDeleted]);

return (
<Layout selectedKey={selectedKey} onSelect={setSelectedKey}>
Expand Down Expand Up @@ -111,7 +115,7 @@ const SubmittedForReviewPage = () => {
status={content.status}
identifier={content?.identifier}
mimeType={content?.mimeType}
mode={'review'}
mode={"review"}
onDelete={() => handleDelete(index)}
/>
</Box>
Expand Down
23 changes: 22 additions & 1 deletion src/services/ContentService.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;
}
};
8 changes: 8 additions & 0 deletions src/services/RestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,11 @@ export async function deleteApi<T>(
): Promise<AxiosResponse> {
return axiosInstance.delete(url, { data: body, headers });
}

export async function delApi<T>(
url: string,
body?: T,
headers: AxiosRequestConfig["headers"] = {}
): Promise<AxiosResponse> {
return axiosInstance.delete(url, { data: body, headers });
}
File renamed without changes.

0 comments on commit 368d316

Please sign in to comment.