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
4d0d415c
Commit
4d0d415c
authored
May 07, 2024
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
addresses field
parent
8cc20100
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
116 additions
and
4 deletions
+116
-4
PublicTagsSubmitForm.tsx
ui/publicTags/submit/PublicTagsSubmitForm.tsx
+7
-2
PublicTagsSubmitFieldAddresses.tsx
...blicTags/submit/fields/PublicTagsSubmitFieldAddresses.tsx
+102
-0
PublicTagsSubmitFieldRequesterEmail.tsx
...ags/submit/fields/PublicTagsSubmitFieldRequesterEmail.tsx
+5
-1
PublicTagsSubmitFieldRequesterName.tsx
...Tags/submit/fields/PublicTagsSubmitFieldRequesterName.tsx
+1
-1
types.ts
ui/publicTags/submit/types.ts
+1
-0
No files found.
ui/publicTags/submit/PublicTagsSubmitForm.tsx
View file @
4d0d415c
...
...
@@ -8,6 +8,7 @@ import type { PublicTagTypesResponse } from 'types/api/addressMetadata';
import
Hint
from
'
ui/shared/Hint
'
;
import
PublicTagsSubmitFieldAddresses
from
'
./fields/PublicTagsSubmitFieldAddresses
'
;
import
PublicTagsSubmitFieldRequesterEmail
from
'
./fields/PublicTagsSubmitFieldRequesterEmail
'
;
import
PublicTagsSubmitFieldRequesterName
from
'
./fields/PublicTagsSubmitFieldRequesterName
'
;
...
...
@@ -18,6 +19,9 @@ interface Props {
const
PublicTagsSubmitForm
=
({
config
}:
Props
)
=>
{
const
formApi
=
useForm
<
FormFields
>
({
mode
:
'
onBlur
'
,
defaultValues
:
{
addresses
:
[
{
hash
:
''
}
],
},
});
const
onFormSubmit
:
SubmitHandler
<
FormFields
>
=
React
.
useCallback
((
data
)
=>
{
...
...
@@ -34,7 +38,7 @@ const PublicTagsSubmitForm = ({ config }: Props) => {
<
Grid
columnGap=
{
5
}
rowGap=
{
{
base
:
5
,
lg
:
4
}
}
templateColumns=
{
{
base
:
'
1fr
'
,
lg
:
'
1fr 1fr minmax(0, 200px)
'
}
}
templateColumns=
{
{
base
:
'
1fr
'
,
lg
:
'
1fr 1fr minmax(0, 200px)
'
,
xl
:
'
1fr 1fr minmax(0, 250px)
'
}
}
>
<
GridItem
colSpan=
{
3
}
as=
"h2"
textStyle=
"h4"
>
Company info
...
...
@@ -48,8 +52,9 @@ const PublicTagsSubmitForm = ({ config }: Props) => {
<
GridItem
colSpan=
{
3
}
as=
"h2"
textStyle=
"h4"
mt=
{
3
}
>
Public tags/labels
<
Hint
label=
"Submit a public tag proposal for our moderation team to review"
ml=
{
1
}
/>
<
Hint
label=
"Submit a public tag proposal for our moderation team to review"
ml=
{
1
}
color=
"link"
/>
</
GridItem
>
<
PublicTagsSubmitFieldAddresses
/>
<
chakra
.
div
bgColor=
"blue.100"
h=
{
20
}
/>
<
chakra
.
div
bgColor=
"blue.100"
h=
{
20
}
/>
<
chakra
.
div
bgColor=
"yellow.100"
h=
{
20
}
/>
...
...
ui/publicTags/submit/fields/PublicTagsSubmitFieldAddresses.tsx
0 → 100644
View file @
4d0d415c
import
{
FormControl
,
GridItem
,
IconButton
,
Input
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
type
{
ControllerFieldState
,
ControllerRenderProps
,
UseFormStateReturn
}
from
'
react-hook-form
'
;
import
{
Controller
,
useFieldArray
,
useFormContext
}
from
'
react-hook-form
'
;
import
type
{
FormFields
}
from
'
../types
'
;
import
{
ADDRESS_REGEXP
}
from
'
lib/validations/address
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
import
InputPlaceholder
from
'
ui/shared/InputPlaceholder
'
;
const
LIMIT
=
10
;
const
PublicTagsSubmitFieldAddresses
=
()
=>
{
const
{
control
,
formState
}
=
useFormContext
<
FormFields
>
();
const
{
fields
,
insert
,
remove
}
=
useFieldArray
<
FormFields
,
'
addresses
'
>
({
name
:
'
addresses
'
,
control
,
});
const
isDisabled
=
formState
.
isSubmitting
;
const
handleAddFieldClick
=
React
.
useCallback
((
event
:
React
.
MouseEvent
)
=>
{
const
index
=
Number
(
event
.
currentTarget
.
getAttribute
(
'
data-index
'
));
if
(
!
Object
.
is
(
index
,
NaN
))
{
insert
(
index
+
1
,
{
hash
:
''
});
}
},
[
insert
]);
const
handleRemoveFieldClick
=
React
.
useCallback
((
event
:
React
.
MouseEvent
)
=>
{
const
index
=
Number
(
event
.
currentTarget
.
getAttribute
(
'
data-index
'
));
if
(
!
Object
.
is
(
index
,
NaN
))
{
remove
(
index
);
}
},
[
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
(
<>
{
fields
.
map
((
field
,
index
)
=>
{
return
(
<
React
.
Fragment
key=
{
field
.
id
}
>
<
GridItem
colSpan=
{
2
}
>
<
Controller
name=
{
`addresses.${ index }.hash`
}
control=
{
control
}
render=
{
renderControl
}
rules=
{
{
required
:
true
,
pattern
:
ADDRESS_REGEXP
}
}
/>
</
GridItem
>
<
GridItem
display=
"flex"
alignItems=
"center"
columnGap=
{
5
}
>
{
fields
.
length
<
LIMIT
&&
!
(
fields
.
length
>
1
&&
index
===
0
)
&&
(
<
IconButton
aria
-
label=
"add"
data
-
index=
{
index
}
variant=
"outline"
w=
"30px"
h=
"30px"
onClick=
{
handleAddFieldClick
}
icon=
{
<
IconSvg
name=
"plus"
boxSize=
{
5
}
/>
}
isDisabled=
{
isDisabled
}
/>
)
}
{
fields
.
length
>
1
&&
(
<
IconButton
aria
-
label=
"delete"
data
-
index=
{
index
}
variant=
"outline"
w=
"30px"
h=
"30px"
onClick=
{
handleRemoveFieldClick
}
icon=
{
<
IconSvg
name=
"minus"
boxSize=
{
5
}
/>
}
isDisabled=
{
isDisabled
}
/>
)
}
</
GridItem
>
</
React
.
Fragment
>
);
})
}
</>
);
};
export
default
React
.
memo
(
PublicTagsSubmitFieldAddresses
);
ui/publicTags/submit/fields/PublicTagsSubmitFieldRequesterEmail.tsx
View file @
4d0d415c
...
...
@@ -9,7 +9,11 @@ import InputPlaceholder from 'ui/shared/InputPlaceholder';
const
PublicTagsSubmitFieldRequesterEmail
=
()
=>
{
const
{
control
}
=
useFormContext
<
FormFields
>
();
const
{
field
,
fieldState
,
formState
}
=
useController
<
FormFields
>
({
control
,
name
:
'
requesterEmail
'
,
rules
:
{
required
:
true
,
pattern
:
EMAIL_REGEXP
}
});
const
{
field
,
fieldState
,
formState
}
=
useController
<
FormFields
,
'
requesterEmail
'
>
({
control
,
name
:
'
requesterEmail
'
,
rules
:
{
required
:
true
,
pattern
:
EMAIL_REGEXP
},
});
const
isDisabled
=
formState
.
isSubmitting
;
...
...
ui/publicTags/submit/fields/PublicTagsSubmitFieldRequesterName.tsx
View file @
4d0d415c
...
...
@@ -8,7 +8,7 @@ import InputPlaceholder from 'ui/shared/InputPlaceholder';
const
PublicTagsSubmitFieldRequesterName
=
()
=>
{
const
{
control
}
=
useFormContext
<
FormFields
>
();
const
{
field
,
fieldState
,
formState
}
=
useController
<
FormFields
>
({
control
,
name
:
'
requesterName
'
,
rules
:
{
required
:
true
}
});
const
{
field
,
fieldState
,
formState
}
=
useController
<
FormFields
,
'
requesterName
'
>
({
control
,
name
:
'
requesterName
'
,
rules
:
{
required
:
true
}
});
const
isDisabled
=
formState
.
isSubmitting
;
...
...
ui/publicTags/submit/types.ts
View file @
4d0d415c
export
interface
FormFields
{
requesterName
:
string
;
requesterEmail
:
string
;
addresses
:
Array
<
{
hash
:
string
}
>
;
}
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