mirror of
https://gitlab.com/comunic/comunicconsole
synced 2024-11-23 13:59:23 +00:00
Can send requests to server
This commit is contained in:
parent
e9c631e78a
commit
b1929fc21f
3
public/config.json
Normal file
3
public/config.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"api_url": "https://devweb.local/comunic/api-v2/admin/"
|
||||||
|
}
|
46
src/App.tsx
46
src/App.tsx
@ -1,30 +1,30 @@
|
|||||||
import React from 'react';
|
import React from "react";
|
||||||
import './App.css';
|
import "./App.css";
|
||||||
import { createMuiTheme, ThemeProvider } from '@material-ui/core';
|
import { createMuiTheme, ThemeProvider } from "@material-ui/core";
|
||||||
import { ApplicationDialogsProvider } from './ui/widgets/DialogsProvider';
|
import { ApplicationDialogsProvider } from "./ui/widgets/DialogsProvider";
|
||||||
import { lightBlue, pink } from '@material-ui/core/colors';
|
import { lightBlue, pink } from "@material-ui/core/colors";
|
||||||
import { InitWidget } from './ui/widgets/InitWidget';
|
import { InitWidget } from "./ui/widgets/InitWidget";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const darkTheme = createMuiTheme({
|
const darkTheme = createMuiTheme({
|
||||||
palette: {
|
palette: {
|
||||||
type: 'dark',
|
type: "dark",
|
||||||
primary: lightBlue,
|
primary: lightBlue,
|
||||||
secondary: pink,
|
secondary: pink,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ThemeProvider theme={darkTheme}>
|
<ThemeProvider theme={darkTheme}>
|
||||||
<div className="App">
|
<div className="App">
|
||||||
{/* Holder of dialogs */}
|
{/* Holder of dialogs */}
|
||||||
<ApplicationDialogsProvider></ApplicationDialogsProvider>
|
<ApplicationDialogsProvider></ApplicationDialogsProvider>
|
||||||
|
|
||||||
{/* Initialization widget */}
|
{/* Initialization widget */}
|
||||||
<InitWidget></InitWidget>
|
<InitWidget></InitWidget>
|
||||||
</div>
|
</div>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
36
src/helpers/APIHelper.ts
Normal file
36
src/helpers/APIHelper.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* API request helper
|
||||||
|
*
|
||||||
|
* @author Pierre Hubert
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { ConfigHelper } from "./ConfigHelper";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform an API request
|
||||||
|
*
|
||||||
|
* @param uri Target URI on the server
|
||||||
|
* @param args Arguments to include in the request
|
||||||
|
* @returns The result of the request, in case of success,
|
||||||
|
* @throws An exception in case of failure
|
||||||
|
*/
|
||||||
|
export async function serverRequest(uri: string, args?: any): Promise<any> {
|
||||||
|
const requestArguments = args || {};
|
||||||
|
|
||||||
|
const fd = new FormData();
|
||||||
|
for (let arg in requestArguments) {
|
||||||
|
if (requestArguments.hasOwnProperty(arg))
|
||||||
|
fd.append(arg, requestArguments[arg]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO : add access token, once supported
|
||||||
|
|
||||||
|
const result = await (
|
||||||
|
await fetch((await ConfigHelper.apiURL()) + uri, {
|
||||||
|
method: "POST",
|
||||||
|
body: fd,
|
||||||
|
})
|
||||||
|
).json();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
@ -4,13 +4,30 @@
|
|||||||
* @author Pierre Hubert
|
* @author Pierre Hubert
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export class AccountHelper {
|
import { serverRequest } from "./APIHelper";
|
||||||
/**
|
|
||||||
* Check whether access token are available
|
export interface AuthOptions {
|
||||||
* or not
|
reset_token: string;
|
||||||
*/
|
}
|
||||||
static get hasAccessToken() : boolean {
|
|
||||||
// TODO : implement support
|
export class AccountHelper {
|
||||||
return false;
|
/**
|
||||||
}
|
* Check whether access token are available
|
||||||
|
* or not
|
||||||
|
*/
|
||||||
|
static get hasAccessToken(): boolean {
|
||||||
|
// TODO : implement support
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get authentication options for a given email address
|
||||||
|
*
|
||||||
|
* @param mail Requested email
|
||||||
|
*/
|
||||||
|
static async getAuthOptions(mail: string): Promise<AuthOptions> {
|
||||||
|
return await serverRequest("accounts/auth_options", {
|
||||||
|
mail: mail,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
22
src/helpers/ConfigHelper.ts
Normal file
22
src/helpers/ConfigHelper.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* Configuration helper
|
||||||
|
*
|
||||||
|
* @author Pierre Hubert
|
||||||
|
*/
|
||||||
|
|
||||||
|
let cache: any;
|
||||||
|
|
||||||
|
export class ConfigHelper {
|
||||||
|
static async load() {
|
||||||
|
if (!cache)
|
||||||
|
cache = JSON.parse(await (await fetch("/config.json")).text());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get server API url
|
||||||
|
*/
|
||||||
|
static async apiURL(): Promise<string> {
|
||||||
|
await this.load();
|
||||||
|
return cache.api_url;
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,7 @@ import {
|
|||||||
|
|
||||||
import LockOutlinedIcon from "@material-ui/icons/LockOutlined";
|
import LockOutlinedIcon from "@material-ui/icons/LockOutlined";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import { AccountHelper } from "../../helpers/AccountHelper";
|
||||||
import { matAlert } from "../widgets/DialogsProvider";
|
import { matAlert } from "../widgets/DialogsProvider";
|
||||||
|
|
||||||
function Copyright() {
|
function Copyright() {
|
||||||
@ -63,7 +64,9 @@ export class LoginRoute extends React.Component<{}, LoginRouteState> {
|
|||||||
|
|
||||||
if (!this.canSubmit) return;
|
if (!this.canSubmit) return;
|
||||||
|
|
||||||
matAlert("good");
|
AccountHelper.getAuthOptions(this.state.currEmail).then((r) =>
|
||||||
|
matAlert("reset token => " + r.reset_token)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -97,7 +100,7 @@ export class LoginRoute extends React.Component<{}, LoginRouteState> {
|
|||||||
<Typography
|
<Typography
|
||||||
component="h1"
|
component="h1"
|
||||||
variant="h5"
|
variant="h5"
|
||||||
style={{ margin: "10px" }}
|
style={{ margin: "10px", marginBottom: "50px" }}
|
||||||
>
|
>
|
||||||
Comunic Console
|
Comunic Console
|
||||||
</Typography>
|
</Typography>
|
||||||
|
Loading…
Reference in New Issue
Block a user