Move sign-in sheet under fb folder

Summary: SignInSheet and "dispatcher/user" are not used in public build, so it doesn't make sense to keep them on github.

Reviewed By: passy

Differential Revision: D28789384

fbshipit-source-id: aa1ab0fc70f2211260017be42762714b753ea877
This commit is contained in:
Anton Nikolaev
2021-06-02 11:29:11 -07:00
committed by Facebook GitHub Bot
parent 178d76bc84
commit c1f161045c
7 changed files with 33 additions and 239 deletions

View File

@@ -9,7 +9,7 @@
import React, {useCallback} from 'react';
import ShareSheetExportUrl from './ShareSheetExportUrl';
import SignInSheet from './SignInSheet';
import SignInSheet from './fb-stubs/SignInSheet';
import ExportDataPluginSheet from './ExportDataPluginSheet';
import ShareSheetExportFile from './ShareSheetExportFile';
import JSEmulatorLauncherSheet from './JSEmulatorLauncherSheet';

View File

@@ -1,189 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {FlexColumn, Button, styled, Text, Input, Link, colors} from '../ui';
import React, {Component} from 'react';
import {writeKeychain, getUser} from '../fb-stubs/user';
import {login} from '../reducers/user';
import {connect} from 'react-redux';
import {State as Store} from '../reducers';
import ContextMenu from '../ui/components/ContextMenu';
import {clipboard} from 'electron';
import {reportPlatformFailures} from '../utils/metrics';
import {Modal} from 'antd';
import {TrackingScope} from 'flipper-plugin';
const Title = styled(Text)({
marginBottom: 6,
fontWeight: 600,
});
const InfoText = styled(Text)({
lineHeight: 1.35,
marginBottom: 15,
});
const TokenInput = styled(Input)({
marginRight: 0,
});
type OwnProps = {
onHide: () => any;
};
type StateFromProps = {};
type DispatchFromProps = {
login: (user: Object) => any;
};
type State = {
token: string;
loading: boolean;
error: string | null | undefined;
};
type Props = OwnProps & StateFromProps & DispatchFromProps;
class SignInSheet extends Component<Props, State> {
state = {
token: '',
loading: false,
error: null,
};
login = async (token: string) => {
await writeKeychain(token);
const user = await getUser();
if (user) {
this.props.login(user);
} else {
throw new Error('Failed to login using the provided token');
}
};
saveToken = async (token: string) => {
this.setState({token, loading: true});
try {
await reportPlatformFailures(this.login(token), 'auth:login');
this.setState({loading: false});
this.props.onHide();
} catch (error) {
this.setState({
loading: false,
error: `${error}`,
});
}
};
onPaste = () => {
if (!this.state.token || this.state.token === '') {
const token = clipboard.readText();
// If pasted content looks like a token, we could try to login using it straight away!
if (token && token.length >= 100 && token.indexOf(' ') < 0) {
this.saveToken(token);
}
}
};
signIn = () => {
this.saveToken(this.state.token);
};
getContextMenu = () => {
const menu: Array<Electron.MenuItemConstructorOptions> = [
{
label: 'Paste',
role: 'paste',
click: this.onPaste,
},
{
label: 'Reset',
click: this.reset,
},
];
return menu;
};
reset = () => {
this.setState({token: '', error: ''});
};
renderSandyContainer(
contents: React.ReactElement,
footer: React.ReactElement,
) {
return (
<TrackingScope scope="logindialog">
<Modal
visible
centered
onCancel={this.props.onHide}
width={570}
title="Login"
footer={footer}>
<FlexColumn>{contents}</FlexColumn>
</Modal>
</TrackingScope>
);
}
render() {
const content = (
<>
<Title>You are not currently logged in to Facebook.</Title>
<InfoText>
To log in you will need to{' '}
<Link href="https://www.internalfb.com/intern/oauth/nuclide/">
open this page
</Link>
, copy the Nuclide access token you find on that page to clipboard,
and click the text input below to paste it.
</InfoText>
<ContextMenu items={this.getContextMenu()}>
<TokenInput
disabled={this.state.loading}
placeholder="Click to paste Nuclide Access Token from clipboard"
onClick={this.onPaste}
value={this.state.token}
onPaste={this.onPaste}
onChange={(e) => this.setState({token: e.target.value})}
/>
</ContextMenu>
{this.state.error && (
<>
<br />
<InfoText color={colors.red}>
<strong>Error:</strong>&nbsp;{this.state.error}
</InfoText>
</>
)}
</>
);
const footer = (
<>
<Button compact padded onClick={this.props.onHide}>
Cancel
</Button>
<Button compact padded onClick={this.reset}>
Reset
</Button>
<Button type="primary" compact padded onClick={this.signIn}>
Sign In
</Button>
</>
);
return this.renderSandyContainer(content, footer);
}
}
export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
() => ({}),
{login},
)(SignInSheet);

View File

@@ -0,0 +1,18 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {Component} from 'react';
class SignInSheet extends Component<{onHide: () => any}, {}> {
render() {
return null;
}
}
export default SignInSheet;

View File

@@ -0,0 +1,12 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
export default () => {
// no public implementation
};

View File

@@ -17,7 +17,7 @@ import tracking from './tracking';
import server from './server';
import notifications from './notifications';
import plugins from './plugins';
import user from './user';
import user from './fb-stubs/user';
import pluginManager from './pluginManager';
import reactNative from './reactNative';
import pluginMarketplace from './fb-stubs/pluginMarketplace';

View File

@@ -1,47 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {Store} from '../reducers/index';
import {Logger} from '../fb-interfaces/Logger';
import {login, logout} from '../reducers/user';
import {getUser, logoutUser} from '../fb-stubs/user';
import {sideEffect} from '../utils/sideEffect';
import config from '../fb-stubs/config';
export default (store: Store, _logger: Logger) => {
if (!config.isFBBuild) {
return;
}
getUser()
.then((user) => {
if (user) {
store.dispatch(login(user));
} else {
store.dispatch(logout());
}
})
.catch((e) => {
store.dispatch(logout());
console.warn('Failed to load user:', e);
});
let prevUserName = store.getState().user.name;
sideEffect(
store,
{name: 'logout', throttleMs: 500},
(state) => state.user.name,
(userName) => {
if (prevUserName && !userName) {
logoutUser();
}
prevUserName = userName;
},
);
};

View File

@@ -39,7 +39,7 @@ import {theme, Layout, withTrackingScope} from 'flipper-plugin';
import SetupDoctorScreen, {checkHasNewProblem} from './SetupDoctorScreen';
import SettingsSheet from '../chrome/SettingsSheet';
import WelcomeScreen from './WelcomeScreen';
import SignInSheet from '../chrome/SignInSheet';
import SignInSheet from '../chrome/fb-stubs/SignInSheet';
import {errorCounterAtom} from '../chrome/ConsoleLogs';
import {ToplevelProps} from './SandyApp';
import {useValue} from 'flipper-plugin';