Capture Photo Info & Change Env Dynamically.

This commit is contained in:
Patrick Fic
2021-05-20 09:36:16 -07:00
parent 48514e72a5
commit 5647a52ef0
10 changed files with 62 additions and 87 deletions

3
App.js
View File

@@ -11,8 +11,7 @@ import { persistor, store } from "./redux/store";
import "./translations/i18n"; import "./translations/i18n";
Sentry.init({ Sentry.init({
dsn: dsn: "https://8d6c3de1940a4e4f8b81cf4d2150bdea@o492140.ingest.sentry.io/5558869",
"https://8d6c3de1940a4e4f8b81cf4d2150bdea@o492140.ingest.sentry.io/5558869",
enableInExpoDevelopment: true, enableInExpoDevelopment: true,
// debug: true, // Sentry will try to print out useful debugging information if something goes wrong with sending an event. Set this to `false` in production. // debug: true, // Sentry will try to print out useful debugging information if something goes wrong with sending an event. Set this to `false` in production.
}); });

View File

@@ -32,6 +32,8 @@ export default function JobDocumentsComponent({ job, loading, refetch }) {
[job.documents] [job.documents]
); );
console.log(job.documents);
return ( return (
<View style={{ flex: 1 }}> <View style={{ flex: 1 }}>
<FlatList <FlatList

View File

@@ -1,14 +1,17 @@
import { useApolloClient } from "@apollo/client"; import { useApolloClient } from "@apollo/client";
import { Ionicons } from "@expo/vector-icons"; import { Ionicons } from "@expo/vector-icons";
//const limit = plimit(2);
import * as FileSystem from "expo-file-system";
import { AssetsSelector } from "expo-images-picker"; import { AssetsSelector } from "expo-images-picker";
import * as MediaLibrary from "expo-media-library"; import * as MediaLibrary from "expo-media-library";
import _ from "lodash"; import _ from "lodash";
import React, { useCallback, useState } from "react"; import React, { useCallback, useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { StyleSheet, Text, View, Alert } from "react-native"; import { Alert, StyleSheet, Text, View } from "react-native";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { createStructuredSelector } from "reselect"; import { createStructuredSelector } from "reselect";
import { logImEXEvent } from "../../firebase/firebase.analytics"; import { logImEXEvent } from "../../firebase/firebase.analytics";
import { GET_DOC_SIZE_TOTALS } from "../../graphql/documents.queries";
import { import {
selectCurrentCameraJobId, selectCurrentCameraJobId,
selectDeleteAfterUpload, selectDeleteAfterUpload,
@@ -21,9 +24,6 @@ import { handleUpload } from "../../util/document-upload.utility";
import CameraSelectJob from "../camera-select-job/camera-select-job.component"; import CameraSelectJob from "../camera-select-job/camera-select-job.component";
import UploadDeleteSwitch from "../upload-delete-switch/upload-delete-switch.component"; import UploadDeleteSwitch from "../upload-delete-switch/upload-delete-switch.component";
import UploadProgress from "../upload-progress/upload-progress.component"; import UploadProgress from "../upload-progress/upload-progress.component";
import { GET_DOC_SIZE_TOTALS } from "../../graphql/documents.queries";
//const limit = plimit(2);
import * as FileSystem from "expo-file-system";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
currentUser: selectCurrentUser, currentUser: selectCurrentUser,
@@ -76,7 +76,7 @@ export function ImageBrowserScreen({
const info = await FileSystem.getInfoAsync(val.uri, { size: true }); const info = await FileSystem.getInfoAsync(val.uri, { size: true });
return (await acc) + info.size; return (await acc) + info.size;
}, 0); }, 0);
console.log("data :>> ", data);
console.log( console.log(
"Size of uploaded documents.", "Size of uploaded documents.",
queryData.data.documents_aggregate.aggregate.sum.size, queryData.data.documents_aggregate.aggregate.sum.size,
@@ -108,6 +108,7 @@ export function ImageBrowserScreen({
let filename; let filename;
//Appears to work for android. //Appears to work for android.
//iOS provides the filename, android doe snot. //iOS provides the filename, android doe snot.
console.log("pid", p.id);
filename = p.filename || p.uri.split("/").pop(); filename = p.filename || p.uri.split("/").pop();
const result = await handleUpload( const result = await handleUpload(
{ {

View File

@@ -12,6 +12,7 @@ import {
selectSigningIn, selectSigningIn,
} from "../../redux/user/user.selectors"; } from "../../redux/user/user.selectors";
import SignInErrorAlertComponent from "../sign-in-error-alert/sign-in-error-alert.component"; import SignInErrorAlertComponent from "../sign-in-error-alert/sign-in-error-alert.component";
import Constants from "expo-constants";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
currentUser: selectCurrentUser, currentUser: selectCurrentUser,
@@ -73,6 +74,12 @@ export function SignIn({ emailSignInStart, signingIn }) {
<Button mode="outlined" loading={signingIn} onPress={handleSubmit}> <Button mode="outlined" loading={signingIn} onPress={handleSubmit}>
<Text>{t("signin.actions.signin")}</Text> <Text>{t("signin.actions.signin")}</Text>
</Button> </Button>
<Text>
{t("settings.labels.version", {
number: Constants.manifest.version,
})}{" "}
{process.env.NODE_ENV || ""}
</Text>
</View> </View>
)} )}
</Formik> </Formik>

64
env.js
View File

@@ -1,47 +1,28 @@
import Constants from "expo-constants";
export const prodUrl = "https://someapp.herokuapp.com";
const ENV = { const ENV = {
dev: { dev: {
API_URL: "https://api.imex.online", API_URL: "https://api.test.imex.online",
uri: "https://db.test.bodyshop.app/v1/graphql",
wsuri: "wss://db.test.bodyshop.app/v1/graphql",
REACT_APP_CLOUDINARY_ENDPOINT_API:
"https://api.cloudinary.com/v1_1/bodyshop",
REACT_APP_CLOUDINARY_ENDPOINT: "https://res.cloudinary.com/bodyshop",
REACT_APP_CLOUDINARY_API_KEY: "473322739956866",
REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS: "c_fill,f_auto,h_250,w_250",
firebase: {
apiKey: "AIzaSyBw7_GTy7GtQyfkIRPVrWHEGKfcqeyXw0c",
authDomain: "imex-test.firebaseapp.com",
projectId: "imex-test",
storageBucket: "imex-test.appspot.com",
messagingSenderId: "991923618608",
appId: "1:991923618608:web:633437569cdad78299bef5",
measurementId: "G-TW0XLZEH18",
},
},
REACT_APP_CLOUDINARY_ENDPOINT_API:
"https://api.cloudinary.com/v1_1/bodyshop",
REACT_APP_CLOUDINARY_ENDPOINT: "https://res.cloudinary.com/bodyshop",
REACT_APP_CLOUDINARY_API_KEY: "473322739956866",
REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS: "c_fill,f_auto,h_250,w_250",
firebase: {
apiKey: "AIzaSyDPLT8GiDHDR1R4nI66Qi0BY1aYviDPioc",
authDomain: "imex-dev.firebaseapp.com",
databaseURL: "https://imex-dev.firebaseio.com",
projectId: "imex-dev",
storageBucket: "imex-dev.appspot.com",
messagingSenderId: "759548147434",
appId: "1:759548147434:web:e8239868a48ceb36700993",
measurementId: "G-K5XRBVVB4S",
},
},
staging: {
API_URL: "https://api.imex.online",
REACT_APP_CLOUDINARY_ENDPOINT_API:
"https://api.cloudinary.com/v1_1/bodyshop",
REACT_APP_CLOUDINARY_ENDPOINT: "https://res.cloudinary.com/bodyshop",
REACT_APP_CLOUDINARY_API_KEY: "473322739956866",
REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS: "c_fill,f_auto,h_250,w_250",
firebase: {
apiKey: "AIzaSyDSezy-jGJreo7ulgpLdlpOwAOrgcaEkhU",
authDomain: "imex-prod.firebaseapp.com",
databaseURL: "https://imex-prod.firebaseio.com",
projectId: "imex-prod",
storageBucket: "imex-prod.appspot.com",
messagingSenderId: "253497221485",
appId: "1:253497221485:web:3c81c483b94db84b227a64",
measurementId: "G-NTWBKG2L0M",
},
},
prod: { prod: {
API_URL: "https://api.imex.online", API_URL: "https://api.imex.online",
uri: "https://db.imex.online/v1/graphql",
wsuri: "wss://db.imex.online/v1/graphql",
REACT_APP_CLOUDINARY_ENDPOINT_API: REACT_APP_CLOUDINARY_ENDPOINT_API:
"https://api.cloudinary.com/v1_1/bodyshop", "https://api.cloudinary.com/v1_1/bodyshop",
REACT_APP_CLOUDINARY_ENDPOINT: "https://res.cloudinary.com/bodyshop", REACT_APP_CLOUDINARY_ENDPOINT: "https://res.cloudinary.com/bodyshop",
@@ -60,7 +41,8 @@ const ENV = {
}, },
}; };
function getEnvVars(env = "") { function getEnvVars() {
let env = process.env.NODE_ENV;
if (env === null || env === undefined || env === "") return ENV.dev; if (env === null || env === undefined || env === "") return ENV.dev;
if (env.indexOf("dev") !== -1) return ENV.dev; if (env.indexOf("dev") !== -1) return ENV.dev;
if (env.indexOf("staging") !== -1) return ENV.staging; if (env.indexOf("staging") !== -1) return ENV.staging;
@@ -68,4 +50,4 @@ function getEnvVars(env = "") {
else return ENV.prod; else return ENV.prod;
} }
export default getEnvVars(Constants.manifest.releaseChannel); export default getEnvVars();

View File

@@ -1,31 +1,11 @@
import * as firebase from "firebase/app"; import * as firebase from "firebase/app";
import "firebase/auth"; import "firebase/auth";
import env from "../env";
//const config = JSON.parse(process.env.REACT_APP_FIREBASE_CONFIG); console.log(env.firebase);
// const config = {
// apiKey: "AIzaSyDPLT8GiDHDR1R4nI66Qi0BY1aYviDPioc",
// authDomain: "imex-dev.firebaseapp.com",
// databaseURL: "https://imex-dev.firebaseio.com",
// projectId: "imex-dev",
// storageBucket: "imex-dev.appspot.com",
// messagingSenderId: "759548147434",
// appId: "1:759548147434:web:e8239868a48ceb36700993",
// measurementId: "G-K5XRBVVB4S",
// };
const config = {
apiKey: "AIzaSyDSezy-jGJreo7ulgpLdlpOwAOrgcaEkhU",
authDomain: "imex-prod.firebaseapp.com",
databaseURL: "https://imex-prod.firebaseio.com",
projectId: "imex-prod",
storageBucket: "imex-prod.appspot.com",
messagingSenderId: "253497221485",
appId: "1:253497221485:web:3c81c483b94db84b227a64",
measurementId: "G-NTWBKG2L0M",
};
if (!firebase.apps.length) { if (!firebase.apps.length) {
firebase.initializeApp(config); firebase.initializeApp(env.firebase);
} }
export const auth = firebase.auth(); export const auth = firebase.auth();

View File

@@ -12,10 +12,10 @@ import { RetryLink } from "@apollo/client/link/retry";
import { WebSocketLink } from "@apollo/client/link/ws"; import { WebSocketLink } from "@apollo/client/link/ws";
import { getMainDefinition } from "@apollo/client/utilities"; import { getMainDefinition } from "@apollo/client/utilities";
import { auth } from "../firebase/firebase.utils"; import { auth } from "../firebase/firebase.utils";
import env from "../env";
const httpLink = new HttpLink({ const httpLink = new HttpLink({
// uri: "https://bodyshop-dev-db.herokuapp.com/v1/graphql", // uri: "https://bodyshop-dev-db.herokuapp.com/v1/graphql",
uri: "https://db.imex.online/v1/graphql", uri: env.uri,
}); });
const wsLink = new WebSocketLink({ const wsLink = new WebSocketLink({

View File

@@ -21,11 +21,12 @@ export const GET_DOCUMENTS_BY_JOB = gql`
} }
} }
} }
documents(order_by: { updated_at: desc }) { documents(order_by: { takenat: desc }) {
id id
name name
key key
type type
takenat
bill { bill {
id id
invoice_number invoice_number

View File

@@ -212,7 +212,7 @@ export const GET_JOB_BY_PK = gql`
updated_at updated_at
created_by created_by
} }
documents(order_by: { created_at: desc }) { documents(order_by: { takenat: desc }) {
id id
name name
key key
@@ -303,7 +303,7 @@ export const QUERY_JOB_CARD_DETAILS = gql`
start start
scheduledreturn scheduledreturn
} }
documents(limit: 3, order_by: { created_at: desc }) { documents(limit: 3, order_by: { takenat: desc }) {
id id
key key
} }
@@ -372,7 +372,7 @@ export const QUERY_TECH_JOB_DETAILS = gql`
created_at created_at
} }
updated_at updated_at
documents(order_by: { created_at: desc }) { documents(order_by: { takenat: desc }) {
id id
key key
} }

View File

@@ -3,6 +3,8 @@ import env from "../env";
import { client } from "../graphql/client"; import { client } from "../graphql/client";
import { INSERT_NEW_DOCUMENT } from "../graphql/documents.queries"; import { INSERT_NEW_DOCUMENT } from "../graphql/documents.queries";
import { axiosAuthInterceptorId } from "./CleanAxios"; import { axiosAuthInterceptorId } from "./CleanAxios";
import * as MediaLibrary from "expo-media-library";
//Context: currentUserEmail, bodyshop, jobid, invoiceid //Context: currentUserEmail, bodyshop, jobid, invoiceid
//Required to prevent headers from getting set and rejected from Cloudinary. //Required to prevent headers from getting set and rejected from Cloudinary.
@@ -45,15 +47,8 @@ export const uploadToCloudinary = async (
onProgress, onProgress,
context context
) => { ) => {
const { const { bodyshop, jobId, billId, uploaded_by, callback, tagsArray, photo } =
bodyshop, context;
jobId,
billId,
uploaded_by,
callback,
tagsArray,
photo,
} = context;
//Set variables for getting the signed URL. //Set variables for getting the signed URL.
let timestamp = Math.floor(Date.now() / 1000); let timestamp = Math.floor(Date.now() / 1000);
@@ -139,7 +134,12 @@ export const uploadToCloudinary = async (
if (onError) onError(cloudinaryUploadResponse.statusText); if (onError) onError(cloudinaryUploadResponse.statusText);
return { success: false, error: cloudinaryUploadResponse.statusText }; return { success: false, error: cloudinaryUploadResponse.statusText };
} }
console.log("mediaId", mediaId);
const imageData = await MediaLibrary.getAssetInfoAsync(mediaId);
console.log(
"🚀 ~ file: document-upload.utility.js ~ line 140 ~ imageData",
imageData.creationTime
);
//Insert the document with the matching key. //Insert the document with the matching key.
const documentInsert = await client.mutate({ const documentInsert = await client.mutate({
mutation: INSERT_NEW_DOCUMENT, mutation: INSERT_NEW_DOCUMENT,
@@ -154,6 +154,9 @@ export const uploadToCloudinary = async (
extension: extension, extension: extension,
bodyshopid: bodyshop.id, bodyshopid: bodyshop.id,
size: cloudinaryUploadResponse.data.bytes || file.size, size: cloudinaryUploadResponse.data.bytes || file.size,
...(imageData.creationTime
? { takenat: new Date(imageData.creationTime) }
: {}),
}, },
], ],
}, },