Skip to content

Commit

Permalink
adding error sumary component implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisDDBT committed Feb 27, 2025
1 parent dc17e25 commit c3d4032
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
16 changes: 9 additions & 7 deletions front_end/src/Components/Common/ErrorSummary/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ export default function ErrorSummary({ errors }) {
</h2>
<div className="govuk-error-summary__body">
<ul className="govuk-list govuk-error-summary__list">
{errors.map((error) => {
return (
<li key={error.label}>
<a href={`#${error.label}`}>{error.message}</a>
</li>
);
})}
{errors &&
Array.isArray(errors) &&
errors.map((error) => {
return (
<li key={error.label}>
<a href={`#${error.label}`}>{error.message}</a>
</li>
);
})}
</ul>
</div>
</div>
Expand Down
10 changes: 7 additions & 3 deletions front_end/src/Components/Notes/NotesCell.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from "react";
import { getURLSegment, postJsonData } from "../../Util";
import ErrorSummary from "../Common/ErrorSummary";

const Modal = ({ isOpen, notes, employee_no, onClose, onSave }) => {
const charLimit = 200;
Expand All @@ -10,8 +11,8 @@ const Modal = ({ isOpen, notes, employee_no, onClose, onSave }) => {
const [charLeft, setCharLeft] = useState(currentLimit);
const [errorMessage, setErrorMessage] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false);
const financialYear = window.financialYear;
const costCentre = window.costCentreCode;
const financialYear = String(window.financialYear);
const costCentre = String(window.costCentreCode);

if (!isOpen) return null;

Expand Down Expand Up @@ -66,7 +67,10 @@ const Modal = ({ isOpen, notes, employee_no, onClose, onSave }) => {
</div>

<form onSubmit={handleSubmit} noValidate>
{errors && <ErrorSummary errors={[{ message: errorMessage }]} />}
{errorMessage && (
<ErrorSummary errors={[{ message: errorMessage, label: "" }]} />
)}

<div className={formGroupClasses}>
<div
className="govuk-character-count"
Expand Down

0 comments on commit c3d4032

Please sign in to comment.