All files / pages/PersonalSchedules PersonalSchedulesEditPage.js

100% Statements 12/12
100% Branches 2/2
100% Functions 3/3
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55                32x 32x   32x                   32x             32x 32x 39x   32x 26x         6x     32x 32x                        
import React from "react";
import { useBackend } from "main/utils/useBackend";
import { useParams } from "react-router-dom";
import BasicLayout from "main/layouts/BasicLayout/BasicLayout";
import PersonalSchedulesTableEdit from "main/components/PersonalSchedules/PersonalScheduleTableEdit";
import { useCurrentUser } from "main/utils/currentUser";
//import { useParams } from "react-router-dom";
export default function PersonalSchedulesEditPage() {
  let { id } = useParams();
  const currentUser = useCurrentUser();
 
  var { data: personalSchedules } = useBackend(
    // Stryker disable next-line all : don't test internal caching of React Query
    ["/api/personalSections/all?psId=" + id],
    { method: "GET", url: "/api/personalSections/all?psId=" + id },
    [],
  );
 
  const {
    data: scheduleData,
    // eslint-disable-next-line react-hooks/rules-of-hooks
  } = useBackend(
    // Stryker disable next-line all : don't test internal caching of React Query
    ["/api/courses/user/psid/all?psId=" + id],
    { method: "GET", url: "/api/courses/user/psid/all?psId=" + id },
    [],
  );
 
  const updatedPersonalSchedules = personalSchedules.map((schedule) => {
    const matchingSchedule = scheduleData.find(
      (data) => data.enrollCd === schedule.classSections[0].enrollCode,
    );
    if (matchingSchedule) {
      return {
        ...schedule,
        id: matchingSchedule.id,
      };
    }
    return schedule;
  });
 
  personalSchedules = updatedPersonalSchedules;
  return (
    <BasicLayout>
      <div className="pt-2">
        <h1>Edit Schedule</h1>
        <PersonalSchedulesTableEdit
          personalSchedules={personalSchedules}
          currentUser={currentUser}
        />
      </div>
    </BasicLayout>
  );
}