Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/api/study-plan/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,25 @@ export async function GET(req: NextRequest) {
});
return res;
}

export async function DELETE(req: NextRequest) {
const user = await getUser(req);

if (!user) {
return NextResponse.json({}, { status: 401 });
}

const semesterRepository = AppDataSource.getRepository(Semester);

const deleteRes = await semesterRepository.delete({
studyPlan: {
user: {
id: user.id,
},
},
});
if (deleteRes.affected === 0) {
return NextResponse.json({}, { status: 404 });
}
return NextResponse.json({}, { status: 200 });
}
12 changes: 12 additions & 0 deletions components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import {
AuditOutlined,
BugOutlined,
DeleteOutlined,
ExperimentOutlined,
InfoCircleOutlined,
PoweroffOutlined,
Expand Down Expand Up @@ -32,11 +33,13 @@ export interface HeaderProps {
avatarUrl: string;
} | null;
isMobile?: boolean;
onResetStudyPlan?: () => void;
}
export default function Header({
isLoading = false,
user,
isMobile = false,
onResetStudyPlan,
}: HeaderProps) {
return (
<Layout.Header
Expand Down Expand Up @@ -252,6 +255,15 @@ export default function Header({
),
icon: <PoweroffOutlined />,
},
{
key: "4",
label: (
<Button type="link" onClick={onResetStudyPlan}>
Reset Study Plan
</Button>
),
icon: <DeleteOutlined />,
},
],
}}
>
Expand Down
14 changes: 14 additions & 0 deletions components/Header/useHeader.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import useSession from "@/services/apiClient/useSession";
import { useLearningPlatformCurrentUser } from "@/services/learningPlatform/hooks/useLearningPlatformCurrentUser";

import { HeaderProps } from ".";

export default function useHeader(): HeaderProps {
const { api } = useSession();
const currentUserQuery = useLearningPlatformCurrentUser();

const avatarUrl = currentUserQuery.data?.me.avatarUrl;
Expand All @@ -21,8 +23,20 @@ export default function useHeader(): HeaderProps {
}
: null;

async function onResetStudyPlan() {
try {
await api?.resetStudyPlan();

location.reload();
} catch (err) {
alert((err as Error).message || "Unknown error");
}
}

return {
isLoading: currentUserQuery.isLoading,
user,

onResetStudyPlan,
};
}
24 changes: 14 additions & 10 deletions components/ModulesListSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ModulesListSectionProps extends Omit<FlexProps, "children"> {
showAddItemButton?: boolean;
isHovered?: boolean;
isDragInProgress?: boolean;
isLoading?: boolean;

onAddItem?: () => void;
}
Expand All @@ -27,6 +28,7 @@ function ModulesListSection({
showAddItemButton = true,
isHovered = false,
isDragInProgress = false,
isLoading = false,

onAddItem,
...rest
Expand Down Expand Up @@ -116,16 +118,18 @@ function ModulesListSection({
}}
>
{provided.placeholder}
{modules.map((module, index) => (
<ModulesListItem
key={module.id}
module={module.module}
assessment={module.assessment}
index={index}
draggableId={"draggable:semester-module:" + module.id}
showPopoverOn="info-icon"
/>
))}
{modules
.filter((i) => (isLoading ? true : i.module != null))
.map((module, index) => (
<ModulesListItem
key={module.id}
module={module.module}
assessment={module.assessment}
index={index}
draggableId={"draggable:semester-module:" + module.id}
showPopoverOn="info-icon"
/>
))}
</div>
</Flex>
)}
Expand Down
7 changes: 7 additions & 0 deletions components/Semester.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface SemesterProps {

setMouseUpInboxId: (inboxId: string | null) => void;
setHoveredInboxId: (inboxId: string | null) => void;

isLoading?: boolean;
}
function SemesterCard({
semester,
Expand All @@ -28,6 +30,7 @@ function SemesterCard({
draggedModules,
setMouseUpInboxId,
setHoveredInboxId,
isLoading = false,
}: SemesterProps) {
const [isHovered, setIsHovered] = useState(false);

Expand Down Expand Up @@ -157,6 +160,7 @@ function SemesterCard({
}}
</Droppable>
<ModulesListSection
isLoading={isLoading}
disabled={
(isDraggingChats &&
draggedModules[0]?.allowEarlyAssessment === false) ||
Expand All @@ -183,6 +187,7 @@ function SemesterCard({
onAddItem={() => {}}
/>
<ModulesListSection
isLoading={isLoading}
droppableId={`droppable:semester:${semester.id}:standardAssessments`}
onMouseUp={() =>
setMouseUpInboxId(
Expand All @@ -204,6 +209,7 @@ function SemesterCard({
disabled={isPastSemester || isstandardDisabled}
/>
<ModulesListSection
isLoading={isLoading}
disabled={
(isDraggingChats &&
draggedModules[0]?.allowAlternativeAssessment === false) ||
Expand All @@ -230,6 +236,7 @@ function SemesterCard({
onAddItem={() => {}}
/>
<ModulesListSection
isLoading={isLoading}
droppableId={`droppable:semester:${semester.id}:reassessments`}
onMouseUp={() =>
setMouseUpInboxId(`droppable:semester:${semester.id}:reassessments`)
Expand Down
1 change: 1 addition & 0 deletions components/SemestersList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export default function SemestersList({
draggedModules={draggedModules}
setMouseUpInboxId={setMouseUpInboxId}
setHoveredInboxId={setHoveredInboxId}
isLoading={isLoading}
/>
))}
</Flex>
Expand Down
16 changes: 16 additions & 0 deletions services/apiClient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ export class StudyPlannerApiClient {

return data;
}

public async resetStudyPlan(): Promise<{}> {
const res = await fetch(this.url + "/study-plan", {
headers: {
"Content-Type": "application/json",
Authorization: this.accessToken,
},
method: "DELETE",
});
if (!res.ok) {
throw new Error(`Failed to reset study plan (code ${res.status})`);
}
const data: {} = await res.json();

return data;
}
}

export type UpdateSemesterModuleInput = Record<string, ModulesRecord>;
Expand Down
Loading