notifications.ts•4.12 kB
/**
* Generated by orval v7.2.0 🍺
* Do not edit manually.
* storyden
* Storyden social API for building community driven platforms.
The Storyden API does not adhere to semantic versioning but instead applies a rolling strategy with deprecations and minimal breaking changes. This has been done mainly for a simpler development process and it may be changed to a more fixed versioning strategy in the future. Ultimately, the primary way Storyden tracks versions is dates, there are no set release tags currently.
* OpenAPI spec version: v1.25.8-canary
*/
import useSwr from "swr";
import type { Key, SWRConfiguration } from "swr";
import useSWRMutation from "swr/mutation";
import type { SWRMutationConfiguration } from "swr/mutation";
import { fetcher } from "../client";
import type {
BadRequestResponse,
InternalServerErrorResponse,
NotFoundResponse,
NotificationListOKResponse,
NotificationListParams,
NotificationUpdateBody,
NotificationUpdateOKResponse,
UnauthorisedResponse,
} from "../openapi-schema";
/**
* Retreive all notifications.
*/
export const notificationList = (params?: NotificationListParams) => {
return fetcher<NotificationListOKResponse>({
url: `/notifications`,
method: "GET",
params,
});
};
export const getNotificationListKey = (params?: NotificationListParams) =>
[`/notifications`, ...(params ? [params] : [])] as const;
export type NotificationListQueryResult = NonNullable<
Awaited<ReturnType<typeof notificationList>>
>;
export type NotificationListQueryError =
| UnauthorisedResponse
| NotFoundResponse
| InternalServerErrorResponse;
export const useNotificationList = <
TError =
| UnauthorisedResponse
| NotFoundResponse
| InternalServerErrorResponse,
>(
params?: NotificationListParams,
options?: {
swr?: SWRConfiguration<
Awaited<ReturnType<typeof notificationList>>,
TError
> & { swrKey?: Key; enabled?: boolean };
},
) => {
const { swr: swrOptions } = options ?? {};
const isEnabled = swrOptions?.enabled !== false;
const swrKey =
swrOptions?.swrKey ??
(() => (isEnabled ? getNotificationListKey(params) : null));
const swrFn = () => notificationList(params);
const query = useSwr<Awaited<ReturnType<typeof swrFn>>, TError>(
swrKey,
swrFn,
swrOptions,
);
return {
swrKey,
...query,
};
};
/**
* Change the read status for a notification.
*/
export const notificationUpdate = (
notificationId: string,
notificationUpdateBody: NotificationUpdateBody,
) => {
return fetcher<NotificationUpdateOKResponse>({
url: `/notifications/${notificationId}`,
method: "PATCH",
headers: { "Content-Type": "application/json" },
data: notificationUpdateBody,
});
};
export const getNotificationUpdateMutationFetcher = (
notificationId: string,
) => {
return (
_: Key,
{ arg }: { arg: NotificationUpdateBody },
): Promise<NotificationUpdateOKResponse> => {
return notificationUpdate(notificationId, arg);
};
};
export const getNotificationUpdateMutationKey = (notificationId: string) =>
[`/notifications/${notificationId}`] as const;
export type NotificationUpdateMutationResult = NonNullable<
Awaited<ReturnType<typeof notificationUpdate>>
>;
export type NotificationUpdateMutationError =
| BadRequestResponse
| UnauthorisedResponse
| InternalServerErrorResponse;
export const useNotificationUpdate = <
TError =
| BadRequestResponse
| UnauthorisedResponse
| InternalServerErrorResponse,
>(
notificationId: string,
options?: {
swr?: SWRMutationConfiguration<
Awaited<ReturnType<typeof notificationUpdate>>,
TError,
Key,
NotificationUpdateBody,
Awaited<ReturnType<typeof notificationUpdate>>
> & { swrKey?: string };
},
) => {
const { swr: swrOptions } = options ?? {};
const swrKey =
swrOptions?.swrKey ?? getNotificationUpdateMutationKey(notificationId);
const swrFn = getNotificationUpdateMutationFetcher(notificationId);
const query = useSWRMutation(swrKey, swrFn, swrOptions);
return {
swrKey,
...query,
};
};