|
1 | 1 | import { FormContext } from "../hooks/form-context"; |
2 | 2 | import type { FormFieldContext } from "../hooks/form-field-context"; |
3 | 3 | import { |
4 | | - ConfigurableProp, ConfigurableProps, |
| 4 | + ConfigurableProp, ConfigurablePropAlert, ConfigurableProps, |
5 | 5 | } from "@pipedream/sdk"; |
6 | | -import { useCustomize } from "../hooks/customization-context"; |
7 | | -import type { CSSProperties } from "react"; |
| 6 | +import { Alert } from "./Alert"; |
8 | 7 |
|
9 | 8 | export type ErrorsProps<T extends ConfigurableProps, U extends ConfigurableProp> = { |
10 | | - errors: string[]; |
11 | 9 | field: FormFieldContext<U>; |
12 | 10 | form: FormContext<T>; |
13 | 11 | }; |
14 | 12 |
|
15 | 13 | export function Errors<T extends ConfigurableProps, U extends ConfigurableProp>(props: ErrorsProps<T, U>) { |
16 | | - const { errors } = props; |
17 | | - |
| 14 | + const { field } = props; |
18 | 15 | const { |
19 | | - getProps, theme, |
20 | | - } = useCustomize(); |
| 16 | + errors = {}, prop = {}, enableDebugging, |
| 17 | + } = field |
21 | 18 |
|
22 | | - const baseStyles: CSSProperties = { |
23 | | - color: theme.colors.danger, |
24 | | - gridArea: "errors", |
25 | | - }; |
| 19 | + if (!enableDebugging) { |
| 20 | + return null |
| 21 | + } |
26 | 22 |
|
27 | | - if (!errors.length) { |
28 | | - return null; |
| 23 | + if (!errors[prop.name]) { |
| 24 | + return null |
29 | 25 | } |
30 | 26 |
|
31 | 27 | // TODO depending on type does different shit... we might need async loader around the label, etc.? |
32 | 28 | // maybe that should just be handled by FormFieldContext instead of container? |
| 29 | + |
| 30 | + const formattedErrors: ConfigurablePropAlert[] = errors[prop.name].map((e) => { |
| 31 | + return { |
| 32 | + type: "alert", |
| 33 | + alertType: "error", |
| 34 | + content: e, |
| 35 | + } |
| 36 | + }) |
| 37 | + |
| 38 | + const baseStyles = { |
| 39 | + display: "grid", |
| 40 | + gridTemplateColumns: "max-content", |
| 41 | + } |
| 42 | + |
| 43 | + const FormattedErrors = () => { |
| 44 | + return <>{formattedErrors.map((fe, idx: number) => <Alert prop={fe} key={idx}/>)}</> |
| 45 | + } |
| 46 | + |
33 | 47 | return ( |
34 | | - <ul {...getProps("errors", baseStyles, props)}> |
35 | | - {errors.map((msg) => <li key={msg} {...getProps("error", baseStyles, props)}>{msg}</li>)} |
36 | | - </ul> |
| 48 | + <div className="pd-errors" style={baseStyles}><FormattedErrors/></div> |
37 | 49 | ); |
38 | 50 | } |
0 commit comments