diff --git a/components/dialogues/AddNotification.tsx b/components/dialogues/AddNotification.tsx index 65b88fb..ca09f2b 100644 --- a/components/dialogues/AddNotification.tsx +++ b/components/dialogues/AddNotification.tsx @@ -18,11 +18,19 @@ export default function AddNotification({ onNotificationAdded, onError, onSucces const { addNotification } = useNotification(); + const clearForm = () => { + setName("") + setType("Select a type") + setTelegramBotToken("") + setTelegramChatId("") + } + const addNotificationHandler = async () => { const config = type === "TELEGRAM" ? `{ "token": "${telegramBotToken}", "chat_id": "${telegramChatId}" }` : ""; const response = addNotification(name, type, config); if (typeof response === "string") { onError && onError(response) + clearForm(); return } try { @@ -34,10 +42,7 @@ export default function AddNotification({ onNotificationAdded, onError, onSucces } catch (apiError: any) { onError && onError(apiError) } finally { - setName("") - setType("Select a type") - setTelegramBotToken("") - setTelegramChatId("") + clearForm(); } }