diff --git a/src/Managing.Application/Users/UserService.cs b/src/Managing.Application/Users/UserService.cs index 431d415..6f7a049 100644 --- a/src/Managing.Application/Users/UserService.cs +++ b/src/Managing.Application/Users/UserService.cs @@ -168,13 +168,13 @@ public class UserService : IUserService public async Task UpdateTelegramChannel(User user, string telegramChannel) { - // Validate Telegram channel format (must start with @ and contain only allowed characters) + // Validate Telegram channel format (numeric channel ID only) if (!string.IsNullOrEmpty(telegramChannel)) { - string pattern = @"^@[a-zA-Z0-9_]{5,32}$"; + string pattern = @"^[0-9]{5,15}$"; if (!Regex.IsMatch(telegramChannel, pattern)) { - throw new Exception("Invalid Telegram channel format. Must start with @ and be 5-32 characters long, containing only letters, numbers, and underscores."); + throw new Exception("Invalid Telegram channel format. Must be numeric channel ID (5-15 digits)."); } } diff --git a/src/Managing.WebApp/src/pages/settingsPage/UserInfoSettings.tsx b/src/Managing.WebApp/src/pages/settingsPage/UserInfoSettings.tsx index cdb900f..d6aeb46 100644 --- a/src/Managing.WebApp/src/pages/settingsPage/UserInfoSettings.tsx +++ b/src/Managing.WebApp/src/pages/settingsPage/UserInfoSettings.tsx @@ -14,9 +14,14 @@ type UpdateAvatarForm = { avatarUrl: string } +type UpdateTelegramChannelForm = { + telegramChannel: string +} + function UserInfoSettings() { const [showUpdateModal, setShowUpdateModal] = useState(false) const [showAvatarModal, setShowAvatarModal] = useState(false) + const [showTelegramModal, setShowTelegramModal] = useState(false) const queryClient = useQueryClient() const { apiUrl } = useApiUrlStore() const api = new UserClient({}, apiUrl) @@ -38,6 +43,12 @@ function UserInfoSettings() { formState: { errors: avatarErrors }, } = useForm() + const { + register: registerTelegram, + handleSubmit: handleSubmitTelegram, + formState: { errors: telegramErrors }, + } = useForm() + const onSubmitAgentName = async (data: UpdateAgentNameForm) => { const toast = new Toast('Updating agent name') try { @@ -64,6 +75,19 @@ function UserInfoSettings() { } } + const onSubmitTelegram = async (data: UpdateTelegramChannelForm) => { + const toast = new Toast('Updating telegram channel') + try { + await api.user_UpdateTelegramChannel(data.telegramChannel) + queryClient.invalidateQueries({ queryKey: ['user'] }) + setShowTelegramModal(false) + toast.update('success', 'Telegram channel updated successfully') + } catch (error) { + console.error('Error updating telegram channel:', error) + toast.update('error', 'Failed to update telegram channel') + } + } + return (
@@ -108,6 +132,17 @@ function UserInfoSettings() {
+ +
+ +

{user?.telegramChannel || 'Not set'}

+ +
@@ -178,6 +213,44 @@ function UserInfoSettings() { + + setShowTelegramModal(false)} + onSubmit={handleSubmitTelegram(onSubmitTelegram)} + titleHeader="Update Telegram Channel" + > +
+ + + {telegramErrors.telegramChannel && ( + + )} +
+
+ +
+
) }