File tree Expand file tree Collapse file tree 5 files changed +99
-0
lines changed Expand file tree Collapse file tree 5 files changed +99
-0
lines changed Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change @@ -4,10 +4,13 @@ import useUpload from '../../lib/hooks/useUpload';
4
4
import useS3Upload from '../../lib/hooks/useS3Upload' ;
5
5
import useUserProfile from './hooks/useUserProfile' ;
6
6
import useUpdateThumbnail from './hooks/useUpdateThumbnail' ;
7
+ import useUser from '../../lib/hooks/useUser' ;
8
+ import RequireLogin from '../../components/common/RequireLogin' ;
7
9
8
10
export type SettingUserProfileContainerProps = { } ;
9
11
10
12
function SettingUserProfileContainer ( props : SettingUserProfileContainerProps ) {
13
+ const user = useUser ( ) ;
11
14
const { profile, loading, update } = useUserProfile ( ) ;
12
15
const [ upload ] = useUpload ( ) ;
13
16
const [ s3Upload , image , error ] = useS3Upload ( ) ;
@@ -29,6 +32,10 @@ function SettingUserProfileContainer(props: SettingUserProfileContainerProps) {
29
32
return update ( params ) ;
30
33
} ;
31
34
35
+ if ( ! user ) {
36
+ return < RequireLogin hasMargin /> ;
37
+ }
38
+
32
39
if ( ! profile ) return null ;
33
40
34
41
return (
Original file line number Diff line number Diff line change @@ -8,5 +8,6 @@ export { default as undrawBugFixing } from './undraw_bug_fixing_oc7a.svg';
8
8
export { default as undrawPageNotFound } from './undraw_page_not_found_su7k.svg' ;
9
9
export { default as undrawServerDown } from './undraw_server_down_s4lk.svg' ;
10
10
export { default as undrawUpdate } from './undraw_update_uxn2.svg' ;
11
+ export { default as undrawLogin } from './undraw_login_v483.svg' ;
11
12
12
13
// export { default as undrawSearching } from './undraw_searching.svg';
You can’t perform that action at this time.
0 commit comments