mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
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:
parent
2fed48e0dd
commit
438902137b
4 changed files with 244 additions and 123 deletions
|
@ -181,7 +181,7 @@ export function NotificationAddForm({ isOpen, toggle }: AddProps) {
|
|||
const queryClient = useQueryClient();
|
||||
|
||||
const createMutation = useMutation({
|
||||
mutationFn: (notification: Notification) => APIClient.notifications.create(notification),
|
||||
mutationFn: (notification: ServiceNotification) => APIClient.notifications.create(notification),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: notificationKeys.lists() });
|
||||
|
||||
|
@ -193,16 +193,16 @@ export function NotificationAddForm({ isOpen, toggle }: AddProps) {
|
|||
}
|
||||
});
|
||||
|
||||
const onSubmit = (formData: unknown) => createMutation.mutate(formData as Notification);
|
||||
const onSubmit = (formData: unknown) => createMutation.mutate(formData as ServiceNotification);
|
||||
|
||||
const testMutation = useMutation({
|
||||
mutationFn: (n: Notification) => APIClient.notifications.test(n),
|
||||
mutationFn: (n: ServiceNotification) => APIClient.notifications.test(n),
|
||||
onError: (err) => {
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
|
||||
const testNotification = (data: unknown) => testMutation.mutate(data as Notification);
|
||||
const testNotification = (data: unknown) => testMutation.mutate(data as ServiceNotification);
|
||||
|
||||
const validate = (values: NotificationAddFormValues) => {
|
||||
const errors = {} as FormikErrors<FormikValues>;
|
||||
|
@ -428,7 +428,7 @@ const EventCheckBoxes = () => (
|
|||
interface UpdateProps {
|
||||
isOpen: boolean;
|
||||
toggle: () => void;
|
||||
notification: Notification;
|
||||
notification: ServiceNotification;
|
||||
}
|
||||
|
||||
interface InitialValues {
|
||||
|
@ -449,7 +449,7 @@ export function NotificationUpdateForm({ isOpen, toggle, notification }: UpdateP
|
|||
const queryClient = useQueryClient();
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationFn: (notification: Notification) => APIClient.notifications.update(notification),
|
||||
mutationFn: (notification: ServiceNotification) => APIClient.notifications.update(notification),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: notificationKeys.lists() });
|
||||
|
||||
|
@ -458,7 +458,7 @@ export function NotificationUpdateForm({ isOpen, toggle, notification }: UpdateP
|
|||
}
|
||||
});
|
||||
|
||||
const onSubmit = (formData: unknown) => mutation.mutate(formData as Notification);
|
||||
const onSubmit = (formData: unknown) => mutation.mutate(formData as ServiceNotification);
|
||||
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: (notificationID: number) => APIClient.notifications.delete(notificationID),
|
||||
|
@ -472,13 +472,13 @@ export function NotificationUpdateForm({ isOpen, toggle, notification }: UpdateP
|
|||
const deleteAction = () => deleteMutation.mutate(notification.id);
|
||||
|
||||
const testMutation = useMutation({
|
||||
mutationFn: (n: Notification) => APIClient.notifications.test(n),
|
||||
mutationFn: (n: ServiceNotification) => APIClient.notifications.test(n),
|
||||
onError: (err) => {
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
|
||||
const testNotification = (data: unknown) => testMutation.mutate(data as Notification);
|
||||
const testNotification = (data: unknown) => testMutation.mutate(data as ServiceNotification);
|
||||
|
||||
const initialValues: InitialValues = {
|
||||
id: notification.id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue