From d6b919e6aeab6369c4c1c107d71fdc8f34fd87ca Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Mon, 12 Jun 2023 11:55:50 +0200 Subject: [PATCH] Channel: Fix URL duplication in username input (#3248) --- src/components/common/UsernameInput.tsx | 12 +++++++++++- .../right/management/ManageChatPrivacyType.tsx | 9 ++++++++- src/components/right/management/ManageGroup.tsx | 4 ++-- src/global/actions/api/management.ts | 6 ++++++ src/global/types.ts | 1 + 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/components/common/UsernameInput.tsx b/src/components/common/UsernameInput.tsx index 7af92404d..f77066403 100644 --- a/src/components/common/UsernameInput.tsx +++ b/src/components/common/UsernameInput.tsx @@ -88,7 +88,17 @@ const UsernameInput: FC = ({ }, [asLink, currentUsername]); const handleUsernameChange = useCallback((e: React.ChangeEvent) => { - const newUsername = e.target.value.trim().replace(LINK_PREFIX_REGEX, ''); + const value = e.target.value.trim(); + // Prevent prefix editing + if (asLink && !value.match(LINK_PREFIX_REGEX)) { + if (!value.length) { + setUsername(''); + onChange?.(''); + } + return; + } + const newUsername = value.replace(LINK_PREFIX_REGEX, ''); + setUsername(newUsername); const isValid = isUsernameValid(newUsername); diff --git a/src/components/right/management/ManageChatPrivacyType.tsx b/src/components/right/management/ManageChatPrivacyType.tsx index 84b77c219..f578c51be 100644 --- a/src/components/right/management/ManageChatPrivacyType.tsx +++ b/src/components/right/management/ManageChatPrivacyType.tsx @@ -68,6 +68,7 @@ const ManageChatPrivacyType: FC = ({ updatePrivateLink, toggleIsProtected, openLimitReachedModal, + resetManagementError, } = getActions(); const firstEditableUsername = useMemo(() => chat.usernames?.find(({ isEditable }) => isEditable), [chat.usernames]); @@ -108,7 +109,13 @@ const ManageChatPrivacyType: FC = ({ const handleUsernameChange = useCallback((value: string) => { setEditableUsername(value); setIsProfileFieldsTouched(true); - }, []); + + if (error) { + resetManagementError({ + chatId: chat.id, + }); + } + }, [chat.id, error]); const handleOptionChange = useCallback((value: string, e: ChangeEvent) => { const myChats = Object.values(getGlobal().chats.byId) diff --git a/src/components/right/management/ManageGroup.tsx b/src/components/right/management/ManageGroup.tsx index a6e3583f2..3270d9d37 100644 --- a/src/components/right/management/ManageGroup.tsx +++ b/src/components/right/management/ManageGroup.tsx @@ -129,7 +129,7 @@ const ManageGroup: FC = ({ const [isForumEnabled, setIsForumEnabled] = useState(chat.isForum); const imageHash = getChatAvatarHash(chat); const currentAvatarBlobUrl = useMedia(imageHash, false, ApiMediaFormat.BlobUrl); - const isPublicGroup = useMemo(() => hasLinkedChannel || isChatPublic(chat), [chat, hasLinkedChannel]); + const isPublicGroup = useMemo(() => isChatPublic(chat), [chat]); const lang = useLang(); // eslint-disable-next-line no-null/no-null const isPreHistoryHiddenCheckboxRef = useRef(null); @@ -442,7 +442,7 @@ const ManageGroup: FC = ({ {formatInteger(chat.membersCount ?? 0)} - {!isPublicGroup && Boolean(chatFullInfo) && ( + {!isPublicGroup && !hasLinkedChannel && Boolean(chatFullInfo) && (
{ + const { chatId, tabId = getCurrentTabId() } = payload || {}; + + return updateManagement(global, chatId, { error: undefined }, tabId); +}); diff --git a/src/global/types.ts b/src/global/types.ts index 11219eb09..cecf473aa 100644 --- a/src/global/types.ts +++ b/src/global/types.ts @@ -1532,6 +1532,7 @@ export interface ActionPayloads { checkPublicLink: { username: string } & WithTabId; updatePublicLink: { username: string } & WithTabId; updatePrivateLink: WithTabId | undefined; + resetManagementError: { chatId: string } & WithTabId; requestChatUpdate: { chatId: string }; loadChatJoinRequests: {