Skip to content

Commit a08220d

Browse files
authored
Merge pull request velopert#117 from velopert/fix/setting-unauth
Show RequireLogin when enter settings page without auth
2 parents e3ebc90 + a3346bd commit a08220d

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import React from 'react';
2+
import { undrawLogin } from '../../static/images';
3+
import styled, { css } from 'styled-components';
4+
import Button from './Button';
5+
import useRequireLogin from '../../lib/hooks/useRequireLogin';
6+
import palette from '../../lib/styles/palette';
7+
import media from '../../lib/styles/media';
8+
9+
export type RequireLoginProps = {
10+
hasMargin?: boolean;
11+
};
12+
13+
function RequireLogin({ hasMargin }: RequireLoginProps) {
14+
const requireLogin = useRequireLogin();
15+
16+
return (
17+
<Block hasMargin={hasMargin}>
18+
<img src={undrawLogin} alt="Please login" />
19+
<h2>로그인 후 이용해주세요.</h2>
20+
<Button onClick={requireLogin}>로그인</Button>
21+
</Block>
22+
);
23+
}
24+
25+
const Block = styled.div<{ hasMargin?: boolean }>`
26+
display: flex;
27+
flex-direction: column;
28+
align-items: center;
29+
width: 100%;
30+
31+
img {
32+
width: 12rem;
33+
height: auto;
34+
display: block;
35+
${media.medium} {
36+
width: 8rem;
37+
}
38+
}
39+
h2 {
40+
font-weight: 400;
41+
color: ${palette.gray8};
42+
margin-top: 2rem;
43+
${media.small} {
44+
font-size: 1.25rem;
45+
}
46+
}
47+
${props =>
48+
props.hasMargin &&
49+
css`
50+
margin-top: 10rem;
51+
${media.medium} {
52+
margin-top: 4rem;
53+
}
54+
`}
55+
`;
56+
57+
export default RequireLogin;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as React from 'react';
2+
import { render, fireEvent } from '@testing-library/react';
3+
import RequireLogin, { RequireLoginProps } from '../RequireLogin';
4+
import renderWithRedux from '../../../lib/renderWithRedux';
5+
6+
describe('RequireLogin', () => {
7+
const setup = (props: Partial<RequireLoginProps> = {}) => {
8+
const initialProps: RequireLoginProps = {};
9+
const utils = renderWithRedux(
10+
<RequireLogin {...initialProps} {...props} />,
11+
);
12+
return {
13+
...utils,
14+
};
15+
};
16+
it('renders properly', () => {
17+
setup();
18+
});
19+
it('calls requireLogin on button click', () => {
20+
const utils = setup();
21+
const button = utils.getByText('로그인');
22+
fireEvent.click(button);
23+
expect(utils.store.getState().core.auth.visible).toBe(true);
24+
});
25+
it('has no margin when hasMargin props is omitted', () => {
26+
const utils = setup();
27+
expect(utils.container.firstChild).not.toHaveStyle('margin-top: 10rem');
28+
});
29+
it('has margin when hasMargin is true', () => {
30+
const utils = setup({ hasMargin: true });
31+
expect(utils.container.firstChild).toHaveStyle('margin-top: 10rem');
32+
});
33+
});

src/containers/setting/SettingUserProfileContainer.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import useUpload from '../../lib/hooks/useUpload';
44
import useS3Upload from '../../lib/hooks/useS3Upload';
55
import useUserProfile from './hooks/useUserProfile';
66
import useUpdateThumbnail from './hooks/useUpdateThumbnail';
7+
import useUser from '../../lib/hooks/useUser';
8+
import RequireLogin from '../../components/common/RequireLogin';
79

810
export type SettingUserProfileContainerProps = {};
911

1012
function SettingUserProfileContainer(props: SettingUserProfileContainerProps) {
13+
const user = useUser();
1114
const { profile, loading, update } = useUserProfile();
1215
const [upload] = useUpload();
1316
const [s3Upload, image, error] = useS3Upload();
@@ -29,6 +32,10 @@ function SettingUserProfileContainer(props: SettingUserProfileContainerProps) {
2932
return update(params);
3033
};
3134

35+
if (!user) {
36+
return <RequireLogin hasMargin />;
37+
}
38+
3239
if (!profile) return null;
3340

3441
return (

src/static/images/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export { default as undrawBugFixing } from './undraw_bug_fixing_oc7a.svg';
88
export { default as undrawPageNotFound } from './undraw_page_not_found_su7k.svg';
99
export { default as undrawServerDown } from './undraw_server_down_s4lk.svg';
1010
export { default as undrawUpdate } from './undraw_update_uxn2.svg';
11+
export { default as undrawLogin } from './undraw_login_v483.svg';
1112

1213
// export { default as undrawSearching } from './undraw_searching.svg';
Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)