From 0ec8f63d7a55c637ebb9fddbee5138043862b061 Mon Sep 17 00:00:00 2001 From: saseungmin Date: Thu, 10 Dec 2020 00:30:22 +0900 Subject: [PATCH 1/3] [Feature] Apply Form submit action for redux - api update applyFields to firebase fields participants --- src/components/introduce/IntroduceHeader.jsx | 2 +- .../introduce/IntroduceContainer.jsx | 4 ++-- src/reducers/groupSlice.js | 23 ++++++++++++++----- src/reducers/groupSlice.test.js | 19 +++++++++++---- src/reducers/rootSlice.js | 1 + src/services/api.js | 4 ++-- 6 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/components/introduce/IntroduceHeader.jsx b/src/components/introduce/IntroduceHeader.jsx index a48a2ba..f761b61 100644 --- a/src/components/introduce/IntroduceHeader.jsx +++ b/src/components/introduce/IntroduceHeader.jsx @@ -64,7 +64,7 @@ const IntroduceHeader = ({ const handleFormSubmit = () => { setModalForm(false); - onApply(); + onApply(applyFields); }; const handleFormCancel = () => { diff --git a/src/containers/introduce/IntroduceContainer.jsx b/src/containers/introduce/IntroduceContainer.jsx index bf636fb..856f6d4 100644 --- a/src/containers/introduce/IntroduceContainer.jsx +++ b/src/containers/introduce/IntroduceContainer.jsx @@ -29,8 +29,8 @@ const IntroduceContainer = ({ groupId }) => { setRealTime(Date.now()); }, 1000); - const onApplyStudy = useCallback(() => { - dispatch(updateParticipant()); + const onApplyStudy = useCallback(({ reason, wantToGet }) => { + dispatch(updateParticipant({ reason, wantToGet })); }, [dispatch]); const onApplyCancel = useCallback(() => { diff --git a/src/reducers/groupSlice.js b/src/reducers/groupSlice.js index 1ce9978..a052471 100644 --- a/src/reducers/groupSlice.js +++ b/src/reducers/groupSlice.js @@ -113,22 +113,31 @@ export const writeStudyGroup = () => async (dispatch, getState) => { const groupId = await postStudyGroup(produce(groupReducer.writeField, (draft) => { draft.moderatorId = user; - draft.participants.push(user); + draft.participants.push({ + id: user, + }); })); dispatch(successWrite(groupId)); dispatch(clearWriteFields()); }; -export const updateParticipant = () => async (dispatch, getState) => { +export const updateParticipant = ({ reason, wantToGet }) => async (dispatch, getState) => { const { groupReducer: { group }, authReducer: { user } } = getState(); + const userInfo = { + id: user, + reason, + wantToGet, + confirm: false, + }; + const newGroup = produce(group, (draft) => { - draft.participants.push(user); + draft.participants.push(userInfo); }); await updatePostParticipant({ - user, + user: userInfo, id: group.id, }); @@ -138,13 +147,15 @@ export const updateParticipant = () => async (dispatch, getState) => { export const deleteParticipant = () => async (dispatch, getState) => { const { groupReducer: { group }, authReducer: { user } } = getState(); + const participants = group.participants.filter(({ id }) => id !== user); + const newGroup = { ...group, - participants: group.participants.filter((participant) => participant !== user), + participants, }; await deletePostParticipant({ - user, + participants, id: group.id, }); diff --git a/src/reducers/groupSlice.test.js b/src/reducers/groupSlice.test.js index b944649..501007d 100644 --- a/src/reducers/groupSlice.test.js +++ b/src/reducers/groupSlice.test.js @@ -232,14 +232,23 @@ describe('async actions', () => { }); }); + const applyFields = { + reason: '이유', + wantToGet: '원하는 것', + }; + it('dispatches setStudyGroup', async () => { - await store.dispatch(updateParticipant()); + await store.dispatch(updateParticipant(applyFields)); const actions = store.getActions(); expect(actions[0]).toEqual(setStudyGroup({ ...STUDY_GROUP, - participants: [...STUDY_GROUP.participants, 'example'], + participants: [...STUDY_GROUP.participants, { + ...applyFields, + id: 'example', + confirm: false, + }], })); }); }); @@ -248,8 +257,8 @@ describe('async actions', () => { const group = { id: 1, participants: [ - 'user2', - 'example', + { id: 'user2' }, + { id: 'example' }, ], }; const user = 'example'; @@ -272,7 +281,7 @@ describe('async actions', () => { expect(actions[0]).toEqual(setStudyGroup({ ...group, - participants: group.participants.filter((participant) => participant !== user), + participants: group.participants.filter(({ id }) => id !== user), })); }); }); diff --git a/src/reducers/rootSlice.js b/src/reducers/rootSlice.js index 1a5a2a6..269daa8 100644 --- a/src/reducers/rootSlice.js +++ b/src/reducers/rootSlice.js @@ -1,4 +1,5 @@ import { combineReducers } from '@reduxjs/toolkit'; + import authReducer from './authSlice'; import groupReducer from './groupSlice'; diff --git a/src/services/api.js b/src/services/api.js index 9a2887a..b3f6b3c 100644 --- a/src/services/api.js +++ b/src/services/api.js @@ -71,11 +71,11 @@ export const updatePostParticipant = async ({ id, user }) => { }); }; -export const deletePostParticipant = async ({ id, user }) => { +export const deletePostParticipant = async ({ id, participants }) => { const groups = db.collection('groups').doc(id); await groups.update({ - participants: fireStore.FieldValue.arrayRemove(user), + participants, }); }; From df287b41381a21f6bbe7175601fb90759c54614a Mon Sep 17 00:00:00 2001 From: saseungmin Date: Thu, 10 Dec 2020 00:49:55 +0900 Subject: [PATCH 2/3] [Refactoring & Fix] Modifying the test by changing the data structure --- .github/workflows/ci.yml | 26 +++++++++++++++++-- fixtures/study-group.js | 2 +- src/components/introduce/IntroduceHeader.jsx | 2 +- .../introduce/IntroduceHeader.test.jsx | 16 ++++++------ .../introduce/IntroduceContainer.test.jsx | 4 +-- 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b9e246..627c560 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,8 +6,6 @@ name: CI on: push: branches: [ main ] - pull_request: - branches: [ main ] jobs: build: @@ -44,3 +42,27 @@ jobs: HEADLESS: true - name: Lint run: npm run lint + +on: + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [12.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: Install + run: npm ci + - name: Lint + run: npm run lint \ No newline at end of file diff --git a/fixtures/study-group.js b/fixtures/study-group.js index d8949ea..bc72214 100644 --- a/fixtures/study-group.js +++ b/fixtures/study-group.js @@ -4,7 +4,7 @@ const studyGroup = { moderatorId: 'user2', applyEndDate: '2020-12-23', participants: [ - 'user2', + { id: 'user2' }, ], personnel: 2, contents: '우리는 이것저것 합니다.2', diff --git a/src/components/introduce/IntroduceHeader.jsx b/src/components/introduce/IntroduceHeader.jsx index f761b61..6909f17 100644 --- a/src/components/introduce/IntroduceHeader.jsx +++ b/src/components/introduce/IntroduceHeader.jsx @@ -80,7 +80,7 @@ const IntroduceHeader = ({ user={user} onApply={handleApply} onCancel={handleApplyCancelConfirmClick} - applyStatus={participants.includes(user)} + applyStatus={participants.some(({ id }) => id === user)} timeStatus={isCheckedTimeStatus({ ...group, time: realTime, applyEndTime })} /> { ...STUDY_GROUP, applyEndDate: tomorrow, participants: [ - 'user2', - 'user', + { id: 'user2' }, + { id: 'user' }, ], personnel: 3, }; @@ -100,7 +100,7 @@ describe('IntroduceHeader', () => { ...STUDY_GROUP, applyEndDate: yesterday, participants: [ - 'user2', + { id: 'user2' }, ], personnel: 2, }; @@ -120,8 +120,8 @@ describe('IntroduceHeader', () => { ...STUDY_GROUP, applyEndDate: tomorrow, participants: [ - 'user2', - 'user3', + { id: 'user2' }, + { id: 'user3' }, ], personnel: 2, }; @@ -141,7 +141,7 @@ describe('IntroduceHeader', () => { ...STUDY_GROUP, applyEndDate: tomorrow, participants: [ - 'user2', + { id: 'user2' }, ], personnel: 2, }; @@ -178,7 +178,7 @@ describe('IntroduceHeader', () => { ...STUDY_GROUP, applyEndDate: tomorrow, participants: [ - 'user2', + { id: 'user2' }, ], personnel: 2, }; @@ -199,7 +199,7 @@ describe('IntroduceHeader', () => { ...STUDY_GROUP, applyEndDate: tomorrow, participants: [ - 'user2', + { id: 'user2' }, ], personnel: 2, }; diff --git a/src/containers/introduce/IntroduceContainer.test.jsx b/src/containers/introduce/IntroduceContainer.test.jsx index 2d058cd..5f4795b 100644 --- a/src/containers/introduce/IntroduceContainer.test.jsx +++ b/src/containers/introduce/IntroduceContainer.test.jsx @@ -141,8 +141,8 @@ describe('IntroduceContainer', () => { ...STUDY_GROUP, applyEndDate: tomorrow, participants: [ - 'user2', - 'user', + { id: 'user2' }, + { id: 'user' }, ], personnel: 3, }; From 754c972577f92d9eab0a90a702926be2bdc567f8 Mon Sep 17 00:00:00 2001 From: saseungmin Date: Thu, 10 Dec 2020 00:53:01 +0900 Subject: [PATCH 3/3] [Fix] ci.yml --- .github/workflows/ci.yml | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 627c560..cce9cc1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,27 +42,3 @@ jobs: HEADLESS: true - name: Lint run: npm run lint - -on: - pull_request: - branches: [ main ] - -jobs: - build: - - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [12.x] - - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - name: Install - run: npm ci - - name: Lint - run: npm run lint \ No newline at end of file