mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-27 23:40:28 +05:30
Fix some flow errors
This commit is contained in:
parent
9760eba3af
commit
6e9542f592
@ -80,7 +80,7 @@
|
||||
"exports-loader": "^0.6.3",
|
||||
"extract-text-webpack-plugin": "^1.0.0",
|
||||
"file-loader": "^0.11.0",
|
||||
"flow-bin": "0.54.1",
|
||||
"flow-bin": "0.71.0",
|
||||
"fontgen-loader": "^0.2.1",
|
||||
"html-loader": "^0.4.3",
|
||||
"html-webpack-plugin": "^2.0.0",
|
||||
|
@ -30,7 +30,7 @@ export default class MeasureHeight extends PureComponent<{
|
||||
}> {
|
||||
static defaultProps = {
|
||||
shouldMeasure: (prevState: any, newState: any) => prevState !== newState,
|
||||
onMeasure: (height) => {} // eslint-disable-line
|
||||
onMeasure: (height: number) => {} // eslint-disable-line
|
||||
};
|
||||
|
||||
el: ?HTMLDivElement;
|
||||
|
@ -1,6 +1,6 @@
|
||||
// @flow
|
||||
import type { OauthData } from 'services/api/oauth';
|
||||
import { browserHistory } from 'services/history';
|
||||
|
||||
import logger from 'services/logger';
|
||||
import localStorage from 'services/localStorage';
|
||||
import loader from 'services/loader';
|
||||
@ -316,16 +316,7 @@ const KNOWN_SCOPES = [
|
||||
*
|
||||
* @return {Promise}
|
||||
*/
|
||||
export function oAuthValidate(oauthData: {
|
||||
clientId: string,
|
||||
redirectUrl: string,
|
||||
responseType: string,
|
||||
description: string,
|
||||
scope: string,
|
||||
prompt: 'none' | 'consent' | 'select_account',
|
||||
loginHint?: string,
|
||||
state?: string
|
||||
}) {
|
||||
export function oAuthValidate(oauthData: OauthData) {
|
||||
// TODO: move to oAuth actions?
|
||||
// test request: /oauth?client_id=ely&redirect_uri=http%3A%2F%2Fely.by&response_type=code&scope=minecraft_server_session&description=foo
|
||||
return wrapInLoader((dispatch) =>
|
||||
@ -370,23 +361,27 @@ export function oAuthValidate(oauthData: {
|
||||
export function oAuthComplete(params: {accept?: bool} = {}) {
|
||||
return wrapInLoader((dispatch, getState) =>
|
||||
oauth.complete(getState().auth.oauth, params)
|
||||
.then((resp: Object) => {
|
||||
.then((resp) => {
|
||||
localStorage.removeItem('oauthData');
|
||||
|
||||
if (resp.redirectUri.startsWith('static_page')) {
|
||||
resp.code = resp.redirectUri.match(/code=(.+)&/)[1];
|
||||
resp.redirectUri = resp.redirectUri.match(/^(.+)\?/)[1];
|
||||
resp.displayCode = resp.redirectUri === 'static_page_with_code';
|
||||
const code = (resp.redirectUri.match(/code=(.+)&/) || [])[1];
|
||||
const displayCode = resp.redirectUri === 'static_page_with_code';
|
||||
resp.redirectUri = (resp.redirectUri.match(/^(.+)\?/) || [])[1];
|
||||
|
||||
dispatch(setOAuthCode({
|
||||
success: resp.success,
|
||||
code: resp.code,
|
||||
displayCode: resp.displayCode
|
||||
code,
|
||||
displayCode
|
||||
}));
|
||||
}
|
||||
|
||||
return resp;
|
||||
}, (resp) => {
|
||||
}, (resp: {
|
||||
acceptRequired: bool,
|
||||
} | {
|
||||
unauthorized: bool,
|
||||
}) => {
|
||||
if (resp.acceptRequired) {
|
||||
dispatch(requirePermissionsAccept());
|
||||
|
||||
@ -398,7 +393,9 @@ export function oAuthComplete(params: {accept?: bool} = {}) {
|
||||
);
|
||||
}
|
||||
|
||||
function handleOauthParamsValidation(resp = {}) {
|
||||
function handleOauthParamsValidation(resp: {
|
||||
userMessage?: string,
|
||||
} | Object = {}) {
|
||||
dispatchBsod();
|
||||
localStorage.removeItem('oauthData');
|
||||
|
||||
|
@ -139,7 +139,7 @@ class LanguageSwitcher extends Component<{
|
||||
};
|
||||
|
||||
onFilterKeyPress() {
|
||||
return (event: SyntheticInputEvent<HTMLInputElement>) => {
|
||||
return (event: SyntheticKeyboardEvent<HTMLInputElement>) => {
|
||||
if (event.key !== 'Enter' || this.state.filter === '') {
|
||||
return;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import type { User } from 'components/user';
|
||||
class Profile extends Component<{
|
||||
user: User
|
||||
}> {
|
||||
UUID: ?HTMLDivElement;
|
||||
UUID: ?HTMLElement;
|
||||
|
||||
render() {
|
||||
const { user } = this.props;
|
||||
@ -134,11 +134,13 @@ class Profile extends Component<{
|
||||
}
|
||||
}
|
||||
|
||||
setUUID(el: ?HTMLDivElement) {
|
||||
setUUID(el: ?HTMLElement) {
|
||||
this.UUID = el;
|
||||
}
|
||||
}
|
||||
|
||||
export default connect((state) => ({
|
||||
user: state.user,
|
||||
export default connect(({ user }): {
|
||||
user: User,
|
||||
} => ({
|
||||
user,
|
||||
}))(Profile);
|
||||
|
@ -112,10 +112,14 @@ export default class Input extends FormInputComponent<{
|
||||
}
|
||||
|
||||
getValue() {
|
||||
return this.el.value;
|
||||
return this.el || this.el.value;
|
||||
}
|
||||
|
||||
focus() {
|
||||
if (!this.el) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.el.focus();
|
||||
setTimeout(this.el.focus.bind(this.el), 10);
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ const PrivateRoute = ({account, component: Component, ...rest}: {
|
||||
)}/>
|
||||
);
|
||||
|
||||
export default connect((state) => ({
|
||||
export default connect((state): {
|
||||
account: ?Account,
|
||||
} => ({
|
||||
account: getActiveAccount(state)
|
||||
}))(PrivateRoute);
|
||||
|
@ -99,6 +99,12 @@ function renderPanelTransition(factory) {
|
||||
import { connect } from 'react-redux';
|
||||
import { withRouter } from 'react-router';
|
||||
|
||||
export default withRouter(connect((state) => ({
|
||||
export default withRouter(connect((state): {
|
||||
client: {
|
||||
id: string,
|
||||
name: string,
|
||||
description: string
|
||||
}
|
||||
} => ({
|
||||
client: state.auth.client
|
||||
}))(AuthPage));
|
||||
|
@ -84,4 +84,4 @@ class MultiFactorAuthPage extends Component<{
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(({user}) => ({user}))(MultiFactorAuthPage);
|
||||
export default connect(({user}): { user: User } => ({user}))(MultiFactorAuthPage);
|
||||
|
@ -143,11 +143,11 @@ export default class RulesPage extends Component<{
|
||||
this.props.history.replace(newPath);
|
||||
}
|
||||
|
||||
static getTitleHash(sectionIndex) {
|
||||
static getTitleHash(sectionIndex: number) {
|
||||
return `rule-${sectionIndex + 1}`;
|
||||
}
|
||||
|
||||
static getRuleHash(sectionIndex, ruleIndex) {
|
||||
static getRuleHash(sectionIndex: number, ruleIndex: number) {
|
||||
return `${RulesPage.getTitleHash(sectionIndex)}-${ruleIndex + 1}`;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
// @flow
|
||||
/* eslint camelcase: off */
|
||||
import type { Resp } from 'services/request';
|
||||
import request from 'services/request';
|
||||
|
||||
export type OauthAppResponse = {
|
||||
@ -17,6 +18,28 @@ export type OauthAppResponse = {
|
||||
minecraftServerIp?: string,
|
||||
};
|
||||
|
||||
type OauthRequestData = {
|
||||
client_id: string,
|
||||
redirect_uri: string,
|
||||
response_type: string,
|
||||
description: string,
|
||||
scope: string,
|
||||
prompt: string,
|
||||
login_hint?: string,
|
||||
state?: string,
|
||||
};
|
||||
|
||||
export type OauthData = {
|
||||
clientId: string,
|
||||
redirectUrl: string,
|
||||
responseType: string,
|
||||
description: string,
|
||||
scope: string,
|
||||
prompt: 'none' | 'consent' | 'select_account',
|
||||
loginHint?: string,
|
||||
state?: string
|
||||
};
|
||||
|
||||
type FormPayloads = {
|
||||
name?: string,
|
||||
description?: string,
|
||||
@ -26,14 +49,17 @@ type FormPayloads = {
|
||||
};
|
||||
|
||||
export default {
|
||||
validate(oauthData: Object) {
|
||||
validate(oauthData: OauthData) {
|
||||
return request.get(
|
||||
'/api/oauth2/v1/validate',
|
||||
getOAuthRequest(oauthData)
|
||||
).catch(handleOauthParamsValidation);
|
||||
},
|
||||
|
||||
complete(oauthData: Object, params: Object = {}) {
|
||||
complete(oauthData: OauthData, params: {accept?: bool} = {}): Promise<Resp<{
|
||||
success: bool,
|
||||
redirectUri: string,
|
||||
}>> {
|
||||
const query = request.buildQuery(getOAuthRequest(oauthData));
|
||||
|
||||
return request.post(
|
||||
@ -44,7 +70,8 @@ export default {
|
||||
// user declined permissions
|
||||
return {
|
||||
success: false,
|
||||
redirectUri: resp.redirectUri
|
||||
redirectUri: resp.redirectUri,
|
||||
originalResponse: resp.originalResponse,
|
||||
};
|
||||
}
|
||||
|
||||
@ -64,27 +91,27 @@ export default {
|
||||
});
|
||||
},
|
||||
|
||||
create(type: string, formParams: FormPayloads): Promise<{success: bool, data: OauthAppResponse}> {
|
||||
create(type: string, formParams: FormPayloads): Promise<Resp<{success: bool, data: OauthAppResponse}>> {
|
||||
return request.post(`/api/v1/oauth2/${type}`, formParams);
|
||||
},
|
||||
|
||||
update(clientId: string, formParams: FormPayloads): Promise<{success: bool, data: OauthAppResponse}> {
|
||||
update(clientId: string, formParams: FormPayloads): Promise<Resp<{success: bool, data: OauthAppResponse}>> {
|
||||
return request.put(`/api/v1/oauth2/${clientId}`, formParams);
|
||||
},
|
||||
|
||||
getApp(clientId: string): Promise<OauthAppResponse> {
|
||||
getApp(clientId: string): Promise<Resp<OauthAppResponse>> {
|
||||
return request.get(`/api/v1/oauth2/${clientId}`);
|
||||
},
|
||||
|
||||
getAppsByUser(userId: number): Promise<Array<OauthAppResponse>> {
|
||||
getAppsByUser(userId: number): Promise<Resp<Array<OauthAppResponse>>> {
|
||||
return request.get(`/api/v1/accounts/${userId}/oauth2/clients`);
|
||||
},
|
||||
|
||||
reset(clientId: string, regenerateSecret: bool = false): Promise<{success: bool, data: OauthAppResponse}> {
|
||||
reset(clientId: string, regenerateSecret: bool = false): Promise<Resp<{success: bool, data: OauthAppResponse}>> {
|
||||
return request.post(`/api/v1/oauth2/${clientId}/reset${regenerateSecret ? '?regenerateSecret' : ''}`);
|
||||
},
|
||||
|
||||
delete(clientId: string): Promise<{success: bool}> {
|
||||
delete(clientId: string): Promise<Resp<{success: bool}>> {
|
||||
return request.delete(`/api/v1/oauth2/${clientId}`);
|
||||
},
|
||||
};
|
||||
@ -99,7 +126,7 @@ export default {
|
||||
*
|
||||
* @return {object}
|
||||
*/
|
||||
function getOAuthRequest(oauthData) {
|
||||
function getOAuthRequest(oauthData: OauthData): OauthRequestData {
|
||||
return {
|
||||
client_id: oauthData.clientId,
|
||||
redirect_uri: oauthData.redirectUrl,
|
||||
|
@ -59,6 +59,7 @@ export interface AuthContext {
|
||||
getState(): Object;
|
||||
navigate(route: string): void;
|
||||
getRequest(): Request;
|
||||
prevState: AbstractState;
|
||||
}
|
||||
|
||||
export default class AuthFlow implements AuthContext {
|
||||
|
@ -1,10 +1,10 @@
|
||||
// @flow
|
||||
import type { AuthContext } from 'services/authFlow';
|
||||
import logger from 'services/logger';
|
||||
|
||||
import AbstractState from './AbstractState';
|
||||
import ActivationState from './ActivationState';
|
||||
import RegisterState from './RegisterState';
|
||||
import type { AuthContext } from 'services/authFlow';
|
||||
|
||||
export default class ResendActivationState extends AbstractState {
|
||||
enter(context: AuthContext) {
|
||||
|
@ -9,8 +9,8 @@ import copyToClipboard from 'copy-to-clipboard';
|
||||
* @return {Promise<*>}
|
||||
*/
|
||||
export default async function copy(content: string): Promise<void> {
|
||||
// $FlowFixMe there is no typing for navigator.clipboard
|
||||
if (navigator.clipboard) {
|
||||
// $FlowFixMe there is no typing for navigator.clipboard
|
||||
return navigator.clipboard.writeText(content);
|
||||
}
|
||||
|
||||
|
@ -2829,9 +2829,9 @@ flatten@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782"
|
||||
|
||||
flow-bin@0.54.1:
|
||||
version "0.54.1"
|
||||
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.54.1.tgz#7101bcccf006dc0652714a8aef0c72078a760510"
|
||||
flow-bin@0.71.0:
|
||||
version "0.71.0"
|
||||
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.71.0.tgz#fd1b27a6458c3ebaa5cb811853182ed631918b70"
|
||||
|
||||
fontgen-loader@^0.2.1:
|
||||
version "0.2.1"
|
||||
|
Loading…
Reference in New Issue
Block a user