Skip to content

Commit

Permalink
[#500] Web: Stub out trails front end by crudely copy-pasting submit.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-stacey committed Sep 2, 2019
1 parent fca0dc0 commit 3023034
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 2 deletions.
3 changes: 2 additions & 1 deletion projects/trails/src/Mirza/Trails/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ defaultDatabaseConnectionString = "dbname=devtrails"

corsOrigins :: [CorsMiddleware.Origin]
corsOrigins = [
"http://localhost:8300"
"http://localhost:8080"
, "http://localhost:8300"
, "https://demo.mirza.d61.io"
]

Expand Down
1 change: 1 addition & 0 deletions projects/web/src/components/submit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function Submit(props: SubmitProps) {
}).then(function(res: Response) {
if (res.status === 200) {
alert('Success!');
window.location.href = 'submitTrail';
} else {
alert('Failed with status: ' + res.status);
}
Expand Down
68 changes: 68 additions & 0 deletions projects/web/src/components/submitTrail.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import * as React from "react";
import { Link } from "react-router-dom";

import { myGlobals } from "../globals";

import { AuthState } from "../auth";

export interface QueryProps {
authState: AuthState;
}

export function SubmitTrail(props: QueryProps) {
const trailEntry = [
{
"version": 1,
"timestamp": "2016-07-22T00:00:00Z",
"org": "000000",
"event_id": "00000000-0000-0000-0000-000000000000",
"previous_signatures": [] as string[],
"signature": "todo"
}];

const submitTrail = () => {

return fetch(myGlobals.trailsUrl + '/trail', {
method: 'POST',
body: JSON.stringify(trailEntry),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + props.authState.getToken().idToken,
},
}).then(function(res: Response) {
if (res.status === 200) {
alert('Success!');
window.location.href = 'submit';
} else {
alert('Failed with status: ' + res.status);
}
}).catch(function(err) {
console.log(err);
});
};

return (
<section>
<div className="border-bottom">
<div className="container">
<h3><Link to="/"><i className="fa fa-chevron-left"></i> </Link></h3>
</div>
</div>
<div className="border-bottom pad-tb">
<div className="container">
<h3>New Trail Entry</h3>
<div className="row">
<div className="column border-right">
<button onClick={submitTrail}>Submit Trail Entry</button>
</div>
<div className="column">
<label>Raw Trail Entry</label>
<textarea style={({ height: "20em" })} value={JSON.stringify(trailEntry, null, 2)} readOnly></textarea>
</div>
</div>
</div>
</div>
</section>
);
}
5 changes: 4 additions & 1 deletion projects/web/src/globals.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
declare const OR_SERVICE_URL: string;

export const orUrl: string = OR_SERVICE_URL;

declare const TRAILS_SERVICE_URL: string;
export const trailsUrl: string = TRAILS_SERVICE_URL;

declare const GOOGLE_MAPS_API_KEY: string;
export const googleMapsApiKey: string = GOOGLE_MAPS_API_KEY;

export const myGlobals = {
edapiUrl: 'http://localhost:8020' as string,
orUrl: OR_SERVICE_URL as string,
trailsUrl : TRAILS_SERVICE_URL as string,
googleMapsApiKey: GOOGLE_MAPS_API_KEY as string,
};
4 changes: 4 additions & 0 deletions projects/web/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Home } from "./components/home";
import { NotFound } from "./components/notFound";
import { Scan } from "./components/scan";
import { Submit } from "./components/submit";
import { SubmitTrail } from "./components/submitTrail";

import { authInit, logIn } from "./auth";
import { BusinessRegistry } from "./business-registry";
Expand Down Expand Up @@ -46,6 +47,9 @@ authInit().then((authState) => {
<Route path="/submit" exact render={() =>
<Submit authState={appState.auth} organisation={appState.organisation} ></Submit>} />

<Route path="/submitTrail" exact render={() =>
<SubmitTrail authState={appState.auth} ></SubmitTrail>} />

<Route path="/scan/:scanData*" exact render={({ match }) =>
<Scan authState={appState.auth}
organisation={appState.organisation}
Expand Down
3 changes: 3 additions & 0 deletions projects/web/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ module.exports = (env) => {
'OR_SERVICE_URL': JSON.stringify(env.production
? 'https://registry.mirza.d61.io'
: 'http://localhost:8200'),
'TRAILS_SERVICE_URL': JSON.stringify(env.production
? 'https://trails.mirza.d61.io'
: 'http://localhost:8300'),
'GOOGLE_MAPS_API_KEY': JSON.stringify(process.env.GOOGLE_MAPS_API_KEY),
}),
]
Expand Down

0 comments on commit 3023034

Please sign in to comment.