Commit e80d35ab authored by tom goriunov's avatar tom goriunov Committed by GitHub

Public tags form improvements (#2796)

* adjust validation of comment field

* add icon url to public tag form

* update screenshots

* fix ts
parent 95eba28f
...@@ -35,6 +35,7 @@ export const FormFieldImagePreview = chakra(React.memo(({ ...@@ -35,6 +35,7 @@ export const FormFieldImagePreview = chakra(React.memo(({
return ( return (
<Image <Image
key={ src }
className={ className } className={ className }
src={ src } src={ src }
alt="Image preview" alt="Image preview"
......
...@@ -124,11 +124,11 @@ const PublicTagsSubmitForm = ({ config, userInfo, onSubmitResult }: Props) => { ...@@ -124,11 +124,11 @@ const PublicTagsSubmitForm = ({ config, userInfo, onSubmitResult }: Props) => {
required required
placeholder={ placeholder={
isMobile ? isMobile ?
'Confirm the connection between addresses and tags.' : 'Confirm the connection between addresses and tags' :
'Provide a comment to confirm the connection between addresses and tags.' 'Provide a comment to confirm the connection between addresses and tags (max 500 characters)'
} }
maxH="160px" maxH="160px"
rules={{ maxLength: 80 }} rules={{ maxLength: 500 }}
asComponent="Textarea" asComponent="Textarea"
size="2xl" size="2xl"
/> />
......
...@@ -14,6 +14,7 @@ import { FormFieldUrl } from 'toolkit/components/forms/fields/FormFieldUrl'; ...@@ -14,6 +14,7 @@ import { FormFieldUrl } from 'toolkit/components/forms/fields/FormFieldUrl';
import { colorValidator } from 'toolkit/components/forms/validators/color'; import { colorValidator } from 'toolkit/components/forms/validators/color';
import EntityTag from 'ui/shared/EntityTags/EntityTag'; import EntityTag from 'ui/shared/EntityTags/EntityTag';
import PublicTagsSubmitFieldTagIcon from './PublicTagsSubmitFieldTagIcon';
import PublicTagsSubmitFieldTagType from './PublicTagsSubmitFieldTagType'; import PublicTagsSubmitFieldTagType from './PublicTagsSubmitFieldTagType';
const CIRCLE_BG_COLOR_DEFAULT = { const CIRCLE_BG_COLOR_DEFAULT = {
...@@ -79,6 +80,9 @@ const PublicTagsSubmitFieldTag = ({ index, isDisabled, errors, onAddClick, onRem ...@@ -79,6 +80,9 @@ const PublicTagsSubmitFieldTag = ({ index, isDisabled, errors, onAddClick, onRem
placeholder="Text (Hex)" placeholder="Text (Hex)"
sampleDefaultBgColor={ CIRCLE_BG_COLOR_DEFAULT.textColor } sampleDefaultBgColor={ CIRCLE_BG_COLOR_DEFAULT.textColor }
/> />
<GridItem colSpan={{ base: 1, lg: 4 }}>
<PublicTagsSubmitFieldTagIcon index={ index }/>
</GridItem>
<GridItem colSpan={{ base: 1, lg: 4 }}> <GridItem colSpan={{ base: 1, lg: 4 }}>
<FormFieldText<FormFields> <FormFieldText<FormFields>
name={ `tags.${ index }.tooltipDescription` } name={ `tags.${ index }.tooltipDescription` }
...@@ -118,6 +122,7 @@ const PublicTagsSubmitFieldTag = ({ index, isDisabled, errors, onAddClick, onRem ...@@ -118,6 +122,7 @@ const PublicTagsSubmitFieldTag = ({ index, isDisabled, errors, onAddClick, onRem
name: field.name || 'Tag name', name: field.name || 'Tag name',
tagType: field.type[0], tagType: field.type[0],
meta: { meta: {
tagIcon: errors?.iconUrl ? undefined : field.iconUrl,
tagUrl: field.url, tagUrl: field.url,
bgColor: field.bgColor && colorValidator(field.bgColor) === true ? field.bgColor : undefined, bgColor: field.bgColor && colorValidator(field.bgColor) === true ? field.bgColor : undefined,
textColor: field.textColor && colorValidator(field.textColor) === true ? field.textColor : undefined, textColor: field.textColor && colorValidator(field.textColor) === true ? field.textColor : undefined,
......
import { Flex } from '@chakra-ui/react';
import React from 'react';
import type { FormFields } from '../types';
import { FormFieldUrl } from 'toolkit/components/forms/fields/FormFieldUrl';
import { FormFieldImagePreview } from 'toolkit/components/forms/fields/image/FormFieldImagePreview';
import { useImageField } from 'toolkit/components/forms/fields/image/useImageField';
import IconSvg from 'ui/shared/IconSvg';
import PublicTagsSubmitFieldTagIconPreview from './PublicTagsSubmitFieldTagIconPreview';
interface Props {
index: number;
}
const PublicTagsSubmitFieldTagIcon = ({ index }: Props) => {
const imageField = useImageField({ name: `tags.${ index }.iconUrl`, isRequired: false });
return (
<Flex columnGap={ 3 }>
<FormFieldUrl<FormFields>
name={ `tags.${ index }.iconUrl` }
placeholder="Label icon URL"
{ ...imageField.input }
/>
<PublicTagsSubmitFieldTagIconPreview url={ imageField.preview.src } isInvalid={ imageField.preview.isInvalid }>
<FormFieldImagePreview
{ ...imageField.preview }
fallback={ <IconSvg name="blobs/image" color="gray.500" boxSize="30px"/> }
boxSize="30px"
/>
</PublicTagsSubmitFieldTagIconPreview>
</Flex>
);
};
export default React.memo(PublicTagsSubmitFieldTagIcon);
import { Center } from '@chakra-ui/react';
import React from 'react';
interface Props {
url: string | undefined;
isInvalid: boolean;
children: React.ReactElement;
}
const PublicTagsSubmitFieldTagIconPreview = ({ url, isInvalid, children }: Props) => {
const borderColorActive = isInvalid ? 'error' : 'input.border.filled';
return (
<Center
boxSize="60px"
flexShrink={ 0 }
borderWidth="2px"
borderColor={ url ? borderColorActive : 'input.border' }
borderRadius="base"
backgroundColor="global.body.bg"
>
{ children }
</Center>
);
};
export default React.memo(PublicTagsSubmitFieldTagIconPreview);
...@@ -26,6 +26,7 @@ const PublicTagsSubmitFieldTags = ({ tagTypes }: Props) => { ...@@ -26,6 +26,7 @@ const PublicTagsSubmitFieldTags = ({ tagTypes }: Props) => {
name: '', name: '',
type: [ 'name' ], type: [ 'name' ],
url: undefined, url: undefined,
iconUrl: undefined,
bgColor: undefined, bgColor: undefined,
textColor: undefined, textColor: undefined,
tooltipDescription: undefined, tooltipDescription: undefined,
......
...@@ -14,6 +14,7 @@ export interface FormFieldTag { ...@@ -14,6 +14,7 @@ export interface FormFieldTag {
name: string; name: string;
type: Array<AddressMetadataTagType>; type: Array<AddressMetadataTagType>;
url: string | undefined; url: string | undefined;
iconUrl: string | undefined;
bgColor: string | undefined; bgColor: string | undefined;
textColor: string | undefined; textColor: string | undefined;
tooltipDescription: string | undefined; tooltipDescription: string | undefined;
...@@ -32,6 +33,7 @@ export interface SubmitRequestBody { ...@@ -32,6 +33,7 @@ export interface SubmitRequestBody {
bgColor?: string; bgColor?: string;
textColor?: string; textColor?: string;
tagUrl?: string; tagUrl?: string;
tagIcon?: string;
tooltipDescription?: string; tooltipDescription?: string;
}; };
} }
......
...@@ -25,6 +25,7 @@ export function convertFormDataToRequestsBody(data: FormFields): Array<SubmitReq ...@@ -25,6 +25,7 @@ export function convertFormDataToRequestsBody(data: FormFields): Array<SubmitReq
bgColor: tag.bgColor, bgColor: tag.bgColor,
textColor: tag.textColor, textColor: tag.textColor,
tagUrl: tag.url, tagUrl: tag.url,
tagIcon: tag.iconUrl,
tooltipDescription: tag.tooltipDescription, tooltipDescription: tag.tooltipDescription,
}, Boolean), }, Boolean),
}); });
...@@ -39,6 +40,7 @@ export function convertTagApiFieldsToFormFields(tag: Pick<SubmitRequestBody, 'na ...@@ -39,6 +40,7 @@ export function convertTagApiFieldsToFormFields(tag: Pick<SubmitRequestBody, 'na
name: tag.name, name: tag.name,
type: [ tag.tagType ], type: [ tag.tagType ],
url: tag.meta.tagUrl, url: tag.meta.tagUrl,
iconUrl: tag.meta.tagIcon,
bgColor: tag.meta.bgColor, bgColor: tag.meta.bgColor,
textColor: tag.meta.textColor, textColor: tag.meta.textColor,
tooltipDescription: tag.meta.tooltipDescription, tooltipDescription: tag.meta.tooltipDescription,
......
...@@ -8,16 +8,14 @@ interface Props { ...@@ -8,16 +8,14 @@ interface Props {
} }
const TokenInfoIconPreview = ({ url, isInvalid, children }: Props) => { const TokenInfoIconPreview = ({ url, isInvalid, children }: Props) => {
const borderColor = { _light: 'gray.100', _dark: 'gray.700' }; const borderColorActive = isInvalid ? 'error' : 'input.border.filled';
const borderColorFilled = { _light: 'gray.300', _dark: 'gray.600' };
const borderColorActive = isInvalid ? 'error' : borderColorFilled;
return ( return (
<Center <Center
boxSize="60px" boxSize="60px"
flexShrink={ 0 } flexShrink={ 0 }
borderWidth="2px" borderWidth="2px"
borderColor={ url ? borderColorActive : borderColor } borderColor={ url ? borderColorActive : 'input.border' }
borderRadius="base" borderRadius="base"
> >
{ children } { children }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment