enhancement(web): modernize APIClient and improve robustness (#1093)

modernized APIClient, removed Notification type collision

enhancement: APIClient now follows the recent RFC3986 (this wasn't the case previously)
enhancement: improved APIClient DX by adding a queryString parameter (avoiding URLSearchParameters)
fix: changed Notification type to ServiceNotification (collision with built-in browser API https://developer.mozilla.org/en-US/docs/Web/API/Notification -- so TS checks wouldn't function as necessary)
This commit is contained in:
stacksmash76 2023-09-10 16:18:39 +02:00 committed by GitHub
parent 2fed48e0dd
commit 438902137b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 244 additions and 123 deletions

View file

@ -64,7 +64,7 @@ function NotificationSettings() {
<div className="hidden md:flex col-span-3 px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Events</div>
</li>
{data && data.map((n: Notification) => (
{data && data.map((n: ServiceNotification) => (
<ListItem key={n.id} notification={n} />
))}
</ol>
@ -108,7 +108,7 @@ const iconComponentMap: componentMapType = {
};
interface ListItemProps {
notification: Notification;
notification: ServiceNotification;
}
function ListItem({ notification }: ListItemProps) {
@ -117,8 +117,8 @@ function ListItem({ notification }: ListItemProps) {
const queryClient = useQueryClient();
const mutation = useMutation({
mutationFn: (notification: Notification) => APIClient.notifications.update(notification).then(() => notification),
onSuccess: (notification: Notification) => {
mutationFn: (notification: ServiceNotification) => APIClient.notifications.update(notification).then(() => notification),
onSuccess: (notification: ServiceNotification) => {
toast.custom(t => <Toast type="success" body={`${notification.name} was ${notification.enabled ? "enabled" : "disabled"} successfully.`} t={t} />);
queryClient.invalidateQueries({ queryKey: notificationKeys.lists() });
}