fix(trading): re-use input errors instead of notification component (#2924)

This commit is contained in:
m.ray 2023-02-20 02:53:16 -05:00 committed by GitHub
parent 0059050440
commit 94c40cce7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 62 deletions

View File

@ -1,4 +1,4 @@
import { FormGroup, Input, NotificationError } from '@vegaprotocol/ui-toolkit'; import { FormGroup, Input, InputError } from '@vegaprotocol/ui-toolkit';
import { t, toDecimal, validateAmount } from '@vegaprotocol/react-helpers'; import { t, toDecimal, validateAmount } from '@vegaprotocol/react-helpers';
import type { DealTicketAmountProps } from './deal-ticket-amount'; import type { DealTicketAmountProps } from './deal-ticket-amount';
@ -20,17 +20,17 @@ export const DealTicketLimitAmount = ({
const renderError = () => { const renderError = () => {
if (sizeError) { if (sizeError) {
return ( return (
<NotificationError testId="dealticket-error-message-size-limit"> <InputError testId="dealticket-error-message-size-limit">
{sizeError} {sizeError}
</NotificationError> </InputError>
); );
} }
if (priceError) { if (priceError) {
return ( return (
<NotificationError testId="dealticket-error-message-price-limit"> <InputError testId="dealticket-error-message-price-limit">
{priceError} {priceError}
</NotificationError> </InputError>
); );
} }

View File

@ -4,7 +4,7 @@ import {
toDecimal, toDecimal,
validateAmount, validateAmount,
} from '@vegaprotocol/react-helpers'; } from '@vegaprotocol/react-helpers';
import { Input, NotificationError, Tooltip } from '@vegaprotocol/ui-toolkit'; import { Input, InputError, Tooltip } from '@vegaprotocol/ui-toolkit';
import { isMarketInAuction } from '../../utils'; import { isMarketInAuction } from '../../utils';
import type { DealTicketAmountProps } from './deal-ticket-amount'; import type { DealTicketAmountProps } from './deal-ticket-amount';
import { getMarketPrice } from '../../utils/get-price'; import { getMarketPrice } from '../../utils/get-price';
@ -77,12 +77,12 @@ export const DealTicketMarketAmount = ({
</div> </div>
</div> </div>
{sizeError && ( {sizeError && (
<NotificationError <InputError
intent="danger" intent="danger"
testId="dealticket-error-message-size-market" testId="dealticket-error-message-size-market"
> >
{sizeError} {sizeError}
</NotificationError> </InputError>
)} )}
</div> </div>
); );

View File

@ -15,7 +15,7 @@ import { normalizeOrderSubmission } from '@vegaprotocol/wallet';
import { useVegaWallet } from '@vegaprotocol/wallet'; import { useVegaWallet } from '@vegaprotocol/wallet';
import { import {
ExternalLink, ExternalLink,
NotificationError, InputError,
Intent, Intent,
Notification, Notification,
} from '@vegaprotocol/ui-toolkit'; } from '@vegaprotocol/ui-toolkit';
@ -308,11 +308,11 @@ const SummaryMessage = memo(
if (isReadOnly) { if (isReadOnly) {
return ( return (
<div className="mb-4"> <div className="mb-4">
<NotificationError testId="dealticket-error-message-summary"> <InputError testId="dealticket-error-message-summary">
{ {
'You need to connect your own wallet to start trading on this market' 'You need to connect your own wallet to start trading on this market'
} }
</NotificationError> </InputError>
</div> </div>
); );
} }
@ -353,9 +353,9 @@ const SummaryMessage = memo(
if (errorMessage) { if (errorMessage) {
return ( return (
<div className="mb-4"> <div className="mb-4">
<NotificationError testId="dealticket-error-message-summary"> <InputError testId="dealticket-error-message-summary">
{errorMessage} {errorMessage}
</NotificationError> </InputError>
</div> </div>
); );
} }

View File

@ -1,4 +1,4 @@
import { FormGroup, Input, NotificationError } from '@vegaprotocol/ui-toolkit'; import { FormGroup, Input, InputError } from '@vegaprotocol/ui-toolkit';
import { formatForInput } from '@vegaprotocol/react-helpers'; import { formatForInput } from '@vegaprotocol/react-helpers';
import { t } from '@vegaprotocol/react-helpers'; import { t } from '@vegaprotocol/react-helpers';
import type { UseFormRegister } from 'react-hook-form'; import type { UseFormRegister } from 'react-hook-form';
@ -35,9 +35,9 @@ export const ExpirySelector = ({
})} })}
/> />
{errorMessage && ( {errorMessage && (
<NotificationError testId="dealticket-error-message-expiry"> <InputError testId="dealticket-error-message-expiry">
{errorMessage} {errorMessage}
</NotificationError> </InputError>
)} )}
</FormGroup> </FormGroup>
); );

View File

@ -1,7 +1,7 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { import {
FormGroup, FormGroup,
NotificationError, InputError,
Select, Select,
Tooltip, Tooltip,
} from '@vegaprotocol/ui-toolkit'; } from '@vegaprotocol/ui-toolkit';
@ -139,9 +139,9 @@ export const TimeInForceSelector = ({
))} ))}
</Select> </Select>
{errorMessage && ( {errorMessage && (
<NotificationError testId="dealticket-error-message-tif"> <InputError testId="dealticket-error-message-tif">
{renderError(errorMessage)} {renderError(errorMessage)}
</NotificationError> </InputError>
)} )}
</FormGroup> </FormGroup>
); );

View File

@ -1,8 +1,4 @@
import { import { FormGroup, InputError, Tooltip } from '@vegaprotocol/ui-toolkit';
FormGroup,
NotificationError,
Tooltip,
} from '@vegaprotocol/ui-toolkit';
import { DataGrid, t } from '@vegaprotocol/react-helpers'; import { DataGrid, t } from '@vegaprotocol/react-helpers';
import * as Schema from '@vegaprotocol/types'; import * as Schema from '@vegaprotocol/types';
import { Toggle } from '@vegaprotocol/ui-toolkit'; import { Toggle } from '@vegaprotocol/ui-toolkit';
@ -82,9 +78,9 @@ export const TypeSelector = ({
onChange={(e) => onSelect(e.target.value as Schema.OrderType)} onChange={(e) => onSelect(e.target.value as Schema.OrderType)}
/> />
{errorMessage && ( {errorMessage && (
<NotificationError testId="dealticket-error-message-type"> <InputError testId="dealticket-error-message-type">
{renderError(errorMessage as MarketModeValidationType)} {renderError(errorMessage as MarketModeValidationType)}
</NotificationError> </InputError>
)} )}
</FormGroup> </FormGroup>
); );

View File

@ -1,52 +1,18 @@
import classNames from 'classnames'; import classNames from 'classnames';
import type { HTMLAttributes } from 'react'; import type { HTMLAttributes } from 'react';
import { Intent } from '../../utils/intent';
import { Notification } from '../notification';
interface InputErrorProps extends HTMLAttributes<HTMLDivElement> { interface InputErrorProps extends HTMLAttributes<HTMLDivElement> {
children?: React.ReactNode; children?: React.ReactNode;
intent?: 'danger' | 'warning'; intent?: 'danger' | 'warning';
forInput?: string; forInput?: string;
}
interface NotificationErrorProps extends HTMLAttributes<HTMLDivElement> {
children?: React.ReactNode;
intent?: Intent | 'danger' | 'warning';
forInput?: string;
testId?: string; testId?: string;
} }
const getIntent = (intent: Intent | 'danger' | 'warning') => {
switch (intent) {
case 'danger':
return Intent.Danger;
case 'warning':
return Intent.Warning;
default:
return intent;
}
};
export const NotificationError = ({
intent = Intent.Danger,
children,
forInput,
testId,
}: NotificationErrorProps) => {
return (
<Notification
intent={getIntent(intent)}
testId={testId || 'input-error-text'}
message={<div className="role">{children}</div>}
aria-describedby={forInput}
/>
);
};
export const InputError = ({ export const InputError = ({
intent = 'danger', intent = 'danger',
children, children,
forInput, forInput,
testId,
...props ...props
}: InputErrorProps) => { }: InputErrorProps) => {
const effectiveClassName = classNames( const effectiveClassName = classNames(
@ -63,7 +29,7 @@ export const InputError = ({
); );
return ( return (
<div <div
data-testid="input-error-text" data-testid={testId || 'input-error-text'}
aria-describedby={forInput} aria-describedby={forInput}
className={effectiveClassName} className={effectiveClassName}
{...props} {...props}