Skip to content

Commit

Permalink
VKT(Frontend & Backend): Enrollment appointment contact form continues
Browse files Browse the repository at this point in the history
  • Loading branch information
jrkkp committed Oct 21, 2024
1 parent 1877df5 commit 4a16a49
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fi.oph.vkt.api.dto.PublicEducationDTO;
import fi.oph.vkt.api.dto.PublicEnrollmentAppointmentDTO;
import fi.oph.vkt.api.dto.PublicEnrollmentAppointmentUpdateDTO;
import fi.oph.vkt.api.dto.PublicEnrollmentContactCreateDTO;
import fi.oph.vkt.api.dto.PublicEnrollmentCreateDTO;
import fi.oph.vkt.api.dto.PublicEnrollmentDTO;
import fi.oph.vkt.api.dto.PublicEnrollmentInitialisationDTO;
Expand Down Expand Up @@ -110,6 +111,12 @@ public List<PublicExaminerDTO> listExaminers() {
return publicExaminerService.listExaminers();
}

@PostMapping(path = "/enrollment/examiner/{examinerId:\\d+}")
@ResponseStatus(HttpStatus.CREATED)
public void createEnrollmentContact(@RequestBody @Valid final PublicEnrollmentContactCreateDTO dto) {
publicEnrollmentService.createEnrollmentContact(dto);
}

@PostMapping(path = "/enrollment/reservation/{reservationId:\\d+}")
@ResponseStatus(HttpStatus.CREATED)
public PublicEnrollmentDTO createEnrollment(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package fi.oph.vkt.api.dto;

import fi.oph.vkt.util.StringUtil;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Builder;
import lombok.NonNull;

@Builder
public record PublicEnrollmentContactCreateDTO(
@NonNull @NotNull Boolean oralSkill,
@NonNull @NotNull Boolean textualSkill,
@NonNull @NotNull Boolean understandingSkill,
@NonNull @NotNull Boolean speakingPartialExam,
@NonNull @NotNull Boolean speechComprehensionPartialExam,
@NonNull @NotNull Boolean writingPartialExam,
@NonNull @NotNull Boolean readingComprehensionPartialExam,
@Size(max = 1024) String previousEnrollment,
@Size(max = 255) @NonNull @NotBlank String email,
@Size(max = 255) @NonNull @NotBlank String firstName,
@Size(max = 255) @NonNull @NotBlank String lastName
) {
public PublicEnrollmentContactCreateDTO {
previousEnrollment = StringUtil.sanitize(previousEnrollment);
email = StringUtil.sanitize(email);
firstName = StringUtil.sanitize(firstName);
lastName = StringUtil.sanitize(lastName);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
package fi.oph.vkt.service;

import fi.oph.vkt.api.dto.EnrollmentDTOCommonFields;
import fi.oph.vkt.api.dto.PublicEnrollmentContactCreateDTO;
import fi.oph.vkt.model.Enrollment;
import fi.oph.vkt.model.EnrollmentAppointment;
import fi.oph.vkt.model.ExamEvent;
import fi.oph.vkt.model.Person;
import fi.oph.vkt.repository.EnrollmentRepository;
import java.util.Optional;

public abstract class AbstractEnrollmentService {

protected void copyDtoFieldsToEnrollment(
final EnrollmentAppointment enrollment,
final PublicEnrollmentContactCreateDTO dto
) {
enrollment.setOralSkill(dto.oralSkill());
enrollment.setTextualSkill(dto.textualSkill());
enrollment.setUnderstandingSkill(dto.understandingSkill());
enrollment.setSpeakingPartialExam(dto.speakingPartialExam());
enrollment.setSpeechComprehensionPartialExam(dto.speechComprehensionPartialExam());
enrollment.setWritingPartialExam(dto.writingPartialExam());
enrollment.setReadingComprehensionPartialExam(dto.readingComprehensionPartialExam());
enrollment.setEmail(dto.email());
}

protected void copyDtoFieldsToEnrollment(final Enrollment enrollment, final EnrollmentDTOCommonFields dto) {
enrollment.setOralSkill(dto.oralSkill());
enrollment.setTextualSkill(dto.textualSkill());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import fi.oph.vkt.api.dto.PublicEducationDTO;
import fi.oph.vkt.api.dto.PublicEnrollmentAppointmentDTO;
import fi.oph.vkt.api.dto.PublicEnrollmentAppointmentUpdateDTO;
import fi.oph.vkt.api.dto.PublicEnrollmentContactCreateDTO;
import fi.oph.vkt.api.dto.PublicEnrollmentCreateDTO;
import fi.oph.vkt.api.dto.PublicEnrollmentDTO;
import fi.oph.vkt.api.dto.PublicEnrollmentInitialisationDTO;
Expand Down Expand Up @@ -671,4 +672,17 @@ public PublicEnrollmentAppointmentDTO saveEnrollmentAppointment(

return createEnrollmentAppointmentDTO(enrollmentAppointment);
}

public void createEnrollmentContact(final PublicEnrollmentContactCreateDTO dto) {
final EnrollmentAppointment enrollmentAppointment = new EnrollmentAppointment();

enrollmentAppointment.setStatus(EnrollmentStatus.EXPECTING_PAYMENT_UNFINISHED_ENROLLMENT);
copyDtoFieldsToEnrollment(enrollmentAppointment, dto);

// TODO: remove
enrollmentAppointment.setAuthHash("asd");


enrollmentAppointmentRepository.saveAndFlush(enrollmentAppointment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,26 @@ import { APIResponseStatus, Color, Variant } from 'shared/enums';

import { useCommonTranslation, usePublicTranslation } from 'configs/i18n';
import { useAppDispatch } from 'configs/redux';
import { AppRoutes } from 'enums/app';
import { PublicEnrollmentContactFormStep } from 'enums/publicEnrollment';
import { PublicEnrollmentContact } from 'interfaces/publicEnrollment';
import { setLoadingPayment } from 'redux/reducers/publicEnrollmentAppointment';
import { loadPublicEnrollmentSave } from 'redux/reducers/publicEnrollmentContact';
import { RouteUtils } from 'utils/routes';
import { AppRoutes } from 'enums/app';

export const PublicEnrollmentContactControlButtons = ({
activeStep,
enrollment,
isStepValid,
setShowValidation,
submitStatus,
examinerId,
}: {
activeStep: PublicEnrollmentContactFormStep;
enrollment: PublicEnrollmentContact;
isStepValid: boolean;
setShowValidation: (showValidation: boolean) => void;
submitStatus: APIResponseStatus;
examinerId: number;
}) => {
const { t } = usePublicTranslation({
keyPrefix: 'vkt.component.publicEnrollment.controlButtons',
Expand All @@ -46,18 +47,18 @@ export const PublicEnrollmentContactControlButtons = ({
if (submitStatus === APIResponseStatus.Success) {
navigate(AppRoutes.PublicGoodAndSatisfactoryLevelLanding);
}
}, [submitStatus, enrollment.id, dispatch]);
}, [submitStatus, navigate]);

const handleBackBtnClick = () => {
const nextStep: PublicEnrollmentContactFormStep = activeStep - 1;
navigate(RouteUtils.contactStepToRoute(nextStep, enrollment.id));
navigate(RouteUtils.contactStepToRoute(nextStep, examinerId));
};

const handleNextBtnClick = () => {
if (isStepValid) {
setShowValidation(false);
const nextStep: PublicEnrollmentContactFormStep = activeStep + 1;
navigate(RouteUtils.contactStepToRoute(nextStep, enrollment.id));
navigate(RouteUtils.contactStepToRoute(nextStep, examinerId));
} else {
setShowValidation(true);
}
Expand All @@ -67,7 +68,7 @@ export const PublicEnrollmentContactControlButtons = ({
if (isStepValid) {
setIsSubmitLoading(true);
setShowValidation(false);
dispatch(loadPublicEnrollmentSave(enrollment));
dispatch(loadPublicEnrollmentSave({ enrollment, examinerId }));
} else {
setShowValidation(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ export const PublicEnrollmentContactDesktopGrid = ({
showValidation,
setIsStepValid,
setShowValidation,
examinerId,
}: {
activeStep: PublicEnrollmentContactFormStep;
isStepValid: boolean;
enrollment: PublicEnrollmentContact;
showValidation: boolean;
setIsStepValid: (isValid: boolean) => void;
setShowValidation: (showValidation: boolean) => void;
examinerId: number;
}) => {
const translateCommon = useCommonTranslation();

Expand Down Expand Up @@ -59,6 +61,7 @@ export const PublicEnrollmentContactDesktopGrid = ({
setShowValidation={setShowValidation}
isStepValid={isStepValid}
submitStatus={enrollmentSubmitStatus}
examinerId={examinerId}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const PublicEnrollmentContactGrid = ({
activeStep: PublicEnrollmentContactFormStep;
}) => {
const params = useParams();
const examinerId =
params.examinerId !== undefined ? +params.examinerId : null;
const dispatch = useAppDispatch();
const { enrollment, loadExamEventStatus } = useAppSelector(
publicEnrollmentContactSelector,
Expand All @@ -23,13 +25,14 @@ export const PublicEnrollmentContactGrid = ({
const [showValidation, setShowValidation] = useState(false);

useEffect(() => {
if (
loadExamEventStatus === APIResponseStatus.NotStarted &&
params.enrollmentId
) {
dispatch(loadPublicExamEvent(+params.enrollmentId));
if (loadExamEventStatus === APIResponseStatus.NotStarted && examinerId) {
dispatch(loadPublicExamEvent(examinerId));
}
}, [dispatch, loadExamEventStatus, params.enrollmentId]);
}, [dispatch, loadExamEventStatus, examinerId]);

if (!examinerId) {
return <></>;
}

return (
<Grid
Expand All @@ -45,6 +48,7 @@ export const PublicEnrollmentContactGrid = ({
setIsStepValid={setIsStepValid}
showValidation={showValidation}
setShowValidation={setShowValidation}
examinerId={examinerId}
/>
</Grid>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const PublicEnrollmentContactStepContents = ({
enrollment={enrollment}
isLoading={false}
setIsStepValid={setIsStepValid}
updatePublicEnrollment={updatePublicEnrollment}
/>
);
case PublicEnrollmentContactFormStep.SelectExam:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ import { InputAutoComplete, TextFieldTypes } from 'shared/enums';
import { usePublicTranslation } from 'configs/i18n';
import { useAppDispatch } from 'configs/redux';
import { PublicEnrollmentContact } from 'interfaces/publicEnrollment';
import { updatePublicEnrollment } from 'redux/reducers/publicEnrollmentContact';

export const FillContactDetails = ({
isLoading,
enrollment,
setIsStepValid,
updatePublicEnrollment,
}: {
isLoading: boolean;
enrollment: PublicEnrollmentContact;
setIsStepValid: (isValid: boolean) => void;
updatePublicEnrollment: (
enrollment: Partial<PublicEnrollmentCommon>,
) => AnyAction;
}) => {
const { t } = usePublicTranslation({
keyPrefix: 'vkt.component.publicEnrollment.steps.fillContactDetails',
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/vkt/src/enums/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export enum APIEndpoints {
PublicAuthLogout = '/vkt/api/v1/auth/logout',
PublicExamEvent = '/vkt/api/v1/examEvent',
PublicEnrollmentAppointment = '/vkt/api/v1/enrollment/appointment',
PublicEnrollmentContact = '/vkt/api/v1/enrollment/contact-request',
PublicEnrollmentContact = '/vkt/api/v1/enrollment/examiner',
PublicExaminer = '/vkt/api/v1/examiner',
PublicEnrollment = '/vkt/api/v1/enrollment',
PublicReservation = '/vkt/api/v1/reservation',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ const publicEnrollmentContactSlice = createSlice({
},
loadPublicEnrollmentSave(
state,
_action: PayloadAction<PublicEnrollmentContact>,
_action: PayloadAction<{
enrollment: PublicEnrollmentContact;
examinerId: number;
}>,
) {
state.enrollmentSubmitStatus = APIResponseStatus.InProgress;
},
Expand Down
10 changes: 7 additions & 3 deletions frontend/packages/vkt/src/redux/sagas/publicEnrollmentContact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ function* loadPublicExamEventSaga(action: PayloadAction<number>) {
}

function* loadPublicEnrollmentSaveSaga(
action: PayloadAction<PublicEnrollmentContact>,
action: PayloadAction<{
enrollment: PublicEnrollmentContact;
examinerId: number;
}>,
) {
const enrollment = action.payload;
const enrollment = action.payload.enrollment;
const examinerId = action.payload.examinerId;

try {
const { id: _unused2, status: _unused5, ...body } = enrollment;

const saveUrl = `${APIEndpoints.PublicEnrollmentContact}/${enrollment.id}`;
const saveUrl = `${APIEndpoints.PublicEnrollmentContact}/${examinerId}`;

yield call(axiosInstance.post, saveUrl, body);

Expand Down
22 changes: 11 additions & 11 deletions frontend/packages/vkt/src/utils/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,31 +139,31 @@ export class RouteUtils {
return route.replace(':enrollmentId', enrollmentId.toString());
}

static replaceExaminerId(route: string, examinerId: number) {
return route.replace(':examinerId', examinerId.toString());
}

static contactStepToRoute(
step: PublicEnrollmentContactFormStep,
enrollmentId?: number,
examinerId: number,
) {
if (!enrollmentId) {
return '';
}

switch (step) {
case PublicEnrollmentContactFormStep.FillContactDetails:
return RouteUtils.replaceEnrollmentId(
return RouteUtils.replaceExaminerId(
AppRoutes.PublicEnrollmentContactContactDetails,
enrollmentId,
examinerId,
);

case PublicEnrollmentContactFormStep.SelectExam:
return RouteUtils.replaceEnrollmentId(
return RouteUtils.replaceExaminerId(
AppRoutes.PublicEnrollmentContactSelectExam,
enrollmentId,
examinerId,
);

case PublicEnrollmentContactFormStep.Done:
return RouteUtils.replaceEnrollmentId(
return RouteUtils.replaceExaminerId(
AppRoutes.PublicEnrollmentContactDone,
enrollmentId,
examinerId,
);
}
}
Expand Down

0 comments on commit 4a16a49

Please sign in to comment.