Time Ticket displays current signed in employee
This commit is contained in:
@@ -1,41 +1,30 @@
|
|||||||
import React, { useCallback, useState } from "react";
|
import React, { useCallback, useState } from "react";
|
||||||
import {
|
import moment from "moment";
|
||||||
View,
|
import { View, Text, StyleSheet, ScrollView, RefreshControl} from "react-native";
|
||||||
Text,
|
import { Button, Card, Headline, Subheading } from "react-native-paper";
|
||||||
StyleSheet,
|
import styles from "../styles";
|
||||||
ScrollView,
|
|
||||||
RefreshControl,
|
|
||||||
} from "react-native";
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { employeeGetRatesStart } from "../../redux/employee/employee.actions";
|
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import {
|
|
||||||
selectCurrentEmployee,
|
|
||||||
selectRates,
|
|
||||||
selectGettingRates,
|
|
||||||
selectSignInError,
|
|
||||||
} from "../../redux/employee/employee.selectors";
|
|
||||||
import { Button, Card } from "react-native-paper";
|
|
||||||
|
|
||||||
import { QUERY_ACTIVE_TIME_TICKETS } from "../../graphql/timetickets.queries";
|
import { employeeGetRatesStart } from "../../redux/employee/employee.actions";
|
||||||
//temp
|
import { selectCurrentEmployee, selectRates, selectGettingRates, selectSignInError, selectEmployeeFullName,
|
||||||
import { useQuery } from "@apollo/client";
|
} from "../../redux/employee/employee.selectors";
|
||||||
import ErrorDisplay from "../error-display/error-display.component";
|
|
||||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
|
|
||||||
import { JobIdSearchSelect } from "../Selects/select-job-id";
|
import { JobIdSearchSelect } from "../Selects/select-job-id";
|
||||||
import { CostCenterSelect } from "../Selects/select-cost-center";
|
import { CostCenterSelect } from "../Selects/select-cost-center";
|
||||||
import {
|
import ErrorDisplay from "../error-display/error-display.component";
|
||||||
selectCurrentTimeTicketJob,
|
import { selectCurrentTimeTicketJob, selectCurrentTimeTicketJobId,
|
||||||
selectCurrentTimeTicketJobId,
|
|
||||||
} from "../../redux/timetickets/timetickets.selectors";
|
} from "../../redux/timetickets/timetickets.selectors";
|
||||||
import moment from "moment";
|
|
||||||
import EmployeeClockedInList from "../time-ticket-lists/employee-clockedin-list.component";
|
|
||||||
import { useNavigation } from "@react-navigation/native";
|
|
||||||
|
|
||||||
import { INSERT_NEW_TIME_TICKET } from "../../graphql/timetickets.queries";
|
import { INSERT_NEW_TIME_TICKET } from "../../graphql/timetickets.queries";
|
||||||
import { useMutation } from "@apollo/client";
|
import { useMutation, useQuery } from "@apollo/client";
|
||||||
|
import { QUERY_ACTIVE_TIME_TICKETS } from "../../graphql/timetickets.queries";
|
||||||
|
|
||||||
|
import EmployeeClockedInList from "../time-ticket-lists/employee-clockedin-list.component";
|
||||||
import { logImEXEvent } from "../../firebase/firebase.analytics";
|
import { logImEXEvent } from "../../firebase/firebase.analytics";
|
||||||
|
import StyleRepeater from "../style-repeater/style-repeater";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
currentEmployee: selectCurrentEmployee,
|
currentEmployee: selectCurrentEmployee,
|
||||||
@@ -45,6 +34,7 @@ const mapStateToProps = createStructuredSelector({
|
|||||||
currentRatesNCostCenters: selectRates,
|
currentRatesNCostCenters: selectRates,
|
||||||
currentSelectedTimeTicketJobId: selectCurrentTimeTicketJobId,
|
currentSelectedTimeTicketJobId: selectCurrentTimeTicketJobId,
|
||||||
currentSelectedTimeTicketJob: selectCurrentTimeTicketJob,
|
currentSelectedTimeTicketJob: selectCurrentTimeTicketJob,
|
||||||
|
currentEmployeeFullName: selectEmployeeFullName,
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
@@ -61,9 +51,8 @@ export function ScreenTimeTicketBrowser({
|
|||||||
currentRatesNCostCenters,
|
currentRatesNCostCenters,
|
||||||
currentSelectedTimeTicketJob,
|
currentSelectedTimeTicketJob,
|
||||||
currentSelectedTimeTicketJobId,
|
currentSelectedTimeTicketJobId,
|
||||||
|
currentEmployeeFullName,
|
||||||
}) {
|
}) {
|
||||||
const navigation = useNavigation();
|
|
||||||
//const employeeId = currentEmployee.technician.id;
|
|
||||||
const [currentSCC, setCurrentSCC] = useState(null);
|
const [currentSCC, setCurrentSCC] = useState(null);
|
||||||
const [currentSJobId, setCurrentSJobId] = useState(null);
|
const [currentSJobId, setCurrentSJobId] = useState(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
@@ -72,31 +61,24 @@ export function ScreenTimeTicketBrowser({
|
|||||||
const [insertTimeTicket] = useMutation(INSERT_NEW_TIME_TICKET, {
|
const [insertTimeTicket] = useMutation(INSERT_NEW_TIME_TICKET, {
|
||||||
refetchQueries: ["QUERY_ACTIVE_TIME_TICKETS"],
|
refetchQueries: ["QUERY_ACTIVE_TIME_TICKETS"],
|
||||||
});
|
});
|
||||||
const [jobCount, setJobCount] = useState(0);
|
|
||||||
|
|
||||||
//test area
|
|
||||||
|
|
||||||
const handleFinish = async (values) => {
|
const handleFinish = async (values) => {
|
||||||
console.log("handleFinish called in ScreenTimeTicketBrowser");
|
console.log("handleFinish called in ScreenTimeTicketBrowser");
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
//do stuff...
|
|
||||||
|
|
||||||
const theTime = (await axios.post("/utils/time")).data;
|
const theTime = (await axios.post("/utils/time")).data;
|
||||||
|
|
||||||
if (!!currentSCC?.value && !!currentSJobId?.value) {
|
if (!!currentSCC?.value && !!currentSJobId?.value) {
|
||||||
setError(null);
|
setError(null);
|
||||||
console.log("have all values");
|
// console.log("have all values");
|
||||||
} else {
|
} else {
|
||||||
console.log("missing values!");
|
// console.log("missing values!");
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setError({ message: "Please make sure all fields have a value." });
|
setError({ message: "Please make sure all fields have a value." });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentSJobId)
|
|
||||||
console.log("jobid or currentSJobId", currentSJobId?.value);
|
|
||||||
|
|
||||||
const tempVariablesObj = {
|
const tempVariablesObj = {
|
||||||
variables: {
|
variables: {
|
||||||
timeTicketInput: [
|
timeTicketInput: [
|
||||||
@@ -123,23 +105,15 @@ export function ScreenTimeTicketBrowser({
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
console.info(
|
// console.info("INSERT_NEW_TIME_TICKET, variables for clockin. : ",tempVariablesObj?.variables?.timeTicketInput[0] );
|
||||||
"INSERT_NEW_TIME_TICKET, variables for clockin. : ",
|
|
||||||
tempVariablesObj?.variables?.timeTicketInput[0]
|
|
||||||
);
|
|
||||||
|
|
||||||
const result = await insertTimeTicket(tempVariablesObj);
|
const result = await insertTimeTicket(tempVariablesObj);
|
||||||
console.log("insertTimeTicket, result :", result);
|
// console.log("insertTimeTicket, result :", result);
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
if (!!result.errors) {
|
if (!!result.errors) {
|
||||||
console.log("insertTimeTicket, result.error :", result.errors);
|
// console.log("insertTimeTicket, result.error :", result.errors);
|
||||||
setError(JSON.stringify(result.errors));
|
setError(JSON.stringify(result.errors));
|
||||||
} else {
|
} else {
|
||||||
console.log("insertTimeTicket, result. :", result.data);
|
// console.log("insertTimeTicket, result. :", result.data);
|
||||||
//show success
|
|
||||||
//clear fields
|
|
||||||
|
|
||||||
setCurrentSJobId(null);
|
setCurrentSJobId(null);
|
||||||
setCurrentSCC(null);
|
setCurrentSCC(null);
|
||||||
}
|
}
|
||||||
@@ -152,14 +126,22 @@ export function ScreenTimeTicketBrowser({
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={localStyles.content}>
|
<ScrollView
|
||||||
<ScrollView
|
style={styles.cardBackground}
|
||||||
style={{ flex: 1 }}
|
// contentContainerStyle={{ flexGrow: 0 }}
|
||||||
contentContainerStyle={{ flexGrow: 1 }}
|
refreshControl={
|
||||||
refreshControl={
|
<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
|
||||||
<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
|
}
|
||||||
}
|
>
|
||||||
>
|
<StyleRepeater childStyle={{ margin: 4 }}>
|
||||||
|
<Card>
|
||||||
|
<Card.Title title={"Logged in Employee"} />
|
||||||
|
<Card.Content>
|
||||||
|
{currentEmployeeFullName && (
|
||||||
|
<Subheading>{currentEmployeeFullName}</Subheading>
|
||||||
|
)}
|
||||||
|
</Card.Content>
|
||||||
|
</Card>
|
||||||
<Card>
|
<Card>
|
||||||
<JobIdSearchSelect
|
<JobIdSearchSelect
|
||||||
currentValue={currentSJobId}
|
currentValue={currentSJobId}
|
||||||
@@ -178,29 +160,15 @@ export function ScreenTimeTicketBrowser({
|
|||||||
<Button mode="outlined" loading={loading} onPress={handleFinish}>
|
<Button mode="outlined" loading={loading} onPress={handleFinish}>
|
||||||
<Text>Clock In</Text>
|
<Text>Clock In</Text>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
</Card>
|
</Card>
|
||||||
{/* <View style={{ flexGrow: 1, flex: 1 }}>
|
</StyleRepeater>
|
||||||
<EmployeeClockedInList
|
|
||||||
technician={currentEmployee}
|
|
||||||
isRefresh={refreshing}
|
|
||||||
onRefresh={onRefresh}
|
|
||||||
/>
|
|
||||||
</View> */}
|
|
||||||
</ScrollView>
|
|
||||||
<View style={{ flexGrow: 1, flex: 1 }}>
|
<View style={{ flexGrow: 1, flex: 1 }}>
|
||||||
<EmployeeClockedInList
|
<EmployeeClockedInList
|
||||||
technician={currentEmployee}
|
technician={currentEmployee}
|
||||||
isRefresh={refreshing}
|
isRefresh={refreshing}
|
||||||
/>
|
/>
|
||||||
</View>
|
|
||||||
{/* <ScrollView style={{flex:1}} contentContainerStyle={{ flexGrow: 1 }} refreshControl={<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />} >
|
|
||||||
|
|
||||||
<View style={{ flexGrow: 1, flex:1 }}>
|
|
||||||
<EmployeeClockedInList technician={currentEmployee} handleRefresh={refreshing} onRefresh={onRefresh} />
|
|
||||||
</View>
|
</View>
|
||||||
</ScrollView> */}
|
</ScrollView>
|
||||||
</View>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,7 @@ const mapStateToProps = createStructuredSelector({
|
|||||||
export function EmployeeClockedInList({ currentEmployee, isRefresh }) {
|
export function EmployeeClockedInList({ currentEmployee, isRefresh }) {
|
||||||
const [refreshKey, setRefreshKey] = useState(isRefresh);
|
const [refreshKey, setRefreshKey] = useState(isRefresh);
|
||||||
const [jobData, setJobData] = useState(data);
|
const [jobData, setJobData] = useState(data);
|
||||||
console.info(
|
// console.info("EmployeeClockedInList, QUERY_ACTIVE_TIME_TICKETS called.",currentEmployee);
|
||||||
"EmployeeClockedInList, QUERY_ACTIVE_TIME_TICKETS called.",
|
|
||||||
currentEmployee
|
|
||||||
);
|
|
||||||
|
|
||||||
// console.info(
|
// console.info(
|
||||||
// "EmployeeClockedInList, isRefresh :",
|
// "EmployeeClockedInList, isRefresh :",
|
||||||
@@ -42,6 +39,9 @@ export function EmployeeClockedInList({ currentEmployee, isRefresh }) {
|
|||||||
// console.log("teste: ", result);
|
// console.log("teste: ", result);
|
||||||
// }
|
// }
|
||||||
// fetchData();
|
// fetchData();
|
||||||
|
if(isRefresh){
|
||||||
|
refetch();
|
||||||
|
}
|
||||||
console.log("useEffect: ", isRefresh);
|
console.log("useEffect: ", isRefresh);
|
||||||
// setRefreshKey(isRefresh);
|
// setRefreshKey(isRefresh);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user