import {ReactElement, ReactEventHandler, useState} from "react"; import "../../styles/notificationConnector.css"; import Loader from "../Loader"; import NotificationConnector from "../api/NotificationConnector"; import INotificationConnector from "../types/INotificationConnector"; import {GotifyItem} from "./Gotify"; import {NtfyItem} from "./Ntfy"; import {LunaseaItem} from "./Lunasea"; import {PushoverItem} from "./Pushover"; export default function NotificationConnectorItem({apiUri, notificationConnector} : {apiUri: string, notificationConnector: INotificationConnector | null}) : ReactElement { if(notificationConnector != null) return const [selectedConnectorElement, setSelectedConnectorElement] = useState(); return New Notification Connector Type { switch (e.currentTarget.value){ case "default": setSelectedConnectorElement(); break; case "gotify": setSelectedConnectorElement(); break; case "ntfy": setSelectedConnectorElement(); break; case "lunasea": setSelectedConnectorElement(); break; case "pushover": setSelectedConnectorElement(); break; } }}> Generic REST Gotify Ntfy Lunasea Pushover {selectedConnectorElement} ; } function DefaultItem({apiUri, notificationConnector}:{apiUri: string, notificationConnector: INotificationConnector | null}) : ReactElement { const AddHeader : ReactEventHandler = () => { let header : Record = {}; let x = info; x.headers = [header, ...x.headers]; setInfo(x); setHeaderElements([...headerElements, ]) } const [headerElements, setHeaderElements] = useState([]); const [info, setInfo] = useState({ name: "", url: "", headers: [], httpMethod: "", body: "" }); const [loading, setLoading] = useState(false); return setInfo({...info, name: e.currentTarget.value})} /> setInfo({...info, httpMethod: e.currentTarget.value})} > Request Method GET POST setInfo({...info, url: e.currentTarget.value})} /> setInfo({...info, body: e.currentTarget.value})} /> {notificationConnector != null ? null : ( Formatting placeholders: "%title" and "%text" can be placed in url, header-values and body and will be replaced when notifications are sent )} {headerElements} {notificationConnector ? notificationConnector.headers.map((h: Record) => () ) : ( Add Header ) } <> { setLoading(true); NotificationConnector.CreateNotificationConnector(apiUri, info) .finally(() => setLoading(false)); }}>Add > } function HeaderElement({record, disabled} : {record: Record, disabled?: boolean | null}) : ReactElement { return record.name = e.currentTarget.value}/> record.value = e.currentTarget.value} /> ; }
Formatting placeholders: "%title" and "%text" can be placed in url, header-values and body and will be replaced when notifications are sent