-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract error notifiction into a component
- Loading branch information
1 parent
2538c66
commit 0240891
Showing
3 changed files
with
66 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from "react"; | ||
import { Divider, Row } from "antd"; | ||
|
||
export interface FeedbackError { | ||
key: string; | ||
errors: string[]; | ||
} | ||
|
||
interface FormValidationErrorsProps { | ||
errors: FeedbackError[]; | ||
} | ||
|
||
export const FormValidationErrors: React.FC<FormValidationErrorsProps> = ({ | ||
errors, | ||
}) => { | ||
let feedbackErrors: React.JSX.Element[] = []; | ||
errors.forEach((err: FeedbackError) => { | ||
let errorsForKey: React.JSX.Element[] = []; | ||
for (let errorForKey of err.errors) { | ||
errorsForKey.push(<Row>{errorForKey}</Row>); | ||
} | ||
|
||
feedbackErrors.push( | ||
<div> | ||
<Divider style={{ margin: "10px 0px" }} /> | ||
<Row style={{ fontWeight: "bold" }}>{err.key}</Row> | ||
<Row>{errorsForKey}</Row> | ||
</div>, | ||
); | ||
}); | ||
|
||
return <div>{feedbackErrors}</div>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters