mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-23 02:17:13 +00:00
Cleaer Add Notification Provider from
This commit is contained in:
parent
947cec0d7a
commit
cfc9bc5951
@ -18,11 +18,19 @@ export default function AddNotification({ onNotificationAdded, onError, onSucces
|
|||||||
|
|
||||||
const { addNotification } = useNotification();
|
const { addNotification } = useNotification();
|
||||||
|
|
||||||
|
const clearForm = () => {
|
||||||
|
setName("")
|
||||||
|
setType("Select a type")
|
||||||
|
setTelegramBotToken("")
|
||||||
|
setTelegramChatId("")
|
||||||
|
}
|
||||||
|
|
||||||
const addNotificationHandler = async () => {
|
const addNotificationHandler = async () => {
|
||||||
const config = type === "TELEGRAM" ? `{ "token": "${telegramBotToken}", "chat_id": "${telegramChatId}" }` : "";
|
const config = type === "TELEGRAM" ? `{ "token": "${telegramBotToken}", "chat_id": "${telegramChatId}" }` : "";
|
||||||
const response = addNotification(name, type, config);
|
const response = addNotification(name, type, config);
|
||||||
if (typeof response === "string") {
|
if (typeof response === "string") {
|
||||||
onError && onError(response)
|
onError && onError(response)
|
||||||
|
clearForm();
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -34,10 +42,7 @@ export default function AddNotification({ onNotificationAdded, onError, onSucces
|
|||||||
} catch (apiError: any) {
|
} catch (apiError: any) {
|
||||||
onError && onError(apiError)
|
onError && onError(apiError)
|
||||||
} finally {
|
} finally {
|
||||||
setName("")
|
clearForm();
|
||||||
setType("Select a type")
|
|
||||||
setTelegramBotToken("")
|
|
||||||
setTelegramChatId("")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user