Skip to content

Commit

Permalink
feat: change new response action button label
Browse files Browse the repository at this point in the history
  • Loading branch information
deeonwuli committed Oct 15, 2024
1 parent 23d5bc7 commit 859e137
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 38 deletions.
6 changes: 5 additions & 1 deletion src/webapp/components/form/FormSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ export const FormSection: React.FC<FormSectionProps> = React.memo(
)}

{addNewField && handleAddNew && (
<AddNewOption id="" onAddNewOption={handleAddNew} />
<AddNewOption
id=""
label={addNewField.label}
onAddNewOption={handleAddNew}
/>
)}

{fields.length && fields.some(f => f.isVisible) ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { FormSectionState } from "../../../components/form/FormSectionsState";
import { FormState } from "../../../components/form/FormState";
import { Option as UIOption } from "../../../components/utils/option";
import { mapToPresentationOptions } from "../mapEntityToFormState";
import { getAnotherOptionSection } from "../risk-assessment/mapRiskAssessmentToInitialFormState";

type ActionPlanSectionKeys =
| "iapType"
Expand All @@ -24,14 +23,30 @@ type ActionPlanSectionKeys =
| "expectedResults"
| "responseActivitiesNarrative";

function getAnotherResponseActionSection(): FormSectionState {
return {
id: "addNewResponseActionSection",
isVisible: true,
fields: [],
addNewField: {
id: "addNewResponseAction",
isVisible: true,
errors: [],
type: "addNew",
value: null,
label: "Add new response action",
},
};
}

export function mapIncidentActionPlanToInitialFormState(
incidentActionPlanFormData: ActionPlanFormData
): FormState {
const { entity: incidentActionPlan, eventTrackerDetails, options } = incidentActionPlanFormData;
const { iapType, phoecLevel } = options;

const iapTypeOptions: UIOption[] = mapToPresentationOptions(iapType);
const phoexLevelOptions: UIOption[] = mapToPresentationOptions(phoecLevel);
const phoecLevelOptions: UIOption[] = mapToPresentationOptions(phoecLevel);

const mainSections: Record<ActionPlanSectionKeys, FormSectionState> = {
iapType: {
Expand Down Expand Up @@ -66,7 +81,7 @@ export function mapIncidentActionPlanToInitialFormState(
errors: [],
type: "select",
multiple: false,
options: phoexLevelOptions,
options: phoecLevelOptions,
value: incidentActionPlan?.phoecLevel || "",
required: true,
},
Expand Down Expand Up @@ -148,7 +163,7 @@ export function mapIncidentActionPlanToInitialFormState(
],
},
expectedResults: {
title: "Expected results",
title: "Sections, functional area objectives, expected results",
id: "expected_results_section",
isVisible: true,
direction: "column",
Expand Down Expand Up @@ -242,7 +257,7 @@ export function mapIncidentResponseActionToInitialFormState(
})
: [initialResponseActionSection];

const addNewOptionSection: FormSectionState = getAnotherOptionSection();
const addNewResponseActionSection: FormSectionState = getAnotherResponseActionSection();

return {
id: eventTrackerDetails.id ?? "",
Expand All @@ -252,7 +267,7 @@ export function mapIncidentResponseActionToInitialFormState(
subtitleDescripton: "Assign response actions",
saveButtonLabel: "Save plan",
isValid: incidentResponseActions.length !== 0 ? true : false,
sections: [...responseActionSections, addNewOptionSection],
sections: [...responseActionSections, addNewResponseActionSection],
};
}

Expand All @@ -270,7 +285,7 @@ function getResponseActionSection(options: {

const responseActionSection: FormSectionState = {
title: "",
id: `response_action_section`,
id: `response_action_section_${index}`,
isVisible: true,
direction: "row",
fields: [
Expand Down Expand Up @@ -379,7 +394,7 @@ function getResponseActionSection(options: {

export function addNewResponseActionSection(sections: FormSectionState[]): FormSectionState {
const responseActionSections = sections.filter(
section => !section.id.startsWith("addNewOptionSection")
section => !section.id.startsWith("addNewResponseActionSection")
);

const newResponseActionSection = getResponseActionSection({
Expand Down
29 changes: 1 addition & 28 deletions src/webapp/pages/form-page/mapFormStateToEntityData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ function mapFormStateToIncidentResponseAction(
const allFields: FormFieldState[] = getAllFieldsFromSections(formState.sections);

const incidentResponseActions: ResponseAction[] = formState.sections
.filter(section => !section.id.includes("addNewOptionSection"))
.filter(section => !section.id.includes("addNewResponseActionSection"))
.map((_, index): ResponseAction => {
const mainTask = allFields.find(field =>
field.id.includes(`${responseActionConstants.mainTask}_${index}`)
Expand Down Expand Up @@ -612,30 +612,3 @@ function getRiskAssessmentQuestionsWithOption(

return { likelihoodOption, consequencesOption, riskOption };
}

// function getIncidentResponseActions(
// allFields: FormFieldState[],
// options: IncidentResponseActionOptions,
// index: string
// ) {
// const likelihood = allFields.find(field =>
// field.id.includes(`${questionType}-likelihood${index}`)
// )?.value as string;
// const likelihoodOption = options.likelihood.find(option => option.id === likelihood);
// if (!likelihoodOption) throw new Error("Likelihood not found");

// const searchAssignRO = allFields.find(field => field.id.includes());

// const consequences = allFields.find(field =>
// field.id.includes(`${questionType}-consequences${index}`)
// )?.value as string;
// const consequencesOption = options.consequences.find(option => option.id === consequences);
// if (!consequencesOption) throw new Error("Consequences not found");

// const risk = allFields.find(field => field.id.includes(`${questionType}-risk${index}`))
// ?.value as string;
// const riskOption = options.risk.find(option => option.id === risk);
// if (!riskOption) throw new Error("Risk not found");

// return { likelihoodOption, consequencesOption, riskOption };
// }
2 changes: 1 addition & 1 deletion src/webapp/pages/form-page/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export function useForm(formType: FormType, id?: Id): State {
setFormState(prevState => {
if (prevState.kind === "loaded") {
const otherSections = prevState.data.sections.filter(
section => section.id !== "addNewOptionSection"
section => section.id !== "addNewResponseActionSection"
);
const addAnotherSection = getAnotherOptionSection();
const newResponseActionSection = addNewResponseActionSection(
Expand Down

0 comments on commit 859e137

Please sign in to comment.