swsnu / swppfall2022-team4

4 stars 1 forks source link

Task Notification 사용법 #72

Open KJYoung opened 1 year ago

KJYoung commented 1 year ago

https://github.com/swsnu/swppfall2022-team4/commit/ea11b0f549bdc8654bae8a202643c5e7e3df09c5 를 참고하시면 사용 방법은 굉장히 간단합니다. 아직 PR이 활성화되지 않았으므로, develop branch에서는 사용 불가능합니다. 더 자세한 설명은 https://teodosii.github.io/react-notifications-component/ 를 참고하세요.

App.tsx에 ReactNotifications를 넣어뒀기 때문에 기본적으로는 아래 코드만 참고하시면 됩니다.

1. Notification을 띄우고 싶을 때 함수 호출(현재 notificationSuccess, Failure의 두 가지 함수가 있습니다).

필요하다면 frontend/src/utils/sendNotification.ts를 참고/수정하세요.

// createComment ------------------------------------------------------------------------
    createComment: (state, action: PayloadAction<commentAPI.createCommentRequestType>) => {
      //create!
    },
    createCommentSuccess: (state, { payload }) => {
      notificationSuccess('댓글', '댓글 작성이 성공하였습니다!');
    },
    createCommentFailure: (state, { payload }) => {
      notificationFailure('댓글', '댓글 작성이 실패했어요.');
    },

2. 위 코드를 테스트하는 코드에 관련 mocking이 들어가야합니다.

import { Store } from 'react-notifications-component';
beforeEach(() => {
  Store.addNotification = jest.fn();
});
afterAll(() => jest.restoreAllMocks());