Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 Student Form #108

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions backend/src/controllers/student.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const editStudent: RequestHandler = async (req, res, next) => {
}),
);

res.status(200).json({ ...updatedStudent, enrollments });
res.status(200).json({ ...updatedStudent.toObject(), enrollments });
} catch (error) {
next(error);
}
Expand All @@ -80,7 +80,7 @@ export const getAllStudents: RequestHandler = async (_, res, next) => {
const hydratedStudents = await Promise.all(
students.map(async (student) => {
const enrollments = await EnrollmentModel.find({ studentId: student._id });
return { ...student.toObject(), programs: enrollments };
return { ...student.toObject(), enrollments };
}),
);

Expand Down
2 changes: 1 addition & 1 deletion backend/src/util/student.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const programValidatorUtil = async (enrollments: Enrollment[]) => {
});

// verify statuses are correct and student is not in more than 2 programs
const allowedStatuses = ["Joined", "Waitlisted", "Archived", "Not a fit"];
const allowedStatuses = ["Joined", "Waitlisted", "Archived", "Not a fit", "Completed"];
const programIds = new Set();
let active = 0;
let varying = 0;
Expand Down
21 changes: 0 additions & 21 deletions backend/src/validators/student.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,6 @@ const makeEnrollments = () =>
.bail()
.custom(programValidatorUtil);

//dietary
//validates entire array
const makeDietaryArrayValidator = () =>
body("dietary")
.optional()
.exists()
.isArray()
.withMessage("Dietary restrictions must be an array");
//validates individual items
const makeDietaryItemsValidator = () =>
body("dietary.*").exists().isString().withMessage("Dietary restriction element must be a string");

const makeDietaryOtherValidator = () =>
body("otherString")
.optional()
.isString()
.withMessage("Other dietary restriction must be a string");

export const createStudent = [
makeLastNamesValidator(),
makeFirstNamesValidator(),
Expand All @@ -203,9 +185,6 @@ export const createStudent = [
makeDocumentsValidator(),
makeProfilePictureValidator(),
makeEnrollments(),
makeDietaryArrayValidator(),
makeDietaryItemsValidator(),
makeDietaryOtherValidator(),
];

export const editStudent = [...createStudent, makeIdValidator()];
5 changes: 5 additions & 0 deletions frontend/public/pencil.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions frontend/public/plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions frontend/src/api/students.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import type { APIResult } from "../api/requests";

export type Student = CreateStudentRequest & {
_id: string;
medication: string;
otherString: string;
progressNotes?: string[];
};

Expand Down
34 changes: 19 additions & 15 deletions frontend/src/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type BaseProps<T extends FieldValues> = {
label?: string;
placeholder: string;
defaultValue?: string;
initialValue?: string;
className?: string;
};

Expand All @@ -29,12 +30,13 @@ export function Dropdown<T extends FieldValues>({
setDropdownValue,
label,
name,
options,
options, // list of options - should be memoized
onChange = () => void 0,
defaultValue = "",
defaultValue, // value if you want a permanent default label that is not really a value (see home page dropdowns)
initialValue, // value if you want a default value that is a value in the list of options (see create/edit student dropdowns)
className,
}: DropdownProps<T>) {
const [selectedOption, setSelectedOption] = useState<string>(defaultValue);
const [selectedOption, setSelectedOption] = useState<string>(defaultValue ?? initialValue ?? "");
const [open, setOpen] = useState(false);
const triggerRef = useRef<HTMLButtonElement>(null);

Expand Down Expand Up @@ -62,7 +64,7 @@ export function Dropdown<T extends FieldValues>({
className,
)}
>
<span className="text-neutral-400">{label + ": "}</span>
{label && <span className="text-neutral-400">{label + ": "}</span>}
<span className="text-neutral-800">{selectedOption ?? ""}</span>
<Image
src="/ic_round-arrow-drop-up.svg"
Expand All @@ -74,17 +76,19 @@ export function Dropdown<T extends FieldValues>({
/>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem
className={menuItemStyle}
style={triggerRef.current ? { width: `${triggerRef.current.clientWidth}px` } : {}}
key={""}
onSelect={() => {
onChange("");
setSelectedOption(defaultValue);
}}
>
<span className="px-3">{defaultValue}</span>
</DropdownMenuItem>
{defaultValue && (
<DropdownMenuItem
className={menuItemStyle}
style={triggerRef.current ? { width: `${triggerRef.current.clientWidth}px` } : {}}
key={""}
onSelect={() => {
onChange("");
setSelectedOption(defaultValue);
}}
>
<span className="px-3">{defaultValue}</span>
</DropdownMenuItem>
)}
{options.map((option) => (
<DropdownMenuItem
className={menuItemStyle}
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/components/StudentForm/ContactInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { UseFormRegister } from "react-hook-form";
import { useFormContext } from "react-hook-form";

import { Student } from "../../api/students";
import { cn } from "../../lib/utils";
import { Textfield } from "../Textfield";

import { StudentFormData } from "./types";

import { camelize } from "@/lib/camelCase";

type ContactRole = "student" | "emergency" | "serviceCoordinator";

type PersonalInfoField = "firstName" | "lastName" | "email" | "phoneNumber";

type ContactInfoProps = {
register: UseFormRegister<StudentFormData>;
classname?: string;
type: "add" | "edit";
data: Student | null;
Expand All @@ -37,7 +38,9 @@ type DefaultFields = Record<PersonalInfoField, FieldProps>;

type ContactInfo = Record<ContactRole, DefaultFields>;

export default function ContactInfo({ register, type, data, classname }: ContactInfoProps) {
export default function ContactInfo({ type, data, classname }: ContactInfoProps) {
const { register } = useFormContext<StudentFormData>();

const defaultFields: DefaultFields = {
firstName: {
name: "name",
Expand Down Expand Up @@ -80,7 +83,7 @@ export default function ContactInfo({ register, type, data, classname }: Contact
//Rename fields to be unique
Object.entries(contactInfo).forEach(([contactType, fieldList]) => {
Object.entries(fieldList).forEach(([_fieldType, fieldProps]) => {
fieldProps.name = `${contactType}_${fieldProps.name}`;
fieldProps.name = camelize(`${contactType} ${fieldProps.name}`);
});
});

Expand Down
Loading
Loading