-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
624bcee
commit 32657e4
Showing
7 changed files
with
29 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 |
---|---|---|
@@ -1,18 +1,21 @@ | ||
import { FieldErrors } from 'react-hook-form'; | ||
import { FieldError, FieldErrors } from 'react-hook-form'; | ||
|
||
export interface ValidationProps { | ||
errors?: FieldErrors; | ||
className?: string; | ||
} | ||
|
||
const Validation = ({ errors = {}, className }: ValidationProps): JSX.Element | null => { | ||
const keys = Object.keys(errors); | ||
if (keys.length === 0) return null; | ||
export const Validation = ({ errors = {}, className = '' }: ValidationProps) => { | ||
const errorEntries = Object.entries(errors); | ||
|
||
if (errorEntries.length === 0) return <></>; | ||
|
||
return ( | ||
<ul className={`text-sm text-red-400 ${className}`}> | ||
{/** @ts-expect-error @todo remove */} | ||
{keys.map((key) => (errors[key] && errors[key]?.message ? <li key={key}>{errors[key]?.message}</li> : null))} | ||
{errorEntries.map(([field, error]) => { | ||
const message = (error as FieldError)?.message; | ||
return typeof message === 'string' ? <li key={field}>{message}</li> : null; | ||
})} | ||
</ul> | ||
); | ||
}; | ||
export default Validation; |
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
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
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