Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion fixtures/study-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const studyGroup = {
moderatorId: 'user2',
applyEndDate: '2020-12-23',
participants: [
'user2',
{ id: 'user2' },
],
personnel: 2,
contents: '우리는 이것저것 합니다.2',
Expand Down
4 changes: 2 additions & 2 deletions src/components/introduce/IntroduceHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const IntroduceHeader = ({

const handleFormSubmit = () => {
setModalForm(false);
onApply();
onApply(applyFields);
};

const handleFormCancel = () => {
Expand All @@ -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 })}
/>
<AskLoginModal
Expand Down
16 changes: 8 additions & 8 deletions src/components/introduce/IntroduceHeader.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ describe('IntroduceHeader', () => {
...STUDY_GROUP,
applyEndDate: tomorrow,
participants: [
'user2',
'user',
{ id: 'user2' },
{ id: 'user' },
],
personnel: 3,
};
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('IntroduceHeader', () => {
...STUDY_GROUP,
applyEndDate: yesterday,
participants: [
'user2',
{ id: 'user2' },
],
personnel: 2,
};
Expand All @@ -120,8 +120,8 @@ describe('IntroduceHeader', () => {
...STUDY_GROUP,
applyEndDate: tomorrow,
participants: [
'user2',
'user3',
{ id: 'user2' },
{ id: 'user3' },
],
personnel: 2,
};
Expand All @@ -141,7 +141,7 @@ describe('IntroduceHeader', () => {
...STUDY_GROUP,
applyEndDate: tomorrow,
participants: [
'user2',
{ id: 'user2' },
],
personnel: 2,
};
Expand Down Expand Up @@ -178,7 +178,7 @@ describe('IntroduceHeader', () => {
...STUDY_GROUP,
applyEndDate: tomorrow,
participants: [
'user2',
{ id: 'user2' },
],
personnel: 2,
};
Expand All @@ -199,7 +199,7 @@ describe('IntroduceHeader', () => {
...STUDY_GROUP,
applyEndDate: tomorrow,
participants: [
'user2',
{ id: 'user2' },
],
personnel: 2,
};
Expand Down
4 changes: 2 additions & 2 deletions src/containers/introduce/IntroduceContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/containers/introduce/IntroduceContainer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ describe('IntroduceContainer', () => {
...STUDY_GROUP,
applyEndDate: tomorrow,
participants: [
'user2',
'user',
{ id: 'user2' },
{ id: 'user' },
],
personnel: 3,
};
Expand Down
23 changes: 17 additions & 6 deletions src/reducers/groupSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand All @@ -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,
});

Expand Down
19 changes: 14 additions & 5 deletions src/reducers/groupSlice.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}],
}));
});
});
Expand All @@ -248,8 +257,8 @@ describe('async actions', () => {
const group = {
id: 1,
participants: [
'user2',
'example',
{ id: 'user2' },
{ id: 'example' },
],
};
const user = 'example';
Expand All @@ -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),
}));
});
});
Expand Down
1 change: 1 addition & 0 deletions src/reducers/rootSlice.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { combineReducers } from '@reduxjs/toolkit';

import authReducer from './authSlice';
import groupReducer from './groupSlice';

Expand Down
4 changes: 2 additions & 2 deletions src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
};

Expand Down