|
@@ -1,7 +1,15 @@
|
|
|
import useSWR, { SWRResponse } from 'swr';
|
|
import useSWR, { SWRResponse } from 'swr';
|
|
|
-import { InAppNotificationStatuses, IInAppNotification, PaginateResult } from '~/interfaces/in-app-notification';
|
|
|
|
|
|
|
+
|
|
|
|
|
+import type { InAppNotificationStatuses, IInAppNotification, PaginateResult } from '~/interfaces/in-app-notification';
|
|
|
|
|
+import { parseSnapshot } from '~/models/serializers/in-app-notification-snapshot/page';
|
|
|
|
|
+import loggerFactory from '~/utils/logger';
|
|
|
|
|
+
|
|
|
import { apiv3Get } from '../client/util/apiv3-client';
|
|
import { apiv3Get } from '../client/util/apiv3-client';
|
|
|
|
|
|
|
|
|
|
+const logger = loggerFactory('growi:cli:InAppNotification');
|
|
|
|
|
+
|
|
|
|
|
+type inAppNotificationPaginateResult = PaginateResult<IInAppNotification>
|
|
|
|
|
+
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
export const useSWRxInAppNotifications = <Data, Error>(
|
|
export const useSWRxInAppNotifications = <Data, Error>(
|
|
|
limit: number,
|
|
limit: number,
|
|
@@ -10,7 +18,18 @@ export const useSWRxInAppNotifications = <Data, Error>(
|
|
|
): SWRResponse<PaginateResult<IInAppNotification>, Error> => {
|
|
): SWRResponse<PaginateResult<IInAppNotification>, Error> => {
|
|
|
return useSWR(
|
|
return useSWR(
|
|
|
['/in-app-notification/list', limit, offset, status],
|
|
['/in-app-notification/list', limit, offset, status],
|
|
|
- endpoint => apiv3Get(endpoint, { limit, offset, status }).then(response => response.data),
|
|
|
|
|
|
|
+ endpoint => apiv3Get(endpoint, { limit, offset, status }).then((response) => {
|
|
|
|
|
+ const inAppNotificationPaginateResult = response.data as inAppNotificationPaginateResult;
|
|
|
|
|
+ inAppNotificationPaginateResult.docs.forEach((doc) => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ doc.parsedSnapshot = parseSnapshot(doc.snapshot as string);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ logger.warn('Failed to parse snapshot', err);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ return inAppNotificationPaginateResult;
|
|
|
|
|
+ }),
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
|
|
|
|