-
Notifications
You must be signed in to change notification settings - Fork 1
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
510: is_application_lead_external 'no' error #534
Changes from all commits
b254ee8
b7f8032
20fe802
4eca5b8
6d1629a
40d9520
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import OperationsForm, { | |
} from "@/app/components/form/OperationsForm"; | ||
import { operationSchema } from "@/app/utils/jsonSchema/operations"; | ||
import { BusinessStructure } from "@/app/components/routes/select-operator/form/types"; | ||
import { UserProfileFormData } from "@/app/components/form/formDataTypes"; | ||
import { RJSFSchema } from "@rjsf/utils"; | ||
import { actionHandler } from "@/app/utils/actions"; | ||
import OperationReview from "./OperationReview"; | ||
|
@@ -12,6 +13,13 @@ import { Fade } from "@mui/material"; | |
import { Status } from "@/app/utils/enums"; | ||
import { Operation as OperationInt } from "@/app/components/routes/operations/types"; | ||
|
||
// 🚀 API call: GET user's data | ||
async function getUserFormData(): Promise< | ||
UserProfileFormData | { error: string } | ||
> { | ||
return actionHandler(`registration/user-profile`, "GET", ""); | ||
} | ||
|
||
// 🛠️ Function to fetch NAICS codes | ||
async function getNaicsCodes() { | ||
try { | ||
|
@@ -194,6 +202,54 @@ export default async function Operation({ numRow }: { numRow?: number }) { | |
operation && | ||
[Status.REJECTED, Status.APPROVED].includes(operation?.status as Status); | ||
|
||
let userProfileFormData: UserProfileFormData | { error: string } = | ||
await getUserFormData(); | ||
|
||
const formData = { | ||
...userProfileFormData, | ||
...operation, | ||
}; | ||
|
||
const userEmail = (userProfileFormData as UserProfileFormData)?.email; | ||
const applicationLeadEmail = formData?.application_lead?.email; | ||
// If the current user is the application lead, we want to show the application lead fields | ||
const isUserApplicationLead = | ||
userEmail === applicationLeadEmail && applicationLeadEmail !== undefined; | ||
|
||
Comment on lines
+216
to
+218
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wasn't entirely sure if this was enough for the check. I figured that if they didn't click the button but entered the same email there was just a misunderstanding so we would check this off. Also I tried to do this with a function similar to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This implementation is making me think a bit here. I don't see any particular problem with this check, but it just feels a bit weird to me. Let's chat quickly so I can fully understand what's happening here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Totally works for now, we probably want to review this implementation later to see if there is a best practice or standard that we can follow for future conditionals. I've added a tech debt card #602 to review this and start a conversation. |
||
// empty array is not a valid value for multiple_operators_array as empty default should be [{}] | ||
// to avoid buggy behaviour opening | ||
const isMultipleOperatorsArray = | ||
formData && | ||
Array.isArray(formData?.multiple_operators_array) && | ||
formData.multiple_operators_array.length > 0; | ||
|
||
// We need to convert some of the information received from django into types RJSF can read. | ||
const transformedFormData = { | ||
...formData, | ||
// Add the correct application lead data | ||
...(isUserApplicationLead | ||
? { | ||
...formData?.application_lead, | ||
} | ||
: { | ||
external_lead_first_name: formData?.application_lead?.first_name, | ||
external_lead_last_name: formData?.application_lead?.last_name, | ||
external_lead_email: formData?.application_lead?.email, | ||
external_lead_phone_number: formData?.application_lead?.phone_number, | ||
external_lead_position_title: | ||
formData?.application_lead?.position_title, | ||
}), | ||
// If you spread anything and it has the same keys as operation (e.g. id, created_by), watch out for accidentally overwriting things. In this case it's safe to spread because the address schema excludes fields | ||
...formData?.application_lead?.address, | ||
"Did you submit a GHG emissions report for reporting year 2022?": | ||
formData?.previous_year_attributable_emissions ? true : false, | ||
is_user_application_lead: isUserApplicationLead, | ||
// fix for null values not opening the multiple operators form if loading a previously saved form | ||
multiple_operators_array: isMultipleOperatorsArray | ||
? formData?.multiple_operators_array | ||
: [{}], | ||
}; | ||
|
||
Comment on lines
+219
to
+252
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved this one file up to keep |
||
// Render the OperationsForm component with schema and formData if the operation already exists | ||
return ( | ||
<> | ||
|
@@ -213,7 +269,7 @@ export default async function Operation({ numRow }: { numRow?: number }) { | |
activities, | ||
businessStructuresList, | ||
)} | ||
formData={operation as OperationsFormData} | ||
formData={transformedFormData as OperationsFormData} | ||
/> | ||
</> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
address
doesn't exist in the user model and was causing the error.