Skip to content

Commit 150c633

Browse files
author
Rajat Saxena
committed
WIP: Sections are adjuster as per course type; marked previous purchase related modules deprecated;
1 parent 9337aee commit 150c633

File tree

20 files changed

+380
-235
lines changed

20 files changed

+380
-235
lines changed

apps/web/app/(with-contexts)/dashboard/(sidebar)/product/[id]/content/page.tsx

Lines changed: 95 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@ import {
3131
import Link from "next/link";
3232
import {
3333
BUTTON_NEW_LESSON_TEXT,
34+
BUTTON_NEW_LESSON_TEXT_DOWNLOAD,
3435
COURSE_CONTENT_HEADER,
3536
EDIT_SECTION_HEADER,
37+
LESSON_GROUP_DELETED,
3638
MANAGE_COURSES_PAGE_HEADING,
3739
TOAST_TITLE_ERROR,
40+
TOAST_TITLE_SUCCESS,
3841
} from "@ui-config/strings";
3942
import DashboardContent from "@components/admin/dashboard-content";
4043
import { AddressContext } from "@components/contexts";
4144
import useProduct from "../../../../../../../hooks/use-product";
4245
import { truncate } from "@ui-lib/utils";
43-
import { Lesson } from "@courselit/common-models";
46+
import { Constants, Lesson } from "@courselit/common-models";
4447
import { DragAndDrop, useToast } from "@courselit/components-library";
4548
import { FetchBuilder } from "@courselit/utils";
4649
import {
@@ -53,7 +56,10 @@ import { Droplets } from "lucide-react";
5356

5457
export default function ContentPage() {
5558
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
56-
const [itemToDelete, setItemToDelete] = useState(null);
59+
const [itemToDelete, setItemToDelete] = useState<Record<
60+
string,
61+
string
62+
> | null>(null);
5763
const [collapsedSections, setCollapsedSections] = useState<string[]>([]);
5864
const [hoveredSectionIndex, setHoveredSectionIndex] = useState<
5965
number | null
@@ -73,9 +79,10 @@ export default function ContentPage() {
7379
];
7480
const { toast } = useToast();
7581

76-
const handleDelete = () => {
82+
const handleDelete = async () => {
7783
setDeleteDialogOpen(false);
7884
setItemToDelete(null);
85+
await removeGroup(itemToDelete?.id!, product?.courseId!);
7986
};
8087

8188
const toggleSectionCollapse = (sectionId: string) => {
@@ -135,6 +142,49 @@ export default function ContentPage() {
135142
}
136143
};
137144

145+
const removeGroup = async (groupId: string, courseId: string) => {
146+
const mutation = `
147+
mutation RemoveGroup ($id: String!, $courseId: String!) {
148+
removeGroup(
149+
id: $id,
150+
courseId: $courseId
151+
) {
152+
courseId
153+
}
154+
}
155+
`;
156+
const fetch = new FetchBuilder()
157+
.setUrl(`${address.backend}/api/graph`)
158+
.setPayload({
159+
query: mutation,
160+
variables: {
161+
id: groupId,
162+
courseId: courseId,
163+
},
164+
})
165+
.setIsGraphQLEndpoint(true)
166+
.build();
167+
try {
168+
const response = await fetch.exec();
169+
if (response.removeGroup?.courseId) {
170+
toast({
171+
title: TOAST_TITLE_SUCCESS,
172+
description: LESSON_GROUP_DELETED,
173+
});
174+
// course.groups.splice(
175+
// course.groups.findIndex((group) => group.id === groupId),
176+
// 1,
177+
// );
178+
}
179+
} catch (err: any) {
180+
toast({
181+
title: TOAST_TITLE_ERROR,
182+
description: err.message,
183+
variant: "destructive",
184+
});
185+
}
186+
};
187+
138188
return (
139189
<DashboardContent breadcrumbs={breadcrumbs}>
140190
<h1 className="text-4xl font-semibold tracking-tight mb-8">
@@ -215,19 +265,28 @@ export default function ContentPage() {
215265
>
216266
Add Section Below
217267
</DropdownMenuItem> */}
218-
<DropdownMenuSeparator />
219-
<DropdownMenuItem
220-
onClick={() => {
221-
setItemToDelete({
222-
type: "section",
223-
title: section.name,
224-
});
225-
setDeleteDialogOpen(true);
226-
}}
227-
className="text-red-600"
228-
>
229-
Delete Section
230-
</DropdownMenuItem>
268+
{!(
269+
product?.type?.toLowerCase() ===
270+
Constants.CourseType.DOWNLOAD &&
271+
product?.groups?.length === 1
272+
) && (
273+
<>
274+
<DropdownMenuSeparator />
275+
<DropdownMenuItem
276+
onClick={() => {
277+
setItemToDelete({
278+
type: "section",
279+
title: section.name,
280+
id: section.id,
281+
});
282+
setDeleteDialogOpen(true);
283+
}}
284+
className="text-red-600"
285+
>
286+
Delete Section
287+
</DropdownMenuItem>
288+
</>
289+
)}
231290
</DropdownMenuContent>
232291
</DropdownMenu>
233292
</div>
@@ -307,7 +366,10 @@ export default function ContentPage() {
307366
href={`/dashboard/product/${productId}/content/section/${section.id}/lesson`}
308367
>
309368
<Plus className="mr-2 h-4 w-4" />
310-
{BUTTON_NEW_LESSON_TEXT}
369+
{product?.type?.toLowerCase() ===
370+
Constants.CourseType.DOWNLOAD
371+
? BUTTON_NEW_LESSON_TEXT_DOWNLOAD
372+
: BUTTON_NEW_LESSON_TEXT}
311373
</Link>
312374
</Button>
313375
</div>
@@ -337,20 +399,23 @@ export default function ContentPage() {
337399
)}
338400
</div>
339401
))}
340-
<div className="mt-8 flex justify-center">
341-
<Button
342-
variant="outline"
343-
className="text-sm font-medium"
344-
asChild
345-
>
346-
<Link
347-
href={`/dashboard/product/${productId}/content/section/new`}
402+
{product?.type?.toLowerCase() !==
403+
Constants.CourseType.DOWNLOAD && (
404+
<div className="mt-8 flex justify-center">
405+
<Button
406+
variant="outline"
407+
className="text-sm font-medium"
408+
asChild
348409
>
349-
<Plus className="mr-2 h-4 w-4" />
350-
Add Section
351-
</Link>
352-
</Button>
353-
</div>
410+
<Link
411+
href={`/dashboard/product/${productId}/content/section/new`}
412+
>
413+
<Plus className="mr-2 h-4 w-4" />
414+
Add Section
415+
</Link>
416+
</Button>
417+
</div>
418+
)}
354419
</ScrollArea>
355420

356421
<Dialog open={deleteDialogOpen} onOpenChange={setDeleteDialogOpen}>

apps/web/app/(with-contexts)/dashboard/(sidebar)/product/[id]/content/section/[section]/lesson/page.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,12 +1038,24 @@ export default function LessonPage() {
10381038
<DashboardContent breadcrumbs={breadcrumbs}>
10391039
<header>
10401040
<h1 className="text-4xl font-semibold">
1041-
{isEditing ? "Edit Lesson" : "New Lesson"}
1041+
{product?.type?.toLowerCase() ===
1042+
Constants.CourseType.COURSE &&
1043+
(isEditing ? "Edit Lesson" : "New Lesson")}
1044+
{product?.type?.toLowerCase() ===
1045+
Constants.CourseType.DOWNLOAD &&
1046+
(isEditing ? "Edit File" : "New File")}
10421047
</h1>
10431048
<p className="text-muted-foreground mt-2">
1044-
{isEditing
1045-
? "Modify the details of your existing lesson"
1046-
: "Create a new lesson for your course"}
1049+
{product?.type?.toLowerCase() ===
1050+
Constants.CourseType.COURSE &&
1051+
(isEditing
1052+
? "Modify the details of your existing lesson"
1053+
: "Create a new lesson for your product")}
1054+
{product?.type?.toLowerCase() ===
1055+
Constants.CourseType.DOWNLOAD &&
1056+
(isEditing
1057+
? "Modify the details of your existing file"
1058+
: "Create a new file for your product")}
10471059
</p>
10481060
</header>
10491061

apps/web/app/(with-contexts)/dashboard/(sidebar)/product/[id]/content/section/new/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { Button } from "@/components/ui/button";
66
import { Input } from "@/components/ui/input";
77
import { Label } from "@/components/ui/label";
88
import Link from "next/link";
9-
import { useToast } from "@/hooks/use-toast";
109
import {
1110
BTN_CONTINUE,
1211
COURSE_CONTENT_HEADER,
@@ -15,10 +14,11 @@ import {
1514
TOAST_TITLE_ERROR,
1615
} from "@ui-config/strings";
1716
import { AddressContext } from "@components/contexts";
18-
import useProduct from "../../../../../../../../../hooks/use-product";
17+
import useProduct from "@/hooks/use-product";
1918
import { truncate } from "@ui-lib/utils";
2019
import DashboardContent from "@components/admin/dashboard-content";
2120
import { FetchBuilder } from "@courselit/utils";
21+
import { useToast } from "@courselit/components-library";
2222

2323
export default function SectionPage() {
2424
const { toast } = useToast();
@@ -68,7 +68,7 @@ export default function SectionPage() {
6868

6969
const createSection = async () => {
7070
const query = `
71-
mutation addGroup($courseId: ID!, $name: String!) {
71+
mutation addGroup($courseId: String!, $name: String!) {
7272
course: addGroup(id: $courseId, name: $name) {
7373
courseId,
7474
groups {

0 commit comments

Comments
 (0)