Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
b9ea29b6
Commit
b9ea29b6
authored
May 08, 2024
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor addresses
parent
bb6af2d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
28 deletions
+13
-28
PublicTagsSubmitFieldAddresses.tsx
...blicTags/submit/fields/PublicTagsSubmitFieldAddresses.tsx
+13
-28
No files found.
ui/publicTags/submit/fields/PublicTagsSubmitFieldAddresses.tsx
View file @
b9ea29b6
import
{
FormControl
,
GridItem
,
IconButton
,
Input
}
from
'
@chakra-ui/react
'
;
import
{
FormControl
,
GridItem
,
IconButton
,
Input
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
ControllerFieldState
,
ControllerRenderProps
,
UseFormStateReturn
}
from
'
react-hook-form
'
;
import
{
useFieldArray
,
useFormContext
}
from
'
react-hook-form
'
;
import
{
Controller
,
useFieldArray
,
useFormContext
}
from
'
react-hook-form
'
;
import
type
{
FormFields
}
from
'
../types
'
;
import
type
{
FormFields
}
from
'
../types
'
;
...
@@ -12,7 +11,7 @@ import InputPlaceholder from 'ui/shared/InputPlaceholder';
...
@@ -12,7 +11,7 @@ import InputPlaceholder from 'ui/shared/InputPlaceholder';
const
LIMIT
=
10
;
const
LIMIT
=
10
;
const
PublicTagsSubmitFieldAddresses
=
()
=>
{
const
PublicTagsSubmitFieldAddresses
=
()
=>
{
const
{
control
,
formState
}
=
useFormContext
<
FormFields
>
();
const
{
control
,
formState
,
register
}
=
useFormContext
<
FormFields
>
();
const
{
fields
,
insert
,
remove
}
=
useFieldArray
<
FormFields
,
'
addresses
'
>
({
const
{
fields
,
insert
,
remove
}
=
useFieldArray
<
FormFields
,
'
addresses
'
>
({
name
:
'
addresses
'
,
name
:
'
addresses
'
,
control
,
control
,
...
@@ -34,37 +33,23 @@ const PublicTagsSubmitFieldAddresses = () => {
...
@@ -34,37 +33,23 @@ const PublicTagsSubmitFieldAddresses = () => {
}
}
},
[
remove
]);
},
[
remove
]);
const
renderControl
=
React
.
useCallback
(({
field
,
formState
,
fieldState
}:
{
field
:
ControllerRenderProps
<
FormFields
,
`addresses.
${
number
}
.hash`
>
;
fieldState
:
ControllerFieldState
;
formState
:
UseFormStateReturn
<
FormFields
>
;
})
=>
{
return
(
<
FormControl
variant=
"floating"
id=
{
field
.
name
}
isRequired
size=
{
{
base
:
'
md
'
,
lg
:
'
lg
'
}
}
>
<
Input
{
...
field
}
isInvalid=
{
Boolean
(
fieldState
.
error
)
}
isDisabled=
{
formState
.
isSubmitting
}
required
autoComplete=
"off"
/>
<
InputPlaceholder
text=
"Smart contract / Address (0x...)"
error=
{
fieldState
.
error
}
/>
</
FormControl
>
);
},
[]);
return
(
return
(
<>
<>
{
fields
.
map
((
field
,
index
)
=>
{
{
fields
.
map
((
field
,
index
)
=>
{
const
error
=
formState
.
errors
?.
addresses
?.[
index
]?.
hash
;
return
(
return
(
<
React
.
Fragment
key=
{
field
.
id
}
>
<
React
.
Fragment
key=
{
field
.
id
}
>
<
GridItem
colSpan=
{
{
base
:
1
,
lg
:
2
}
}
>
<
GridItem
colSpan=
{
{
base
:
1
,
lg
:
2
}
}
>
<
Controller
<
FormControl
variant=
"floating"
isRequired
size=
{
{
base
:
'
md
'
,
lg
:
'
lg
'
}
}
>
name=
{
`addresses.${ index }.hash`
}
<
Input
control=
{
control
}
{
...
register
(`
addresses
.
$
{
index
}
.
hash
`,
{
required
:
true
,
pattern
:
ADDRESS_REGEXP
})
}
render=
{
renderControl
}
isInvalid=
{
Boolean
(
error
)
}
rules=
{
{
required
:
true
,
pattern
:
ADDRESS_REGEXP
}
}
isDisabled=
{
formState
.
isSubmitting
}
/>
autoComplete=
"off"
/>
<
InputPlaceholder
text=
"Smart contract / Address (0x...)"
error=
{
error
}
/>
</
FormControl
>
</
GridItem
>
</
GridItem
>
<
GridItem
display=
"flex"
alignItems=
"center"
columnGap=
{
5
}
>
<
GridItem
display=
"flex"
alignItems=
"center"
columnGap=
{
5
}
>
{
fields
.
length
<
LIMIT
&&
!
(
fields
.
length
>
1
&&
index
===
0
)
&&
(
{
fields
.
length
<
LIMIT
&&
!
(
fields
.
length
>
1
&&
index
===
0
)
&&
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment