From 5193ceb0715da93fd5e00d5003b4548c43b6f438 Mon Sep 17 00:00:00 2001 From: Royce59 Date: Sat, 11 Apr 2026 21:35:34 +0200 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=B0=D0=BB=D0=B8=D0=B4=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B2=D0=B2=D0=BE=D0=B4=D0=B8=D0=BC=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=B8=D0=BC=D0=B5=D0=BD=D0=B8=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SettingsInput/SettingsInput.tsx | 18 +++++++++-- app/views/Profile/MyProfile.tsx | 32 ++++++++++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/app/components/SettingsInput/SettingsInput.tsx b/app/components/SettingsInput/SettingsInput.tsx index e4231d0..0e4f039 100644 --- a/app/components/SettingsInput/SettingsInput.tsx +++ b/app/components/SettingsInput/SettingsInput.tsx @@ -24,6 +24,8 @@ export interface SettingsInputDefaultProps { mt?: StyleProp; rightSection?: ReactNode; type?: HTMLInputTypeAttribute; + onErrorStateChange?: (error: boolean) => void; + regexp?: RegExp; } export interface SettingsInputGroupProps { mt?: StyleProp; @@ -260,7 +262,6 @@ function SettingsInputClickable( function SettingsInputDefault(props : SettingsInputDefaultProps) { const colors = useRosettaColors(); const input = useRef(undefined); - const onClick = (e : MouseEvent) => { e.stopPropagation(); if(!props.disabled){ @@ -268,6 +269,19 @@ function SettingsInputDefault(props : SettingsInputDefaultProps) { 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 (<> { onClick(e) - }} onChange={props.onChange} variant={'unstyled'} spellCheck={false} color="gray" classNames={{ + }} onChange={onChange} variant={'unstyled'} spellCheck={false} color="gray" classNames={{ input: classes.input }} placeholder={props.placeholder}>) } diff --git a/app/views/Profile/MyProfile.tsx b/app/views/Profile/MyProfile.tsx index b6877f5..2da03d0 100644 --- a/app/views/Profile/MyProfile.tsx +++ b/app/views/Profile/MyProfile.tsx @@ -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 { useState } from "react"; 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 { useLogout } from "@/app/providers/AccountProvider/useLogout"; import { RosettaPower } from "@/app/components/RosettaPower/RosettaPower"; +import { modals } from "@mantine/modals"; export function MyProfile() { const publicKey = usePublicKey(); @@ -28,8 +29,34 @@ export function MyProfile() { const navigate = useNavigate(); const send = useSender(); const logout = useLogout(); + const [usernameError, setUsernameError] = useState(false); + + const openProfileModal = (text : string) => { + modals.open({ + centered: true, + children: ( + <> + + {text} + + + + + + ), + withCloseButton: false + }); + } const saveProfileData = () => { + if(usernameError) { + openProfileModal("You enter invalid username. Username must be a latin chars in lowercase."); + return; + } let packet = new PacketUserInfo(); packet.setUsername(username); packet.setTitle(title); @@ -70,10 +97,13 @@ export function MyProfile() { setUsernameError(error)} placeholder="ex. freddie871" onChange={(e) => setUsername(e.target.value)} + regexp={new RegExp(/^([a-z0-9]{5,16})?$/)} > + {usernameError && Invalid username.}