Просмотр исходного кода

change response data to 'number'

kaori 4 лет назад
Родитель
Сommit
af2fc99769

+ 5 - 3
packages/app/src/components/InAppNotification/InAppNotificationDropdown.tsx

@@ -53,7 +53,7 @@ const InAppNotificationDropdown: FC<Props> = (props: Props) => {
 
 
   const toggleDropdownHandler = async() => {
-    if (!isOpen && inAppNotificationStatusData != null && inAppNotificationStatusData.count > 0) {
+    if (!isOpen && inAppNotificationStatusData != null && inAppNotificationStatusData > 0) {
       await updateNotificationStatus();
       mutateInAppNotificationStatusData();
     }
@@ -66,13 +66,15 @@ const InAppNotificationDropdown: FC<Props> = (props: Props) => {
   };
 
   let badge;
-  if (inAppNotificationStatusData != null && inAppNotificationStatusData.count > 0) {
-    badge = <span className="badge badge-pill badge-danger grw-notification-badge">{inAppNotificationStatusData.count}</span>;
+  if (inAppNotificationStatusData != null && inAppNotificationStatusData > 0) {
+    badge = <span className="badge badge-pill badge-danger grw-notification-badge">{inAppNotificationStatusData}</span>;
   }
   else {
     badge = '';
   }
 
+  console.log('inAppNotificationStatusData', inAppNotificationStatusData);
+
   return (
     <Dropdown className="notification-wrapper" isOpen={isOpen} toggle={toggleDropdownHandler}>
       <DropdownToggle tag="a">

+ 1 - 3
packages/app/src/server/routes/apiv3/in-app-notification.ts

@@ -1,4 +1,3 @@
-import { InAppNotification } from '../../models/in-app-notification';
 import { IInAppNotification } from '../../../interfaces/in-app-notification';
 
 const express = require('express');
@@ -69,8 +68,7 @@ module.exports = (crowi) => {
     const userId = req.user._id;
     try {
       const count = await inAppNotificationService.getUnreadCountByUser(userId);
-      const result = { count };
-      return res.apiv3(result);
+      return res.apiv3({ count });
     }
     catch (err) {
       return res.apiv3Err(err);

+ 2 - 2
packages/app/src/stores/in-app-notification.ts

@@ -16,9 +16,9 @@ export const useSWRxInAppNotifications = <Data, Error>(
 
 // eslint-disable-next-line @typescript-eslint/no-unused-vars
 export const useSWRxInAppNotificationStatus = <Data, Error>
-  (): SWRResponse<{ count: number }, Error> => {
+  (): SWRResponse<number, Error> => {
   return useSWR(
     ['/in-app-notification/status'],
-    endpoint => apiv3Get(endpoint).then(response => response.data),
+    endpoint => apiv3Get(endpoint).then(response => response.data.count),
   );
 };