File tree Expand file tree Collapse file tree 4 files changed +23
-11
lines changed
Expand file tree Collapse file tree 4 files changed +23
-11
lines changed Original file line number Diff line number Diff line change 1- /* eslint-disable @typescript-eslint/no-explicit-any */
21import { useRef } from "react" ;
3- import { useController } from "react-hook-form" ;
2+ import {
3+ Control ,
4+ FieldPath ,
5+ FieldValues ,
6+ RegisterOptions ,
7+ useController ,
8+ } from "react-hook-form" ;
49import { FormErrorMessage } from "../atoms" ;
510
6- type UncontrolledImageInputProps = {
7- name : string ;
8- control : any ;
9- rules ?: any ;
11+ type UncontrolledImageInputProps <
12+ TFieldValues extends FieldValues = FieldValues ,
13+ TName extends FieldPath < TFieldValues > = FieldPath < TFieldValues > ,
14+ > = {
15+ name : TName ;
16+ control : Control < TFieldValues > ;
17+ rules ?: RegisterOptions < TFieldValues , TName > ;
1018 placeholder ?: string ;
1119 dataTestId ?: string ;
1220} ;
1321
14- export const UncontrolledImageInput = ( {
22+ export const UncontrolledImageInput = < T extends FieldValues > ( {
1523 name,
1624 control,
1725 rules,
1826 placeholder,
1927 dataTestId,
20- } : UncontrolledImageInputProps ) => {
28+ } : UncontrolledImageInputProps < T > ) => {
2129 const {
2230 field : { onChange } ,
2331 fieldState,
Original file line number Diff line number Diff line change @@ -77,6 +77,6 @@ export const Rules = {
7777 value : IMAGE_REGEX ,
7878 message : i18n . t ( "registration.fields.validations.image" ) ,
7979 } ,
80- validate : ( value : string ) => isValidImageUrl ( value , { optional : true } ) ,
80+ validate : ( value : unknown ) => isValidImageUrl ( value , { optional : true } ) ,
8181 } ,
8282} ;
Original file line number Diff line number Diff line change 389389 "tooLongUrl" : " Url must be less than 128 bytes" ,
390390 "mustBeStakeAddress" : " It must be reward address in bech32 format" ,
391391 "mustBeReceivingAddress" : " Invalid payment address" ,
392- "couldNotGenerateImageSha" : " Could not generate image sha"
392+ "couldNotGenerateImageSha" : " Could not generate image sha" ,
393+ "invalidValueType" : " Invalid value type"
393394 }
394395 },
395396 "proposalDiscussion" : {
Original file line number Diff line number Diff line change @@ -82,7 +82,10 @@ export async function isDRepView(view?: string) {
8282 return i18n . t ( "forms.errors.mustBeDRepView" ) ;
8383}
8484
85- export async function isValidImageUrl ( url : string , options ?: Options ) {
85+ export async function isValidImageUrl ( url : unknown , options ?: Options ) {
86+ if ( typeof url !== "string" ) {
87+ return i18n . t ( "forms.errors.invalidValueType" ) ;
88+ }
8689 if ( options ?. optional && ! url ) return true ;
8790 if ( ! url . length ) return false ;
8891
You can’t perform that action at this time.
0 commit comments