Skip to content
This repository was archived by the owner on Jan 9, 2026. It is now read-only.

Commit e80d35a

Browse files
authored
Public tags form improvements (blockscout#2796)
* adjust validation of comment field * add icon url to public tag form * update screenshots * fix ts
1 parent 95eba28 commit e80d35a

11 files changed

+82
-7
lines changed

toolkit/components/forms/fields/image/FormFieldImagePreview.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const FormFieldImagePreview = chakra(React.memo(({
3535

3636
return (
3737
<Image
38+
key={ src }
3839
className={ className }
3940
src={ src }
4041
alt="Image preview"

ui/publicTags/submit/PublicTagsSubmitForm.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ const PublicTagsSubmitForm = ({ config, userInfo, onSubmitResult }: Props) => {
124124
required
125125
placeholder={
126126
isMobile ?
127-
'Confirm the connection between addresses and tags.' :
128-
'Provide a comment to confirm the connection between addresses and tags.'
127+
'Confirm the connection between addresses and tags' :
128+
'Provide a comment to confirm the connection between addresses and tags (max 500 characters)'
129129
}
130130
maxH="160px"
131-
rules={{ maxLength: 80 }}
131+
rules={{ maxLength: 500 }}
132132
asComponent="Textarea"
133133
size="2xl"
134134
/>
9.33 KB
Loading
8 KB
Loading

ui/publicTags/submit/fields/PublicTagsSubmitFieldTag.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { FormFieldUrl } from 'toolkit/components/forms/fields/FormFieldUrl';
1414
import { colorValidator } from 'toolkit/components/forms/validators/color';
1515
import EntityTag from 'ui/shared/EntityTags/EntityTag';
1616

17+
import PublicTagsSubmitFieldTagIcon from './PublicTagsSubmitFieldTagIcon';
1718
import PublicTagsSubmitFieldTagType from './PublicTagsSubmitFieldTagType';
1819

1920
const CIRCLE_BG_COLOR_DEFAULT = {
@@ -79,6 +80,9 @@ const PublicTagsSubmitFieldTag = ({ index, isDisabled, errors, onAddClick, onRem
7980
placeholder="Text (Hex)"
8081
sampleDefaultBgColor={ CIRCLE_BG_COLOR_DEFAULT.textColor }
8182
/>
83+
<GridItem colSpan={{ base: 1, lg: 4 }}>
84+
<PublicTagsSubmitFieldTagIcon index={ index }/>
85+
</GridItem>
8286
<GridItem colSpan={{ base: 1, lg: 4 }}>
8387
<FormFieldText<FormFields>
8488
name={ `tags.${ index }.tooltipDescription` }
@@ -118,6 +122,7 @@ const PublicTagsSubmitFieldTag = ({ index, isDisabled, errors, onAddClick, onRem
118122
name: field.name || 'Tag name',
119123
tagType: field.type[0],
120124
meta: {
125+
tagIcon: errors?.iconUrl ? undefined : field.iconUrl,
121126
tagUrl: field.url,
122127
bgColor: field.bgColor && colorValidator(field.bgColor) === true ? field.bgColor : undefined,
123128
textColor: field.textColor && colorValidator(field.textColor) === true ? field.textColor : undefined,
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Flex } from '@chakra-ui/react';
2+
import React from 'react';
3+
4+
import type { FormFields } from '../types';
5+
6+
import { FormFieldUrl } from 'toolkit/components/forms/fields/FormFieldUrl';
7+
import { FormFieldImagePreview } from 'toolkit/components/forms/fields/image/FormFieldImagePreview';
8+
import { useImageField } from 'toolkit/components/forms/fields/image/useImageField';
9+
import IconSvg from 'ui/shared/IconSvg';
10+
11+
import PublicTagsSubmitFieldTagIconPreview from './PublicTagsSubmitFieldTagIconPreview';
12+
13+
interface Props {
14+
index: number;
15+
}
16+
17+
const PublicTagsSubmitFieldTagIcon = ({ index }: Props) => {
18+
19+
const imageField = useImageField({ name: `tags.${ index }.iconUrl`, isRequired: false });
20+
21+
return (
22+
<Flex columnGap={ 3 }>
23+
<FormFieldUrl<FormFields>
24+
name={ `tags.${ index }.iconUrl` }
25+
placeholder="Label icon URL"
26+
{ ...imageField.input }
27+
/>
28+
<PublicTagsSubmitFieldTagIconPreview url={ imageField.preview.src } isInvalid={ imageField.preview.isInvalid }>
29+
<FormFieldImagePreview
30+
{ ...imageField.preview }
31+
fallback={ <IconSvg name="blobs/image" color="gray.500" boxSize="30px"/> }
32+
boxSize="30px"
33+
/>
34+
</PublicTagsSubmitFieldTagIconPreview>
35+
</Flex>
36+
);
37+
};
38+
39+
export default React.memo(PublicTagsSubmitFieldTagIcon);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Center } from '@chakra-ui/react';
2+
import React from 'react';
3+
4+
interface Props {
5+
url: string | undefined;
6+
isInvalid: boolean;
7+
children: React.ReactElement;
8+
}
9+
10+
const PublicTagsSubmitFieldTagIconPreview = ({ url, isInvalid, children }: Props) => {
11+
const borderColorActive = isInvalid ? 'error' : 'input.border.filled';
12+
13+
return (
14+
<Center
15+
boxSize="60px"
16+
flexShrink={ 0 }
17+
borderWidth="2px"
18+
borderColor={ url ? borderColorActive : 'input.border' }
19+
borderRadius="base"
20+
backgroundColor="global.body.bg"
21+
>
22+
{ children }
23+
</Center>
24+
);
25+
};
26+
27+
export default React.memo(PublicTagsSubmitFieldTagIconPreview);

ui/publicTags/submit/fields/PublicTagsSubmitFieldTags.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const PublicTagsSubmitFieldTags = ({ tagTypes }: Props) => {
2626
name: '',
2727
type: [ 'name' ],
2828
url: undefined,
29+
iconUrl: undefined,
2930
bgColor: undefined,
3031
textColor: undefined,
3132
tooltipDescription: undefined,

ui/publicTags/submit/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface FormFieldTag {
1414
name: string;
1515
type: Array<AddressMetadataTagType>;
1616
url: string | undefined;
17+
iconUrl: string | undefined;
1718
bgColor: string | undefined;
1819
textColor: string | undefined;
1920
tooltipDescription: string | undefined;
@@ -32,6 +33,7 @@ export interface SubmitRequestBody {
3233
bgColor?: string;
3334
textColor?: string;
3435
tagUrl?: string;
36+
tagIcon?: string;
3537
tooltipDescription?: string;
3638
};
3739
}

ui/publicTags/submit/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function convertFormDataToRequestsBody(data: FormFields): Array<SubmitReq
2525
bgColor: tag.bgColor,
2626
textColor: tag.textColor,
2727
tagUrl: tag.url,
28+
tagIcon: tag.iconUrl,
2829
tooltipDescription: tag.tooltipDescription,
2930
}, Boolean),
3031
});
@@ -39,6 +40,7 @@ export function convertTagApiFieldsToFormFields(tag: Pick<SubmitRequestBody, 'na
3940
name: tag.name,
4041
type: [ tag.tagType ],
4142
url: tag.meta.tagUrl,
43+
iconUrl: tag.meta.tagIcon,
4244
bgColor: tag.meta.bgColor,
4345
textColor: tag.meta.textColor,
4446
tooltipDescription: tag.meta.tooltipDescription,

0 commit comments

Comments
 (0)