-
Notifications
You must be signed in to change notification settings - Fork 7
/
GitHubSetting.tsx
122 lines (108 loc) 路 3.05 KB
/
GitHubSetting.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import React, { Component, Fragment } from 'react'
import {
Button,
TextInputField,
toaster,
// @ts-ignore
} from 'evergreen-ui'
import styled from 'styled-components'
import autobind from 'autobind-decorator'
import { UserInfoInterface } from '../../service/user-info.service'
import { SettingInfoState } from '../../reducers/setting-info.reducers'
import { RepoState } from '../../reducers/repos.reducers'
import { FetchResponseType } from '../../saga/repos.saga'
import { SETTING_GUIDE_LINK } from '../../main/appConfig'
const Center = styled.div`
text-align: center;
`
interface GitHubSettingProps {
repos: RepoState
settingInfo: SettingInfoState
onClickSubmit: (info: UserInfoInterface) => void
onClickClose: () => void
}
interface GitHubSettingState {
name: string
token: string
}
export class GitHubSetting extends Component<
GitHubSettingProps,
GitHubSettingState
> {
public state: GitHubSettingState = {
name: '',
token: '',
}
componentDidMount() {
const { name, token } = this.props.settingInfo.userInfo
if (name !== '' && token !== '') {
this.setState({ name: name as string, token: token as string })
}
}
render() {
const { onClickClose, repos, settingInfo } = this.props
const { name: storageName, token: storageToken } = settingInfo.userInfo
const { name, token } = this.state
const { fetchResponseType } = repos
const isDone =
fetchResponseType === FetchResponseType.SUCCESS &&
storageName === name &&
storageToken === token &&
name !== '' &&
token !== ''
let ButtonSection
if (isDone) {
ButtonSection = (
<Button onClick={onClickClose} appearance="blue" height={28}>
Done
</Button>
)
} else {
ButtonSection = (
<Button onClick={this.handleSubmit} height={28}>
Submit
</Button>
)
}
return (
<Fragment>
<TextInputField
value={this.state.name}
label="Account name"
placeholder="owner's name"
inputHeight={28}
data-id="name"
onChange={this.handleUpdateValue}
/>
<TextInputField
value={this.state.token}
label="Access token"
description={`Check, ${SETTING_GUIDE_LINK}`}
placeholder="secret access token"
inputHeight={28}
data-id="token"
onChange={this.handleUpdateValue}
/>
<Center>{ButtonSection}</Center>
</Fragment>
)
}
@autobind
private handleSubmit() {
const { onClickSubmit } = this.props
const { name, token } = this.state
if (name !== '' && token !== '') {
onClickSubmit({ name, token })
toaster.success('Complete to connect!', { duration: 1 })
} else {
toaster.warning('Invalid input!', { duration: 1 })
}
}
@autobind
private handleUpdateValue({ target }: React.ChangeEvent<HTMLInputElement>) {
const key = target.dataset.id as keyof GitHubSettingState
const value = target.value
// @ts-ignore
this.setState({ [key]: value })
}
}