feat: 登录界面

This commit is contained in:
Ivan Li 2021-07-10 18:52:45 +08:00
parent c6b09aa075
commit 5350966785
9 changed files with 125 additions and 41 deletions

2
.gitignore vendored
View File

@ -21,3 +21,5 @@
npm-debug.log* npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
.vscode/chrome

3
.vscode/launch.json vendored
View File

@ -8,10 +8,9 @@
"name": "chrome", "name": "chrome",
"type": "chrome", "type": "chrome",
"request": "launch", "request": "launch",
"reAttach": true,
"url": "http://fennec.localhost/", "url": "http://fennec.localhost/",
"webRoot": "${workspaceFolder}", "webRoot": "${workspaceFolder}",
"userDataDir": "/Users/ivan/Projects/.chrome" "userDataDir": ".vscode/chrome"
} }
] ]
} }

15
package-lock.json generated
View File

@ -34,7 +34,7 @@
"formik-material-ui": "^3.0.1", "formik-material-ui": "^3.0.1",
"formik-material-ui-pickers": "^0.0.12", "formik-material-ui-pickers": "^0.0.12",
"graphql": "^15.5.0", "graphql": "^15.5.0",
"graphql-scalars": "^1.9.3", "graphql-scalars": "^1.10.0",
"material-ui-confirm": "^2.1.2", "material-ui-confirm": "^2.1.2",
"notistack": "^1.0.6", "notistack": "^1.0.6",
"ramda": "^0.27.1", "ramda": "^0.27.1",
@ -11326,9 +11326,9 @@
} }
}, },
"node_modules/graphql-scalars": { "node_modules/graphql-scalars": {
"version": "1.9.3", "version": "1.10.0",
"resolved": "https://registry.npmjs.org/graphql-scalars/-/graphql-scalars-1.9.3.tgz", "resolved": "https://registry.npmjs.org/graphql-scalars/-/graphql-scalars-1.10.0.tgz",
"integrity": "sha512-vP71Og4ALfe3PCk6T+B7LcJHH55gL0tYidmAE/kWT3ScE2FUCFS7iiMXFQXjCaYLi8nZcRLn9HuejGcjZ8kRug==", "integrity": "sha512-LONlj8FfhA2iGpkZJWf5e4PVAHXxnZEHSOEvowLYvNXl/TNnhIck8VmE+lren/aa6GKrG+lZufo5lgnyjxcF6g==",
"dependencies": { "dependencies": {
"tslib": "~2.2.0" "tslib": "~2.2.0"
}, },
@ -28129,6 +28129,7 @@
"integrity": "sha512-hS4pxwn1ZGXVkmgD4tpFpaumUaAg2ZzbTrxltfC5yPw4BJV+mGkfnQOB4VpWEYZw2jv65Z0wLwDE/piQiPPZ3w==", "integrity": "sha512-hS4pxwn1ZGXVkmgD4tpFpaumUaAg2ZzbTrxltfC5yPw4BJV+mGkfnQOB4VpWEYZw2jv65Z0wLwDE/piQiPPZ3w==",
"requires": { "requires": {
"@babel/runtime": "^7.6.0", "@babel/runtime": "^7.6.0",
"@date-io/core": "1.x",
"@types/styled-jsx": "^2.2.8", "@types/styled-jsx": "^2.2.8",
"clsx": "^1.0.2", "clsx": "^1.0.2",
"react-transition-group": "^4.0.0", "react-transition-group": "^4.0.0",
@ -34355,9 +34356,9 @@
} }
}, },
"graphql-scalars": { "graphql-scalars": {
"version": "1.9.3", "version": "1.10.0",
"resolved": "https://registry.npmjs.org/graphql-scalars/-/graphql-scalars-1.9.3.tgz", "resolved": "https://registry.npmjs.org/graphql-scalars/-/graphql-scalars-1.10.0.tgz",
"integrity": "sha512-vP71Og4ALfe3PCk6T+B7LcJHH55gL0tYidmAE/kWT3ScE2FUCFS7iiMXFQXjCaYLi8nZcRLn9HuejGcjZ8kRug==", "integrity": "sha512-LONlj8FfhA2iGpkZJWf5e4PVAHXxnZEHSOEvowLYvNXl/TNnhIck8VmE+lren/aa6GKrG+lZufo5lgnyjxcF6g==",
"requires": { "requires": {
"tslib": "~2.2.0" "tslib": "~2.2.0"
}, },

View File

@ -29,7 +29,7 @@
"formik-material-ui": "^3.0.1", "formik-material-ui": "^3.0.1",
"formik-material-ui-pickers": "^0.0.12", "formik-material-ui-pickers": "^0.0.12",
"graphql": "^15.5.0", "graphql": "^15.5.0",
"graphql-scalars": "^1.9.3", "graphql-scalars": "^1.10.0",
"material-ui-confirm": "^2.1.2", "material-ui-confirm": "^2.1.2",
"notistack": "^1.0.6", "notistack": "^1.0.6",
"ramda": "^0.27.1", "ramda": "^0.27.1",

View File

@ -0,0 +1,45 @@
import { createContext, useContext, useState } from "react";
import { FC } from "react";
import { Login } from "./login";
export interface AuthContext {
accessToken: string | undefined;
setAccessToken: (token: string) => void;
setRefreshToken: (token: string) => void;
refreshToken: string | undefined;
login: (dto: any) => void;
account?: any;
setAccount: (dto: any) => void;
}
const Context = createContext({} as AuthContext);
export const useAuth = () => useContext(Context);
export const AuthProvider: FC = ({ children }) => {
const [accessToken, setAccessToken] = useState<string>();
const [refreshToken, setRefreshToken] = useState<string>();
const [account, setAccount] = useState<any>();
const login = (dto: any) => {
setAccessToken(dto.accessToken);
setRefreshToken(dto.refreshToken);
setAccount(dto.account);
};
return (
<Context.Provider
value={{
accessToken,
setAccessToken,
refreshToken,
setRefreshToken,
login,
account,
setAccount,
}}
>
{children}
{/* {accessToken ? null : <Login />} */}
</Context.Provider>
);
};

View File

@ -0,0 +1,51 @@
import { makeStyles } from "@material-ui/core";
import { FC, useEffect, useRef } from "react";
import { useAuth } from "./auth.provider";
const useStyles = makeStyles({
iframe: {
height: "300px",
width: "500px",
position: "absolute",
top: "100px",
left: "50%",
transform: "translateX(-50%)",
},
});
export const Login: FC = () => {
const iframeRef = useRef<HTMLIFrameElement>(null);
const { login } = useAuth();
useEffect(() => {
const iframe = iframeRef.current;
if (!iframe) {
return;
}
let messagePort: MessagePort;
const onLoad = (ev: MessageEvent) => {
if (ev.data !== "init-channel") {
return;
}
messagePort = ev.ports?.[0] as MessagePort;
messagePort.onmessage = (ev: MessageEvent) => {
if (ev.data?.type === "logged") {
login(ev.data.payload);
}
};
};
window.addEventListener("message", onLoad);
return () => {
window.removeEventListener("message", onLoad);
};
}, [login]);
const classes = useStyles();
return (
<iframe
ref={iframeRef}
className={classes.iframe}
title="Auth"
src="http://user.localhost/auth/login"
></iframe>
);
};

View File

@ -1949,22 +1949,6 @@
"description": null, "description": null,
"fields": null, "fields": null,
"inputFields": [ "inputFields": [
{
"name": "projectId",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "branch", "name": "branch",
"description": null, "description": null,

View File

@ -255,7 +255,6 @@ export enum TaskStatuses {
} }
export type UpdatePipelineInput = { export type UpdatePipelineInput = {
projectId: Scalars['String'];
branch: Scalars['String']; branch: Scalars['String'];
name: Scalars['String']; name: Scalars['String'];
workUnitMetadata: WorkUnitMetadataInput; workUnitMetadata: WorkUnitMetadataInput;

View File

@ -10,24 +10,27 @@ import DateFnsUtils from "@date-io/date-fns";
import zhLocale from "date-fns/locale/zh-CN"; import zhLocale from "date-fns/locale/zh-CN";
import { ConfirmProvider } from "material-ui-confirm"; import { ConfirmProvider } from "material-ui-confirm";
import { SnackbarProvider } from "notistack"; import { SnackbarProvider } from "notistack";
import Router from './commons/route/router'; import Router from "./commons/route/router";
import { AuthProvider } from "./commons/auth/auth.provider";
ReactDOM.render( ReactDOM.render(
<React.StrictMode> <React.StrictMode>
<ConfirmProvider> <ConfirmProvider>
<SnackbarProvider maxSnack={5}> <SnackbarProvider maxSnack={5}>
<FennecApolloClientProvider> <FennecApolloClientProvider>
<MuiPickersUtilsProvider utils={DateFnsUtils} locale={zhLocale}> <MuiPickersUtilsProvider utils={DateFnsUtils} locale={zhLocale}>
<AuthProvider>
<Router> <Router>
<App /> <App />
</Router> </Router>
</AuthProvider>
</MuiPickersUtilsProvider> </MuiPickersUtilsProvider>
</FennecApolloClientProvider> </FennecApolloClientProvider>
</SnackbarProvider> </SnackbarProvider>
</ConfirmProvider> </ConfirmProvider>
</React.StrictMode>, </React.StrictMode>,
document.getElementById("root") document.getElementById("root")
); );
// If you want to start measuring performance in your app, pass a function // If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log)) // to log results (for example: reportWebVitals(console.log))