Added job list container. Removed all previous migrations.

This commit is contained in:
Patrick Fic
2019-12-06 09:26:50 -08:00
parent f875e9611b
commit ab1e4d5424
85 changed files with 104 additions and 1088 deletions

View File

@@ -10,7 +10,7 @@ export default function Auth() {
useEffect(() => {
return firebase.auth().onAuthStateChanged(async user => {
console.log("user", user);
console.log("User in App Container.js: ", user);
if (user) {
const token = await user.getIdToken();
const idTokenResult = await user.getIdTokenResult();
@@ -31,6 +31,10 @@ export default function Auth() {
setAuthState({ status: "in", user, token });
});
}
console.log("#####Logged In. make a gql call to upsert", user);
} else {
setAuthState({ status: "out" });
}

View File

@@ -10,6 +10,7 @@ import "./App.css";
import HeaderAppBarContainer from "../components/header-app-bar/header-app-bar.container";
import SignIn from "../components/sign-in/sign-in.component";
import initialState from "../graphql/initial-state";
import JobListContainer from "../components/job-list/job-list.container";
//Todo: Issue with this line. Not sure why.
const graphqlEndpoint =
@@ -37,11 +38,11 @@ export default function App({ authState }) {
data: initialState
});
console.log(client);
return (
<ApolloProvider client={client}>
<HeaderAppBarContainer />
<SignIn />
<JobListContainer />
</ApolloProvider>
);
}

View File

@@ -28,6 +28,7 @@ const HeaderAppBarContainer = () => (
<Query query={GET_NAV_ITEMS}>
{({ loading, error, data }) => {
if (loading) return <Spin size="large" />;
if (error) return <Alert message={error.message} />;
return (
<HeaderAppBar
selectedNavItem={selectedNavItem}

View File

@@ -0,0 +1,6 @@
import React from "react";
export default function JobList() {
//console.log("JobList props", this.props);
return <div>JobList</div>;
}

View File

@@ -0,0 +1,28 @@
import React from "react";
import { Query } from "react-apollo";
import { gql } from "apollo-boost";
import { Spin, Alert } from "antd";
import JobList from "./job-list.component";
const GET_JOBS = gql`
query get_jobs {
estimates {
ro_number
}
}
`;
const JobListContainer = () => (
<Query query={GET_JOBS}>
{({ loading, error, data }) => {
if (loading) return <Spin size="large" />;
if (error) return <Alert message={error.message} />;
console.log("JobListContainer Data:", data);
return <JobList jobs={data} />;
}}
</Query>
);
export default JobListContainer;

View File

@@ -1,91 +0,0 @@
import firebase from "firebase/app";
import "firebase/auth";
import "firebase/database";
import React, { useState, useEffect } from "react";
import App from "./App";
const provider = new firebase.auth.GoogleAuthProvider();
// Find these options in your Firebase console
firebase.initializeApp({
apiKey: "xxx",
authDomain: "xxx",
databaseURL: "xxx",
projectId: "xxx",
storageBucket: "xxx",
messagingSenderId: "xxx"
});
export default function Auth() {
const [authState, setAuthState] = useState({ status: "loading" });
useEffect(() => {
return firebase.auth().onAuthStateChanged(async user => {
if (user) {
const token = await user.getIdToken();
const idTokenResult = await user.getIdTokenResult();
const hasuraClaim =
idTokenResult.claims["https://hasura.io/jwt/claims"];
if (hasuraClaim) {
setAuthState({ status: "in", user, token });
} else {
// Check if refresh is required.
const metadataRef = firebase
.database()
.ref("metadata/" + user.uid + "/refreshTime");
metadataRef.on("value", async () => {
// Force refresh to pick up the latest custom claims changes.
const token = await user.getIdToken(true);
setAuthState({ status: "in", user, token });
});
}
} else {
setAuthState({ status: "out" });
}
});
}, []);
const signInWithGoogle = async () => {
try {
await firebase.auth().signInWithPopup(provider);
} catch (error) {
console.log(error);
}
};
const signOut = async () => {
try {
setAuthState({ status: "loading" });
await firebase.auth().signOut();
setAuthState({ status: "out" });
} catch (error) {
console.log(error);
}
};
let content;
if (authState.status === "loading") {
content = null;
} else {
content = (
<>
<div>
{authState.status === "in" ? (
<div>
<h2>Welcome, {authState.user.displayName}</h2>
<button onClick={signOut}>Sign out</button>
</div>
) : (
<button onClick={signInWithGoogle}>Sign in with Google</button>
)}
</div>
<App authState={authState} />
</>
);
}
return <div className="auth">{content}</div>;
}