-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathgithub-connect.js
More file actions
61 lines (48 loc) · 1.4 KB
/
github-connect.js
File metadata and controls
61 lines (48 loc) · 1.4 KB
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
import ENV from 'code-corps-ember/config/environment';
import Component from '@ember/component';
import { get, set } from '@ember/object';
import { inject as service } from '@ember/service';
const baseUrl = 'https://github.com/login/oauth/authorize';
/**
The github-connect component is used to to connect to github
## default usage
```handlebars
{{github-connect state=state}}
```
@module Component
@class github-connect
@extends Ember.Component
@public
*/
export default Component.extend({
tagName: 'a',
classNames: ['github-connect', 'button', 'default'],
attributeBindings: ['url:href', 'target:target'],
githubState: service(),
metrics: service(),
clientId: `${ENV.github.clientId}`,
redirectUri: `${ENV.github.redirectUri}`,
scope: `${ENV.github.scope}`,
state: null,
target: null,
url: null,
init() {
this._super(...arguments);
this._initState();
this._initUrl();
},
click() {
get(this, 'metrics').trackEvent({
event: 'Clicked Connect with GitHub'
});
},
_initState() {
let githubState = get(this, 'githubState').generate();
set(this, 'state', githubState);
},
_initUrl() {
let { clientId, scope, state, redirectUri }
= this.getProperties('clientId', 'scope', 'state', 'redirectUri');
set(this, 'url', `${baseUrl}?scope=${scope}&client_id=${clientId}&state=${state}&redirect_uri=${redirectUri}`);
}
});