Skip to content

Instantly share code, notes, and snippets.

@thomas-jeepe
Created October 6, 2017 23:07
Show Gist options
  • Save thomas-jeepe/f58739e7e91ee5700006f487ac5b1910 to your computer and use it in GitHub Desktop.
Save thomas-jeepe/f58739e7e91ee5700006f487ac5b1910 to your computer and use it in GitHub Desktop.
module Verify = {
type state = {
verifying: bool,
token: string
};
type action =
| SendVerification string
| DidVerify;
let component = ReasonReact.reducerComponent "Verify";
let make ::history ::email ::token _children => {
...component,
initialState: fun () => {
verifying: true,
token:
switch token {
| Some token => token
| None => ""
}
},
reducer: fun action _ =>
switch action {
| SendVerification token =>
ReasonReact.SideEffects (
fun _ => {
let _ = Fetch.fetch "haha";
()
}
)
| DidVerify =>
ReasonReact.SideEffects (
fun _ => {
let queries =
Router.Query.stringify {
"email":
switch email {
| Some email => email
| None => raise (Failure "DidVerify called without email")
},
"token": token
};
Router.History.push url::("/launchpad/create-password" ^ queries) state::[] history
}
)
},
render: fun {reduce} =>
switch (email, token) {
| (None, _) => <Router.Redirect to_="/launchpad/login" />
| (Some _, None) =>
<div>
<input
onChange=(
reduce (
fun ev =>
SendVerification (ReactDOMRe.domElementToObj (ReactEventRe.Form.target ev))##value
)
)
/>
</div>
| (Some _, Some _) => <div />
}
};
};
module Invite = {
let component = ReasonReact.statelessComponent "Verify";
let make _children => {
...component,
render: fun _ => <div> (ReasonReact.stringToElement "Verify") </div>
};
};
module CreatePassword = {
let component = ReasonReact.statelessComponent "Verify";
let make _children => {
...component,
render: fun _ => <div> (ReasonReact.stringToElement "Verify") </div>
};
};
module CreateAccount = {
let component = ReasonReact.statelessComponent "Verify";
let make _children => {
...component,
render: fun _ => <div> (ReasonReact.stringToElement "Verify") </div>
};
};
module Login = {
let component = ReasonReact.statelessComponent "Verify";
let make _children => {
...component,
render: fun _ => <div> (ReasonReact.stringToElement "Verify") </div>
};
};
external atob : string => string = "" [@@bs.val];
let decodeToken token => {
let segments = Js.String.split "." token;
let parsed = Js.Json.parseExn (atob segments.(0));
switch (Js.Json.decodeObject parsed) {
| Some obj => obj
| None => raise (Failure "Token was real bad")
}
};
type state = {
token: option string,
lastSelectedAccount: option string
};
let thing = {
token: Dom_storage.getItem "token" Dom_storage.localStorage,
lastSelectedAccount: Dom_storage.getItem "lastSelectedAccount" Dom_storage.localStorage
};
let component = ReasonReact.statelessComponent "Launchpad";
let make _children => {
...component,
render: fun _ =>
<Router.Switch>
<Router.Route
render=(
fun props => {
let queries = Router.History.Location.queries props##location;
let email: option string = Js.Null_undefined.to_opt queries##email;
let token: option string = Js.Null_undefined.to_opt queries##token;
<Verify history=props##history email token />
}
)
path="/launchpad/verify"
/>
<Router.Route
render=(fun _ => <div> (ReasonReact.stringToElement "Invite") </div>)
path="/launchpad/invite"
/>
<Router.Route
render=(fun _ => <div> (ReasonReact.stringToElement "Create Password") </div>)
path="/launchpad/createPassword"
/>
<Router.Route
render=(fun _ => <div> (ReasonReact.stringToElement "Create Account") </div>)
path="/launchpad/createAccount"
/>
<Router.Route
render=(fun _ => <div> (ReasonReact.stringToElement "Login") </div>)
path="/launchpad/login"
/>
</Router.Switch>
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment