Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/change reg purpose frontend/2169 #2771

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3d78ba5
chore: in progress - vitests
andrea-williams Feb 6, 2025
95608fd
chore: created basic ConfirmChangeOfRegistrationPurposeModal reuseabl…
andrea-williams Jan 28, 2025
013cd5b
chore: industry users will receive warning when changing registration…
andrea-williams Jan 29, 2025
dd01f0b
chore: in progress. Confused
andrea-williams Jan 29, 2025
07a9c23
chore: in progress
andrea-williams Jan 30, 2025
64a7e16
chore: in progress
andrea-williams Feb 4, 2025
c13cc05
chore: refactored registration section of operation details page to u…
andrea-williams Feb 5, 2025
cbeb79a
chore: re-introduced Confirmation modal when changing reg purpose - b…
andrea-williams Feb 5, 2025
b658fbe
chore: added activities back in; now RP preface isn't showing up
andrea-williams Feb 6, 2025
1be5367
chore: fixed RegistrationPurposeHelpText. I think all features complete
andrea-williams Feb 6, 2025
9fb2858
chore: in progress - vitests erratic
andrea-williams Feb 6, 2025
ded650b
chore: fixed vitests in admin/OperationInformationForm
andrea-williams Feb 6, 2025
2b93328
chore: made reg vitests fail more
andrea-williams Feb 7, 2025
588c7e3
chore: fixed rebase conflicts
andrea-williams Feb 10, 2025
736474e
chore: debugging vitests - in progress. Registration tests failing
andrea-williams Feb 11, 2025
55d8bc2
test: refactor fetchFormEnums
BCerki Feb 11, 2025
9448d2e
chore: fix prettier
BCerki Feb 11, 2025
fb9d2e7
chore: try incrasing timeout
BCerki Feb 11, 2025
81aa53f
chore: try increasing timeout
BCerki Feb 11, 2025
733a1ce
chore: increase timeout
BCerki Feb 11, 2025
e5d558f
chore: try increasing timeout
BCerki Feb 11, 2025
f3add6d
chore: tmate
BCerki Feb 12, 2025
903486e
chore: only run one project in CI vitests
BCerki Feb 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/test-code.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ jobs:
uses: ./.github/actions/dev-env-setup
- name: Run Nx Affected Tests with Remote Caching
id: nx-tests
run: |
yarn nx affected --base=origin/develop --target=test --parallel
run: yarn nx run components:test
shell: bash

yarn-audit:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"use client";

import { useState } from "react";
import { useEffect, useState } from "react";
import { useRouter, useSearchParams } from "next/navigation";

import { UUID } from "crypto";
import SingleStepTaskListForm from "@bciers/components/form/SingleStepTaskListForm";
import { RJSFSchema } from "@rjsf/utils";
import { IChangeEvent } from "@rjsf/core";
import { administrationOperationInformationUiSchema } from "../../data/jsonSchema/operationInformation/administrationOperationInformation";
import {
OperationInformationFormData,
Expand All @@ -20,6 +21,7 @@ import { FormMode, FrontEndRoles } from "@bciers/utils/src/enums";
import { useSessionRole } from "@bciers/utils/src/sessionUtils";
import Note from "@bciers/components/layout/Note";
import Link from "next/link";
import ConfirmChangeOfRegistrationPurposeModal from "apps/registration/app/components/operations/registration/ConfirmChangeOfRegistrationPurposeModal";

const OperationInformationForm = ({
formData,
Expand All @@ -31,12 +33,25 @@ const OperationInformationForm = ({
schema: RJSFSchema;
}) => {
const [error, setError] = useState(undefined);
const [selectedPurpose, setSelectedPurpose] = useState(
formData.registration_purpose || "",
);
const [
pendingChangeRegistrationPurpose,
setPendingChangeRegistrationPurpose,
] = useState("");
const router = useRouter();
// To get the user's role from the session
const role = useSessionRole();
const searchParams = useSearchParams();
const isRedirectedFromContacts = searchParams.get("from_contacts") as string;

useEffect(() => {
if (selectedPurpose) {
formData.registration_purpose = selectedPurpose;
}
}, [selectedPurpose]);

const handleSubmit = async (data: {
formData?: OperationInformationFormData;
}) => {
Expand Down Expand Up @@ -80,6 +95,25 @@ const OperationInformationForm = ({
return { error: response2.error };
}
};

const cancelRegistrationPurposeChange = () => {
setPendingChangeRegistrationPurpose("");
};

const confirmRegistrationPurposeChange = () => {
if (pendingChangeRegistrationPurpose !== "") {
setSelectedPurpose(pendingChangeRegistrationPurpose);
}
formData.registration_purpose = pendingChangeRegistrationPurpose;
setPendingChangeRegistrationPurpose("");
};

const handleSelectedPurposeChange = (newSelectedPurpose: string) => {
if (newSelectedPurpose && selectedPurpose) {
setPendingChangeRegistrationPurpose(newSelectedPurpose);
}
};

return (
<>
{isRedirectedFromContacts && !role.includes("cas_") && (
Expand All @@ -88,6 +122,11 @@ const OperationInformationForm = ({
contact to replace them.
</Note>
)}
<ConfirmChangeOfRegistrationPurposeModal
open={pendingChangeRegistrationPurpose !== ""}
cancelRegistrationPurposeChange={cancelRegistrationPurposeChange}
confirmRegistrationPurposeChange={confirmRegistrationPurposeChange}
/>
<SingleStepTaskListForm
allowEdit={!role.includes("cas_")}
mode={FormMode.READ_ONLY}
Expand All @@ -96,6 +135,12 @@ const OperationInformationForm = ({
uiSchema={administrationOperationInformationUiSchema}
formData={formData ?? {}}
onSubmit={handleSubmit}
onChange={(e: IChangeEvent) => {
let newSelectedPurpose = e.formData?.section3?.registration_purpose;
if (newSelectedPurpose !== selectedPurpose) {
handleSelectedPurposeChange(newSelectedPurpose);
}
}}
onCancel={() => router.push("/operations")}
formContext={{
operationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ export const createAdministrationOperationInformationSchema = async (
),
section2: await createMultipleOperatorsInformationSchema(),
...(status === OperationStatus.REGISTERED && {
section3: await createAdministrationRegistrationInformationSchema(
registrationPurposeValue,
),
section3: await createAdministrationRegistrationInformationSchema(),
}),
},
};
Expand All @@ -52,16 +50,16 @@ export const administrationOperationInformationUiSchema: UiSchema = {
"operation_representatives",
"registration_purpose",
"regulated_operation_preface",
"regulated_products",
"reporting_operation_preface",
"opted_in_preface",
"opted_in_operation",
"new_entrant_preface",
"potential_reporting_preface",
"activities",
"regulated_products",
"opted_in_operation",
"date_of_first_shipment",
"new_entrant_application",
],
registration_purpose: {
"ui:widget": "ReadOnlyWidget",
},
...optedInOperationDetailsUiSchema,
},
};
Loading
Loading