@ludo.ninja/components 2.1.30 → 2.1.32

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.
@@ -1,18 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const react_1 = require("react");
4
- const router_1 = require("next/router");
5
4
  const client_1 = require("@apollo/client");
6
5
  const api_1 = require("@ludo.ninja/api");
7
6
  const type_1 = require("@ludo.ninja/ui/build/system/Alert/type");
8
7
  const store_1 = require("../../../../modules/user/store");
9
8
  const ui_1 = require("../../../../store/ui");
10
- const notifications_1 = require("../../../../modules/notifications");
11
- const ludoDomains_1 = require("@ludo.ninja/core/build/ludoDomains");
12
- const env_1 = require("../../../../store/env");
13
9
  const useFetchMyExperienceWithLevel = () => {
14
- const NEXT_PUBLIC_ENV_VALUE = (0, env_1.useEnvStore)(state => state.NEXT_PUBLIC_ENV_VALUE);
15
- const { user, isSignedIn, setUserExp, resetUserExp, setErrorExp, setIsLoadingExp, } = (0, store_1.useUserStore)((state) => ({
10
+ const { isSignedIn, setUserExp, resetUserExp, setErrorExp, setIsLoadingExp, } = (0, store_1.useUserStore)((state) => ({
16
11
  user: state.user,
17
12
  isSignedIn: state.isSignedIn,
18
13
  setUserExp: state.setUserExp,
@@ -20,13 +15,10 @@ const useFetchMyExperienceWithLevel = () => {
20
15
  setErrorExp: state.setErrorExp,
21
16
  setIsLoadingExp: state.setIsLoadingExp,
22
17
  }));
23
- const { openAlert, addNotification } = (0, ui_1.useUiStore)((state) => ({
24
- openAlert: state.openAlert,
25
- addNotification: state.addNotification,
18
+ const { openAlert } = (0, ui_1.useUiStore)((state) => ({
19
+ openAlert: state.openAlert
26
20
  }));
27
- const router = (0, router_1.useRouter)();
28
- const userId = user?.userId || "";
29
- const [fetchExp, { subscribeToMore }] = (0, client_1.useLazyQuery)(api_1.experiencesSchema.FetchMyExperienceV2Document, {
21
+ const [fetchExp] = (0, client_1.useLazyQuery)(api_1.experiencesSchema.FetchMyExperienceV2Document, {
30
22
  context: {
31
23
  uri: api_1.hosts.experiencesHost,
32
24
  },
@@ -38,7 +30,6 @@ const useFetchMyExperienceWithLevel = () => {
38
30
  levelMaxXps,
39
31
  levelMinXps,
40
32
  });
41
- // subscribe();
42
33
  },
43
34
  onError: (err) => {
44
35
  openAlert({
@@ -50,39 +41,6 @@ const useFetchMyExperienceWithLevel = () => {
50
41
  setIsLoadingExp(false);
51
42
  },
52
43
  });
53
- const subscribe = () => {
54
- const { authToken } = api_1.authCookies.getCookies();
55
- subscribeToMore({
56
- variables: { authToken },
57
- document: api_1.experiencesSchema.OnMyExperienceIncrementedDocument,
58
- updateQuery: (prev, { subscriptionData: { data } }) => {
59
- if (!data)
60
- return prev;
61
- const { xps, level, levelMaxXps, levelMinXps, xpsIncrement, description, } = data.onMyExperienceIncremented;
62
- if (xpsIncrement) {
63
- addNotification((0, notifications_1.createXpNotification)({
64
- xpsIncrement,
65
- ...(description ? { description } : {}),
66
- onClick: () => {
67
- const domain = ludoDomains_1.ludoDomains[NEXT_PUBLIC_ENV_VALUE]["app"];
68
- if (domain === window.origin) {
69
- router.push(`/rewards/${userId}`);
70
- }
71
- else {
72
- window.open(`${domain}/rewards/${userId}`, '_self');
73
- }
74
- },
75
- }));
76
- }
77
- setUserExp({
78
- xps,
79
- level,
80
- levelMaxXps,
81
- levelMinXps,
82
- });
83
- },
84
- });
85
- };
86
44
  (0, react_1.useEffect)(() => {
87
45
  if (isSignedIn) {
88
46
  setIsLoadingExp(true);
@@ -4,7 +4,7 @@ declare const useFetchUserpic: () => {
4
4
  loading: boolean;
5
5
  error: import("@apollo/client").ApolloError | undefined;
6
6
  refetch: (variables?: Partial<schema.Exact<{
7
- userId: schema.Scalars["ID"];
7
+ userId: string;
8
8
  }>> | undefined) => Promise<import("@apollo/client").ApolloQueryResult<schema.IFetchUserpicQuery>>;
9
9
  load: (userId: string) => void;
10
10
  userPic: string | null;
@@ -12,8 +12,8 @@ export declare const useFetchFindAllTopEntitiesByName: () => {
12
12
  loading: boolean;
13
13
  error: import("@apollo/client").ApolloError | undefined;
14
14
  load: ({ name, pageSize }: schema.IQueryFindAllTopEntitiesByNameArgs) => Promise<import("@apollo/client").QueryResult<schema.IFindAllTopEntitiesByNameQuery, schema.Exact<{
15
- name: schema.Scalars["String"];
16
- pageSize: schema.Scalars["Int"];
15
+ name: string;
16
+ pageSize: number;
17
17
  }>>>;
18
18
  topEntities: {
19
19
  assets: AssetEntity[];
@@ -28,8 +28,8 @@ declare const _default: {
28
28
  loading: boolean;
29
29
  error: import("@apollo/client").ApolloError | undefined;
30
30
  load: ({ name, pageSize }: schema.IQueryFindAllTopEntitiesByNameArgs) => Promise<import("@apollo/client").QueryResult<schema.IFindAllTopEntitiesByNameQuery, schema.Exact<{
31
- name: schema.Scalars["String"];
32
- pageSize: schema.Scalars["Int"];
31
+ name: string;
32
+ pageSize: number;
33
33
  }>>>;
34
34
  topEntities: {
35
35
  assets: AssetEntity[];
@@ -18,15 +18,16 @@ const Header = () => {
18
18
  const isSignedIn = (0, store_1.useUserStore)((state) => state.isSignedIn);
19
19
  const getUser = (0, store_1.useUserStore)((state) => state.user);
20
20
  const NEXT_PUBLIC_ENV_VALUE = (0, env_1.useEnvStore)((state) => state.NEXT_PUBLIC_ENV_VALUE);
21
+ const isProd = (0, env_1.useEnvStore)((state) => state.isProd);
21
22
  const openSidebar = (0, ui_1.useUiStore)((state) => state.openSidebar);
22
23
  const redirectToLoginWindow = (0, auth_1.useRedirectToLoginWindow)();
23
24
  return ((0, jsx_runtime_1.jsx)(header_1.Header, { isAuthorized: isSignedIn, handle: {
24
25
  login: redirectToLoginWindow,
25
26
  openSidebar,
26
27
  }, slots: {
27
- headerExpLabel: ((0, jsx_runtime_1.jsx)(headerExperienceLabel_1.default, { userId: getUser?.userId || '' })),
28
- headerUserPick: (0, jsx_runtime_1.jsx)(headerUserPic_1.default, { userId: getUser?.userId || '' }),
29
- logoLinkComponent: ({ children }) => (0, jsx_runtime_1.jsx)(link_1.default, { href: ludoDomains_1.ludoDomains[NEXT_PUBLIC_ENV_VALUE]["app"], children: children }),
28
+ headerExpLabel: ((0, jsx_runtime_1.jsx)(headerExperienceLabel_1.default, { userId: getUser?.userId || "" })),
29
+ headerUserPick: (0, jsx_runtime_1.jsx)(headerUserPic_1.default, { userId: getUser?.userId || "" }),
30
+ logoLinkComponent: ({ children }) => (0, jsx_runtime_1.jsx)(link_1.default, { href: ludoDomains_1.ludoDomains[NEXT_PUBLIC_ENV_VALUE][isProd() ? "profile" : "app"], children: children }),
30
31
  } }));
31
32
  };
32
33
  // Export
@@ -27,7 +27,7 @@ const HeaderSearch = () => {
27
27
  }, slots: {
28
28
  headerExpLabel: ((0, jsx_runtime_1.jsx)(headerExperienceLabel_1.default, { userId: getUser?.userId || '' })),
29
29
  headerUserPick: (0, jsx_runtime_1.jsx)(headerUserPic_1.default, { userId: getUser?.userId || '' }),
30
- logoLinkComponent: ({ children }) => (0, jsx_runtime_1.jsx)("a", { href: ludoDomains_1.ludoDomains[NEXT_PUBLIC_ENV_VALUE]["app"], children: children }),
30
+ logoLinkComponent: ({ children }) => (0, jsx_runtime_1.jsx)("a", { href: ludoDomains_1.ludoDomains[NEXT_PUBLIC_ENV_VALUE][isProd() ? "profile" : "app"], children: children }),
31
31
  searchInput: ({ setInputFocused }) => {
32
32
  // Todo seacrh pages, hide search input from header
33
33
  return isProd() ? undefined : ((0, jsx_runtime_1.jsx)(searchSimpleInput_1.default, { onFocusHandler: setInputFocused }));
@@ -71,7 +71,8 @@ const HeaderSimple = () => {
71
71
  };
72
72
  const scrollDirection = (0, utils_1.useScrollDirection)();
73
73
  const NEXT_PUBLIC_ENV_VALUE = (0, env_1.useEnvStore)((state) => state.NEXT_PUBLIC_ENV_VALUE);
74
- return ((0, jsx_runtime_1.jsx)(StyledHeaderSimple, { className: scrollDirection, children: (0, jsx_runtime_1.jsx)("div", { className: 'logo', children: (0, jsx_runtime_1.jsx)("a", { href: ludoDomains_1.ludoDomains[NEXT_PUBLIC_ENV_VALUE]["app"], children: renderDesktopLogoOrMobile() }) }) }));
74
+ const isProd = (0, env_1.useEnvStore)((state) => state.isProd);
75
+ return ((0, jsx_runtime_1.jsx)(StyledHeaderSimple, { className: scrollDirection, children: (0, jsx_runtime_1.jsx)("div", { className: 'logo', children: (0, jsx_runtime_1.jsx)("a", { href: ludoDomains_1.ludoDomains[NEXT_PUBLIC_ENV_VALUE][isProd() ? "profile" : "app"], children: renderDesktopLogoOrMobile() }) }) }));
75
76
  };
76
77
  // Export
77
78
  exports.default = HeaderSimple;
@@ -1 +1,2 @@
1
+ export declare const useVerification: () => (currentLocation: string) => Promise<void>;
1
2
  export declare const useAuthVerification: () => void;
@@ -23,51 +23,55 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.useAuthVerification = void 0;
26
+ exports.useAuthVerification = exports.useVerification = void 0;
27
27
  const react_1 = require("react");
28
28
  const router_1 = require("next/router");
29
29
  const useSignIn_1 = require("./useSignIn");
30
30
  const useSignOut_1 = require("./useSignOut");
31
- const useAuthVerification = () => {
32
- const router = (0, router_1.useRouter)();
31
+ const useVerification = () => {
33
32
  const signIn = (0, useSignIn_1.useSignIn)();
34
33
  const signOut = (0, useSignOut_1.useSignOut)();
35
- (0, react_1.useEffect)(() => {
36
- const verification = async () => {
37
- try {
38
- const authCookies = await Promise.resolve().then(() => __importStar(require('@ludo.ninja/api/build/cookies'))); //update check version cookie in client
39
- const authCookiesParsed = authCookies.getCookies();
40
- if (authCookiesParsed.authToken &&
41
- authCookiesParsed.wallets &&
42
- authCookiesParsed.refreshToken &&
43
- authCookiesParsed.newUser &&
44
- authCookiesParsed.userId &&
45
- authCookiesParsed.inviteCode &&
46
- authCookiesParsed.role) {
47
- signIn({
48
- userId: authCookiesParsed.userId,
49
- wallets: authCookiesParsed.wallets,
50
- authToken: authCookiesParsed.authToken,
51
- refreshToken: authCookiesParsed.refreshToken,
52
- newUser: authCookiesParsed.newUser === 'true',
53
- inviteCode: authCookiesParsed.inviteCode,
54
- role: authCookiesParsed.role,
55
- });
56
- }
57
- else {
58
- if (router.pathname !== '/forms/[formId]') {
59
- await signOut();
60
- }
61
- }
34
+ return async (currentLocation) => {
35
+ try {
36
+ const authCookies = await Promise.resolve().then(() => __importStar(require("@ludo.ninja/api/build/cookies"))); //update check version cookie in client
37
+ const authCookiesParsed = authCookies.getCookies();
38
+ if (authCookiesParsed.authToken &&
39
+ authCookiesParsed.wallets &&
40
+ authCookiesParsed.refreshToken &&
41
+ authCookiesParsed.newUser &&
42
+ authCookiesParsed.userId &&
43
+ authCookiesParsed.inviteCode &&
44
+ authCookiesParsed.role) {
45
+ signIn({
46
+ userId: authCookiesParsed.userId,
47
+ wallets: authCookiesParsed.wallets,
48
+ authToken: authCookiesParsed.authToken,
49
+ refreshToken: authCookiesParsed.refreshToken,
50
+ newUser: authCookiesParsed.newUser === "true",
51
+ inviteCode: authCookiesParsed.inviteCode,
52
+ role: authCookiesParsed.role,
53
+ });
62
54
  }
63
- catch (e) {
64
- // console.error('verification', e);
55
+ else {
56
+ if (currentLocation !== "/forms/[formId]") {
57
+ await signOut();
58
+ }
65
59
  }
66
- };
67
- verification();
68
- document.addEventListener('visibilitychange', verification);
60
+ }
61
+ catch (e) {
62
+ // console.error('verification', e);
63
+ }
64
+ };
65
+ };
66
+ exports.useVerification = useVerification;
67
+ const useAuthVerification = () => {
68
+ const router = (0, router_1.useRouter)();
69
+ const verification = (0, exports.useVerification)();
70
+ (0, react_1.useEffect)(() => {
71
+ const authVerification = () => verification(router.pathname);
72
+ document.addEventListener("visibilitychange", authVerification);
69
73
  return () => {
70
- document.removeEventListener('visibilitychange', verification);
74
+ document.removeEventListener("visibilitychange", authVerification);
71
75
  };
72
76
  }, [router.query]);
73
77
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ludo.ninja/components",
3
- "version": "2.1.30",
3
+ "version": "2.1.32",
4
4
  "private": false,
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",