8000 [Feature] Click the cancel button and clear redux store by saseungmin · Pull Request #28 · CodeSoom/ConStu · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Feature] Click the cancel button and clear redux store #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
8000
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/components/write/WriteButtons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import styled from '@emotion/styled';

const WriteButtonsWrapper = styled.div``;

const WriteButtons = ({ onSubmit }) => (
const WriteButtons = ({ onSubmit, onCancel }) => (
<WriteButtonsWrapper>
<button
type="button"
>
>
등록하기
</button>
<button type="button">취소</button>
<button
type="button"
>
>
취소
</button>
</WriteButtonsWrapper>
);

Expand Down
6 changes: 5 additions & 1 deletion src/containers/write/WriteButtonsContainer.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useEffect, useCallback } from 'react';

import { useDispatch, useSelector } from 'react-redux';

import { useHistory } from 'react-router-dom';

import { get } from '../../util/utils';
Expand All @@ -28,10 +27,15 @@ const WriteButtonsContainer = () => {
}
}, [history, group]);

const => {
history.push('/');
};

return (
<WriteButtons
fields={writeField}
>
>
/>
);
};
Expand Down
16 changes: 15 additions & 1 deletion src/containers/write/WriteButtonsContainer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,23 @@ describe('WriteButtonsContainer', () => {
expect(container).toHaveTextContent('취소');
});

describe('when click cancel button', () => {
given('group', () => (null));

it('Go to the main page', () => {
const { getByText } = renderWriteButtonsContainer();

fireEvent.click(getByText('취소'));

expect(mockPush).toBeCalledWith('/');
});
});

describe('when click submit button', () => {
context('with group', () => {
given('group', () => (STUDY_GROUP));
it('dispatch action submit event', () => {

it('dispatch action writeStudyGroup event', () => {
const { getByText } = renderWriteButtonsContainer();

fireEvent.click(getByText('등록하기'));
Expand All @@ -63,6 +76,7 @@ describe('WriteButtonsContainer', () => {

context('without group', () => {
given('group', () => (null));

it('dispatch action submit event', () => {
const { getByText } = renderWriteButtonsContainer();

Expand Down
8 changes: 6 additions & 2 deletions src/containers/write/WriteFormContainer.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import React, { useEffect } from 'react';

import { useDispatch, useSelector } from 'react-redux';

import { get } from '../../util/utils';
import WriteForm from '../../components/write/WriteForm';

import { changeWriteField } from '../../reducers/slice';
import { changeWriteField, clearWriteFields } from '../../reducers/slice';

const WriteFormContainer = () => {
const dispatch = useDispatch();
Expand All @@ -21,6 +21,10 @@ const WriteFormContainer = () => {
);
};

useEffect(() => () => {
dispatch(clearWriteFields());
}, [dispatch]);

return (
<WriteForm
fields={writeField}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/MainPage.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';

import { Link } from 'react-router-dom';

import styled from '@emotion/styled';

import { Link } from 'react-router-dom';
import StudyGroupsContainer from '../containers/groups/StudyGroupsContainer';
import Responsive from '../styles/Responsive';
import palette from '../styles/palette';
Expand Down
0