@erpsquad/common 1.8.146 → 1.8.148

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ import _ from "lodash";
4
4
  import { getCountries } from "libphonenumber-js";
5
5
  import { u, c, d, a, b } from "../useLocationFilter-D57qqjeN.esm.js";
6
6
  import { useMemo, useState, useEffect, useCallback } from "react";
7
- import { useTranslation } from "react-i18next";
7
+ import { getI18n, useTranslation } from "react-i18next";
8
8
  import { useTranslation as useTranslation2 } from "react-i18next";
9
9
  import { l as loadModuleTranslations } from "../translations-BLI-qNqf.esm.js";
10
10
  import { m as modules } from "../modules-CjfmbQNF.esm.js";
@@ -403,46 +403,52 @@ let globalInitialLoad = true;
403
403
  const useAppTranslations = () => {
404
404
  const [isLoading, setIsLoading] = useState(globalInitialLoad);
405
405
  const location = window.location;
406
+ const i18nInstance = getI18n();
407
+ const { user, loading } = useAuth();
408
+ console.log("🚀 ~ useAppTranslations ~ location.pathname:: >>", location.pathname);
406
409
  const { t } = useTranslation();
407
410
  useEffect(() => {
408
- const erpModules = modules(t);
409
- const currentPath = location.pathname.toLowerCase();
410
- const matchedModule = erpModules.find(
411
- (mod) => {
412
- var _a;
413
- return mod.link.toLowerCase() === currentPath || ((_a = mod.connectedRoutes) == null ? void 0 : _a.some((route) => currentPath.startsWith(route.toLowerCase())));
411
+ if ((user == null ? void 0 : user.id) && !loading) {
412
+ const erpModules = modules(t);
413
+ const currentPath = location.pathname.toLowerCase();
414
+ console.log("🚀 ~ useAppTranslations ~ currentPath:: >>", currentPath);
415
+ const matchedModule = erpModules.find(
416
+ (mod) => {
417
+ var _a;
418
+ return mod.link.toLowerCase() === currentPath || ((_a = mod.connectedRoutes) == null ? void 0 : _a.some((route) => currentPath.startsWith(route.toLowerCase())));
419
+ }
420
+ );
421
+ let modulesToLoad = [];
422
+ if (matchedModule == null ? void 0 : matchedModule.translationModule) {
423
+ modulesToLoad = [...matchedModule.translationModule, "common"];
424
+ } else if (!matchedModule && currentPath === "/dashboard") {
425
+ modulesToLoad = ["common"];
414
426
  }
415
- );
416
- let modulesToLoad = [];
417
- if (matchedModule == null ? void 0 : matchedModule.translationModule) {
418
- modulesToLoad = [...matchedModule.translationModule, "common"];
419
- } else if (!matchedModule && currentPath === "/dashboard") {
420
- modulesToLoad = ["common"];
421
- }
422
- if (modulesToLoad.length > 0) {
423
- const moduleKey = [...modulesToLoad].sort().join(",");
424
- if (globalLastLoadedModules === moduleKey || globalIsLoading) {
427
+ if (modulesToLoad.length > 0) {
428
+ const moduleKey = [...modulesToLoad].sort().join(",");
429
+ if (globalLastLoadedModules === moduleKey || globalIsLoading) {
430
+ if (globalInitialLoad) {
431
+ setIsLoading(false);
432
+ globalInitialLoad = false;
433
+ }
434
+ return;
435
+ }
436
+ globalIsLoading = true;
437
+ globalLastLoadedModules = moduleKey;
438
+ setIsLoading(true);
439
+ loadModuleTranslations(modulesToLoad, i18nInstance).finally(() => {
440
+ globalIsLoading = false;
441
+ setIsLoading(false);
442
+ globalInitialLoad = false;
443
+ });
444
+ } else {
425
445
  if (globalInitialLoad) {
426
446
  setIsLoading(false);
427
447
  globalInitialLoad = false;
428
448
  }
429
- return;
430
- }
431
- globalIsLoading = true;
432
- globalLastLoadedModules = moduleKey;
433
- setIsLoading(true);
434
- loadModuleTranslations(modulesToLoad).finally(() => {
435
- globalIsLoading = false;
436
- setIsLoading(false);
437
- globalInitialLoad = false;
438
- });
439
- } else {
440
- if (globalInitialLoad) {
441
- setIsLoading(false);
442
- globalInitialLoad = false;
443
449
  }
444
450
  }
445
- }, [location.pathname, t]);
451
+ }, [location.pathname, t, user, loading, i18nInstance]);
446
452
  return { isLoading };
447
453
  };
448
454
  const useNameSkuUniquenessCheck = ({