1+ import React , { useContext } from "react"
2+ import Accordion from 'react-bootstrap/Accordion' ;
3+ import { useAccordionButton } from 'react-bootstrap/AccordionButton' ;
4+ import Card from 'react-bootstrap/Card' ;
5+ import AccordionContext from 'react-bootstrap/AccordionContext' ;
6+ import * as CONST from "./constants"
7+ import { MdKeyboardArrowDown , MdKeyboardArrowRight } from "react-icons/md"
8+
9+ // function to show custom buttons on Show/Hide in Accordians
10+ function ToggleErrorDisplay ( { children, eventKey, expandComponent, hideComponent, css } ) {
11+ const { activeEventKey } = useContext ( AccordionContext ) ;
12+
13+ const onExpand = useAccordionButton ( eventKey , ( ) => { } ) ;
14+
15+ const isCurrentEventKey = activeEventKey === eventKey ;
16+
17+ return (
18+ < button
19+ type = "button"
20+ className = { css }
21+ onClick = { onExpand }
22+ >
23+ { isCurrentEventKey ? hideComponent : expandComponent }
24+ </ button >
25+ ) ;
26+ }
27+
28+ // function displays accordians per property error
29+ /**
30+ *
31+ * @param {* } propertyName property name
32+ * @param {* } errorType error description per property
33+ * @param {* } message message per property
34+ * @returns
35+ */
36+ export const DisplayErrorPerProperty = ( { propertyName, errorType, message } ) => {
37+ return < Accordion className = "bg-transparent border-0 w-100" >
38+ < Accordion . Item eventKey = { propertyName } className = { "bg-transparent border-0 alert_danger_text" } >
39+ < div className = "mb-3" >
40+ < div className = "fw-bold d-flex" >
41+ < ToggleErrorDisplay eventKey = { propertyName }
42+ css = { CONST . ERROR_DOC_EXPAND_ICON_CLASSNAME }
43+ expandComponent = { < MdKeyboardArrowRight /> }
44+ hideComponent = { < MdKeyboardArrowDown /> } />
45+ { errorType }
46+ < pre className = "alert_danger_border ml-1 p-1 rounded" > { propertyName } </ pre >
47+ </ div >
48+ </ div >
49+ </ Accordion . Item >
50+ < Accordion . Collapse eventKey = { propertyName } className = { "bg-transparent" } >
51+ < div style = { { whiteSpace : "pre-wrap" } } > { message } </ div >
52+ </ Accordion . Collapse >
53+ </ Accordion >
54+ }
55+
56+
57+ // function display error messages
58+ export const ErrorDisplay = ( { errorData, message, css } ) => {
59+ return < Accordion className = "bg-transparent border-0 w-100" >
60+ < Card className = "bg-transparent border-0" >
61+ < Card . Header className = "bg-transparent" >
62+ < span className = "text-uppercase" > { message } </ span >
63+ < ToggleErrorDisplay eventKey = "0" expandComponent = { "More Info" } hideComponent = { "Hide" } css = { css } />
64+ </ Card . Header >
65+ < Accordion . Collapse eventKey = "0" >
66+ < Card . Body >
67+ { /*<pre>{JSON.stringify(errorData, null, 2)}</pre>*/ }
68+ { errorData }
69+ </ Card . Body >
70+ </ Accordion . Collapse >
71+ </ Card >
72+ </ Accordion >
73+ }
0 commit comments