Skip to content

Commit

Permalink
PR feedback: merge types
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdoming committed Sep 17, 2023
1 parent cffd4f8 commit 51119d6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from "react";
import { useHistory } from "react-router-dom";
import { HStack, Spacer, Tooltip } from "@chakra-ui/react";

import type { TestSessionEditingData } from "../../../APIClients/types/TestSessionClientTypes";
import * as Routes from "../../../constants/Routes";
import type { TestSessionItemStats } from "../../../types/TestSessionTypes";
import { TestSessionStatus } from "../../../types/TestSessionTypes";
Expand All @@ -11,14 +10,10 @@ import Copyable from "../../common/Copyable";
import TestSessionListItemBody from "./TestSessionListItemBody";
import TestSessionListItemPopover from "./TestSessionListItemPopover";
import TestSessionListItemStatistics from "./TestSessionListItemStatistics";
import type { FormattedAssessmentData } from "./useAssessmentDataQuery";

export type TestSessionListItemProps = {
session: TestSessionEditingData & {
// Target date should be the start date of the session UNLESS
// the session is active, in which case it should be the end date
targetDate: Date;
accessCode: string;
};
session: FormattedAssessmentData;
isReadOnly?: boolean;
stats?: TestSessionItemStats;
inClassroomPage?: boolean;
Expand All @@ -33,8 +28,14 @@ const TestSessionListItem = ({
inClassroomPage = false,
}: TestSessionListItemProps): React.ReactElement => {
const history = useHistory();
const { testSessionId, classroomName, testName, status } = session;
const { targetDate, accessCode, ...testSessionEditingData } = session;
const {
testSessionId,
classroomName,
testName,
status,
targetDate,
accessCode,
} = session;
const isPast = status === TestSessionStatus.PAST;

const formattedAccessCode = `${accessCode.slice(
Expand Down Expand Up @@ -94,11 +95,7 @@ const TestSessionListItem = ({
label="Access Code"
value={accessCode}
/>
{!isReadOnly && (
<TestSessionListItemPopover
testSessionEditingData={testSessionEditingData}
/>
)}
{!isReadOnly && <TestSessionListItemPopover session={session} />}
</>
)}
</HStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ import { Divider, useDisclosure, VStack } from "@chakra-ui/react";

import { DELETE_TEST_SESSION } from "../../../APIClients/mutations/TestSessionMutations";
import { GET_TEST_SESSIONS_BY_TEACHER_ID } from "../../../APIClients/queries/TestSessionQueries";
import type { TestSessionEditingData } from "../../../APIClients/types/TestSessionClientTypes";
import * as Routes from "../../../constants/Routes";
import { TestSessionStatus } from "../../../types/TestSessionTypes";
import { getQueryName } from "../../../utils/GeneralUtils";
import DeleteAssessmentModal from "../../admin/assessment-status/EditStatusModals/DeleteAssessmentModal";
import Popover from "../../common/popover/Popover";
import PopoverButton from "../../common/popover/PopoverButton";

import type { FormattedAssessmentData } from "./useAssessmentDataQuery";

type TestSessionPopoverProps = {
testSessionEditingData: TestSessionEditingData;
session: FormattedAssessmentData;
};

const TestSessionListItemPopover = ({
testSessionEditingData,
session,
}: TestSessionPopoverProps): ReactElement => {
const {
isOpen: isDeleteModalOpen,
Expand All @@ -29,19 +30,19 @@ const TestSessionListItemPopover = ({
const history = useHistory();

const [deleteTestSession] = useMutation(DELETE_TEST_SESSION, {
variables: { id: testSessionEditingData.testSessionId },
variables: { id: session.testSessionId },
refetchQueries: [getQueryName(GET_TEST_SESSIONS_BY_TEACHER_ID)],
});

const onEditTestSession = () => {
history.push(Routes.DISTRIBUTE_ASSESSMENT_PAGE, testSessionEditingData);
history.push(Routes.DISTRIBUTE_ASSESSMENT_PAGE, session);
};

return (
<Popover>
<VStack divider={<Divider />} spacing={0}>
<PopoverButton name="Edit" onClick={onEditTestSession} />
{testSessionEditingData.status === TestSessionStatus.UPCOMING && (
{session.status === TestSessionStatus.UPCOMING && (
<PopoverButton name="Delete" onClick={openDeleteModal} />
)}
</VStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import TestSessionListItem from "./TestSessionListItem";
import type { FormattedAssessmentData } from "./useAssessmentDataQuery";

type TestSessionTabsProps = {
data?: FormattedAssessmentData;
data?: FormattedAssessmentData[];
setCurrentTab: (status: TestSessionStatus) => void;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ export type FormattedAssessmentData = {
classroomName: string;
startDate: Date;
endDate: Date;
// Target date is the start date of the session UNLESS the session is
// active, in which case it is the end date
targetDate: Date;
status: TestSessionStatus;
accessCode: string;
}[];
};

type AssessmentDataQueryResult = {
loading: boolean;
error?: Error;
data?: FormattedAssessmentData;
data?: FormattedAssessmentData[];
};

const useAssessmentDataQuery = (limit?: number): AssessmentDataQueryResult => {
Expand Down

0 comments on commit 51119d6

Please sign in to comment.