Minor bug fixing after smoke testing.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
VITE_APP_GRAPHQL_ENDPOINT=https://db.dev.bodyshop.app/v1/graphql
|
VITE_APP_GRAPHQL_ENDPOINT=https://db.dev.bodyshop.app/v1/graphql
|
||||||
VITE_APP_GRAPHQL_ENDPOINT_WS=wss://db.dev.bodyshop.app/v1/graphql
|
VITE_APP_GRAPHQL_ENDPOINT_WS=wss://db.dev.bodyshop.app/v1/graphql
|
||||||
VITE_APP_GA_CODE=231099835
|
VITE_APP_GA_CODE=231099835
|
||||||
VITE_APP_FIREBASE_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"}
|
VITE_APP_FIREBASE_CONFIG={ "apiKey": "AIzaSyAuLQR9SV5LsVxjU8wh9hvFLdhcAHU6cxE", "authDomain": "rome-prod-1.firebaseapp.com", "projectId": "rome-prod-1", "storageBucket": "rome-prod-1.appspot.com", "messagingSenderId": "147786367145", "appId": "1:147786367145:web:9d4cba68071c3f29a8a9b8", "measurementId": "G-G8Z9DRHTZS"}
|
||||||
VITE_APP_CLOUDINARY_ENDPOINT_API=https://api.cloudinary.com/v1_1/io-test
|
VITE_APP_CLOUDINARY_ENDPOINT_API=https://api.cloudinary.com/v1_1/io-test
|
||||||
VITE_APP_CLOUDINARY_ENDPOINT=https://res.cloudinary.com/io-test
|
VITE_APP_CLOUDINARY_ENDPOINT=https://res.cloudinary.com/io-test
|
||||||
VITE_APP_CLOUDINARY_API_KEY=957865933348715
|
VITE_APP_CLOUDINARY_API_KEY=957865933348715
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ GENERATE_SOURCEMAP=true
|
|||||||
VITE_APP_GRAPHQL_ENDPOINT=https://db.imex.online/v1/graphql
|
VITE_APP_GRAPHQL_ENDPOINT=https://db.imex.online/v1/graphql
|
||||||
VITE_APP_GRAPHQL_ENDPOINT_WS=wss://db.imex.online/v1/graphql
|
VITE_APP_GRAPHQL_ENDPOINT_WS=wss://db.imex.online/v1/graphql
|
||||||
VITE_APP_GA_CODE=231103507
|
VITE_APP_GA_CODE=231103507
|
||||||
VITE_APP_FIREBASE_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"}
|
VITE_APP_FIREBASE_CONFIG={ "apiKey": "AIzaSyAuLQR9SV5LsVxjU8wh9hvFLdhcAHU6cxE", "authDomain": "rome-prod-1.firebaseapp.com", "projectId": "rome-prod-1", "storageBucket": "rome-prod-1.appspot.com", "messagingSenderId": "147786367145", "appId": "1:147786367145:web:9d4cba68071c3f29a8a9b8", "measurementId": "G-G8Z9DRHTZS"}
|
||||||
VITE_APP_CLOUDINARY_ENDPOINT_API=https://api.cloudinary.com/v1_1/bodyshop
|
VITE_APP_CLOUDINARY_ENDPOINT_API=https://api.cloudinary.com/v1_1/bodyshop
|
||||||
VITE_APP_CLOUDINARY_ENDPOINT=https://res.cloudinary.com/bodyshop
|
VITE_APP_CLOUDINARY_ENDPOINT=https://res.cloudinary.com/bodyshop
|
||||||
VITE_APP_CLOUDINARY_API_KEY=473322739956866
|
VITE_APP_CLOUDINARY_API_KEY=473322739956866
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
VITE_APP_GRAPHQL_ENDPOINT=https://db.test.bodyshop.app/v1/graphql
|
VITE_APP_GRAPHQL_ENDPOINT=https://db.test.bodyshop.app/v1/graphql
|
||||||
VITE_APP_GRAPHQL_ENDPOINT_WS=wss://db.test.bodyshop.app/v1/graphql
|
VITE_APP_GRAPHQL_ENDPOINT_WS=wss://db.test.bodyshop.app/v1/graphql
|
||||||
VITE_APP_GA_CODE=231099835
|
VITE_APP_GA_CODE=231099835
|
||||||
VITE_APP_FIREBASE_CONFIG={ "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"}
|
VITE_APP_FIREBASE_CONFIG={ "apiKey": "AIzaSyAuLQR9SV5LsVxjU8wh9hvFLdhcAHU6cxE", "authDomain": "rome-prod-1.firebaseapp.com", "projectId": "rome-prod-1", "storageBucket": "rome-prod-1.appspot.com", "messagingSenderId": "147786367145", "appId": "1:147786367145:web:9d4cba68071c3f29a8a9b8", "measurementId": "G-G8Z9DRHTZS"}
|
||||||
VITE_APP_CLOUDINARY_ENDPOINT_API=https://api.cloudinary.com/v1_1/bodyshop
|
VITE_APP_CLOUDINARY_ENDPOINT_API=https://api.cloudinary.com/v1_1/bodyshop
|
||||||
VITE_APP_CLOUDINARY_ENDPOINT=https://res.cloudinary.com/bodyshop
|
VITE_APP_CLOUDINARY_ENDPOINT=https://res.cloudinary.com/bodyshop
|
||||||
VITE_APP_CLOUDINARY_API_KEY=473322739956866
|
VITE_APP_CLOUDINARY_API_KEY=473322739956866
|
||||||
|
|||||||
@@ -11,24 +11,28 @@ let isDarkMode = false;
|
|||||||
* @type {{components: {Menu: {itemDividerBorderColor: string}}}}
|
* @type {{components: {Menu: {itemDividerBorderColor: string}}}}
|
||||||
*/
|
*/
|
||||||
const defaultTheme = {
|
const defaultTheme = {
|
||||||
components: {
|
components: {
|
||||||
Table: {
|
Table: {
|
||||||
rowHoverBg: '#e7f3ff',
|
rowHoverBg: '#e7f3ff',
|
||||||
rowSelectedBg: '#e6f7ff',
|
rowSelectedBg: '#e6f7ff',
|
||||||
headerSortHoverBg: 'transparent',
|
headerSortHoverBg: 'transparent',
|
||||||
},
|
|
||||||
Menu: {
|
|
||||||
darkItemHoverBg: '#1677ff',
|
|
||||||
itemHoverBg: '#1677ff',
|
|
||||||
horizontalItemHoverBg: '#1677ff',
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
token: {
|
Menu: {
|
||||||
colorPrimary: InstanceRenderMgr({
|
darkItemHoverBg: '#1890ff',
|
||||||
imex: "#1677ff",
|
itemHoverBg: '#1890ff',
|
||||||
rome:"#326ade"}) ,
|
horizontalItemHoverBg: '#1890ff',
|
||||||
colorInfo: "#326ade"
|
},
|
||||||
}
|
},
|
||||||
|
token: {
|
||||||
|
colorPrimary: InstanceRenderMgr({ //TODO:AIO Add in ProMan colors.
|
||||||
|
imex: '#1890ff',
|
||||||
|
rome: '#326ade',
|
||||||
|
}),
|
||||||
|
colorInfo: InstanceRenderMgr({
|
||||||
|
imex: '#1890ff',
|
||||||
|
rome: '#326ade',
|
||||||
|
}),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ function Header({
|
|||||||
promanager: HasFeatureAccess({ featureName: 'bills', bodyshop }),
|
promanager: HasFeatureAccess({ featureName: 'bills', bodyshop }),
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
accountingChildren.push([
|
accountingChildren.push(
|
||||||
{
|
{
|
||||||
key: 'bills',
|
key: 'bills',
|
||||||
icon: <Icon component={FaFileInvoiceDollar} />,
|
icon: <Icon component={FaFileInvoiceDollar} />,
|
||||||
@@ -128,8 +128,8 @@ function Header({
|
|||||||
context: {},
|
context: {},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
]);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Simple_Inventory.treatment === 'on') {
|
if (Simple_Inventory.treatment === 'on') {
|
||||||
@@ -378,7 +378,7 @@ function Header({
|
|||||||
...(InstanceRenderManager({
|
...(InstanceRenderManager({
|
||||||
imex: true,
|
imex: true,
|
||||||
rome: true,
|
rome: true,
|
||||||
promanager: false// HasFeatureAccess({ featureName: 'courtesycars', bodyshop }),
|
promanager: false, // HasFeatureAccess({ featureName: 'courtesycars', bodyshop }),
|
||||||
})
|
})
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
@@ -587,9 +587,9 @@ function Header({
|
|||||||
label: (
|
label: (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
title={`A more modern ${InstanceRenderManager({
|
title={`A more modern ${InstanceRenderManager({
|
||||||
imex: t("titles.imexonline"),
|
imex: t('titles.imexonline'),
|
||||||
rome: t("titles.romeonline"),
|
rome: t('titles.romeonline'),
|
||||||
promanager: t("titles.promanager")
|
promanager: t('titles.promanager'),
|
||||||
})} is ready for you to try! You can switch back at any time.`}
|
})} is ready for you to try! You can switch back at any time.`}
|
||||||
>
|
>
|
||||||
<InfoCircleOutlined />
|
<InfoCircleOutlined />
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export function OwnerNameDisplayFunction(ownerObject, forceFirstLast = false) {
|
|||||||
|
|
||||||
const rdxStore = store.getState();
|
const rdxStore = store.getState();
|
||||||
|
|
||||||
if (rdxStore.user.bodyshop.last_name_first && !forceFirstLast)
|
if (rdxStore.user?.bodyshop?.last_name_first && !forceFirstLast)
|
||||||
return `${ownerObject?.ownr_ln || ""}, ${ownerObject?.ownr_fn || ""} ${
|
return `${ownerObject?.ownr_ln || ""}, ${ownerObject?.ownr_fn || ""} ${
|
||||||
ownerObject?.ownr_co_nm || ""
|
ownerObject?.ownr_co_nm || ""
|
||||||
}`.trim();
|
}`.trim();
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ export default connect(mapStateToProps, mapDispatchToProps)(ShopInfoComponent);
|
|||||||
|
|
||||||
export function ShopInfoComponent({bodyshop, form, saveLoading}) {
|
export function ShopInfoComponent({bodyshop, form, saveLoading}) {
|
||||||
|
|
||||||
const {treatments: {CriticalPartsScanning, EnhancedPayroll}} = useSplitTreatments({
|
const {treatments: {CriticalPartsScanning, Enhanced_Payroll}} = useSplitTreatments({
|
||||||
attributes: {},
|
attributes: {},
|
||||||
names: ["CriticalPartsScanning","EnhancedPayroll"],
|
names: ["CriticalPartsScanning","Enhanced_Payroll"],
|
||||||
splitKey: bodyshop.imexshopid,
|
splitKey: bodyshop.imexshopid,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -95,14 +95,13 @@ export function ShopInfoComponent({bodyshop, form, saveLoading}) {
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
...EnhancedPayroll.treatment === "on" ? [
|
...Enhanced_Payroll.treatment === "on" ? [
|
||||||
{
|
{
|
||||||
key: 'task-presets',
|
key: 'task-presets',
|
||||||
label: t("bodyshop.labels.task-presets"),
|
label: t("bodyshop.labels.task-presets"),
|
||||||
children: <ShopInfoTaskPresets form={form}/>
|
children: <ShopInfoTaskPresets form={form}/>
|
||||||
}]: []
|
}]: []
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
extra={
|
extra={
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export function SignInComponent({
|
|||||||
return (
|
return (
|
||||||
<div className="login-container">
|
<div className="login-container">
|
||||||
<div className="login-logo-container">
|
<div className="login-logo-container">
|
||||||
<img src={InstanceRenderManager({imex:ImEXOnlineLogo, rome:RomeLogo})} width={200} alt={InstanceRenderManager({imex:t("titles.imexonline"), rome: t("titles.romeonline"), promanager:t("titles.promanager")})}/>
|
<img src={InstanceRenderManager({imex:ImEXOnlineLogo, rome:RomeLogo, promanager:'https://www.web-est.com/img/web_est_logo_software.gif'})} width={200} alt={InstanceRenderManager({imex:t("titles.imexonline"), rome: t("titles.romeonline"), promanager:t("titles.promanager")})}/>
|
||||||
<Typography.Title>{
|
<Typography.Title>{
|
||||||
InstanceRenderManager({imex: t("titles.imexonline"), rome: t("titles.romeonline"), promanager:t("titles.promanager")})
|
InstanceRenderManager({imex: t("titles.imexonline"), rome: t("titles.romeonline"), promanager:t("titles.promanager")})
|
||||||
}</Typography.Title>
|
}</Typography.Title>
|
||||||
|
|||||||
@@ -360,6 +360,8 @@ export function TimeTicketList({
|
|||||||
dataSource={timetickets}
|
dataSource={timetickets}
|
||||||
onChange={handleTableChange}
|
onChange={handleTableChange}
|
||||||
summary={() => {
|
summary={() => {
|
||||||
|
if(Enhanced_Payroll.treatment === "on") return null;
|
||||||
|
if(Enhanced_Payroll.treatment === "off")
|
||||||
return (
|
return (
|
||||||
<Table.Summary.Row>
|
<Table.Summary.Row>
|
||||||
<Table.Summary.Cell>
|
<Table.Summary.Cell>
|
||||||
|
|||||||
@@ -143,14 +143,13 @@ const JobRelatedTicketsTable = ({
|
|||||||
}, Dinero());
|
}, Dinero());
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: `${item.jobKey}${costCenter}`,
|
id: `${item.jobKey}${costCenter}`,
|
||||||
costCenter,
|
costCenter,
|
||||||
item,
|
item,
|
||||||
actHrs: actHrs.toFixed(1),
|
actHrs: actHrs.toFixed(1),
|
||||||
prodHrs: prodHrs.toFixed(1),
|
prodHrs: prodHrs.toFixed(1),
|
||||||
clockHrs,
|
clockHrs,
|
||||||
...InstanceRenderManager({rome: {pay}})
|
...InstanceRenderManager({ imex: {}, rome: { pay } }),
|
||||||
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
@@ -210,7 +209,7 @@ const JobRelatedTicketsTable = ({
|
|||||||
state.sortedInfo.columnKey === "clockHrs" && state.sortedInfo.order,
|
state.sortedInfo.columnKey === "clockHrs" && state.sortedInfo.order,
|
||||||
render: (text, record) => record.clockHrs.toFixed(2),
|
render: (text, record) => record.clockHrs.toFixed(2),
|
||||||
},
|
},
|
||||||
...InstanceRenderManager({rome:{
|
...InstanceRenderManager({ imex: [], rome:[{
|
||||||
title: "Pay",
|
title: "Pay",
|
||||||
dataIndex: "Pay",
|
dataIndex: "Pay",
|
||||||
key: "Pay",
|
key: "Pay",
|
||||||
@@ -218,7 +217,7 @@ const JobRelatedTicketsTable = ({
|
|||||||
sortOrder:
|
sortOrder:
|
||||||
state.sortedInfo.columnKey === "clockHrs" && state.sortedInfo.order,
|
state.sortedInfo.columnKey === "clockHrs" && state.sortedInfo.order,
|
||||||
render: (text, record) => record.pay.toFormat("$0.00"),
|
render: (text, record) => record.pay.toFormat("$0.00"),
|
||||||
}})
|
}]})
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
title: t("general.labels.actions"),
|
title: t("general.labels.actions"),
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {setBreadcrumbs, setSelectedHeader,} from "../../redux/application/applic
|
|||||||
import {selectBodyshop} from "../../redux/user/user.selectors";
|
import {selectBodyshop} from "../../redux/user/user.selectors";
|
||||||
import ContractCreatePageComponent from "./contract-create.page.component";
|
import ContractCreatePageComponent from "./contract-create.page.component";
|
||||||
import InstanceRenderManager from '../../utils/instanceRenderMgr';
|
import InstanceRenderManager from '../../utils/instanceRenderMgr';
|
||||||
|
import FeatureWrapperComponent from "../../components/feature-wrapper/feature-wrapper.component";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -122,6 +123,7 @@ export function ContractCreatePageContainer({
|
|||||||
}, [t, setBreadcrumbs, setSelectedHeader]);
|
}, [t, setBreadcrumbs, setSelectedHeader]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<FeatureWrapperComponent featureName='courtesycars'>
|
||||||
<RbacWrapper action="contracts:create">
|
<RbacWrapper action="contracts:create">
|
||||||
<Form
|
<Form
|
||||||
form={form}
|
form={form}
|
||||||
@@ -137,6 +139,7 @@ export function ContractCreatePageContainer({
|
|||||||
/>
|
/>
|
||||||
</Form>
|
</Form>
|
||||||
</RbacWrapper>
|
</RbacWrapper>
|
||||||
|
</FeatureWrapperComponent>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,31 +107,31 @@ export function JobsDetailPage({
|
|||||||
// The union and spread is required to keep values coming in from the estimating system that aren't displayed.
|
// The union and spread is required to keep values coming in from the estimating system that aren't displayed.
|
||||||
parts_tax_rates: _.union(
|
parts_tax_rates: _.union(
|
||||||
Object.keys(job.parts_tax_rates),
|
Object.keys(job.parts_tax_rates),
|
||||||
Object.keys(values.parts_tax_rates)
|
Object.keys(values.parts_tax_rates || {})
|
||||||
).reduce((acc, val) => {
|
).reduce((acc, val) => {
|
||||||
acc[val] = {
|
acc[val] = {
|
||||||
...job.parts_tax_rates[val],
|
...job.parts_tax_rates[val],
|
||||||
...values.parts_tax_rates[val],
|
...values.parts_tax_rates?.[val], //TODO:AIO Verify that these still save for Rome Online with this null coalescing.
|
||||||
};
|
};
|
||||||
return acc;
|
return acc;
|
||||||
}, {}),
|
}, {}),
|
||||||
materials: _.union(
|
materials: _.union(
|
||||||
Object.keys(job.materials),
|
Object.keys(job.materials),
|
||||||
Object.keys(values.materials)
|
Object.keys(values.materials|| {})
|
||||||
).reduce((acc, val) => {
|
).reduce((acc, val) => {
|
||||||
acc[val] = {
|
acc[val] = {
|
||||||
...job.materials[val],
|
...job.materials[val],
|
||||||
...values.materials[val],
|
...values.materials?.[val],
|
||||||
};
|
};
|
||||||
return acc;
|
return acc;
|
||||||
}, {}),
|
}, {}),
|
||||||
cieca_pfl: _.union(
|
cieca_pfl: _.union(
|
||||||
Object.keys(job.cieca_pfl),
|
Object.keys(job.cieca_pfl),
|
||||||
Object.keys(values.cieca_pfl)
|
Object.keys(values.cieca_pfl|| {})
|
||||||
).reduce((acc, val) => {
|
).reduce((acc, val) => {
|
||||||
acc[val] = {
|
acc[val] = {
|
||||||
...job.cieca_pfl[val],
|
...job.cieca_pfl[val],
|
||||||
...values.cieca_pfl[val],
|
...values.cieca_pfl?.[val],
|
||||||
};
|
};
|
||||||
return acc;
|
return acc;
|
||||||
}, {}),
|
}, {}),
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
// opt-in, read https://cra.link/PWA
|
// opt-in, read https://cra.link/PWA
|
||||||
|
|
||||||
const isLocalhost = Boolean(
|
const isLocalhost = Boolean(
|
||||||
window.location.hostname === 'localhost' ||
|
window.location.hostname === 'localhost' ||
|
||||||
// [::1] is the IPv6 localhost address.
|
// [::1] is the IPv6 localhost address.
|
||||||
window.location.hostname === '[::1]' ||
|
window.location.hostname === '[::1]' ||
|
||||||
// 127.0.0.0/8 are considered localhost for IPv4.
|
// 127.0.0.0/8 are considered localhost for IPv4.
|
||||||
@@ -21,117 +21,117 @@ const isLocalhost = Boolean(
|
|||||||
export function register(config) {
|
export function register(config) {
|
||||||
if (import.meta.env.PROD && 'serviceWorker' in navigator) {
|
if (import.meta.env.PROD && 'serviceWorker' in navigator) {
|
||||||
// The URL constructor is available in all browsers that support SW.
|
// The URL constructor is available in all browsers that support SW.
|
||||||
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
|
const publicUrl = new URL('process.env.PUBLIC_URL', window.location.href);
|
||||||
if (publicUrl.origin !== window.location.origin) {
|
if (publicUrl.origin !== window.location.origin) {
|
||||||
// Our service worker won't work if PUBLIC_URL is on a different origin
|
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||||
// from what our page is served on. This might happen if a CDN is used to
|
// from what our page is served on. This might happen if a CDN is used to
|
||||||
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
|
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//TODO:AIO Resolve this for all 3 host names.
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
const swUrl = `service-worker.js`;
|
||||||
|
|
||||||
window.addEventListener('load', () => {
|
if (isLocalhost) {
|
||||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
// This is running on localhost. Let's check if a service worker still exists or not.
|
||||||
|
checkValidServiceWorker(swUrl, config);
|
||||||
|
|
||||||
if (isLocalhost) {
|
// Add some additional logging to localhost, pointing developers to the
|
||||||
// This is running on localhost. Let's check if a service worker still exists or not.
|
// service worker/PWA documentation.
|
||||||
checkValidServiceWorker(swUrl, config);
|
navigator.serviceWorker.ready.then(() => {
|
||||||
|
console.log(
|
||||||
// Add some additional logging to localhost, pointing developers to the
|
'This web app is being served cache-first by a service ' +
|
||||||
// service worker/PWA documentation.
|
'worker. To learn more, visit https://cra.link/PWA'
|
||||||
navigator.serviceWorker.ready.then(() => {
|
);
|
||||||
console.log(
|
|
||||||
'This web app is being served cache-first by a service ' +
|
|
||||||
'worker. To learn more, visit https://cra.link/PWA'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// Is not localhost. Just register service worker
|
|
||||||
registerValidSW(swUrl, config);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
|
// Is not localhost. Just register service worker
|
||||||
|
registerValidSW(swUrl, config);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerValidSW(swUrl, config) {
|
function registerValidSW(swUrl, config) {
|
||||||
navigator.serviceWorker
|
navigator.serviceWorker
|
||||||
.register(swUrl)
|
.register(swUrl)
|
||||||
.then((registration) => {
|
.then((registration) => {
|
||||||
registration.onupdatefound = () => {
|
registration.onupdatefound = () => {
|
||||||
const installingWorker = registration.installing;
|
const installingWorker = registration.installing;
|
||||||
if (installingWorker == null) {
|
if (installingWorker == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
installingWorker.onstatechange = () => {
|
installingWorker.onstatechange = () => {
|
||||||
if (installingWorker.state === 'installed') {
|
if (installingWorker.state === 'installed') {
|
||||||
if (navigator.serviceWorker.controller) {
|
if (navigator.serviceWorker.controller) {
|
||||||
// At this point, the updated precached content has been fetched,
|
// At this point, the updated precached content has been fetched,
|
||||||
// but the previous service worker will still serve the older
|
// but the previous service worker will still serve the older
|
||||||
// content until all client tabs are closed.
|
// content until all client tabs are closed.
|
||||||
console.log(
|
console.log(
|
||||||
'New content is available and will be used when all ' +
|
'New content is available and will be used when all ' +
|
||||||
'tabs for this page are closed. See https://cra.link/PWA.'
|
'tabs for this page are closed. See https://cra.link/PWA.'
|
||||||
);
|
);
|
||||||
|
|
||||||
// Execute callback
|
// Execute callback
|
||||||
if (config && config.onUpdate) {
|
if (config && config.onUpdate) {
|
||||||
config.onUpdate(registration);
|
config.onUpdate(registration);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// At this point, everything has been precached.
|
// At this point, everything has been precached.
|
||||||
// It's the perfect time to display a
|
// It's the perfect time to display a
|
||||||
// "Content is cached for offline use." message.
|
// "Content is cached for offline use." message.
|
||||||
console.log('Content is cached for offline use.');
|
console.log('Content is cached for offline use.');
|
||||||
|
|
||||||
// Execute callback
|
// Execute callback
|
||||||
if (config && config.onSuccess) {
|
if (config && config.onSuccess) {
|
||||||
config.onSuccess(registration);
|
config.onSuccess(registration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error('Error during service worker registration:', error);
|
console.error('Error during service worker registration:', error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkValidServiceWorker(swUrl, config) {
|
function checkValidServiceWorker(swUrl, config) {
|
||||||
// Check if the service worker can be found. If it can't reload the page.
|
// Check if the service worker can be found. If it can't reload the page.
|
||||||
fetch(swUrl, {
|
fetch(swUrl, {
|
||||||
headers: {'Service-Worker': 'script'},
|
headers: { 'Service-Worker': 'script' },
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
// Ensure service worker exists, and that we really are getting a JS file.
|
// Ensure service worker exists, and that we really are getting a JS file.
|
||||||
const contentType = response.headers.get('content-type');
|
const contentType = response.headers.get('content-type');
|
||||||
if (
|
if (
|
||||||
response.status === 404 ||
|
response.status === 404 ||
|
||||||
(contentType != null && contentType.indexOf('javascript') === -1)
|
(contentType != null && contentType.indexOf('javascript') === -1)
|
||||||
) {
|
) {
|
||||||
// No service worker found. Probably a different app. Reload the page.
|
// No service worker found. Probably a different app. Reload the page.
|
||||||
navigator.serviceWorker.ready.then((registration) => {
|
navigator.serviceWorker.ready.then((registration) => {
|
||||||
registration.unregister().then(() => {
|
registration.unregister().then(() => {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// Service worker found. Proceed as normal.
|
|
||||||
registerValidSW(swUrl, config);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
console.log('No internet connection found. App is running in offline mode.');
|
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
// Service worker found. Proceed as normal.
|
||||||
|
registerValidSW(swUrl, config);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
console.log('No internet connection found. App is running in offline mode.');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unregister() {
|
export function unregister() {
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
navigator.serviceWorker.ready
|
navigator.serviceWorker.ready
|
||||||
.then((registration) => {
|
.then((registration) => {
|
||||||
registration.unregister();
|
registration.unregister();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error.message);
|
console.error(error.message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user