diff --git a/projects/trails/src/Mirza/Trails/Main.hs b/projects/trails/src/Mirza/Trails/Main.hs index 17e14ffb..4958e5c6 100644 --- a/projects/trails/src/Mirza/Trails/Main.hs +++ b/projects/trails/src/Mirza/Trails/Main.hs @@ -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" ] diff --git a/projects/web/src/components/submit.tsx b/projects/web/src/components/submit.tsx index 431fd09d..3f9983a4 100644 --- a/projects/web/src/components/submit.tsx +++ b/projects/web/src/components/submit.tsx @@ -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); } diff --git a/projects/web/src/components/submitTrail.tsx b/projects/web/src/components/submitTrail.tsx new file mode 100644 index 00000000..761f3e73 --- /dev/null +++ b/projects/web/src/components/submitTrail.tsx @@ -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 ( +
+
+
+

+
+
+
+
+

New Trail Entry

+
+
+ +
+
+ + +
+
+
+
+
+ ); +} diff --git a/projects/web/src/globals.ts b/projects/web/src/globals.ts index 2bdb1092..e52ed898 100644 --- a/projects/web/src/globals.ts +++ b/projects/web/src/globals.ts @@ -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, }; diff --git a/projects/web/src/index.tsx b/projects/web/src/index.tsx index 71c112d4..535e027e 100644 --- a/projects/web/src/index.tsx +++ b/projects/web/src/index.tsx @@ -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"; @@ -46,6 +47,9 @@ authInit().then((authState) => { } /> + + } /> + { '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), }), ]