Added bodyshop querying before starting application. Basic job query and list view.

This commit is contained in:
Patrick Fic
2020-08-12 16:39:03 -07:00
parent 1f8d16370a
commit 7cc384e7ff
14 changed files with 167 additions and 186 deletions

View File

@@ -13,12 +13,15 @@
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": ["**/*"],
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
},
"web": {
"favicon": "./assets/logo240.png"
}
},
"description": ""
}
}

View File

@@ -0,0 +1,10 @@
import React from "react";
import { View, Text } from "react-native";
export default function ErrorDisplay({ errorMessage }) {
return (
<View style={{ backgroundColor: "red" }}>
<Text>{errorMessage}</Text>
</View>
);
}

View File

@@ -0,0 +1,83 @@
import React from "react";
import {
View,
Text,
ActivityIndicator,
ListView,
RefreshControl,
} from "react-native";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectBodyshop } from "../../redux/user/user.selectors";
import { useQuery } from "@apollo/client";
import { QUERY_ALL_ACTIVE_JOBS } from "../../graphql/jobs.queries";
import styles from "../styles";
import {
Container,
Content,
Card,
CardItem,
Icon,
Right,
H1,
} from "native-base";
import { FlatList } from "react-native-gesture-handler";
import ErrorDisplay from "../error-display/error-display.component";
import LoadingDisplay from "../loading-display/loading-display.component";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
});
export function JobListComponent({ bodyshop }) {
const { loading, error, data, refetch } = useQuery(QUERY_ALL_ACTIVE_JOBS, {
variables: {
statuses: bodyshop.md_ro_statuses.open_statuses || ["Open", "Open*"],
},
skip: !bodyshop,
});
const onRefresh = async () => {
await refetch();
};
if (loading) return <LoadingDisplay />;
if (error) return <ErrorDisplay errorMessage={error.message} />;
return (
<FlatList
refreshControl={
<RefreshControl refreshing={loading} onRefresh={onRefresh} />
}
style={{ flex: 1 }}
data={data ? data.jobs : []}
renderItem={renderItem}
/>
);
}
const renderItem = ({ item }) => {
return (
<CardItem>
<View>
<H1>{`${item.est_number}${
item.ro_number ? ` ${item.ro_number}` : ""
}`}</H1>
<Text>{`${item.ownr_fn || ""} ${item.ownr_ln || ""} ${
item.ownr_co_nm || ""
}`}</Text>
<Text>{`${item.v_model_yr || ""} ${item.v_make_desc || ""} ${
item.v_model_desc || ""
}`}</Text>
</View>
<Right>
<Text>{item.ded_amt}</Text>
</Right>
<Right>
<Icon name="arrow-forward" />
</Right>
</CardItem>
);
};
export default connect(mapStateToProps, null)(JobListComponent);

View File

@@ -0,0 +1,14 @@
import React from "react";
import { View, Text } from "react-native";
import { BarIndicator } from "react-native-indicators";
import { Container, Content } from "native-base";
export default function LoadingDisplay({ size, count = 5 }) {
return (
<Container>
<Content>
<BarIndicator size={size || "large"} count={count} />
</Content>
</Container>
);
}

View File

@@ -1,18 +1,7 @@
import { Container, Content } from "native-base";
import React from "react";
import { View, Text, Button } from "react-native";
import { useTranslation } from "react-i18next";
import { useQuery, useLazyQuery, useSubscription } from "@apollo/client";
import { QUERY_BODYSHOP } from "../../graphql/bodyshop.queries.js";
import JobListComponent from "../job-list/job-list.component.jsx";
export default function ScreenJobList({ navigation }) {
const { t } = useTranslation();
const { loading, error, data } = useSubscription(QUERY_BODYSHOP);
console.log("ScreenJobList -> error", error);
console.log("ScreenJobList -> loading", loading);
console.log("BodyshopData", data);
return (
<View>
<Text>This is the Job List.</Text>
<Text>{t("joblist.labels.activejobs")}</Text>
</View>
);
return <JobListComponent />;
}

View File

@@ -47,9 +47,7 @@ const JobStackNavigator = () => (
<JobStack.Screen
name="JobList"
options={({ route }) => ({
title: `${i18n.t("joblist.labels.activejobs")} ${
JSON.stringify(route.params) | "X"
}`,
title: `${i18n.t("joblist.labels.activejobs")}`,
})}
component={ScreenJobList}
/>
@@ -96,19 +94,32 @@ const DrawerNavigator = () => (
</Drawer.Navigator>
);
export function ScreenMainComponent({ checkUserSession, currentUser }) {
export function ScreenMainComponent({
checkUserSession,
currentUser,
bodyshop,
}) {
useEffect(() => {
checkUserSession();
}, [checkUserSession]);
const { t } = useTranslation();
useEffect(() => {
if (currentUser.authorized) console.log("Authed");
//Do the saga shit.
}, [currentUser]);
return (
<NavigationContainer>
{currentUser.authorized === null ? (
<ScreenSplash />
) : currentUser.authorized ? (
bodyshop ? (
<DrawerNavigator />
) : (
<ScreenSplash />
)
) : (
<ScreenSignIn />
)}

View File

@@ -1,7 +1,5 @@
import firebase from "firebase/app";
import * as firebase from "firebase/app";
import "firebase/auth";
import "firebase/database";
import "firebase/firestore";
//const config = JSON.parse(process.env.REACT_APP_FIREBASE_CONFIG);
const config = {
@@ -20,7 +18,6 @@ if (!firebase.apps.length) {
}
export const auth = firebase.auth();
export const firestore = firebase.firestore();
//export const analytics = firebase.analytics();
export default firebase;

View File

@@ -1,65 +1,16 @@
import gql from "graphql-tag";
export const QUERY_BODYSHOP = gql`
subscription QUERY_BODYSHOP {
query QUERY_BODYSHOP {
bodyshops(where: { associations: { active: { _eq: true } } }) {
associations {
authlevel
useremail
user {
authid
email
dashboardlayout
employee {
id
}
}
}
address1
address2
city
country
created_at
email
federal_tax_id
id
insurance_vendor_id
logo_img_path
md_ro_statuses
md_order_statuses
shopname
state
state_tax_id
updated_at
zip_post
shoprates
region_config
md_responsibility_centers
messagingservicesid
template_header
textid
production_config
invoice_tax_rates
inhousevendorid
accountingconfig
appt_length
stripe_acct_id
ssbuckets
scoreboard_target
md_referral_sources
md_messaging_presets
intakechecklist
speedprint
md_parts_locations
md_notes_presets
md_rbac
employees {
id
first_name
last_name
employee_number
cost_center
}
}
}
`;

View File

@@ -8,7 +8,6 @@ import {
from,
} from "@apollo/client";
import { setContext } from "@apollo/client/link/context";
import apolloLogger from "apollo-link-logger";
import { RetryLink } from "@apollo/client/link/retry";
import { WebSocketLink } from "@apollo/client/link/ws";
import { SubscriptionClient } from "subscriptions-transport-ws";
@@ -116,17 +115,18 @@ const retryLink = new RetryLink({
},
});
const middlewares = [];
if (process.env.NODE_ENV === "development") {
middlewares.push(apolloLogger);
}
// const middlewares = [];
// if (process.env.NODE_ENV === "development") {
// middlewares.push(apolloLogger);
// }
middlewares.push(retryLink.concat(errorLink.concat(authLink.concat(link))));
// middlewares.push(retryLink.concat(errorLink.concat(authLink.concat(link))));
const cache = new InMemoryCache({});
export const client = new ApolloClient({
//link: ApolloLink.from(middlewares),
//link: from([apolloLogger, errorLink, authLink, link]),
link: from([authLink, link]),
cache,
// connectToDevTools: process.env.NODE_ENV !== "production",

View File

@@ -15,12 +15,6 @@
"@react-navigation/drawer": "^5.9.0",
"@react-navigation/native": "^5.7.3",
"@react-navigation/stack": "^5.9.0",
"apollo-link-context": "^1.0.20",
"apollo-link-error": "^1.1.13",
"apollo-link-http": "^1.5.17",
"apollo-link-logger": "^1.2.3",
"apollo-link-retry": "^2.2.16",
"apollo-link-ws": "^1.0.20",
"expo": "~38.0.8",
"expo-font": "~8.2.1",
"expo-localization": "~8.2.1",
@@ -35,6 +29,7 @@
"react-i18next": "^11.7.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz",
"react-native-gesture-handler": "~1.6.0",
"react-native-indicators": "^0.17.0",
"react-native-reanimated": "~1.9.0",
"react-native-safe-area-context": "~3.0.7",
"react-native-screens": "~2.9.0",

View File

@@ -10,7 +10,11 @@ const sagaMiddleWare = createSagaMiddleware();
const middlewares = [sagaMiddleWare];
if (process.env.NODE_ENV === "development") {
middlewares.push(createLogger({ collapsed: true, diff: true }));
middlewares.push(
createLogger({
collapsed: true,
})
);
}
const enhancer = compose(

View File

@@ -15,8 +15,11 @@ import {
updateUserDetailsSuccess,
validatePasswordResetFailure,
validatePasswordResetSuccess,
setBodyshop,
} from "./user.actions";
import UserActionTypes from "./user.types";
import { client } from "../../graphql/client";
import { QUERY_BODYSHOP } from "../../graphql/bodyshop.queries";
export function* onEmailSignInStart() {
yield takeLatest(UserActionTypes.EMAIL_SIGN_IN_START, signInWithEmail);
@@ -75,7 +78,6 @@ export function* signOutStart() {
yield auth.signOut();
yield put(signOutSuccess());
localStorage.removeItem("token");
} catch (error) {
yield put(signOutFailure(error.message));
}
@@ -99,7 +101,13 @@ export function* onSignInSuccess() {
}
export function* signInSuccessSaga({ payload }) {
//yield logImEXEvent("redux_sign_in_success");
try {
const shop = yield client.query({ query: QUERY_BODYSHOP });
yield put(setBodyshop(shop.data.bodyshops[0]));
} catch (error) {
console.log("UHOH. Couldn't get shop details.", error);
}
}
export function* onSendPasswordResetStart() {

View File

@@ -14,6 +14,7 @@ const UserActionTypes = {
SET_USER_LANGUAGE: "SET_USER_LANGUAGE",
UPDATE_USER_DETAILS: "UPDATE_USER_DETAILS",
UPDATE_USER_DETAILS_SUCCESS: "UPDATE_USER_DETAILS_SUCCESS",
QUERY_SHOP_DETAILS: "QUERY_SHOP_DETAILS",
SET_SHOP_DETAILS: "SET_SHOP_DETAILS",
SET_INSTANCE_ID: "SET_INSTANCE_ID",
CHECK_INSTANCE_ID: "CHECK_INSTANCE_ID",

105
yarn.lock
View File

@@ -1706,7 +1706,7 @@
dependencies:
"@types/yargs-parser" "*"
"@types/zen-observable@0.8.0", "@types/zen-observable@^0.8.0":
"@types/zen-observable@^0.8.0":
version "0.8.0"
resolved "https://registry.yarnpkg.com/@types/zen-observable/-/zen-observable-0.8.0.tgz#8b63ab7f1aa5321248aad5ac890a485656dcea4d"
integrity sha512-te5lMAWii1uEJ4FwLjzdlbw3+n0FZNOvFXHxQDKeT0dilh7HOzdMzV2TrJVUzq8ep7J4Na8OUYPRLSQkJHAlrg==
@@ -1734,13 +1734,6 @@
dependencies:
tslib "^1.9.3"
"@wry/equality@^0.1.2":
version "0.1.11"
resolved "https://registry.yarnpkg.com/@wry/equality/-/equality-0.1.11.tgz#35cb156e4a96695aa81a9ecc4d03787bc17f1790"
integrity sha512-mwEVBDUVODlsQQ5dfuLUS5/Tf7jqUKyhKYHmVi4fPB6bDMOfWvUPJmKgS1Z7Za/sOI3vzWt4+O7yCiL/70MogA==
dependencies:
tslib "^1.9.3"
"@wry/equality@^0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@wry/equality/-/equality-0.2.0.tgz#a312d1b6a682d0909904c2bcd355b02303104fb7"
@@ -1868,83 +1861,6 @@ anymatch@^2.0.0:
micromatch "^3.1.4"
normalize-path "^2.1.1"
apollo-link-context@^1.0.20:
version "1.0.20"
resolved "https://registry.yarnpkg.com/apollo-link-context/-/apollo-link-context-1.0.20.tgz#1939ac5dc65d6dff0c855ee53521150053c24676"
integrity sha512-MLLPYvhzNb8AglNsk2NcL9AvhO/Vc9hn2ZZuegbhRHGet3oGr0YH9s30NS9+ieoM0sGT11p7oZ6oAILM/kiRBA==
dependencies:
apollo-link "^1.2.14"
tslib "^1.9.3"
apollo-link-error@^1.1.13:
version "1.1.13"
resolved "https://registry.yarnpkg.com/apollo-link-error/-/apollo-link-error-1.1.13.tgz#c1a1bb876ffe380802c8df0506a32c33aad284cd"
integrity sha512-jAZOOahJU6bwSqb2ZyskEK1XdgUY9nkmeclCrW7Gddh1uasHVqmoYc4CKdb0/H0Y1J9lvaXKle2Wsw/Zx1AyUg==
dependencies:
apollo-link "^1.2.14"
apollo-link-http-common "^0.2.16"
tslib "^1.9.3"
apollo-link-http-common@^0.2.16:
version "0.2.16"
resolved "https://registry.yarnpkg.com/apollo-link-http-common/-/apollo-link-http-common-0.2.16.tgz#756749dafc732792c8ca0923f9a40564b7c59ecc"
integrity sha512-2tIhOIrnaF4UbQHf7kjeQA/EmSorB7+HyJIIrUjJOKBgnXwuexi8aMecRlqTIDWcyVXCeqLhUnztMa6bOH/jTg==
dependencies:
apollo-link "^1.2.14"
ts-invariant "^0.4.0"
tslib "^1.9.3"
apollo-link-http@^1.5.17:
version "1.5.17"
resolved "https://registry.yarnpkg.com/apollo-link-http/-/apollo-link-http-1.5.17.tgz#499e9f1711bf694497f02c51af12d82de5d8d8ba"
integrity sha512-uWcqAotbwDEU/9+Dm9e1/clO7hTB2kQ/94JYcGouBVLjoKmTeJTUPQKcJGpPwUjZcSqgYicbFqQSoJIW0yrFvg==
dependencies:
apollo-link "^1.2.14"
apollo-link-http-common "^0.2.16"
tslib "^1.9.3"
apollo-link-logger@^1.2.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/apollo-link-logger/-/apollo-link-logger-1.2.3.tgz#1f3e6f7849ce7a7e3aa822141fe062cfa278b1e1"
integrity sha512-GaVwdHyXmawfvBlHfZkFkBHH3+YH7wibzSCc4/YpIbPVtbtZqi0Qop18w++jgpw385W083DMOdYe2eJsKkZdag==
apollo-link-retry@^2.2.16:
version "2.2.16"
resolved "https://registry.yarnpkg.com/apollo-link-retry/-/apollo-link-retry-2.2.16.tgz#745ff51e60a7a68b34c8d382832856c43a9c306c"
integrity sha512-7F9+meFAz4dw5gtgtLsRFqJW6QzNOhTzt5R5Hsy+yFhkTW9LddgYO7gxN9n7RN/7Ouosh3TcpUkdHs2laC+0sA==
dependencies:
"@types/zen-observable" "0.8.0"
apollo-link "^1.2.14"
tslib "^1.9.3"
apollo-link-ws@^1.0.20:
version "1.0.20"
resolved "https://registry.yarnpkg.com/apollo-link-ws/-/apollo-link-ws-1.0.20.tgz#dfad44121f8445c6d7b7f8101a1b24813ba008ed"
integrity sha512-mjSFPlQxmoLArpHBeUb2Xj+2HDYeTaJqFGOqQ+I8NVJxgL9lJe84PDWcPah/yMLv3rB7QgBDSuZ0xoRFBPlySw==
dependencies:
apollo-link "^1.2.14"
tslib "^1.9.3"
apollo-link@^1.2.14:
version "1.2.14"
resolved "https://registry.yarnpkg.com/apollo-link/-/apollo-link-1.2.14.tgz#3feda4b47f9ebba7f4160bef8b977ba725b684d9"
integrity sha512-p67CMEFP7kOG1JZ0ZkYZwRDa369w5PIjtMjvrQd/HnIV8FRsHRqLqK+oAZQnFa1DDdZtOtHTi+aMIW6EatC2jg==
dependencies:
apollo-utilities "^1.3.0"
ts-invariant "^0.4.0"
tslib "^1.9.3"
zen-observable-ts "^0.8.21"
apollo-utilities@^1.3.0:
version "1.3.4"
resolved "https://registry.yarnpkg.com/apollo-utilities/-/apollo-utilities-1.3.4.tgz#6129e438e8be201b6c55b0f13ce49d2c7175c9cf"
integrity sha512-pk2hiWrCXMAy2fRPwEyhvka+mqwzeP60Jr1tRYi5xru+3ko94HI9o6lK0CT33/w4RDlxWchmdhDCrvdr+pHCig==
dependencies:
"@wry/equality" "^0.1.2"
fast-json-stable-stringify "^2.0.0"
ts-invariant "^0.4.0"
tslib "^1.10.0"
argparse@^1.0.7:
version "1.0.10"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
@@ -5301,6 +5217,13 @@ react-native-gesture-handler@~1.6.0:
invariant "^2.2.4"
prop-types "^15.7.2"
react-native-indicators@^0.17.0:
version "0.17.0"
resolved "https://registry.yarnpkg.com/react-native-indicators/-/react-native-indicators-0.17.0.tgz#92f95efaf5fb53be576dfe4e1980a25655a93f55"
integrity sha512-s23em477GHGxWeGczWrixScAZD6tQU4mx1fttlrwhEGKOxhBgp55Kh3RoD9Wj4yna4e5W35xQNoPqoJAT6QW5A==
dependencies:
prop-types "^15.5.10"
react-native-iphone-x-helper@^1.0.3, react-native-iphone-x-helper@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/react-native-iphone-x-helper/-/react-native-iphone-x-helper-1.2.1.tgz#645e2ffbbb49e80844bb4cbbe34a126fda1e6772"
@@ -6191,7 +6114,7 @@ toidentifier@1.0.0:
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553"
integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==
ts-invariant@^0.4.0, ts-invariant@^0.4.4:
ts-invariant@^0.4.4:
version "0.4.4"
resolved "https://registry.yarnpkg.com/ts-invariant/-/ts-invariant-0.4.4.tgz#97a523518688f93aafad01b0e80eb803eb2abd86"
integrity sha512-uEtWkFM/sdZvRNNDL3Ehu4WVpwaulhwQszV8mrtcdeE8nN00BV9mAmQ88RkrBhFgl9gMgvjJLAQcZbnPXI9mlA==
@@ -6681,15 +6604,7 @@ yargs@^15.0.2, yargs@^15.1.0:
y18n "^4.0.0"
yargs-parser "^18.1.2"
zen-observable-ts@^0.8.21:
version "0.8.21"
resolved "https://registry.yarnpkg.com/zen-observable-ts/-/zen-observable-ts-0.8.21.tgz#85d0031fbbde1eba3cd07d3ba90da241215f421d"
integrity sha512-Yj3yXweRc8LdRMrCC8nIc4kkjWecPAUVh0TI0OUrWXx6aX790vLcDlWca6I4vsyCGH3LpWxq0dJRcMOFoVqmeg==
dependencies:
tslib "^1.9.3"
zen-observable "^0.8.0"
zen-observable@^0.8.0, zen-observable@^0.8.14:
zen-observable@^0.8.14:
version "0.8.15"
resolved "https://registry.yarnpkg.com/zen-observable/-/zen-observable-0.8.15.tgz#96415c512d8e3ffd920afd3889604e30b9eaac15"
integrity sha512-PQ2PC7R9rslx84ndNBZB/Dkv8V8fZEpk83RLgXtYd0fwUgEjseMn1Dgajh2x6S8QbZAFa9p2qVCEuYZNgve0dQ==