Skip to content

Commit

Permalink
added backend stuff cannot test becuase dk how to do migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
denniwang committed Oct 26, 2024
1 parent 118ec62 commit 5a1a9b2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/api/src/plan/entities/plan.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ export class Plan {

@UpdateDateColumn()
updatedAt: Date;

@Column({ nullable: true })
note: string;
}
4 changes: 4 additions & 0 deletions packages/common/src/api-dtos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export class UpdatePlanDto {
@Min(1898)
@Max(3000)
catalogYear?: number;

@IsOptional()
@IsString()
note?: string;
}

export class SignUpStudentDto {
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/api-response-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class PlanModel<T> {
catalogYear: number;
createdAt: Date;
updatedAt: Date;
note: string | undefined;
}

export class GetPlanResponse extends PlanModel<null> {}
Expand Down
44 changes: 41 additions & 3 deletions packages/frontend/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
MajorValidationResult,
PlanModel,
ScheduleCourse2,
UpdatePlanDto,
} from "@graduate/common";
import { memo, PropsWithChildren, useEffect, useRef, useState } from "react";
import { DraggableScheduleCourse } from "../ScheduleCourse";
Expand All @@ -24,6 +25,7 @@ import {
getSectionError,
getAllCoursesInMajor,
BETA_MAJOR_TOOLTIP_MSG,
toast,
} from "../../utils";
import {
handleApiClientError,
Expand All @@ -37,11 +39,12 @@ import {
WorkerMessageType,
WorkerPostInfo,
} from "../../validation-worker/worker-messages";
import { useFetchCourses, useMajor } from "../../hooks";
import { useFetchCourses, useMajor, usePlan } from "../../hooks";

Check failure on line 42 in packages/frontend/components/Sidebar/Sidebar.tsx

View workflow job for this annotation

GitHub Actions / Run linting for all packages

'usePlan' is defined but never used. Allowed unused vars must match /^_/u
import { HelperToolTip } from "../Help";
import NUPathSection from "./NUPathSection";
import DropdownWarning from "./DropdownWarning";
import { NUPathEnum } from "@graduate/common";
import { API } from "@graduate/api-client";

export enum SidebarValidationStatus {
Loading = "Loading",
Expand Down Expand Up @@ -216,6 +219,7 @@ const Sidebar: React.FC<SidebarProps> = memo(
creditsToTake={major.totalCreditsRequired}
renderCoopBlock
renderBetaMajorBlock={major.metadata?.verified !== true}
planId={selectedPlan.id}
>
{courseData && (
<>
Expand Down Expand Up @@ -313,6 +317,7 @@ interface SidebarContainerProps {
renderCoopBlock?: boolean;
renderBetaMajorBlock?: boolean;
renderDropdownWarning?: boolean;
planId?: string | number;
}

export const NoPlanSidebar: React.FC = () => {
Expand All @@ -327,12 +332,45 @@ const SidebarContainer: React.FC<PropsWithChildren<SidebarContainerProps>> = ({
renderCoopBlock,
renderBetaMajorBlock,
renderDropdownWarning = true,
planId,
children,
}) => {
const [notes, setNotes] = useState<string>("");
const handleNewNotes = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
const router = useRouter();
//fetch existing notes
useEffect(() => {
const fetchNotes = async () => {
try {
if (planId) {
const response = await API.plans.get(planId);
setNotes(response.note ?? "");
} else {
toast.error(`Plan ID: ${planId} not found`);
}
} catch (error) {
handleApiClientError(error as Error, router);
return;
}
};
fetchNotes();
}, []);

Check warning on line 356 in packages/frontend/components/Sidebar/Sidebar.tsx

View workflow job for this annotation

GitHub Actions / Run linting for all packages

React Hook useEffect has missing dependencies: 'planId' and 'router'. Either include them or remove the dependency array
const handleNewNotes = async (e: React.ChangeEvent<HTMLTextAreaElement>) => {
setNotes(e.target.value);
console.log("New notes: ", e.target.value);

const newPlan: UpdatePlanDto = {
note: notes,
};

try {
if (planId) {
await API.plans.update(planId, newPlan);
} else {
toast.error(`Plan ID: ${planId} not found`);
}
} catch (error) {
handleApiClientError(error as Error, router);
return;
}
};
return (
<Box pt="xl" borderRight="1px" borderRightColor="neutral.200" minH="100%">
Expand Down

0 comments on commit 5a1a9b2

Please sign in to comment.