Валидация вводимого имени пользователя
This commit is contained in:
@@ -24,6 +24,8 @@ export interface SettingsInputDefaultProps {
|
|||||||
mt?: StyleProp<MantineSpacing>;
|
mt?: StyleProp<MantineSpacing>;
|
||||||
rightSection?: ReactNode;
|
rightSection?: ReactNode;
|
||||||
type?: HTMLInputTypeAttribute;
|
type?: HTMLInputTypeAttribute;
|
||||||
|
onErrorStateChange?: (error: boolean) => void;
|
||||||
|
regexp?: RegExp;
|
||||||
}
|
}
|
||||||
export interface SettingsInputGroupProps {
|
export interface SettingsInputGroupProps {
|
||||||
mt?: StyleProp<MantineSpacing>;
|
mt?: StyleProp<MantineSpacing>;
|
||||||
@@ -260,7 +262,6 @@ function SettingsInputClickable(
|
|||||||
function SettingsInputDefault(props : SettingsInputDefaultProps) {
|
function SettingsInputDefault(props : SettingsInputDefaultProps) {
|
||||||
const colors = useRosettaColors();
|
const colors = useRosettaColors();
|
||||||
const input = useRef<any>(undefined);
|
const input = useRef<any>(undefined);
|
||||||
|
|
||||||
const onClick = (e : MouseEvent) => {
|
const onClick = (e : MouseEvent) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if(!props.disabled){
|
if(!props.disabled){
|
||||||
@@ -268,6 +269,19 @@ function SettingsInputDefault(props : SettingsInputDefaultProps) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onChange = (e) => {
|
||||||
|
let value = e.target.value;
|
||||||
|
if(props.regexp && !props.regexp.test(value)) {
|
||||||
|
props.onErrorStateChange && props.onErrorStateChange(true);
|
||||||
|
props.onChange && props.onChange(e);
|
||||||
|
}else{
|
||||||
|
props.onErrorStateChange && props.onErrorStateChange(false);
|
||||||
|
console.info('fa');
|
||||||
|
props.onChange && props.onChange(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (<>
|
return (<>
|
||||||
<Paper mt={props.mt} style={props.style} withBorder styles={{
|
<Paper mt={props.mt} style={props.style} withBorder styles={{
|
||||||
root: {
|
root: {
|
||||||
@@ -298,7 +312,7 @@ function SettingsInputDefault(props : SettingsInputDefaultProps) {
|
|||||||
{!props.rightSection && (
|
{!props.rightSection && (
|
||||||
<Input type={props.type} defaultValue={!props.onChange ? props.value : undefined} value={!props.onChange ? undefined : props.value} ref={input} disabled={props.disabled} onClick={(e) => {
|
<Input type={props.type} defaultValue={!props.onChange ? props.value : undefined} value={!props.onChange ? undefined : props.value} ref={input} disabled={props.disabled} onClick={(e) => {
|
||||||
onClick(e)
|
onClick(e)
|
||||||
}} onChange={props.onChange} variant={'unstyled'} spellCheck={false} color="gray" classNames={{
|
}} onChange={onChange} variant={'unstyled'} spellCheck={false} color="gray" classNames={{
|
||||||
input: classes.input
|
input: classes.input
|
||||||
}} placeholder={props.placeholder}></Input>)
|
}} placeholder={props.placeholder}></Input>)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ColorSwatch, Text, useComputedColorScheme } from "@mantine/core";
|
import { Button, ColorSwatch, Flex, Text, useComputedColorScheme } from "@mantine/core";
|
||||||
import { SettingsInput } from "@/app/components/SettingsInput/SettingsInput";
|
import { SettingsInput } from "@/app/components/SettingsInput/SettingsInput";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Breadcrumbs } from "@/app/components/Breadcrumbs/Breadcrumbs";
|
import { Breadcrumbs } from "@/app/components/Breadcrumbs/Breadcrumbs";
|
||||||
@@ -17,6 +17,7 @@ import { SettingsIcon } from "@/app/components/SettingsIcon/SettingsIcon";
|
|||||||
import { IconBrush, IconHomeCog, IconLogout, IconRefresh } from "@tabler/icons-react";
|
import { IconBrush, IconHomeCog, IconLogout, IconRefresh } from "@tabler/icons-react";
|
||||||
import { useLogout } from "@/app/providers/AccountProvider/useLogout";
|
import { useLogout } from "@/app/providers/AccountProvider/useLogout";
|
||||||
import { RosettaPower } from "@/app/components/RosettaPower/RosettaPower";
|
import { RosettaPower } from "@/app/components/RosettaPower/RosettaPower";
|
||||||
|
import { modals } from "@mantine/modals";
|
||||||
|
|
||||||
export function MyProfile() {
|
export function MyProfile() {
|
||||||
const publicKey = usePublicKey();
|
const publicKey = usePublicKey();
|
||||||
@@ -28,8 +29,34 @@ export function MyProfile() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const send = useSender();
|
const send = useSender();
|
||||||
const logout = useLogout();
|
const logout = useLogout();
|
||||||
|
const [usernameError, setUsernameError] = useState(false);
|
||||||
|
|
||||||
|
const openProfileModal = (text : string) => {
|
||||||
|
modals.open({
|
||||||
|
centered: true,
|
||||||
|
children: (
|
||||||
|
<>
|
||||||
|
<Text size="sm">
|
||||||
|
{text}
|
||||||
|
</Text>
|
||||||
|
<Flex align={'center'} justify={'flex-end'}>
|
||||||
|
<Button style={{
|
||||||
|
outline: 'none'
|
||||||
|
}} color={'red'} variant={'subtle'} onClick={() => modals.closeAll()} mt="md">
|
||||||
|
Close
|
||||||
|
</Button>
|
||||||
|
</Flex>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
withCloseButton: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const saveProfileData = () => {
|
const saveProfileData = () => {
|
||||||
|
if(usernameError) {
|
||||||
|
openProfileModal("You enter invalid username. Username must be a latin chars in lowercase.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
let packet = new PacketUserInfo();
|
let packet = new PacketUserInfo();
|
||||||
packet.setUsername(username);
|
packet.setUsername(username);
|
||||||
packet.setTitle(title);
|
packet.setTitle(title);
|
||||||
@@ -70,10 +97,13 @@ export function MyProfile() {
|
|||||||
<SettingsInput.Default
|
<SettingsInput.Default
|
||||||
hit="Username"
|
hit="Username"
|
||||||
value={username}
|
value={username}
|
||||||
|
onErrorStateChange={(error) => setUsernameError(error)}
|
||||||
placeholder="ex. freddie871"
|
placeholder="ex. freddie871"
|
||||||
onChange={(e) => setUsername(e.target.value)}
|
onChange={(e) => setUsername(e.target.value)}
|
||||||
|
regexp={new RegExp(/^([a-z0-9]{5,16})?$/)}
|
||||||
></SettingsInput.Default>
|
></SettingsInput.Default>
|
||||||
</SettingsInput.Group>
|
</SettingsInput.Group>
|
||||||
|
{usernameError && <Text c={'red'} fz={10} pl={'xs'} mt={3}>Invalid username.</Text>}
|
||||||
<SettingsInput.Copy mt={'sm'} hit="Public Key" value={
|
<SettingsInput.Copy mt={'sm'} hit="Public Key" value={
|
||||||
publicKey
|
publicKey
|
||||||
} placeholder="Public"></SettingsInput.Copy>
|
} placeholder="Public"></SettingsInput.Copy>
|
||||||
|
|||||||
Reference in New Issue
Block a user