- the great reformat

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-02-06 18:20:58 -05:00
parent 30c530bcc4
commit e83badb454
912 changed files with 108516 additions and 107493 deletions

View File

@@ -1,56 +1,56 @@
import i18n from "i18next";
const AuditTrailMapping = {
admin_job_remove_from_ar: (status) =>
i18n.t("audit_trail.messages.admin_job_remove_from_ar", { status }),
admin_jobfieldchange: (field, value) =>
"ADMIN: " +
i18n.t("audit_trail.messages.jobfieldchanged", { field, value }),
admin_jobmarkexported: () =>
i18n.t("audit_trail.messages.admin_jobmarkexported"),
admin_jobmarkforreexport: () =>
i18n.t("audit_trail.messages.admin_jobmarkforreexport"),
admin_jobstatuschange: (status) =>
"ADMIN: " + i18n.t("audit_trail.messages.jobstatuschange", { status }),
admin_jobuninvoice: () => i18n.t("audit_trail.messages.admin_jobuninvoice"),
admin_jobunvoid: () => i18n.t("audit_trail.messages.admin_jobunvoid"),
alertToggle: (status) =>
i18n.t("audit_trail.messages.alerttoggle", { status }),
appointmentcancel: (lost_sale_reason) =>
i18n.t("audit_trail.messages.appointmentcancel", { lost_sale_reason }),
appointmentinsert: (start) =>
i18n.t("audit_trail.messages.appointmentinsert", { start }),
billposted: (invoice_number) =>
i18n.t("audit_trail.messages.billposted", { invoice_number }),
billupdated: (invoice_number) =>
i18n.t("audit_trail.messages.billupdated", { invoice_number }),
failedpayment: () => i18n.t("audit_trail.messages.failedpayment"),
jobassignmentchange: (operation, name) =>
i18n.t("audit_trail.messages.jobassignmentchange", { operation, name }),
jobassignmentremoved: (operation) =>
i18n.t("audit_trail.messages.jobassignmentremoved", { operation }),
jobchecklist: (type, inproduction, status) =>
i18n.t("audit_trail.messages.jobchecklist", { type, inproduction, status }),
jobconverted: (ro_number) =>
i18n.t("audit_trail.messages.jobconverted", { ro_number }),
jobfieldchange: (field, value) =>
i18n.t("audit_trail.messages.jobfieldchanged", { field, value }),
jobimported: () => i18n.t("audit_trail.messages.jobimported"),
jobinproductionchange: (inproduction) =>
i18n.t("audit_trail.messages.jobinproductionchange", { inproduction }),
jobinvoiced: () => i18n.t("audit_trail.messages.jobinvoiced"),
jobmodifylbradj: ({ mod_lbr_ty, hours }) =>
i18n.t("audit_trail.messages.jobmodifylbradj", { mod_lbr_ty, hours }),
jobnoteadded: () => i18n.t("audit_trail.messages.jobnoteadded"),
jobnotedeleted: () => i18n.t("audit_trail.messages.jobnotedeleted"),
jobnoteupdated: () => i18n.t("audit_trail.messages.jobnoteupdated"),
jobspartsorder: (order_number) =>
i18n.t("audit_trail.messages.jobspartsorder", { order_number }),
jobspartsreturn: (order_number) =>
i18n.t("audit_trail.messages.jobspartsreturn", { order_number }),
jobstatuschange: (status) =>
i18n.t("audit_trail.messages.jobstatuschange", { status }),
jobsupplement: () => i18n.t("audit_trail.messages.jobsupplement"),
admin_job_remove_from_ar: (status) =>
i18n.t("audit_trail.messages.admin_job_remove_from_ar", {status}),
admin_jobfieldchange: (field, value) =>
"ADMIN: " +
i18n.t("audit_trail.messages.jobfieldchanged", {field, value}),
admin_jobmarkexported: () =>
i18n.t("audit_trail.messages.admin_jobmarkexported"),
admin_jobmarkforreexport: () =>
i18n.t("audit_trail.messages.admin_jobmarkforreexport"),
admin_jobstatuschange: (status) =>
"ADMIN: " + i18n.t("audit_trail.messages.jobstatuschange", {status}),
admin_jobuninvoice: () => i18n.t("audit_trail.messages.admin_jobuninvoice"),
admin_jobunvoid: () => i18n.t("audit_trail.messages.admin_jobunvoid"),
alertToggle: (status) =>
i18n.t("audit_trail.messages.alerttoggle", {status}),
appointmentcancel: (lost_sale_reason) =>
i18n.t("audit_trail.messages.appointmentcancel", {lost_sale_reason}),
appointmentinsert: (start) =>
i18n.t("audit_trail.messages.appointmentinsert", {start}),
billposted: (invoice_number) =>
i18n.t("audit_trail.messages.billposted", {invoice_number}),
billupdated: (invoice_number) =>
i18n.t("audit_trail.messages.billupdated", {invoice_number}),
failedpayment: () => i18n.t("audit_trail.messages.failedpayment"),
jobassignmentchange: (operation, name) =>
i18n.t("audit_trail.messages.jobassignmentchange", {operation, name}),
jobassignmentremoved: (operation) =>
i18n.t("audit_trail.messages.jobassignmentremoved", {operation}),
jobchecklist: (type, inproduction, status) =>
i18n.t("audit_trail.messages.jobchecklist", {type, inproduction, status}),
jobconverted: (ro_number) =>
i18n.t("audit_trail.messages.jobconverted", {ro_number}),
jobfieldchange: (field, value) =>
i18n.t("audit_trail.messages.jobfieldchanged", {field, value}),
jobimported: () => i18n.t("audit_trail.messages.jobimported"),
jobinproductionchange: (inproduction) =>
i18n.t("audit_trail.messages.jobinproductionchange", {inproduction}),
jobinvoiced: () => i18n.t("audit_trail.messages.jobinvoiced"),
jobmodifylbradj: ({mod_lbr_ty, hours}) =>
i18n.t("audit_trail.messages.jobmodifylbradj", {mod_lbr_ty, hours}),
jobnoteadded: () => i18n.t("audit_trail.messages.jobnoteadded"),
jobnotedeleted: () => i18n.t("audit_trail.messages.jobnotedeleted"),
jobnoteupdated: () => i18n.t("audit_trail.messages.jobnoteupdated"),
jobspartsorder: (order_number) =>
i18n.t("audit_trail.messages.jobspartsorder", {order_number}),
jobspartsreturn: (order_number) =>
i18n.t("audit_trail.messages.jobspartsreturn", {order_number}),
jobstatuschange: (status) =>
i18n.t("audit_trail.messages.jobstatuschange", {status}),
jobsupplement: () => i18n.t("audit_trail.messages.jobsupplement"),
};
export default AuditTrailMapping;

View File

@@ -1,101 +1,101 @@
import React from "react";
import { Select } from "antd";
import {Select} from "antd";
import i18n from "../translations/i18n";
export default function CiecaSelect(parts = true, labor = true) {
return (
<>
{labor && (
return (
<>
<Select.Option value="LAA">
{i18n.t("joblines.fields.lbr_types.LAA")}
</Select.Option>
<Select.Option value="LAB">
{i18n.t("joblines.fields.lbr_types.LAB")}
</Select.Option>
<Select.Option value="LAD">
{i18n.t("joblines.fields.lbr_types.LAD")}
</Select.Option>
<Select.Option value="LAE">
{i18n.t("joblines.fields.lbr_types.LAE")}
</Select.Option>
<Select.Option value="LAF">
{i18n.t("joblines.fields.lbr_types.LAF")}
</Select.Option>
<Select.Option value="LAG">
{i18n.t("joblines.fields.lbr_types.LAG")}
</Select.Option>
<Select.Option value="LAM">
{i18n.t("joblines.fields.lbr_types.LAM")}
</Select.Option>
<Select.Option value="LAR">
{i18n.t("joblines.fields.lbr_types.LAR")}
</Select.Option>
<Select.Option value="LAS">
{i18n.t("joblines.fields.lbr_types.LAS")}
</Select.Option>
<Select.Option value="LAU">
{i18n.t("joblines.fields.lbr_types.LAU")}
</Select.Option>
<Select.Option value="LA1">
{i18n.t("joblines.fields.lbr_types.LA1")}
</Select.Option>
<Select.Option value="LA2">
{i18n.t("joblines.fields.lbr_types.LA2")}
</Select.Option>
<Select.Option value="LA3">
{i18n.t("joblines.fields.lbr_types.LA3")}
</Select.Option>
<Select.Option value="LA4">
{i18n.t("joblines.fields.lbr_types.LA4")}
</Select.Option>
</>
)}
{parts && (
<>
<Select.Option value="PAA">
{i18n.t("joblines.fields.part_types.PAA")}
</Select.Option>
<Select.Option value="PAC">
{i18n.t("joblines.fields.part_types.PAC")}
</Select.Option>
{labor && (
<>
<Select.Option value="LAA">
{i18n.t("joblines.fields.lbr_types.LAA")}
</Select.Option>
<Select.Option value="LAB">
{i18n.t("joblines.fields.lbr_types.LAB")}
</Select.Option>
<Select.Option value="LAD">
{i18n.t("joblines.fields.lbr_types.LAD")}
</Select.Option>
<Select.Option value="LAE">
{i18n.t("joblines.fields.lbr_types.LAE")}
</Select.Option>
<Select.Option value="LAF">
{i18n.t("joblines.fields.lbr_types.LAF")}
</Select.Option>
<Select.Option value="LAG">
{i18n.t("joblines.fields.lbr_types.LAG")}
</Select.Option>
<Select.Option value="LAM">
{i18n.t("joblines.fields.lbr_types.LAM")}
</Select.Option>
<Select.Option value="LAR">
{i18n.t("joblines.fields.lbr_types.LAR")}
</Select.Option>
<Select.Option value="LAS">
{i18n.t("joblines.fields.lbr_types.LAS")}
</Select.Option>
<Select.Option value="LAU">
{i18n.t("joblines.fields.lbr_types.LAU")}
</Select.Option>
<Select.Option value="LA1">
{i18n.t("joblines.fields.lbr_types.LA1")}
</Select.Option>
<Select.Option value="LA2">
{i18n.t("joblines.fields.lbr_types.LA2")}
</Select.Option>
<Select.Option value="LA3">
{i18n.t("joblines.fields.lbr_types.LA3")}
</Select.Option>
<Select.Option value="LA4">
{i18n.t("joblines.fields.lbr_types.LA4")}
</Select.Option>
</>
)}
{parts && (
<>
<Select.Option value="PAA">
{i18n.t("joblines.fields.part_types.PAA")}
</Select.Option>
<Select.Option value="PAC">
{i18n.t("joblines.fields.part_types.PAC")}
</Select.Option>
<Select.Option value="PAL">
{i18n.t("joblines.fields.part_types.PAL")}
</Select.Option>
<Select.Option value="PAG">
{i18n.t("joblines.fields.part_types.PAG")}
</Select.Option>
<Select.Option value="PAM">
{i18n.t("joblines.fields.part_types.PAM")}
</Select.Option>
<Select.Option value="PAP">
{i18n.t("joblines.fields.part_types.PAP")}
</Select.Option>
<Select.Option value="PAN">
{i18n.t("joblines.fields.part_types.PAN")}
</Select.Option>
<Select.Option value="PAO">
{i18n.t("joblines.fields.part_types.PAO")}
</Select.Option>
<Select.Option value="PAR">
{i18n.t("joblines.fields.part_types.PAR")}
</Select.Option>
<Select.Option value="PAS">
{i18n.t("joblines.fields.part_types.PAS")}
</Select.Option>
<Select.Option value="PAL">
{i18n.t("joblines.fields.part_types.PAL")}
</Select.Option>
<Select.Option value="PAG">
{i18n.t("joblines.fields.part_types.PAG")}
</Select.Option>
<Select.Option value="PAM">
{i18n.t("joblines.fields.part_types.PAM")}
</Select.Option>
<Select.Option value="PAP">
{i18n.t("joblines.fields.part_types.PAP")}
</Select.Option>
<Select.Option value="PAN">
{i18n.t("joblines.fields.part_types.PAN")}
</Select.Option>
<Select.Option value="PAO">
{i18n.t("joblines.fields.part_types.PAO")}
</Select.Option>
<Select.Option value="PAR">
{i18n.t("joblines.fields.part_types.PAR")}
</Select.Option>
<Select.Option value="PAS">
{i18n.t("joblines.fields.part_types.PAS")}
</Select.Option>
</>
)}
</>
)}
</>
);
);
}
export function GetPartTypeName(part_type) {
if (!part_type) return null;
return i18n.t(`joblines.fields.part_types.${part_type.toUpperCase()}`);
if (!part_type) return null;
return i18n.t(`joblines.fields.part_types.${part_type.toUpperCase()}`);
}
export function Get(part_type) {
if (!part_type) return null;
return i18n.t(`joblines.fields.part_types.${part_type.toUpperCase()}`);
if (!part_type) return null;
return i18n.t(`joblines.fields.part_types.${part_type.toUpperCase()}`);
}

View File

@@ -1,23 +1,23 @@
import axios from "axios";
import { auth } from "../firebase/firebase.utils";
import {auth} from "../firebase/firebase.utils";
if (process.env.NODE_ENV === "production") {
axios.defaults.baseURL =
process.env.REACT_APP_AXIOS_BASE_API_URL || "https://api.imex.online/";
axios.defaults.baseURL =
process.env.REACT_APP_AXIOS_BASE_API_URL || "https://api.imex.online/";
}
export const axiosAuthInterceptorId = axios.interceptors.request.use(
async (config) => {
if (!config.headers.Authorization) {
const token = auth.currentUser && (await auth.currentUser.getIdToken());
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
}
async (config) => {
if (!config.headers.Authorization) {
const token = auth.currentUser && (await auth.currentUser.getIdToken());
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
}
return config;
},
(error) => Promise.reject(error)
return config;
},
(error) => Promise.reject(error)
);
const cleanAxios = axios.create();

View File

@@ -1,15 +1,15 @@
import React from "react";
import { NumericFormat } from "react-number-format";
import {NumericFormat} from "react-number-format";
export default function CurrencyFormatter(props) {
return (
<NumericFormat
thousandSeparator={true}
decimalScale={2}
fixedDecimalScale={true}
prefix={"$"}
value={props.children}
displayType={"text"}
/>
);
return (
<NumericFormat
thousandSeparator={true}
decimalScale={2}
fixedDecimalScale={true}
prefix={"$"}
value={props.children}
displayType={"text"}
/>
);
}

View File

@@ -1,40 +1,42 @@
import { Tooltip } from "antd";
import {Tooltip} from "antd";
import dayjs from "../utils/day";
import React from "react";
export function DateFormatter(props) {
return props.children
? dayjs(props.children).format(
props.includeDay ? "ddd MM/DD/YYYY" : "MM/DD/YYYY"
)
: null;
return props.children
? dayjs(props.children).format(
props.includeDay ? "ddd MM/DD/YYYY" : "MM/DD/YYYY"
)
: null;
}
export function DateTimeFormatter(props) {
return props.children
? dayjs(props.children).format(
props.format ? props.format : "MM/DD/YYYY hh:mm a"
)
: null;
return props.children
? dayjs(props.children).format(
props.format ? props.format : "MM/DD/YYYY hh:mm a"
)
: null;
}
export function DateTimeFormatterFunction(date) {
return dayjs(date).format("MM/DD/YYYY hh:mm a");
}
export function TimeFormatter(props) {
return props.children
? dayjs(props.children).format(props.format ? props.format : "hh:mm a")
: null;
return props.children
? dayjs(props.children).format(props.format ? props.format : "hh:mm a")
: null;
}
export function TimeAgoFormatter(props) {
const m = dayjs(props.children);
return props.children ? (
<Tooltip placement="top" title={m.format("MM/DD/YYY hh:mm A")}>
{m.fromNow()}
</Tooltip>
) : null;
const m = dayjs(props.children);
return props.children ? (
<Tooltip placement="top" title={m.format("MM/DD/YYY hh:mm A")}>
{m.fromNow()}
</Tooltip>
) : null;
}
export function DateTimeFormat(value) {
return dayjs(value).format("MM/DD/YYYY hh:mm A");
return dayjs(value).format("MM/DD/YYYY hh:mm A");
}

View File

@@ -1,62 +1,62 @@
import dayjs from "./day";
const range = [
{
label: 'Today',
value: [dayjs(), dayjs()]
},
{
label: 'Last 14 days',
value: [dayjs().subtract(14, "day"), dayjs()]
},
{
label: 'Last 7 days',
value: [dayjs().subtract(7, "day"), dayjs()]
},
{
label: 'Next 7 days',
value: [dayjs(), dayjs().add(7, "day")]
},
{
label: 'Next 14 days',
value: [dayjs(), dayjs().add(14, "day")],
},
{
label: 'Last Month',
value: [
dayjs().startOf("month").subtract(1, "month"),
dayjs().startOf("month").subtract(1, "month").endOf("month"),
]
},
{
label: 'This Month',
value: [dayjs().startOf("month"), dayjs().endOf("month")]
},
{
label: 'Next Month',
value: [
dayjs().startOf("month").add(1, "month"),
dayjs().startOf("month").add(1, "month").endOf("month"),
]
},
{
label: 'Last Quarter',
value: [
dayjs().startOf("quarter").subtract(1, "quarter"),
dayjs().startOf("quarter").subtract(1, "day"),
]
},
{
label: 'This Quarter',
value: [
dayjs().startOf("quarter"),
dayjs().startOf("quarter").add(1, "quarter").subtract(1, "day"),
]
},
{
label: 'Last 90 Days',
value: [dayjs().add(-90, "day"), dayjs()],
}
{
label: 'Today',
value: [dayjs(), dayjs()]
},
{
label: 'Last 14 days',
value: [dayjs().subtract(14, "day"), dayjs()]
},
{
label: 'Last 7 days',
value: [dayjs().subtract(7, "day"), dayjs()]
},
{
label: 'Next 7 days',
value: [dayjs(), dayjs().add(7, "day")]
},
{
label: 'Next 14 days',
value: [dayjs(), dayjs().add(14, "day")],
},
{
label: 'Last Month',
value: [
dayjs().startOf("month").subtract(1, "month"),
dayjs().startOf("month").subtract(1, "month").endOf("month"),
]
},
{
label: 'This Month',
value: [dayjs().startOf("month"), dayjs().endOf("month")]
},
{
label: 'Next Month',
value: [
dayjs().startOf("month").add(1, "month"),
dayjs().startOf("month").add(1, "month").endOf("month"),
]
},
{
label: 'Last Quarter',
value: [
dayjs().startOf("quarter").subtract(1, "quarter"),
dayjs().startOf("quarter").subtract(1, "day"),
]
},
{
label: 'This Quarter',
value: [
dayjs().startOf("quarter"),
dayjs().startOf("quarter").add(1, "quarter").subtract(1, "day"),
]
},
{
label: 'Last 90 Days',
value: [dayjs().add(-90, "day"), dayjs()],
}
]
export default range;

View File

@@ -1,191 +1,188 @@
import { ApolloClient, ApolloLink, InMemoryCache, split } from "@apollo/client";
import { setContext } from "@apollo/client/link/context";
import { HttpLink } from "@apollo/client/link/http"; //"apollo-link-http";
import { RetryLink } from "@apollo/client/link/retry";
import { WebSocketLink } from "@apollo/client/link/ws";
import {
getMainDefinition,
offsetLimitPagination,
} from "@apollo/client/utilities";
import {ApolloClient, ApolloLink, InMemoryCache, split} from "@apollo/client";
import {setContext} from "@apollo/client/link/context";
import {HttpLink} from "@apollo/client/link/http"; //"apollo-link-http";
import {RetryLink} from "@apollo/client/link/retry";
import {WebSocketLink} from "@apollo/client/link/ws";
import {getMainDefinition, offsetLimitPagination,} from "@apollo/client/utilities";
//import { split } from "apollo-link";
import apolloLogger from "apollo-link-logger";
//import axios from "axios";
import { auth } from "../firebase/firebase.utils";
import {auth} from "../firebase/firebase.utils";
import errorLink from "../graphql/apollo-error-handling";
import { SentryLink } from "apollo-link-sentry";
import {SentryLink} from "apollo-link-sentry";
//import { store } from "../redux/store";
const httpLink = new HttpLink({
uri: process.env.REACT_APP_GRAPHQL_ENDPOINT,
uri: process.env.REACT_APP_GRAPHQL_ENDPOINT,
});
const wsLink = new WebSocketLink({
uri: process.env.REACT_APP_GRAPHQL_ENDPOINT_WS,
options: {
lazy: true,
reconnect: true,
connectionParams: async () => {
const token = auth.currentUser && (await auth.currentUser.getIdToken());
if (token) {
return {
headers: {
authorization: token ? `Bearer ${token}` : "",
},
};
}
uri: process.env.REACT_APP_GRAPHQL_ENDPOINT_WS,
options: {
lazy: true,
reconnect: true,
connectionParams: async () => {
const token = auth.currentUser && (await auth.currentUser.getIdToken());
if (token) {
return {
headers: {
authorization: token ? `Bearer ${token}` : "",
},
};
}
},
},
},
});
const roundTripLink = new ApolloLink((operation, forward) => {
// Called before operation is sent to server
operation.setContext({ start: new Date() });
// Called before operation is sent to server
operation.setContext({start: new Date()});
return forward(operation).map((data) => {
// Called after server responds
const time = new Date() - operation.getContext().start;
// console.log(
// `Operation ${operation.operationName} took ${time} to complete`
// );
TrackExecutionTime(operation.operationName, time);
return data;
});
return forward(operation).map((data) => {
// Called after server responds
const time = new Date() - operation.getContext().start;
// console.log(
// `Operation ${operation.operationName} took ${time} to complete`
// );
TrackExecutionTime(operation.operationName, time);
return data;
});
});
const TrackExecutionTime = async (operationName, time) => {
// if (process.env.NODE_ENV === "development") return;
// const rdxStore = store.getState();
// try {
// axios.post("/ioevent", {
// operationName,
// time,
// dbevent: true,
// user:
// rdxStore.user &&
// rdxStore.user.currentUser &&
// rdxStore.user.currentUser.email,
// imexshopid:
// rdxStore.user &&
// rdxStore.user.bodyshop &&
// rdxStore.user.bodyshop.imexshopid,
// });
// } catch (error) {
// console.log("IOEvent Error", error);
// }
// if (process.env.NODE_ENV === "development") return;
// const rdxStore = store.getState();
// try {
// axios.post("/ioevent", {
// operationName,
// time,
// dbevent: true,
// user:
// rdxStore.user &&
// rdxStore.user.currentUser &&
// rdxStore.user.currentUser.email,
// imexshopid:
// rdxStore.user &&
// rdxStore.user.bodyshop &&
// rdxStore.user.bodyshop.imexshopid,
// });
// } catch (error) {
// console.log("IOEvent Error", error);
// }
};
const subscriptionMiddleware = {
applyMiddleware: async (options, next) => {
options.authToken =
auth.currentUser && (await auth.currentUser.getIdToken());
next();
},
applyMiddleware: async (options, next) => {
options.authToken =
auth.currentUser && (await auth.currentUser.getIdToken());
next();
},
};
wsLink.subscriptionClient.use([subscriptionMiddleware]);
const link = split(
// split based on operation type
({ query }) => {
const definition = getMainDefinition(query);
// console.log(
// "##Intercepted GQL Transaction : " +
// definition.operation +
// "|" +
// definition.name.value +
// "##",
// query
// );
return (
definition.kind === "OperationDefinition" &&
definition.operation === "subscription"
);
},
wsLink,
httpLink
// split based on operation type
({query}) => {
const definition = getMainDefinition(query);
// console.log(
// "##Intercepted GQL Transaction : " +
// definition.operation +
// "|" +
// definition.name.value +
// "##",
// query
// );
return (
definition.kind === "OperationDefinition" &&
definition.operation === "subscription"
);
},
wsLink,
httpLink
);
const authLink = setContext((_, { headers }) => {
return (
auth.currentUser &&
auth.currentUser
.getIdToken()
.then((token) => {
if (token) {
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : "",
},
};
} else {
console.error(
"Authentication error. Unable to add authorization token because it was empty."
);
return { headers };
}
})
.catch((error) => {
console.error(
"Authentication error. Unable to add authorization token.",
error.message
);
return { headers };
})
);
const authLink = setContext((_, {headers}) => {
return (
auth.currentUser &&
auth.currentUser
.getIdToken()
.then((token) => {
if (token) {
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : "",
},
};
} else {
console.error(
"Authentication error. Unable to add authorization token because it was empty."
);
return {headers};
}
})
.catch((error) => {
console.error(
"Authentication error. Unable to add authorization token.",
error.message
);
return {headers};
})
);
});
const retryLink = new RetryLink({
delay: {
initial: 500,
max: 5,
jitter: true,
},
attempts: {
max: 5,
retryIf: (error, _operation) => !!error,
},
delay: {
initial: 500,
max: 5,
jitter: true,
},
attempts: {
max: 5,
retryIf: (error, _operation) => !!error,
},
});
const middlewares = [];
if (process.env.NODE_ENV === "development") {
middlewares.push(apolloLogger);
middlewares.push(apolloLogger);
}
middlewares.push(
new SentryLink().concat(
roundTripLink.concat(
retryLink.concat(errorLink.concat(authLink.concat(link)))
new SentryLink().concat(
roundTripLink.concat(
retryLink.concat(errorLink.concat(authLink.concat(link)))
)
)
)
);
const cache = new InMemoryCache({
typePolicies: {
Query: {
fields: {
conversations: offsetLimitPagination(),
},
typePolicies: {
Query: {
fields: {
conversations: offsetLimitPagination(),
},
},
},
},
});
const client = new ApolloClient({
link: ApolloLink.from(middlewares),
cache,
connectToDevTools: process.env.NODE_ENV !== "production",
defaultOptions: {
watchQuery: {
fetchPolicy: "network-only",
nextFetchPolicy: "network-only",
errorPolicy: "ignore",
link: ApolloLink.from(middlewares),
cache,
connectToDevTools: process.env.NODE_ENV !== "production",
defaultOptions: {
watchQuery: {
fetchPolicy: "network-only",
nextFetchPolicy: "network-only",
errorPolicy: "ignore",
},
query: {
fetchPolicy: "network-only",
errorPolicy: "all",
},
mutate: {
errorPolicy: "all",
},
},
query: {
fetchPolicy: "network-only",
errorPolicy: "all",
},
mutate: {
errorPolicy: "all",
},
},
});
export default client;

View File

@@ -3,6 +3,6 @@ import parsePhoneNumber from "libphonenumber-js";
import React from "react";
export default function PhoneNumberFormatter(props) {
const p = parsePhoneNumber(props.children || "", "CA");
return p ? <span>{p.formatNational()}</span> : null;
const p = parsePhoneNumber(props.children || "", "CA");
return p ? <span>{p.formatNational()}</span> : null;
}

View File

@@ -1,50 +1,50 @@
import { AlertOutlined } from "@ant-design/icons";
import { Button, notification, Space } from "antd";
import {AlertOutlined} from "@ant-design/icons";
import {Button, notification, Space} from "antd";
import i18n from "i18next";
import React from "react";
import * as serviceWorkerRegistration from "../serviceWorkerRegistration";
import { store } from "../redux/store";
import {store} from "../redux/store";
const onServiceWorkerUpdate = (registration) => {
console.log("onServiceWorkerUpdate", registration);
console.log("onServiceWorkerUpdate", registration);
const btn = (
<Space flex>
<Button
onClick={async () => {
window.open("https://imex-online.noticeable.news/", "_blank");
}}
>
{i18n.t("general.actions.viewreleasenotes")}
</Button>
<Button
type="primary"
onClick={async () => {
if (registration && registration.waiting) {
await registration.unregister();
// Makes Workbox call skipWaiting()
registration.waiting.postMessage({ type: "SKIP_WAITING" });
// Once the service worker is unregistered, we can reload the page to let
// the browser download a fresh copy of our app (invalidating the cache)
window.location.reload();
}
}}
>
{i18n.t("general.actions.refresh")}
</Button>
</Space>
);
const btn = (
<Space flex>
<Button
onClick={async () => {
window.open("https://imex-online.noticeable.news/", "_blank");
}}
>
{i18n.t("general.actions.viewreleasenotes")}
</Button>
<Button
type="primary"
onClick={async () => {
if (registration && registration.waiting) {
await registration.unregister();
// Makes Workbox call skipWaiting()
registration.waiting.postMessage({type: "SKIP_WAITING"});
// Once the service worker is unregistered, we can reload the page to let
// the browser download a fresh copy of our app (invalidating the cache)
window.location.reload();
}
}}
>
{i18n.t("general.actions.refresh")}
</Button>
</Space>
);
store.dispatch()
store.dispatch()
notification.open({
icon: <AlertOutlined />,
message: i18n.t("general.messages.newversiontitle"),
description: i18n.t("general.messages.newversionmessage"),
duration: 0,
btn,
key: "updateavailable",
});
notification.open({
icon: <AlertOutlined/>,
message: i18n.t("general.messages.newversiontitle"),
description: i18n.t("general.messages.newversionmessage"),
duration: 0,
btn,
key: "updateavailable",
});
};
serviceWorkerRegistration.register({ onUpdate: onServiceWorkerUpdate });
serviceWorkerRegistration.register({onUpdate: onServiceWorkerUpdate});

View File

@@ -1,14 +1,15 @@
import { gql } from "@apollo/client";
import {gql} from "@apollo/client";
import jsreport from "@jsreport/browser-client";
import { notification } from "antd";
import {notification} from "antd";
import axios from "axios";
import _ from "lodash";
import { auth } from "../firebase/firebase.utils";
import { setEmailOptions } from "../redux/email/email.actions";
import { store } from "../redux/store";
import {auth} from "../firebase/firebase.utils";
import {setEmailOptions} from "../redux/email/email.actions";
import {store} from "../redux/store";
import client from "../utils/GraphQLClient";
import cleanAxios from "./CleanAxios";
import { TemplateList } from "./TemplateConstants";
import {TemplateList} from "./TemplateConstants";
const server = process.env.REACT_APP_REPORTS_SERVER_URL;
jsreport.serverUrl = server;
@@ -16,343 +17,343 @@ jsreport.serverUrl = server;
const Templates = TemplateList();
export default async function RenderTemplate(
templateObject,
bodyshop,
renderAsHtml = false,
renderAsExcel = false,
renderAsText = false
) {
if (window.jsr3) {
jsreport.serverUrl = "https://reports3.test.imex.online/";
}
const jsrAuth = (await axios.post("/utils/jsr")).data;
jsreport.headers["Authorization"] = jsrAuth;
//Query assets that match the template name. Must be in format <<templateName>>.query
let { contextData, useShopSpecificTemplate } = await fetchContextData(
templateObject,
jsrAuth
);
const { ignoreCustomMargins } = Templates[templateObject.name];
let reportRequest = {
template: {
name: useShopSpecificTemplate
? `/${bodyshop.imexshopid}/${templateObject.name}`
: `/${templateObject.name}`,
...(renderAsHtml
? {}
: {
recipe: "chrome-pdf",
...(!ignoreCustomMargins && {
chrome: {
marginTop:
bodyshop.logo_img_path &&
bodyshop.logo_img_path.headerMargin &&
bodyshop.logo_img_path.headerMargin > 36
? bodyshop.logo_img_path.headerMargin
: "36px",
marginBottom:
bodyshop.logo_img_path &&
bodyshop.logo_img_path.footerMargin &&
bodyshop.logo_img_path.footerMargin > 50
? bodyshop.logo_img_path.footerMargin
: "50px",
},
}),
}),
...(renderAsExcel ? { recipe: "html-to-xlsx" } : {}),
...(renderAsText ? { recipe: "text" } : {}),
},
data: {
...contextData,
...templateObject.variables,
...templateObject.context,
headerpath: `/${bodyshop.imexshopid}/header.html`,
footerpath: `/${bodyshop.imexshopid}/footer.html`,
bodyshop: bodyshop,
offset: bodyshop.timezone, //dayjs().utcOffset(),
},
};
try {
const render = await jsreport.render(reportRequest);
if (!renderAsHtml) {
render.download(
(Templates[templateObject.name] &&
Templates[templateObject.name].title) ||
""
);
} else {
let pdf;
if (bodyshop.attach_pdf_to_email) {
const pdfRequest = _.cloneDeep(reportRequest); //Updates to spread in the header details.
pdfRequest.template = {
...pdfRequest.template,
...{
recipe: "chrome-pdf",
...(!ignoreCustomMargins && {
chrome: {
marginTop:
bodyshop.logo_img_path &&
bodyshop.logo_img_path.headerMargin &&
bodyshop.logo_img_path.headerMargin > 36
? bodyshop.logo_img_path.headerMargin
: "36px",
marginBottom:
bodyshop.logo_img_path &&
bodyshop.logo_img_path.footerMargin &&
bodyshop.logo_img_path.footerMargin > 50
? bodyshop.logo_img_path.footerMargin
: "50px",
},
}),
},
};
const pdfRender = await jsreport.render(pdfRequest);
pdf = await pdfRender.toDataURI();
}
const html = await render.toString();
return new Promise((resolve, reject) => {
resolve({
pdf,
filename:
Templates[templateObject.name] &&
Templates[templateObject.name].title,
html,
});
});
bodyshop,
renderAsHtml = false,
renderAsExcel = false,
renderAsText = false
) {
if (window.jsr3) {
jsreport.serverUrl = "https://reports3.test.imex.online/";
}
const jsrAuth = (await axios.post("/utils/jsr")).data;
jsreport.headers["Authorization"] = jsrAuth;
//Query assets that match the template name. Must be in format <<templateName>>.query
let {contextData, useShopSpecificTemplate} = await fetchContextData(
templateObject,
jsrAuth
);
const {ignoreCustomMargins} = Templates[templateObject.name];
let reportRequest = {
template: {
name: useShopSpecificTemplate
? `/${bodyshop.imexshopid}/${templateObject.name}`
: `/${templateObject.name}`,
...(renderAsHtml
? {}
: {
recipe: "chrome-pdf",
...(!ignoreCustomMargins && {
chrome: {
marginTop:
bodyshop.logo_img_path &&
bodyshop.logo_img_path.headerMargin &&
bodyshop.logo_img_path.headerMargin > 36
? bodyshop.logo_img_path.headerMargin
: "36px",
marginBottom:
bodyshop.logo_img_path &&
bodyshop.logo_img_path.footerMargin &&
bodyshop.logo_img_path.footerMargin > 50
? bodyshop.logo_img_path.footerMargin
: "50px",
},
}),
}),
...(renderAsExcel ? {recipe: "html-to-xlsx"} : {}),
...(renderAsText ? {recipe: "text"} : {}),
},
data: {
...contextData,
...templateObject.variables,
...templateObject.context,
headerpath: `/${bodyshop.imexshopid}/header.html`,
footerpath: `/${bodyshop.imexshopid}/footer.html`,
bodyshop: bodyshop,
offset: bodyshop.timezone, //dayjs().utcOffset(),
},
};
try {
const render = await jsreport.render(reportRequest);
if (!renderAsHtml) {
render.download(
(Templates[templateObject.name] &&
Templates[templateObject.name].title) ||
""
);
} else {
let pdf;
if (bodyshop.attach_pdf_to_email) {
const pdfRequest = _.cloneDeep(reportRequest); //Updates to spread in the header details.
pdfRequest.template = {
...pdfRequest.template,
...{
recipe: "chrome-pdf",
...(!ignoreCustomMargins && {
chrome: {
marginTop:
bodyshop.logo_img_path &&
bodyshop.logo_img_path.headerMargin &&
bodyshop.logo_img_path.headerMargin > 36
? bodyshop.logo_img_path.headerMargin
: "36px",
marginBottom:
bodyshop.logo_img_path &&
bodyshop.logo_img_path.footerMargin &&
bodyshop.logo_img_path.footerMargin > 50
? bodyshop.logo_img_path.footerMargin
: "50px",
},
}),
},
};
const pdfRender = await jsreport.render(pdfRequest);
pdf = await pdfRender.toDataURI();
}
const html = await render.toString();
return new Promise((resolve, reject) => {
resolve({
pdf,
filename:
Templates[templateObject.name] &&
Templates[templateObject.name].title,
html,
});
});
}
} catch (error) {
notification["error"]({message: JSON.stringify(error)});
}
} catch (error) {
notification["error"]({ message: JSON.stringify(error) });
}
}
export async function RenderTemplates(
templateObjects,
bodyshop,
renderAsHtml = false
templateObjects,
bodyshop,
renderAsHtml = false
) {
//Query assets that match the template name. Must be in format <<templateName>>.query
let unsortedTemplatesAndData = [];
let proms = [];
const jsrAuth = (await axios.post("/utils/jsr")).data;
jsreport.headers["Authorization"] = jsrAuth;
//Query assets that match the template name. Must be in format <<templateName>>.query
let unsortedTemplatesAndData = [];
let proms = [];
const jsrAuth = (await axios.post("/utils/jsr")).data;
jsreport.headers["Authorization"] = jsrAuth;
templateObjects.forEach((template) => {
proms.push(
(async () => {
let { contextData, useShopSpecificTemplate } = await fetchContextData(
template,
jsrAuth
templateObjects.forEach((template) => {
proms.push(
(async () => {
let {contextData, useShopSpecificTemplate} = await fetchContextData(
template,
jsrAuth
);
unsortedTemplatesAndData.push({
templateObject: template,
contextData,
useShopSpecificTemplate,
});
})()
);
unsortedTemplatesAndData.push({
templateObject: template,
contextData,
useShopSpecificTemplate,
});
})()
);
});
await Promise.all(proms);
});
await Promise.all(proms);
//Re-order list to follow speedprint.
// var templateAndData = _.sortBy(unsortedTemplatesAndData, function (item) {
// return templateObjects.findIndex(
// (template) => template.name === item.templateObject.name
// );
// });
if (window.jsr3) {
jsreport.serverUrl = "https://reports3.test.imex.online/";
}
unsortedTemplatesAndData.sort(function (a, b) {
return (
templateObjects.findIndex((x) => x.name === a.templateObject.name) -
templateObjects.findIndex((x) => x.name === b.templateObject.name)
);
});
const templateAndData = unsortedTemplatesAndData;
let rootTemplate = templateAndData.shift();
let reportRequest = {
template: {
name: rootTemplate.useShopSpecificTemplate
? `/${bodyshop.imexshopid}/${rootTemplate.templateObject.name}`
: `/${rootTemplate.templateObject.name}`,
...(renderAsHtml
? {}
: {
recipe: "chrome-pdf",
chrome: {
marginTop:
bodyshop.logo_img_path &&
bodyshop.logo_img_path.headerMargin &&
bodyshop.logo_img_path.headerMargin > 36
? bodyshop.logo_img_path.headerMargin
: "36px",
marginBottom:
bodyshop.logo_img_path &&
bodyshop.logo_img_path.footerMargin &&
bodyshop.logo_img_path.footerMargin > 50
? bodyshop.logo_img_path.footerMargin
: "50px",
},
}),
pdfOperations: [
{
template: {
name: "/components/Header-Footer",
recipe: "chrome-pdf",
engine: "handlebars",
},
type: "merge",
},
...templateAndData.map((template) => {
return {
template: {
chrome: {
marginTop:
bodyshop.logo_img_path &&
bodyshop.logo_img_path.headerMargin &&
bodyshop.logo_img_path.headerMargin > 36
? bodyshop.logo_img_path.headerMargin
: "36px",
marginBottom:
bodyshop.logo_img_path &&
bodyshop.logo_img_path.footerMargin &&
bodyshop.logo_img_path.footerMargin > 50
? bodyshop.logo_img_path.footerMargin
: "50px",
},
name: template.useShopSpecificTemplate
? `/${bodyshop.imexshopid}/${template.templateObject.name}`
: `/${template.templateObject.name}`,
...(renderAsHtml ? {} : { recipe: "chrome-pdf" }),
},
type: "append",
// mergeWholeDocument: true,
// renderForEveryPage: true,
};
}),
],
},
data: {
...extend(
rootTemplate.contextData,
...templateAndData.map((temp) => temp.contextData)
),
// ...rootTemplate.templateObject.variables,
// ...rootTemplate.templateObject.context,
headerpath: `/${bodyshop.imexshopid}/header.html`,
footerpath: `/${bodyshop.imexshopid}/footer.html`,
bodyshop: bodyshop,
offset: bodyshop.timezone,
},
};
try {
const render = await jsreport.render(reportRequest);
if (!renderAsHtml) {
render.download("Speed Print");
} else {
return render.toString();
//Re-order list to follow speedprint.
// var templateAndData = _.sortBy(unsortedTemplatesAndData, function (item) {
// return templateObjects.findIndex(
// (template) => template.name === item.templateObject.name
// );
// });
if (window.jsr3) {
jsreport.serverUrl = "https://reports3.test.imex.online/";
}
unsortedTemplatesAndData.sort(function (a, b) {
return (
templateObjects.findIndex((x) => x.name === a.templateObject.name) -
templateObjects.findIndex((x) => x.name === b.templateObject.name)
);
});
const templateAndData = unsortedTemplatesAndData;
let rootTemplate = templateAndData.shift();
let reportRequest = {
template: {
name: rootTemplate.useShopSpecificTemplate
? `/${bodyshop.imexshopid}/${rootTemplate.templateObject.name}`
: `/${rootTemplate.templateObject.name}`,
...(renderAsHtml
? {}
: {
recipe: "chrome-pdf",
chrome: {
marginTop:
bodyshop.logo_img_path &&
bodyshop.logo_img_path.headerMargin &&
bodyshop.logo_img_path.headerMargin > 36
? bodyshop.logo_img_path.headerMargin
: "36px",
marginBottom:
bodyshop.logo_img_path &&
bodyshop.logo_img_path.footerMargin &&
bodyshop.logo_img_path.footerMargin > 50
? bodyshop.logo_img_path.footerMargin
: "50px",
},
}),
pdfOperations: [
{
template: {
name: "/components/Header-Footer",
recipe: "chrome-pdf",
engine: "handlebars",
},
type: "merge",
},
...templateAndData.map((template) => {
return {
template: {
chrome: {
marginTop:
bodyshop.logo_img_path &&
bodyshop.logo_img_path.headerMargin &&
bodyshop.logo_img_path.headerMargin > 36
? bodyshop.logo_img_path.headerMargin
: "36px",
marginBottom:
bodyshop.logo_img_path &&
bodyshop.logo_img_path.footerMargin &&
bodyshop.logo_img_path.footerMargin > 50
? bodyshop.logo_img_path.footerMargin
: "50px",
},
name: template.useShopSpecificTemplate
? `/${bodyshop.imexshopid}/${template.templateObject.name}`
: `/${template.templateObject.name}`,
...(renderAsHtml ? {} : {recipe: "chrome-pdf"}),
},
type: "append",
// mergeWholeDocument: true,
// renderForEveryPage: true,
};
}),
],
},
data: {
...extend(
rootTemplate.contextData,
...templateAndData.map((temp) => temp.contextData)
),
// ...rootTemplate.templateObject.variables,
// ...rootTemplate.templateObject.context,
headerpath: `/${bodyshop.imexshopid}/header.html`,
footerpath: `/${bodyshop.imexshopid}/footer.html`,
bodyshop: bodyshop,
offset: bodyshop.timezone,
},
};
try {
const render = await jsreport.render(reportRequest);
if (!renderAsHtml) {
render.download("Speed Print");
} else {
return render.toString();
}
} catch (error) {
notification["error"]({message: JSON.stringify(error)});
}
} catch (error) {
notification["error"]({ message: JSON.stringify(error) });
}
}
export const GenerateDocument = async (
template,
messageOptions,
sendType,
jobid
template,
messageOptions,
sendType,
jobid
) => {
const bodyshop = store.getState().user.bodyshop;
if (sendType === "e") {
store.dispatch(
setEmailOptions({
jobid,
messageOptions: {
...messageOptions,
to: Array.isArray(messageOptions.to)
? messageOptions.to
: [messageOptions.to],
},
template,
})
);
} else if (sendType === "x") {
console.log("excel");
await RenderTemplate(template, bodyshop, false, true);
} else if (sendType === "text") {
await RenderTemplate(template, bodyshop, false, false, true);
} else {
await RenderTemplate(template, bodyshop);
}
const bodyshop = store.getState().user.bodyshop;
if (sendType === "e") {
store.dispatch(
setEmailOptions({
jobid,
messageOptions: {
...messageOptions,
to: Array.isArray(messageOptions.to)
? messageOptions.to
: [messageOptions.to],
},
template,
})
);
} else if (sendType === "x") {
console.log("excel");
await RenderTemplate(template, bodyshop, false, true);
} else if (sendType === "text") {
await RenderTemplate(template, bodyshop, false, false, true);
} else {
await RenderTemplate(template, bodyshop);
}
};
export const GenerateDocuments = async (templates) => {
const bodyshop = store.getState().user.bodyshop;
await RenderTemplates(templates, bodyshop);
const bodyshop = store.getState().user.bodyshop;
await RenderTemplates(templates, bodyshop);
};
const fetchContextData = async (templateObject, jsrAuth) => {
const bodyshop = store.getState().user.bodyshop;
const bodyshop = store.getState().user.bodyshop;
jsreport.headers["FirebaseAuthorization"] =
"Bearer " + (await auth.currentUser.getIdToken());
jsreport.headers["FirebaseAuthorization"] =
"Bearer " + (await auth.currentUser.getIdToken());
const folders = await cleanAxios.get(`${server}/odata/folders`, {
headers: { Authorization: jsrAuth },
});
const shopSpecificFolder = folders.data.value.find(
(f) => f.name === bodyshop.imexshopid
);
const jsReportQueries = await cleanAxios.get(
`${server}/odata/assets?$filter=name eq '${templateObject.name}.query'`,
{ headers: { Authorization: jsrAuth } }
);
let templateQueryToExecute;
let useShopSpecificTemplate = false;
// let shopSpecificTemplate;
if (shopSpecificFolder) {
let shopSpecificTemplate = jsReportQueries.data.value.find(
(f) => f?.folder?.shortid === shopSpecificFolder.shortid
);
if (shopSpecificTemplate) {
useShopSpecificTemplate = true;
templateQueryToExecute = atob(shopSpecificTemplate.content);
}
}
if (!templateQueryToExecute) {
const generalTemplate = jsReportQueries.data.value.find((f) => !f.folder);
useShopSpecificTemplate = false;
templateQueryToExecute = atob(generalTemplate.content);
}
let contextData = {};
if (templateQueryToExecute) {
const { data } = await client.query({
query: gql(templateQueryToExecute),
variables: { ...templateObject.variables },
const folders = await cleanAxios.get(`${server}/odata/folders`, {
headers: {Authorization: jsrAuth},
});
contextData = data;
}
const shopSpecificFolder = folders.data.value.find(
(f) => f.name === bodyshop.imexshopid
);
return { contextData, useShopSpecificTemplate };
const jsReportQueries = await cleanAxios.get(
`${server}/odata/assets?$filter=name eq '${templateObject.name}.query'`,
{headers: {Authorization: jsrAuth}}
);
let templateQueryToExecute;
let useShopSpecificTemplate = false;
// let shopSpecificTemplate;
if (shopSpecificFolder) {
let shopSpecificTemplate = jsReportQueries.data.value.find(
(f) => f?.folder?.shortid === shopSpecificFolder.shortid
);
if (shopSpecificTemplate) {
useShopSpecificTemplate = true;
templateQueryToExecute = atob(shopSpecificTemplate.content);
}
}
if (!templateQueryToExecute) {
const generalTemplate = jsReportQueries.data.value.find((f) => !f.folder);
useShopSpecificTemplate = false;
templateQueryToExecute = atob(generalTemplate.content);
}
let contextData = {};
if (templateQueryToExecute) {
const {data} = await client.query({
query: gql(templateQueryToExecute),
variables: {...templateObject.variables},
});
contextData = data;
}
return {contextData, useShopSpecificTemplate};
};
//export const displayTemplateInWindow = (html) => {
@@ -388,21 +389,21 @@ const fetchContextData = async (templateObject, jsrAuth) => {
// };
function extend(o1, o2, o3) {
var result = {},
obj;
var result = {},
obj;
for (var i = 0; i < arguments.length; i++) {
obj = arguments[i];
for (var key in obj) {
if (Object.prototype.toString.call(obj[key]) === "[object Object]") {
if (typeof result[key] === "undefined") {
result[key] = {};
for (var i = 0; i < arguments.length; i++) {
obj = arguments[i];
for (var key in obj) {
if (Object.prototype.toString.call(obj[key]) === "[object Object]") {
if (typeof result[key] === "undefined") {
result[key] = {};
}
result[key] = extend(result[key], obj[key]);
} else {
result[key] = obj[key];
}
}
result[key] = extend(result[key], obj[key]);
} else {
result[key] = obj[key];
}
}
}
return result;
return result;
}

View File

@@ -1,45 +1,45 @@
import _ from "lodash";
export const CheckJobBucket = (buckets, job) => {
const jobHours =
job.labhrs.aggregate.sum.mod_lb_hrs + job.larhrs.aggregate.sum.mod_lb_hrs;
const jobHours =
job.labhrs.aggregate.sum.mod_lb_hrs + job.larhrs.aggregate.sum.mod_lb_hrs;
const matchingBucket = buckets.filter((b) =>
b.gte <= jobHours && b.lt ? b.lt > jobHours : true
);
const matchingBucket = buckets.filter((b) =>
b.gte <= jobHours && b.lt ? b.lt > jobHours : true
);
return matchingBucket[0] && matchingBucket[0].id;
return matchingBucket[0] && matchingBucket[0].id;
};
export const CalculateLoad = (currentLoad, buckets, jobsIn, jobsOut) => {
//Add the jobs coming
const newLoad = _.cloneDeep(currentLoad);
jobsIn.forEach((job) => {
const bucketId = CheckJobBucket(buckets, job);
if (bucketId) {
newLoad[bucketId].count = newLoad[bucketId].count + 1;
} else {
console.log(
"[Util Arr Job]Uh oh, this job doesn't fit in a bucket!",
job
);
}
});
//Add the jobs coming
const newLoad = _.cloneDeep(currentLoad);
jobsIn.forEach((job) => {
const bucketId = CheckJobBucket(buckets, job);
if (bucketId) {
newLoad[bucketId].count = newLoad[bucketId].count + 1;
} else {
console.log(
"[Util Arr Job]Uh oh, this job doesn't fit in a bucket!",
job
);
}
});
jobsOut.forEach((job) => {
const bucketId = CheckJobBucket(buckets, job);
if (bucketId) {
newLoad[bucketId].count = newLoad[bucketId].count - 1;
if (newLoad[bucketId].count < 0) {
console.log("***ERROR: NEGATIVE LOAD", bucketId, job);
}
} else {
console.log(
"[Util Out Job]Uh oh, this job doesn't fit in a bucket!",
job
);
}
});
jobsOut.forEach((job) => {
const bucketId = CheckJobBucket(buckets, job);
if (bucketId) {
newLoad[bucketId].count = newLoad[bucketId].count - 1;
if (newLoad[bucketId].count < 0) {
console.log("***ERROR: NEGATIVE LOAD", bucketId, job);
}
} else {
console.log(
"[Util Out Job]Uh oh, this job doesn't fit in a bucket!",
job
);
}
});
return newLoad;
return newLoad;
};

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
import React from "react";
export function PartsLabelMulti() {
return <div></div>;
return <div></div>;
}

View File

@@ -1,148 +1,148 @@
export const MockBodyshop = {
address1: "123 Fake St",
address2: "Unit #100",
city: "Vancouver",
country: "Canada",
created_at: "2019-12-10T20:03:06.420853+00:00",
email: "snaptsoft@gmail.com",
federal_tax_id: "GST10150492",
id: "52b7357c-0edd-4c95-85c3-dfdbcdfad9ac",
insurance_vendor_id: "F123456",
logo_img_path: "https://www.snapt.ca/assets/logo-placeholder.png",
md_ro_statuses: {
statuses: [
"Open",
"Scheduled",
"Arrived",
"Repair Plan",
"Parts",
"Body",
"Prep",
"Paint",
"Reassembly",
"Sublet",
"Detail",
"Completed",
"Delivered",
"Invoiced",
"Exported",
],
open_statuses: [
"Open",
"Scheduled",
"Arrived",
"Repair Plan",
"Parts",
"Body",
"Prep",
"Paint",
],
default_arrived: "Arrived",
default_exported: "Exported",
default_imported: "Open",
default_invoiced: "Invoiced",
default_completed: "Completed",
default_delivered: "Delivered",
default_scheduled: "Scheduled",
},
md_order_statuses: {
statuses: ["Ordered", "Received", "Canceled", "Backordered"],
default_bo: "Backordered",
default_ordered: "Ordered",
default_canceled: "Canceled",
default_received: "Received",
},
shopname: "Testing Collision",
state: "BC",
state_tax_id: "PST1000-2991",
updated_at: "2020-03-23T22:06:03.509544+00:00",
zip_post: "V6B 1M9",
region_config: "CA_BC",
md_responsibility_centers: {
costs: [
"Aftermarket",
"ATS",
"Body",
"Detail",
"Daignostic",
"Electrical",
"Chrome",
"Frame",
"Mechanical",
"Refinish",
"Structural",
"Existing",
"Glass",
"LKQ",
"OEM",
"OEM Partial",
"Re-cored",
"Remanufactured",
"Other",
"Sublet",
"Towing",
],
profits: [
"Aftermarket",
"ATS",
"Body",
"Detail",
"Daignostic",
"Electrical",
"Chrome",
"Frame",
"Mechanical",
"Refinish",
"Structural",
"Existing",
"Glass",
"LKQ",
"OEM",
"OEM Partial",
"Re-cored",
"Remanufactured",
"Other",
"Sublet",
"Towing",
],
defaults: {
ATS: "ATS",
LAB: "Body",
LAD: "Diagnostic",
LAE: "Electrical",
LAF: "Frame",
LAG: "Glass",
LAM: "Mechanical",
LAR: "Refinish",
LAS: "Structural",
LAU: "Detail",
PAA: "Aftermarket",
PAC: "Chrome",
PAL: "LKQ",
PAM: "Remanufactured",
PAN: "OEM",
PAO: "Other",
PAP: "OEM Partial",
PAR: "16",
TOW: "Towing",
address1: "123 Fake St",
address2: "Unit #100",
city: "Vancouver",
country: "Canada",
created_at: "2019-12-10T20:03:06.420853+00:00",
email: "snaptsoft@gmail.com",
federal_tax_id: "GST10150492",
id: "52b7357c-0edd-4c95-85c3-dfdbcdfad9ac",
insurance_vendor_id: "F123456",
logo_img_path: "https://www.snapt.ca/assets/logo-placeholder.png",
md_ro_statuses: {
statuses: [
"Open",
"Scheduled",
"Arrived",
"Repair Plan",
"Parts",
"Body",
"Prep",
"Paint",
"Reassembly",
"Sublet",
"Detail",
"Completed",
"Delivered",
"Invoiced",
"Exported",
],
open_statuses: [
"Open",
"Scheduled",
"Arrived",
"Repair Plan",
"Parts",
"Body",
"Prep",
"Paint",
],
default_arrived: "Arrived",
default_exported: "Exported",
default_imported: "Open",
default_invoiced: "Invoiced",
default_completed: "Completed",
default_delivered: "Delivered",
default_scheduled: "Scheduled",
},
},
employees: [
{
id: "075b744c-8919-49ca-abb2-ccd51040326d",
first_name: "Patrick",
last_name: "BODY123",
employee_number: "101",
cost_center: "Body",
__typename: "employees",
md_order_statuses: {
statuses: ["Ordered", "Received", "Canceled", "Backordered"],
default_bo: "Backordered",
default_ordered: "Ordered",
default_canceled: "Canceled",
default_received: "Received",
},
{
id: "8cc787d3-1cfe-49d3-8a15-8469cd5c2e41",
first_name: "Patrick",
last_name: "Painter",
employee_number: "10211",
cost_center: "REFINISH",
__typename: "employees",
shopname: "Testing Collision",
state: "BC",
state_tax_id: "PST1000-2991",
updated_at: "2020-03-23T22:06:03.509544+00:00",
zip_post: "V6B 1M9",
region_config: "CA_BC",
md_responsibility_centers: {
costs: [
"Aftermarket",
"ATS",
"Body",
"Detail",
"Daignostic",
"Electrical",
"Chrome",
"Frame",
"Mechanical",
"Refinish",
"Structural",
"Existing",
"Glass",
"LKQ",
"OEM",
"OEM Partial",
"Re-cored",
"Remanufactured",
"Other",
"Sublet",
"Towing",
],
profits: [
"Aftermarket",
"ATS",
"Body",
"Detail",
"Daignostic",
"Electrical",
"Chrome",
"Frame",
"Mechanical",
"Refinish",
"Structural",
"Existing",
"Glass",
"LKQ",
"OEM",
"OEM Partial",
"Re-cored",
"Remanufactured",
"Other",
"Sublet",
"Towing",
],
defaults: {
ATS: "ATS",
LAB: "Body",
LAD: "Diagnostic",
LAE: "Electrical",
LAF: "Frame",
LAG: "Glass",
LAM: "Mechanical",
LAR: "Refinish",
LAS: "Structural",
LAU: "Detail",
PAA: "Aftermarket",
PAC: "Chrome",
PAL: "LKQ",
PAM: "Remanufactured",
PAN: "OEM",
PAO: "Other",
PAP: "OEM Partial",
PAR: "16",
TOW: "Towing",
},
},
],
employees: [
{
id: "075b744c-8919-49ca-abb2-ccd51040326d",
first_name: "Patrick",
last_name: "BODY123",
employee_number: "101",
cost_center: "Body",
__typename: "employees",
},
{
id: "8cc787d3-1cfe-49d3-8a15-8469cd5c2e41",
first_name: "Patrick",
last_name: "Painter",
employee_number: "10211",
cost_center: "REFINISH",
__typename: "employees",
},
],
};

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,3 @@
export function onlyUnique(value, index, self, key) {
return self.indexOf(value) === index;
return self.indexOf(value) === index;
}

View File

@@ -1,9 +1,9 @@
function confirmDialog(msg) {
return new Promise(function (resolve, reject) {
let confirmed = window.confirm(msg);
return new Promise(function (resolve, reject) {
let confirmed = window.confirm(msg);
return confirmed ? resolve(true) : resolve(false);
});
return confirmed ? resolve(true) : resolve(false);
});
}
export default confirmDialog;

View File

@@ -1,4 +1,3 @@
// Sometimes referred to as PageSize, this variable controls the amount of records
// to show on one page during pagination.
export const pageLimit = 50;

View File

@@ -1,9 +1,9 @@
import i18n from "i18next";
export function CreateRecentItem(id, type, labelid, url) {
return {
id,
label: `${i18n.t(`general.itemtypes.${type}`)}: ${labelid}`,
url,
};
return {
id,
label: `${i18n.t(`general.itemtypes.${type}`)}: ${labelid}`,
url,
};
}

View File

@@ -1,12 +1,12 @@
import axios from "axios";
import { notification } from "antd";
import {notification} from "antd";
async function CriticalPartsScan(jobid) {
try {
await axios.post("/job/partsscan", { jobid });
} catch (error) {
notification.open({ type: "error", message: JSON.stringify(error) });
}
try {
await axios.post("/job/partsscan", {jobid});
} catch (error) {
notification.open({type: "error", message: JSON.stringify(error)});
}
}
export default CriticalPartsScan;

View File

@@ -1,69 +1,69 @@
export default async function FcmHandler({ client, payload }) {
switch (payload.type) {
case "messaging-inbound":
client.cache.modify({
id: client.cache.identify({
__typename: "conversations",
id: payload.conversationid,
}),
fields: {
messages_aggregate(cached) {
return { aggregate: { count: cached.aggregate.count + 1 } };
},
},
});
client.cache.modify({
fields: {
messages_aggregate(cached) {
return { aggregate: { count: cached.aggregate.count + 1 } };
},
},
});
break;
case "messaging-outbound":
client.cache.modify({
id: client.cache.identify({
__typename: "conversations",
id: payload.conversationid,
}),
fields: {
updated_at(oldupdated0) {
return new Date();
},
// messages_aggregate(cached) {
// return { aggregate: { count: cached.aggregate.count + 1 } };
// },
},
});
break;
case "messaging-mark-conversation-read":
let previousUnreadCount = 0;
client.cache.modify({
id: client.cache.identify({
__typename: "conversations",
id: payload.conversationid,
}),
fields: {
messages_aggregate(cached) {
previousUnreadCount = cached.aggregate.count;
return { aggregate: { count: 0 } };
},
},
});
client.cache.modify({
fields: {
messages_aggregate(cached) {
return {
aggregate: {
count: cached.aggregate.count - previousUnreadCount,
},
};
},
},
});
break;
default:
console.log("No payload type set.");
break;
}
export default async function FcmHandler({client, payload}) {
switch (payload.type) {
case "messaging-inbound":
client.cache.modify({
id: client.cache.identify({
__typename: "conversations",
id: payload.conversationid,
}),
fields: {
messages_aggregate(cached) {
return {aggregate: {count: cached.aggregate.count + 1}};
},
},
});
client.cache.modify({
fields: {
messages_aggregate(cached) {
return {aggregate: {count: cached.aggregate.count + 1}};
},
},
});
break;
case "messaging-outbound":
client.cache.modify({
id: client.cache.identify({
__typename: "conversations",
id: payload.conversationid,
}),
fields: {
updated_at(oldupdated0) {
return new Date();
},
// messages_aggregate(cached) {
// return { aggregate: { count: cached.aggregate.count + 1 } };
// },
},
});
break;
case "messaging-mark-conversation-read":
let previousUnreadCount = 0;
client.cache.modify({
id: client.cache.identify({
__typename: "conversations",
id: payload.conversationid,
}),
fields: {
messages_aggregate(cached) {
previousUnreadCount = cached.aggregate.count;
return {aggregate: {count: 0}};
},
},
});
client.cache.modify({
fields: {
messages_aggregate(cached) {
return {
aggregate: {
count: cached.aggregate.count - previousUnreadCount,
},
};
},
},
});
break;
default:
console.log("No payload type set.");
break;
}
}

View File

@@ -1,10 +1,10 @@
export default function formatBytes(a, b = 2) {
if (0 === a || !a) return "0 Bytes";
const c = 0 > b ? 0 : b,
d = Math.floor(Math.log(a) / Math.log(1024));
return (
parseFloat((a / Math.pow(1024, d)).toFixed(c)) +
" " +
["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"][d]
);
if (0 === a || !a) return "0 Bytes";
const c = 0 > b ? 0 : b,
d = Math.floor(Math.log(a) / Math.log(1024));
return (
parseFloat((a / Math.pow(1024, d)).toFixed(c)) +
" " +
["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"][d]
);
}

View File

@@ -24,7 +24,7 @@ export const handleBeta = () => {
// Beta is enabled, but the current host name does start with beta.
if (isBeta && !currentHostName.startsWith('beta')) {
const href= `${window.location.protocol}//beta.${currentHostName}${window.location.pathname}${window.location.search}${window.location.hash}`;
const href = `${window.location.protocol}//beta.${currentHostName}${window.location.pathname}${window.location.search}${window.location.hash}`;
window.location.replace(href);
}

View File

@@ -1,4 +1,4 @@
export default function IsJobReadOnly(job) {
if (!job) return false;
return job.date_exported || job.date_invoiced || job.voided;
if (!job) return false;
return job.date_exported || job.date_invoiced || job.voided;
}

View File

@@ -1,6 +1,6 @@
import { store } from "../redux/store";
import {store} from "../redux/store";
export function CreateExplorerLinkForJob({ jobid }) {
const bodyshop = store.getState().user.bodyshop;
return `imexmedia://${bodyshop.localmediaservernetwork}\\Jobs\\${jobid}`;
export function CreateExplorerLinkForJob({jobid}) {
const bodyshop = store.getState().user.bodyshop;
return `imexmedia://${bodyshop.localmediaservernetwork}\\Jobs\\${jobid}`;
}

View File

@@ -1,5 +1,6 @@
import {useBeforeUnload, useBlocker} from "react-router-dom";
import {useCallback, useEffect, useRef} from "react";
function usePrompt(message, {beforeUnload} = {}) {
let blocker = useBlocker(

View File

@@ -1,19 +1,19 @@
export function alphaSort(a, b) {
return (a ? a.toLowerCase() : "").localeCompare(b ? b.toLowerCase() : "");
return (a ? a.toLowerCase() : "").localeCompare(b ? b.toLowerCase() : "");
// if (A < B)
// //sort string ascending
// return -1;
// if (A > B) return 1;
// return 0; //default return value (no sorting)
// if (A < B)
// //sort string ascending
// return -1;
// if (A > B) return 1;
// return 0; //default return value (no sorting)
}
export function dateSort(a, b) {
return new Date(a) - new Date(b);
return new Date(a) - new Date(b);
}
export function statusSort(a, b, statusList) {
return (
statusList.findIndex((x) => x === a) - statusList.findIndex((x) => x === b)
);
return (
statusList.findIndex((x) => x === a) - statusList.findIndex((x) => x === b)
);
}

View File

@@ -1,10 +1,10 @@
export default function UndefinedToNull(obj, keys) {
Object.keys(obj).forEach((key) => {
if (keys && keys.indexOf(key) >= 0) {
if (obj[key] === undefined) obj[key] = null;
} else {
if (obj[key] === undefined) obj[key] = null;
}
});
return obj;
Object.keys(obj).forEach((key) => {
if (keys && keys.indexOf(key) >= 0) {
if (obj[key] === undefined) obj[key] = null;
} else {
if (obj[key] === undefined) obj[key] = null;
}
});
return obj;
}

View File

@@ -1,40 +1,40 @@
import { useState } from "react";
import {useState} from "react";
export default function useLocalStorage(key, initialValue) {
// State to store our value
// Pass initial state function to useState so logic is only executed once
const [storedValue, setStoredValue] = useState(() => {
if (typeof window === "undefined") {
return initialValue;
}
try {
// Get from local storage by key
const item = window.localStorage.getItem(key);
// Parse stored json or if none return initialValue
return item ? JSON.parse(item) : initialValue;
} catch (error) {
// If error also return initialValue
console.log(error);
return initialValue;
}
});
// Return a wrapped version of useState's setter function that ...
// ... persists the new value to localStorage.
const setValue = (value) => {
try {
// Allow value to be a function so we have same API as useState
const valueToStore =
value instanceof Function ? value(storedValue) : value;
// Save state
setStoredValue(valueToStore);
// Save to local storage
if (typeof window !== "undefined") {
window.localStorage.setItem(key, JSON.stringify(valueToStore));
}
} catch (error) {
// A more advanced implementation would handle the error case
console.log(error);
}
};
return [storedValue, setValue];
// State to store our value
// Pass initial state function to useState so logic is only executed once
const [storedValue, setStoredValue] = useState(() => {
if (typeof window === "undefined") {
return initialValue;
}
try {
// Get from local storage by key
const item = window.localStorage.getItem(key);
// Parse stored json or if none return initialValue
return item ? JSON.parse(item) : initialValue;
} catch (error) {
// If error also return initialValue
console.log(error);
return initialValue;
}
});
// Return a wrapped version of useState's setter function that ...
// ... persists the new value to localStorage.
const setValue = (value) => {
try {
// Allow value to be a function so we have same API as useState
const valueToStore =
value instanceof Function ? value(storedValue) : value;
// Save state
setStoredValue(valueToStore);
// Save to local storage
if (typeof window !== "undefined") {
window.localStorage.setItem(key, JSON.stringify(valueToStore));
}
} catch (error) {
// A more advanced implementation would handle the error case
console.log(error);
}
};
return [storedValue, setValue];
}

View File

@@ -1,18 +1,19 @@
import { useEffect, useRef } from "react";
import {useEffect, useRef} from "react";
function useTraceUpdate(props) {
const prev = useRef(props);
useEffect(() => {
const changedProps = Object.entries(props).reduce((ps, [k, v]) => {
if (prev.current[k] !== v) {
ps[k] = [prev.current[k], v];
}
return ps;
}, {});
if (Object.keys(changedProps).length > 0) {
console.log("Changed props:", changedProps);
}
prev.current = props;
});
const prev = useRef(props);
useEffect(() => {
const changedProps = Object.entries(props).reduce((ps, [k, v]) => {
if (prev.current[k] !== v) {
ps[k] = [prev.current[k], v];
}
return ps;
}, {});
if (Object.keys(changedProps).length > 0) {
console.log("Changed props:", changedProps);
}
prev.current = props;
});
}
export default useTraceUpdate;