Skip to content

Commit

Permalink
refactor: replace stageInterviewType with TaskDtoTypeEnum in intervie…
Browse files Browse the repository at this point in the history
…w-related components (#2567)
  • Loading branch information
valerydluski authored Dec 23, 2024
1 parent 15a2e0e commit d926b4e
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 27 deletions.
5 changes: 2 additions & 3 deletions client/src/domain/interview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Tag } from 'antd';
import { TaskDtoTypeEnum } from 'api';
import { StageInterviewFeedbackVerdict, InterviewDetails as CommonInterviewDetails } from 'common/models';
import { Decision } from 'data/interviews/technical-screening';
import dayjs from 'dayjs';
Expand Down Expand Up @@ -48,8 +49,6 @@ export enum InterviewStatus {
Canceled,
}

export const stageInterviewType = 'stage-interview';

export function isInterviewRegistrationInProgress(interviewStartDate: string) {
const startDate = dayjs(interviewStartDate).subtract(2, 'weeks');

Expand Down Expand Up @@ -79,7 +78,7 @@ export function getInterviewFeedbackUrl({
if (!featureToggles.feedback && isScreening) {
return `/course/mentor/interview-technical-screening?course=${courseAlias}&githubId=${studentGithubId}`;
}
const type = isScreening ? stageInterviewType : template;
const type = isScreening ? TaskDtoTypeEnum.StageInterview : template;
return `/course/interview/${type}/feedback?course=${courseAlias}&githubId=${studentGithubId}&studentId=${studentId}&interviewId=${interviewId}`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
StudentsApi,
CoursesInterviewsApi,
InterviewFeedbackDto,
TaskDtoTypeEnum,
} from 'api';
import { templates } from 'data/interviews';
import { getTasksTotalScore } from 'domain/course';
import { stageInterviewType } from 'domain/interview';
import { notAuthorizedResponse } from 'modules/Course/data';
import { GetServerSideProps, GetServerSidePropsContext } from 'next';
import { ParsedUrlQuery } from 'querystring';
Expand All @@ -25,7 +25,7 @@ export type StageFeedbackProps = CourseOnlyPageProps & {
studentsCount: number;
};
interviewFeedback: InterviewFeedbackDto;
type: typeof stageInterviewType;
type: typeof TaskDtoTypeEnum.StageInterview;
};

export type FeedbackProps = CourseOnlyPageProps & {
Expand All @@ -49,7 +49,7 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async ctx => {
return notAuthorizedResponse;
}

const pageProps = await (type === stageInterviewType
const pageProps = await (type === TaskDtoTypeEnum.StageInterview
? getStageInterviewData({ ctx, courseId: course.id, token })
: getInterviewData({ ctx, courseId: course.id, token }));

Expand Down Expand Up @@ -96,7 +96,7 @@ async function getStageInterviewData({
new StudentsApi(axiosConfig).getStudent(Number(studentId)),
new CoursesTasksApi(axiosConfig).getCourseTasks(courseId),
new CourseStatsApi(axiosConfig).getCourseStats(courseId),
new CoursesInterviewsApi(axiosConfig).getInterviewFeedback(courseId, interviewId, stageInterviewType),
new CoursesInterviewsApi(axiosConfig).getInterviewFeedback(courseId, interviewId, TaskDtoTypeEnum.StageInterview),
]);
if (!student) {
throw new Error('Student not found');
Expand All @@ -110,7 +110,7 @@ async function getStageInterviewData({
studentsCount: activeStudentsCount,
},
interviewFeedback,
type: stageInterviewType,
type: TaskDtoTypeEnum.StageInterview,
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { CoursesApi, CoursesInterviewsApi } from 'api';
import { CoursesApi, CoursesInterviewsApi, TaskDtoTypeEnum } from 'api';
import { notAuthorizedResponse, noAccessResponse } from 'modules/Course/data';
import { GetServerSideProps } from 'next';
import type { PageProps } from './index';
import { getApiConfiguration } from 'utils/axios';
import { getTokenFromContext } from 'utils/server';
import dayjs from 'dayjs';
import { stageInterviewType } from 'domain/interview';

export const getServerSideProps: GetServerSideProps<PageProps> = async ctx => {
try {
Expand Down Expand Up @@ -35,7 +34,7 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async ctx => {
return notAuthorizedResponse;
}

const isStage = interview.type === stageInterviewType;
const isStage = interview.type === TaskDtoTypeEnum.StageInterview;
if (!isStage && dayjs(interview.startDate).isAfter(dayjs())) {
return notAuthorizedResponse;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import { useAsync } from 'react-use';
import { CourseService } from 'services/course';
import { CoursePageProps } from 'services/models';
import { isCourseManager, isMentor } from 'domain/user';
import { AvailableStudentDto, CoursesInterviewsApi, InterviewDto } from 'api';
import { AvailableStudentDto, CoursesInterviewsApi, InterviewDto, TaskDtoTypeEnum } from 'api';
import { getApiConfiguration } from 'utils/axios';
import { getRating, stageInterviewType } from 'domain/interview';
import { getRating } from 'domain/interview';
import { SessionContext } from 'modules/Course/contexts';

const api = new CoursesInterviewsApi(getApiConfiguration());
Expand All @@ -32,7 +32,7 @@ export function InterviewWaitingList({ course, interview }: PageProps) {
const [loading, withLoading] = useLoading(false);
const [availableStudents, setAvailableStudents] = useState<AvailableStudentDto[]>([]);
const courseService = useMemo(() => new CourseService(courseId), [courseId]);
const isStageInterview = interview.type === stageInterviewType;
const isStageInterview = interview.type === TaskDtoTypeEnum.StageInterview;

useAsync(
withLoading(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { Alert, Typography } from 'antd';
import InfoCircleTwoTone from '@ant-design/icons/InfoCircleTwoTone';
import dayjs from 'dayjs';
import { useContext } from 'react';
import { stageInterviewType } from 'domain/interview';
import { InterviewDto } from 'api';
import { InterviewDto, TaskDtoTypeEnum } from 'api';
import { MentorOptionsContext } from './MentorPreferencesModal';
import { useAlert } from '../hooks/useAlert';

Expand All @@ -15,7 +14,7 @@ export function RegistrationNoticeAlert(props: { interview: InterviewDto; startD

if (isDismissed) return null;

if (interview.type !== stageInterviewType) {
if (interview.type !== TaskDtoTypeEnum.StageInterview) {
return null;
}

Expand Down
7 changes: 5 additions & 2 deletions client/src/modules/Mentor/pages/Interviews/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CoursesInterviewsApi, InterviewDto } from 'api';
import { CoursesInterviewsApi, InterviewDto, TaskDtoTypeEnum } from 'api';
import { PageLayout } from 'components/PageLayout';
import { useLoading } from 'components/useLoading';
import { useCallback, useState, useContext } from 'react';
Expand All @@ -24,7 +24,10 @@ export function Interviews() {

const loadData = async () => {
const [{ data }] = await Promise.all([
new CoursesInterviewsApi().getInterviews(course.id, false, ['interview', 'stage-interview']),
new CoursesInterviewsApi().getInterviews(course.id, false, [
TaskDtoTypeEnum.Interview,
TaskDtoTypeEnum.StageInterview,
]),
fetchStudentInterviews(),
]);

Expand Down
1 change: 1 addition & 0 deletions client/src/pages/course/admin/events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function Page() {
size="small"
dataSource={data}
columns={getColumns(handleEditEvent, handleDeleteItem, { timeZone, events })}
scroll={{ x: 1020, y: 'calc(100vh - 265px)' }}
/>
{modalData && (
<CourseEventModal
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/course/admin/tasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function Page() {
size="small"
dataSource={data}
columns={getColumns(getDropdownMenu)}
scroll={{ x: 1020, y: 'calc(100vh - 260px)' }}
scroll={{ x: 1020, y: 'calc(100vh - 265px)' }}
/>
{modalData ? (
<CourseTaskModal onCancel={() => setModalData(null)} onSubmit={handleModalSubmit} data={modalData} />
Expand Down
4 changes: 2 additions & 2 deletions client/src/pages/course/interview/[type]/feedback.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stageInterviewType } from 'domain/interview';
import { TaskDtoTypeEnum } from 'api';
import { SessionProvider, ActiveCourseProvider } from 'modules/Course/contexts';
import { Feedback } from 'modules/Interviews/pages/feedback';
import { InterviewFeedback } from 'modules/Interviews/pages/InterviewFeedback';
Expand All @@ -11,7 +11,7 @@ export default function (props: PageProps) {
return (
<ActiveCourseProvider>
<SessionProvider allowedRoles={[CourseRole.Mentor]} course={props.course}>
{props.type === stageInterviewType ? <Feedback {...props} /> : <InterviewFeedback {...props} />}
{props.type === TaskDtoTypeEnum.StageInterview ? <Feedback {...props} /> : <InterviewFeedback {...props} />}
</SessionProvider>
</ActiveCourseProvider>
);
Expand Down
13 changes: 8 additions & 5 deletions client/src/pages/course/student/interviews.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { useMemo, useState, useContext } from 'react';
import { useAsync } from 'react-use';
import { CourseService } from 'services/course';
import { formatShortDate } from 'services/formatter';
import { getInterviewResult, InterviewDetails, InterviewStatus, stageInterviewType } from 'domain/interview';
import { getInterviewResult, InterviewDetails, InterviewStatus } from 'domain/interview';
import { Decision } from 'data/interviews/technical-screening';
import { ActiveCourseProvider, SessionContext, SessionProvider, useActiveCourseContext } from 'modules/Course/contexts';
import { CoursesInterviewsApi, InterviewDto } from 'api';
import { CoursesInterviewsApi, InterviewDto, TaskDtoTypeEnum } from 'api';

const coursesInterviewApi = new CoursesInterviewsApi();

Expand All @@ -27,7 +27,10 @@ function StudentInterviewPage() {
setLoading(true);
const [data, { data: interviews }] = await Promise.all([
courseService.getStudentInterviews(session.githubId),
coursesInterviewApi.getInterviews(course.id),
coursesInterviewApi.getInterviews(course.id, false, [
TaskDtoTypeEnum.Interview,
TaskDtoTypeEnum.StageInterview,
]),
] as const);
const registeredInterviews = await getRegisteredInterviews(interviews);

Expand Down Expand Up @@ -69,7 +72,7 @@ function StudentInterviewPage() {

const getRegisteredInterviews = async (interviews: InterviewDto[]) => {
const requests = interviews
.map(({ type, id }) => (type === stageInterviewType ? 'stage' : id.toString()))
.map(({ type, id }) => (type === TaskDtoTypeEnum.StageInterview ? 'stage' : id.toString()))
.map(async id => {
const data = await courseService.getInterviewStudent(session.githubId, id).catch(() => null);
return data ? id : null;
Expand All @@ -80,7 +83,7 @@ function StudentInterviewPage() {
};

const renderExtra = (interview: InterviewDto) => {
const id = interview.type === stageInterviewType ? 'stage' : interview.id.toString();
const id = interview.type === TaskDtoTypeEnum.StageInterview ? 'stage' : interview.id.toString();
const hasInterview = registeredInterviews.includes(id);
return interview.studentRegistrationStartDate && new Date() < new Date(interview.studentRegistrationStartDate) ? (
<Tag color="orange">Registration starts at {formatShortDate(interview.studentRegistrationStartDate)}</Tag>
Expand Down

0 comments on commit d926b4e

Please sign in to comment.