Skip to content

Commit

Permalink
chore: apply changes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
BCerki committed Sep 27, 2024
1 parent 87cd039 commit a37c090
Show file tree
Hide file tree
Showing 7 changed files with 327 additions and 322 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
def register_edit_operation_information(
request: HttpRequest, operation_id: UUID, payload: OperationInformationIn
) -> Tuple[Literal[200], Operation]:
# raise Exception('d')
return 200, OperationServiceV2.register_operation_information(get_current_user_guid(request), operation_id, payload)
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def operation_registration_submission(
request: HttpRequest, operation_id: UUID, payload: OperationRegistrationSubmissionIn
) -> Tuple[Literal[200], Operation]:
# Check if all checkboxes are checked
# raise Exception('d')
if not all(
[payload.acknowledgement_of_review, payload.acknowledgement_of_information, payload.acknowledgement_of_records]
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import MultiStepBase from "@bciers/components/form/MultiStepBase";
import { OperationInformationFormData } from "apps/registration/app/components/operations/registration/types";
import { actionHandler } from "@bciers/actions";
import { RJSFSchema } from "@rjsf/utils";
import { useEffect, useState } from "react";
import { useState } from "react";
import { IChangeEvent } from "@rjsf/core";
import { getOperationV2 } from "@bciers/actions/api";
import {
Expand All @@ -13,7 +13,6 @@ import {
} from "@bciers/components/form/formDataUtils";
import { registrationOperationInformationUiSchema } from "@/registration/app/data/jsonSchema/operationInformation/registrationOperationInformation";
import { useRouter } from "next/navigation";
import { UUID } from "crypto";

interface OperationInformationFormProps {
rawFormData: OperationInformationFormData;
Expand All @@ -31,18 +30,6 @@ const OperationInformationForm = ({
const router = useRouter();
const [selectedOperation, setSelectedOperation] = useState("");
const [error, setError] = useState(undefined);
const [onSubmitSuccessfulResponse, setOnSubmitSuccessfulResponse] = useState<
{ id: UUID } | undefined
>(undefined);

useEffect(() => {
if (onSubmitSuccessfulResponse) {
const nextStepUrl = `/register-an-operation/${
onSubmitSuccessfulResponse.id
}/${step + 1}`;
router.push(nextStepUrl);
}
}, [onSubmitSuccessfulResponse]);

const nestedFormData = rawFormData
? createNestedFormData(rawFormData, schema)
Expand Down Expand Up @@ -85,8 +72,17 @@ const OperationInformationForm = ({
{
body,
},
);
// errors are handled in MultiStepBase
).then((resolve) => {
console.log("!!!!!resolve", resolve);
if (resolve?.error) {
return { error: resolve.error };
} else if (resolve?.id) {
// this form step needs a custom push (can't use the push in MultiStepBase) because the resolve.id is in the url
const nextStepUrl = `/register-an-operation/${resolve.id}/${step + 1}`;
router.push(nextStepUrl);
return resolve;
}
});
return response;
};
const handleSelectOperationChange = async (data: any) => {
Expand All @@ -108,7 +104,6 @@ const OperationInformationForm = ({
cancelUrl="/"
formData={formState}
onSubmit={handleSubmit}
setOnSubmitSuccessfulResponse={setOnSubmitSuccessfulResponse}
schema={schema}
step={step}
steps={steps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ const RegistrationSubmissionForm = ({
}: OperationRegistrationFormProps) => {
const [formState, setFormState] = useState({});
const [submitButtonDisabled, setSubmitButtonDisabled] = useState(true);
const [onSubmitSuccessfulResponse, setOnSubmitSuccessfulResponse] =
useState(undefined);
const [isSubmitted, setIsSubmitted] = useState(false);

const handleChange = (e: IChangeEvent) => {
setFormState(e.formData);
Expand All @@ -43,14 +42,22 @@ const RegistrationSubmissionForm = ({
...e.formData,
}),
},
);
// errors are handled in MultiStepBase
).then((resolve) => {
if (resolve?.error) {
setSubmitButtonDisabled(false);
return { error: resolve.error };
} else {
setIsSubmitted(true);
return resolve;
}
});

return response;
};

return (
<>
{onSubmitSuccessfulResponse ? (
{isSubmitted ? (
<Success step={step} steps={steps} />
) : (
<MultiStepBase
Expand All @@ -59,7 +66,6 @@ const RegistrationSubmissionForm = ({
cancelUrl="/"
formData={formState}
onSubmit={handleSubmit}
setOnSubmitSuccessfulResponse={setOnSubmitSuccessfulResponse}
schema={schema}
step={step}
steps={steps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ describe("the OperationInformationForm component", () => {
},
async () => {
fetchFormEnums();
actionHandler.mockReturnValueOnce({ id: "uuid2", name: "Operation 2" });
actionHandler.mockResolvedValueOnce({
id: "b974a7fc-ff63-41aa-9d57-509ebe2553a4",
}); // mock the POST response from the submit handler
render(
<OperationInformationForm
rawFormData={{}}
Expand Down Expand Up @@ -348,7 +350,9 @@ describe("the OperationInformationForm component", () => {
},
);
});
expect(mockPush).toHaveBeenCalledWith("/register-an-operation/uuid2/2");
expect(mockPush).toHaveBeenCalledWith(
"/register-an-operation/b974a7fc-ff63-41aa-9d57-509ebe2553a4/2",
);
},
);

Expand Down
Loading

0 comments on commit a37c090

Please sign in to comment.