Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Merge pull request #42 from scrum-gang/hotfix
Browse files Browse the repository at this point in the history
Hotfix
  • Loading branch information
CamiloGarciaLaRotta committed Mar 25, 2019
2 parents 75e2b25 + c950d92 commit 4667f1e
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 45 deletions.
43 changes: 25 additions & 18 deletions src/App.re
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
type state = {
id: option(string),
token: option(string),
loading: bool,
};

type action =
Expand All @@ -15,10 +16,10 @@ let make = _children => {
reducer: (action, _state) =>
switch (action) {
| DidMount(maybeId, maybeJwt) =>
ReasonReact.Update({id: maybeId, token: maybeJwt})
ReasonReact.Update({id: maybeId, token: maybeJwt, loading: false})
| Login(maybeId, maybeJwt) =>
ReasonReact.UpdateWithSideEffects(
{id: maybeId, token: maybeJwt},
{id: maybeId, token: maybeJwt, loading: false},
(
_self => {
SyncStorage.refreshId(maybeId);
Expand All @@ -28,11 +29,11 @@ let make = _children => {
)
| Logout =>
ReasonReact.UpdateWithSideEffects(
{id: None, token: None},
{id: None, token: None, loading: false},
(_self => SyncStorage.clear()),
)
},
initialState: () => {id: None, token: None},
initialState: () => {id: None, token: None, loading: true},
didMount: self => {
let handleExpiredToken = () => Logout |> self.send;
let handleRetrievedId = (maybeId, maybeJwt) =>
Expand Down Expand Up @@ -82,21 +83,27 @@ let make = _children => {
render: self =>
<div className="app">
(
switch (self.state.token) {
| None =>
<Login
updateAuth=(
(maybeId, maybeToken) =>
Login(maybeId, maybeToken) |> self.send
self.state.loading ?
<div className="login-size"> <div className="loader" /> </div> :
<div>
(
switch (self.state.token) {
| None =>
<Login
updateAuth=(
(maybeId, maybeToken) =>
Login(maybeId, maybeToken) |> self.send
)
/>
| Some(token) =>
<JobApp
signOutHandler=(_event => self.send(Logout))
id=(Belt.Option.getWithDefault(self.state.id, ""))
jwt=token
/>
}
)
/>
| Some(token) =>
<JobApp
signOutHandler=(_event => self.send(Logout))
id=(Belt.Option.getWithDefault(self.state.id, ""))
jwt=token
/>
}
</div>
)
</div>,
};
2 changes: 1 addition & 1 deletion src/Constants.re
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let linkedinCDNURL = "https://static.licdn.com";

let linkedinCompanyNameLowerCase = "linkedin";

let authUrl = "https://jobhub-authentication.herokuapp.com";
let authUrl = " https://jobhub-authentication-staging.herokuapp.com";

let jobAppUrl = "https://scrum-gang-job-applications.herokuapp.com";

Expand Down
41 changes: 22 additions & 19 deletions src/JobApp.re
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type state = {
error: bool,
success: bool,
loading: bool,
errorCause: string,
};

type action =
Expand All @@ -31,27 +32,22 @@ type action =
| UpdateStatus(string)
| Submit
| SuccesfulSubmit
| FailedSubmit;
| FailedSubmit(string);

let reducer = (action, state) =>
switch (action) {
| UpdateUrl(value) =>
ReasonReact.Update({...state, url: value, error: false})
| UpdateCompany(value) =>
ReasonReact.Update({...state, company: value, error: false})
| UpdatePosition(value) =>
ReasonReact.Update({...state, position: value, error: false})
| UpdateUrl(value) => ReasonReact.Update({...state, url: value})
| UpdateCompany(value) => ReasonReact.Update({...state, company: value})
| UpdatePosition(value) => ReasonReact.Update({...state, position: value})
| UpdatePostedDate(value) =>
ReasonReact.Update({...state, postedDate: value, error: false})
| UpdateDeadline(value) =>
ReasonReact.Update({...state, deadline: value, error: false})
ReasonReact.Update({...state, postedDate: value})
| UpdateDeadline(value) => ReasonReact.Update({...state, deadline: value})
| UpdateCompanyNames(value) =>
ReasonReact.Update({...state, companies: value})
| UpdateResumes(value) => ReasonReact.Update({...state, resumes: value})
| UpdateResumeValue(value) =>
ReasonReact.Update({...state, resumeValue: value, error: false})
| UpdateStatus(value) =>
ReasonReact.Update({...state, status: value, error: false})
ReasonReact.Update({...state, resumeValue: value})
| UpdateStatus(value) => ReasonReact.Update({...state, status: value})
| Submit =>
ReasonReact.UpdateWithSideEffects(
{...state, loading: true, error: false},
Expand All @@ -68,7 +64,7 @@ let reducer = (action, state) =>
~id=state.id,
~jwt=state.jwt,
~callback=() => self.send(SuccesfulSubmit),
~failure=() => self.send(FailedSubmit),
~failure=why => self.send(FailedSubmit(why)),
)
),
)
Expand All @@ -79,12 +75,13 @@ let reducer = (action, state) =>
success: true,
loading: false,
})
| FailedSubmit =>
| FailedSubmit(why) =>
ReasonReact.Update({
...state,
error: true,
success: false,
loading: false,
errorCause: why,
})
};

Expand All @@ -108,6 +105,7 @@ let make = (~signOutHandler, ~id, ~jwt, _children) => {
error: false,
success: false,
loading: false,
errorCause: "",
},
didMount: self => {
let setCompanyNames = x => UpdateCompanyNames(x) |> self.send;
Expand All @@ -132,7 +130,9 @@ let make = (~signOutHandler, ~id, ~jwt, _children) => {
let changeDeadline = x => UpdateDeadline(x) |> self.send;
let changeResumeValue = x => UpdateResumeValue(x) |> self.send;
let changeStatusValue = x => UpdateStatus(x) |> self.send;
let errorMessage = self.state.error ? "Failed to add application" : "";
let errorMessage =
self.state.error ?
"Failed to add application: " ++ self.state.errorCause : "";
let successMessage = self.state.success ? "Added application" : "";
self.state.loading ?
<div className="jobapp-size"> <div className="loader" /> </div> :
Expand Down Expand Up @@ -202,7 +202,7 @@ let make = (~signOutHandler, ~id, ~jwt, _children) => {
name="postedDate"
placeholder=""
value=self.state.postedDate
required=(Js.Boolean.to_js_boolean(false))
required=(Js.Boolean.to_js_boolean(true))
/>
</div>
<div className="form-horizontal-separator">
Expand All @@ -211,6 +211,7 @@ let make = (~signOutHandler, ~id, ~jwt, _children) => {
_type="date"
name="deadline"
value=self.state.deadline
required=(Js.Boolean.to_js_boolean(true))
onChange=(ev => ev |> Utilities.valueFromEvent |> changeDeadline)
/>
</div>
Expand All @@ -219,7 +220,8 @@ let make = (~signOutHandler, ~id, ~jwt, _children) => {
<input
_type="radio"
name="status"
value="applied"
value="Applied"
required=(Js.Boolean.to_js_boolean(true))
onChange=(ev => valueFromEvent(ev) |> changeStatusValue)
/>
("Applied" |> str)
Expand All @@ -228,7 +230,7 @@ let make = (~signOutHandler, ~id, ~jwt, _children) => {
<input
_type="radio"
name="status"
value="toApply"
value="To apply"
onChange=(ev => valueFromEvent(ev) |> changeStatusValue)
/>
("To apply" |> str)
Expand All @@ -237,6 +239,7 @@ let make = (~signOutHandler, ~id, ~jwt, _children) => {
<select
id="resumes"
value=self.state.resumeValue
required=(Js.Boolean.to_js_boolean(true))
onChange=(
evt => Utilities.valueFromEvent(evt) |> changeResumeValue
)>
Expand Down
97 changes: 90 additions & 7 deletions src/Services.re
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
type userId = {id: string};

type postingExistsResponse = {status: bool};

type authResponse = {
iat: int,
exp: int,
Expand Down Expand Up @@ -36,6 +38,8 @@ module Decode = {
token: json |> field("token", string),
id: json |> field("user", userId),
};
let postingExistsResponse = json : postingExistsResponse =>
Json.Decode.{status: json |> field("status", bool)};
let selfResponse = json : selfResponse =>
Json.Decode.{
id: json |> field("_id", string),
Expand Down Expand Up @@ -76,10 +80,13 @@ let authenticate = (~email, ~password, ~callback, ~failure, _self) => {
|> Decode.authResponse
|> (
resp =>
callback(
Js.Option.some(resp.id.id),
Js.Option.some(resp.token),
)
{
Js.log(resp);
callback(
Js.Option.some(resp.id.id),
Js.Option.some(resp.token),
);
}
|> resolve
)
)
Expand All @@ -93,7 +100,47 @@ let authenticate = (~email, ~password, ~callback, ~failure, _self) => {
|> ignore;
};

let submitApplication =
let checkAlreadyApplied = (~url, ~jwt, ~callback, ~failure) => {
let headers =
Fetch.HeadersInit.make({
"Content-Type": "application/json",
"Authorization": "Bearer " ++ jwt,
});
let jobAppURL = Constants.jobAppUrl ++ "/applications/exists?url=" ++ url;
Js.log("HERE " ++ jwt);
Js.log("HERE " ++ url);
Js.Promise.(
Fetch.fetchWithInit(
jobAppURL,
Fetch.RequestInit.make(~method_=Get, ~headers, ~mode=Fetch.CORS, ()),
)
|> then_(response => Fetch.Response.json(response))
|> then_(json =>
json
|> Decode.postingExistsResponse
|> (
res =>
res.status ?
{
failure("Already applied to this URL");
resolve();
} :
{
callback();
resolve();
}
)
)
|> catch(err => {
Js.log(err);
failure("Connection Error");
resolve();
})
)
|> ignore;
};

let submit =
(
~company,
~position,
Expand Down Expand Up @@ -144,19 +191,55 @@ let submitApplication =
callback();
resolve();
| _ =>
failure();
failure("Connection Error");
resolve();
};
})
|> catch(err => {
Js.log(err);
failure();
failure("Connection Error");
resolve();
})
)
|> ignore;
};

let submitApplication =
(
~company,
~position,
~url,
~resume,
~date_posted,
~deadline,
~status,
~id,
~jwt,
~callback,
~failure,
) =>
/** TODO here before anything check if already applied */
checkAlreadyApplied(
~url,
~jwt,
~callback=
_ =>
submit(
~company,
~position,
~url,
~resume,
~date_posted,
~deadline,
~status,
~id,
~jwt,
~callback,
~failure,
),
~failure,
);

let getResumeRevisions = (~id, ~jwt, ~callback, ~failure) => {
let headers =
Fetch.HeadersInit.make({
Expand Down

0 comments on commit 4667f1e

Please sign in to comment.