Channel: Fix URL duplication in username input (#3248)
This commit is contained in:
parent
f833c39f62
commit
d6b919e6ae
@ -88,7 +88,17 @@ const UsernameInput: FC<OwnProps> = ({
|
||||
}, [asLink, currentUsername]);
|
||||
|
||||
const handleUsernameChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
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);
|
||||
|
||||
@ -68,6 +68,7 @@ const ManageChatPrivacyType: FC<OwnProps & StateProps> = ({
|
||||
updatePrivateLink,
|
||||
toggleIsProtected,
|
||||
openLimitReachedModal,
|
||||
resetManagementError,
|
||||
} = getActions();
|
||||
|
||||
const firstEditableUsername = useMemo(() => chat.usernames?.find(({ isEditable }) => isEditable), [chat.usernames]);
|
||||
@ -108,7 +109,13 @@ const ManageChatPrivacyType: FC<OwnProps & StateProps> = ({
|
||||
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<HTMLInputElement>) => {
|
||||
const myChats = Object.values(getGlobal().chats.byId)
|
||||
|
||||
@ -129,7 +129,7 @@ const ManageGroup: FC<OwnProps & StateProps> = ({
|
||||
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<HTMLDivElement>(null);
|
||||
@ -442,7 +442,7 @@ const ManageGroup: FC<OwnProps & StateProps> = ({
|
||||
<span className="subtitle">{formatInteger(chat.membersCount ?? 0)}</span>
|
||||
</ListItem>
|
||||
|
||||
{!isPublicGroup && Boolean(chatFullInfo) && (
|
||||
{!isPublicGroup && !hasLinkedChannel && Boolean(chatFullInfo) && (
|
||||
<div className="ListItem narrow no-selection" ref={isPreHistoryHiddenCheckboxRef}>
|
||||
<Checkbox
|
||||
checked={!chatFullInfo.isPreHistoryHidden}
|
||||
|
||||
@ -466,3 +466,9 @@ addActionHandler('uploadContactProfilePhoto', async (global, actions, payload):
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
addActionHandler('resetManagementError', (global, actions, payload): ActionReturnType => {
|
||||
const { chatId, tabId = getCurrentTabId() } = payload || {};
|
||||
|
||||
return updateManagement(global, chatId, { error: undefined }, tabId);
|
||||
});
|
||||
|
||||
@ -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: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user