mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* simple profile button and auth modal layout * connect email and code screens to API * add screens to modal for wallet authentication * migrate to pin input * user profile menu * refactor otp field * fix passing set-cookie from api response * add wallet info into profile menu * add mobile menu * show connected wallet address in button * my profile page re-design * custom behaviour of connect button on dapp page * style pin input * add logout * handle case when account is disabled * handle case when wc is disabled * remove old components * refactoring * workflow to link wallet or email to account * link wallet from profile * show better OTP code errors * add email alert on watchlist and verified addresses pages * deprecate env and remove old code * remove code for unverified email page * add auth guard to address action items * move useRedirectForInvalidAuthToken hook * add mixpanel events * refetch csrf token after login and fix connect wallet from contract page * Add NEXT_PUBLIC_RE_CAPTCHA_V3_APP_SITE_KEY env * migrate to reCAPTCHA v3 * resend code and change email from profile page * better wallet sign-in message error * fix demo envs * update some screenshots * profile button design fixes * fix behaviour "connect wallet" button on contract page * fix linking email and wallet to existing account * bug fixes * restore the login page * update screenshots * tests for auth modal and user profile * add name field to profile page and write some tests * [skip ci] clean up and more tests * update texts * change text once more * fix verified email checkmark behaviour * pass api error to the toast while signing in with wallet * [skip ci] disable email field on profile page * bug fixes * update screenshot * Blockscout account V2 Fixes #2029 * fix texts and button paddings * Form fields refactoring (#2320) * text and address fields for watchlist form * checkbox field component * refactor private tags form * refactor api keys and custom abi * refactor verifiy address and token info forms (pt. 1) * refactor token info forms (pt. 2) * refactor token info forms (pt. 3) * refactor public tags form * refactor contract verification form * refactor contract audit form * refactor auth, profile and csv export forms * renaming and moving * more refactoring and test fixes --------- Co-authored-by: aagaev <[email protected]>
116 lines
2.9 KiB
TypeScript
116 lines
2.9 KiB
TypeScript
import type { ChakraProps } from '@chakra-ui/react';
|
|
import { FormControl, Input, InputGroup, InputRightElement, Textarea, chakra, shouldForwardProp } from '@chakra-ui/react';
|
|
import React from 'react';
|
|
import type { FieldValues, Path } from 'react-hook-form';
|
|
import { useController, useFormContext } from 'react-hook-form';
|
|
|
|
import type { FormFieldPropsBase } from './types';
|
|
|
|
import FormInputPlaceholder from '../inputs/FormInputPlaceholder';
|
|
|
|
interface Props<
|
|
FormFields extends FieldValues,
|
|
Name extends Path<FormFields> = Path<FormFields>,
|
|
> extends FormFieldPropsBase<FormFields, Name> {
|
|
asComponent?: 'Input' | 'Textarea';
|
|
}
|
|
|
|
const FormFieldText = <
|
|
FormFields extends FieldValues,
|
|
Name extends Path<FormFields> = Path<FormFields>,
|
|
>({
|
|
name,
|
|
placeholder,
|
|
isReadOnly,
|
|
isRequired,
|
|
rules,
|
|
onBlur,
|
|
type = 'text',
|
|
rightElement,
|
|
asComponent,
|
|
max,
|
|
|
|
className,
|
|
size = 'md',
|
|
bgColor,
|
|
minH,
|
|
maxH,
|
|
}: Props<FormFields, Name>) => {
|
|
const { control } = useFormContext<FormFields>();
|
|
const { field, fieldState, formState } = useController<FormFields, typeof name>({
|
|
control,
|
|
name,
|
|
rules: { ...rules, required: isRequired },
|
|
});
|
|
|
|
const isDisabled = formState.isSubmitting;
|
|
|
|
const handleBlur = React.useCallback(() => {
|
|
field.onBlur();
|
|
onBlur?.();
|
|
}, [ field, onBlur ]);
|
|
|
|
const Component = asComponent === 'Textarea' ? Textarea : Input;
|
|
const input = (
|
|
<Component
|
|
{ ...field }
|
|
onBlur={ handleBlur }
|
|
isInvalid={ Boolean(fieldState.error) }
|
|
isDisabled={ isDisabled }
|
|
isReadOnly={ isReadOnly }
|
|
autoComplete="off"
|
|
type={ type }
|
|
placeholder=" "
|
|
max={ max }
|
|
size={ size }
|
|
bgColor={ bgColor }
|
|
minH={ minH }
|
|
maxH={ maxH }
|
|
/>
|
|
);
|
|
const inputPlaceholder = size !== 'xs' && <FormInputPlaceholder text={ placeholder } error={ fieldState.error }/>;
|
|
|
|
return (
|
|
<FormControl
|
|
className={ className }
|
|
variant="floating"
|
|
isDisabled={ isDisabled }
|
|
isRequired={ isRequired }
|
|
size={ size }
|
|
bgColor={ bgColor }
|
|
>
|
|
{ rightElement ? (
|
|
<InputGroup>
|
|
{ input }
|
|
{ inputPlaceholder }
|
|
<InputRightElement h="100%"> { rightElement({ field }) } </InputRightElement>
|
|
</InputGroup>
|
|
) : (
|
|
<>
|
|
{ input }
|
|
{ inputPlaceholder }
|
|
</>
|
|
) }
|
|
</FormControl>
|
|
);
|
|
};
|
|
|
|
const WrappedFormFieldText = chakra(FormFieldText, {
|
|
shouldForwardProp: (prop) => {
|
|
const isChakraProp = !shouldForwardProp(prop);
|
|
|
|
if (isChakraProp && ![ 'bgColor', 'size', 'minH', 'maxH' ].includes(prop)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
},
|
|
});
|
|
|
|
export type WrappedComponent = <
|
|
FormFields extends FieldValues,
|
|
Name extends Path<FormFields> = Path<FormFields>,
|
|
>(props: Props<FormFields, Name> & ChakraProps) => JSX.Element;
|
|
|
|
export default React.memo(WrappedFormFieldText) as WrappedComponent;
|