@ludo.ninja/components 2.4.37 → 2.4.39
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.
- package/build/components/headers/components/headerExperienceLabel/index.js +4 -2
- package/build/components/sidebar/sidebarInviteCodeLabel/index.js +4 -2
- package/build/modules/user/profileData/profileDataInitialization.js +3 -1
- package/build/modules/user/store.d.ts +3 -0
- package/build/modules/user/store.js +7 -0
- package/build/system/Labels/CreditsLabel/CreditsLabel.test.d.ts +1 -0
- package/build/system/Labels/CreditsLabel/CreditsLabel.test.js +44 -0
- package/build/system/Labels/CreditsLabel/index.d.ts +10 -0
- package/build/system/Labels/CreditsLabel/index.js +89 -0
- package/package.json +1 -1
|
@@ -11,6 +11,7 @@ const ScreenWidth_1 = require("../../../../styles/ScreenWidth");
|
|
|
11
11
|
const ExperienceLabel_1 = __importDefault(require("../../../../system/Labels/ExperienceLabel"));
|
|
12
12
|
const env_1 = require("../../../../store/env");
|
|
13
13
|
const ludoDomains_1 = require("@ludo.ninja/core/build/ludoDomains");
|
|
14
|
+
const CreditsLabel_1 = __importDefault(require("../../../../system/Labels/CreditsLabel"));
|
|
14
15
|
// Styles
|
|
15
16
|
const StyledHeaderExperienceLabel = styled_components_1.default.div `
|
|
16
17
|
margin-right: 20px;
|
|
@@ -21,14 +22,15 @@ const StyledHeaderExperienceLabel = styled_components_1.default.div `
|
|
|
21
22
|
// Component
|
|
22
23
|
const HeaderExperienceLabel = ({ userId }) => {
|
|
23
24
|
const NEXT_PUBLIC_ENV_VALUE = (0, env_1.useEnvStore)((state) => state.NEXT_PUBLIC_ENV_VALUE);
|
|
24
|
-
const { userExp, isLoadingExp, errorExp } = (0, store_1.useUserStore)((state) => ({
|
|
25
|
+
const { userCredits, userExp, isLoadingExp, errorExp } = (0, store_1.useUserStore)((state) => ({
|
|
26
|
+
userCredits: state.userCredits,
|
|
25
27
|
userExp: state.userExp,
|
|
26
28
|
isLoadingExp: state.isLoadingExp,
|
|
27
29
|
errorExp: state.errorExp,
|
|
28
30
|
}));
|
|
29
31
|
if (!userId)
|
|
30
32
|
return null;
|
|
31
|
-
return ((0, jsx_runtime_1.jsx)(StyledHeaderExperienceLabel, { children: (0, jsx_runtime_1.jsx)(ExperienceLabel_1.default, { value: userExp.xps, link: `${ludoDomains_1.ludoDomains[NEXT_PUBLIC_ENV_VALUE]["app"]}/rewards/${userId}`, loading: isLoadingExp || !!errorExp }) }));
|
|
33
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(StyledHeaderExperienceLabel, { children: (0, jsx_runtime_1.jsx)(CreditsLabel_1.default, { value: userCredits, link: `${ludoDomains_1.ludoDomains[NEXT_PUBLIC_ENV_VALUE]["app"]}/rewards/${userId}`, loading: isLoadingExp || !!errorExp }) }), (0, jsx_runtime_1.jsx)(StyledHeaderExperienceLabel, { children: (0, jsx_runtime_1.jsx)(ExperienceLabel_1.default, { value: userExp.xps, link: `${ludoDomains_1.ludoDomains[NEXT_PUBLIC_ENV_VALUE]["app"]}/rewards/${userId}`, loading: isLoadingExp || !!errorExp }) })] }));
|
|
32
34
|
};
|
|
33
35
|
// Export
|
|
34
36
|
exports.default = HeaderExperienceLabel;
|
|
@@ -37,6 +37,7 @@ const ludoDomains_1 = require("@ludo.ninja/core/build/ludoDomains");
|
|
|
37
37
|
const typography_1 = require("@ludo.ninja/ui/build/styles/typography");
|
|
38
38
|
const _4k_1 = require("@ludo.ninja/ui/build/utils/4k");
|
|
39
39
|
const styled_components_1 = __importStar(require("styled-components"));
|
|
40
|
+
const CreditsLabel_1 = __importDefault(require("../../../system/Labels/CreditsLabel"));
|
|
40
41
|
// import UserStreak from "@/components/base/UserStreak";
|
|
41
42
|
// Styles
|
|
42
43
|
const StyledSidebarInviteCodeLabel = styled_components_1.default.div `
|
|
@@ -67,8 +68,9 @@ const SidebarBoostBadge = (0, styled_components_1.default)(boostBadge_1.default)
|
|
|
67
68
|
`;
|
|
68
69
|
// Component
|
|
69
70
|
const SidebarInviteCodeLabel = () => {
|
|
70
|
-
const { getUser, userExp, isLoadingExp, errorExp, isLoadingProfileData, inviteCodes } = (0, store_1.useUserStore)((state) => ({
|
|
71
|
+
const { getUser, userCredits, userExp, isLoadingExp, errorExp, isLoadingProfileData, inviteCodes } = (0, store_1.useUserStore)((state) => ({
|
|
71
72
|
getUser: state.user,
|
|
73
|
+
userCredits: state.userCredits,
|
|
72
74
|
userExp: state.userExp,
|
|
73
75
|
isLoadingExp: state.isLoadingExp,
|
|
74
76
|
errorExp: state.errorExp,
|
|
@@ -79,7 +81,7 @@ const SidebarInviteCodeLabel = () => {
|
|
|
79
81
|
const isProd = (0, env_1.useEnvStore)((state) => state.isProd);
|
|
80
82
|
const unUsedInviteCodes = inviteCodes?.filter((code) => !code.isUsed);
|
|
81
83
|
const profileData = (0, store_1.useUserStore)((state) => state.profileData);
|
|
82
|
-
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)(StyledSidebarInviteCodeLabel, { children: [(0, jsx_runtime_1.jsx)(ExperienceLabel_1.default, { value: userExp.xps, link: `${ludoDomains_1.ludoDomains[NEXT_PUBLIC_ENV_VALUE]["app"]}/rewards/${getUser?.userId}`, loading: isLoadingExp || !!errorExp }), (0, jsx_runtime_1.jsx)(
|
|
84
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)(StyledSidebarInviteCodeLabel, { children: [(0, jsx_runtime_1.jsx)(SidebarBoostBadge, { boostType: profileData?.getBoost(), previousBoostType: profileData?.getPreviousBoost(), backgroundColor: '#ffffff' }), (0, jsx_runtime_1.jsx)(ExperienceLabel_1.default, { value: userExp.xps, link: `${ludoDomains_1.ludoDomains[NEXT_PUBLIC_ENV_VALUE]["app"]}/rewards/${getUser?.userId}`, loading: isLoadingExp || !!errorExp }), (0, jsx_runtime_1.jsx)(CreditsLabel_1.default, { value: userCredits, link: `${ludoDomains_1.ludoDomains[NEXT_PUBLIC_ENV_VALUE]["app"]}/rewards/${getUser?.userId}`, loading: isLoadingExp || !!errorExp }), !!unUsedInviteCodes && !isProd() && ((0, jsx_runtime_1.jsx)(InviteLabel_1.default, { value: unUsedInviteCodes.length, link: `${ludoDomains_1.ludoDomains[NEXT_PUBLIC_ENV_VALUE]["app"]}/invite-codes`, loading: isLoadingProfileData }))] }) }));
|
|
83
85
|
};
|
|
84
86
|
// Export
|
|
85
87
|
exports.default = SidebarInviteCodeLabel;
|
|
@@ -12,13 +12,14 @@ const FetcherMyProfile = ( /*{ userId }: { userId: string }*/) => {
|
|
|
12
12
|
const openAlert = (0, ui_1.useUiStore)((state) => state.openAlert);
|
|
13
13
|
const { setIsLoadingProfileData, setProfileData,
|
|
14
14
|
// profileData,
|
|
15
|
-
setUserExp, setInviteCodes, setMyShareLink, } = (0, store_1.useUserStore)((state) => ({
|
|
15
|
+
setUserExp, setInviteCodes, setMyShareLink, setUserCredits, } = (0, store_1.useUserStore)((state) => ({
|
|
16
16
|
setIsLoadingProfileData: state.setIsLoadingProfileData,
|
|
17
17
|
setProfileData: state.setProfileData,
|
|
18
18
|
profileData: state.profileData,
|
|
19
19
|
setUserExp: state.setUserExp,
|
|
20
20
|
setInviteCodes: state.setInviteCodes,
|
|
21
21
|
setMyShareLink: state.setMyShareLink,
|
|
22
|
+
setUserCredits: state.setUserCredits,
|
|
22
23
|
}));
|
|
23
24
|
// console.log('profileData', profileData);
|
|
24
25
|
api_2.identitySchema.useFetchMyProfileV2Query({
|
|
@@ -29,6 +30,7 @@ const FetcherMyProfile = ( /*{ userId }: { userId: string }*/) => {
|
|
|
29
30
|
onCompleted: ({ fetchMyProfileV2: fetchMyProfile }) => {
|
|
30
31
|
// console.log('fetchMyProfile', fetchMyProfile);
|
|
31
32
|
setProfileData(fetchMyProfile);
|
|
33
|
+
setUserCredits(fetchMyProfile.credits || 0);
|
|
32
34
|
if (fetchMyProfile.shareLink) {
|
|
33
35
|
setMyShareLink(fetchMyProfile.shareLink);
|
|
34
36
|
}
|
|
@@ -12,6 +12,9 @@ export interface IUserStore {
|
|
|
12
12
|
user: IUser | null;
|
|
13
13
|
setUser: (user: IUser | null) => void;
|
|
14
14
|
isSignedIn: boolean;
|
|
15
|
+
userCredits: number;
|
|
16
|
+
setUserCredits: (userCredits: number) => void;
|
|
17
|
+
resetUserCredits: () => void;
|
|
15
18
|
userExp: UserXp;
|
|
16
19
|
setUserExp: (userExp: UserXp) => void;
|
|
17
20
|
resetUserExp: () => void;
|
|
@@ -21,6 +21,13 @@ const creators = (0, next_zustand_1.createProvider)()((setState) => ({
|
|
|
21
21
|
setUser: (user) => {
|
|
22
22
|
setState({ user, isSignedIn: !!user });
|
|
23
23
|
},
|
|
24
|
+
userCredits: 0,
|
|
25
|
+
setUserCredits: (userCredits) => {
|
|
26
|
+
setState({ userCredits });
|
|
27
|
+
},
|
|
28
|
+
resetUserCredits: () => {
|
|
29
|
+
setState({ userCredits: 0 });
|
|
30
|
+
},
|
|
24
31
|
userExp: initialUserExp,
|
|
25
32
|
setUserExp: (userExp) => {
|
|
26
33
|
setState({ userExp });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const react_1 = require("@testing-library/react");
|
|
8
|
+
const index_1 = __importDefault(require("./index"));
|
|
9
|
+
describe('CreditsLabel Component', () => {
|
|
10
|
+
test('renders with value and link', () => {
|
|
11
|
+
const props = {
|
|
12
|
+
value: 50,
|
|
13
|
+
link: '/profile/123',
|
|
14
|
+
loading: false,
|
|
15
|
+
};
|
|
16
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(index_1.default, { ...props }));
|
|
17
|
+
const inviteText = react_1.screen.getByText('50 credits');
|
|
18
|
+
expect(inviteText).toBeInTheDocument();
|
|
19
|
+
const linkElement = react_1.screen.getByRole('link', { name: /50 profile/i });
|
|
20
|
+
expect(linkElement).toHaveAttribute('href', '/profile/123');
|
|
21
|
+
});
|
|
22
|
+
test('renders loading skeleton', () => {
|
|
23
|
+
const props = {
|
|
24
|
+
value: 0,
|
|
25
|
+
link: '/profile/123',
|
|
26
|
+
loading: true,
|
|
27
|
+
};
|
|
28
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)("div", { "data-testid": 'test_container', children: (0, jsx_runtime_1.jsx)(index_1.default, { ...props }) }));
|
|
29
|
+
const skeletonElement = react_1.screen
|
|
30
|
+
.getByTestId('test_container')
|
|
31
|
+
.querySelector('.react-loading-skeleton');
|
|
32
|
+
expect(skeletonElement).toBeInTheDocument();
|
|
33
|
+
});
|
|
34
|
+
test('does not render when value is falsy', () => {
|
|
35
|
+
const props = {
|
|
36
|
+
value: 0,
|
|
37
|
+
link: '/profile/123',
|
|
38
|
+
loading: false,
|
|
39
|
+
};
|
|
40
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(index_1.default, { ...props }));
|
|
41
|
+
const inviteText = react_1.screen.queryByText('0 credits');
|
|
42
|
+
expect(inviteText).not.toBeInTheDocument();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
declare const CreditsLabel: ({ value, link, loading, className, style, withIcon, }: {
|
|
3
|
+
value: number;
|
|
4
|
+
withIcon?: boolean;
|
|
5
|
+
link?: string;
|
|
6
|
+
loading?: boolean;
|
|
7
|
+
className?: string;
|
|
8
|
+
style?: React.CSSProperties;
|
|
9
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export default CreditsLabel;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
30
|
+
const vars_1 = require("../../../fonts/vars");
|
|
31
|
+
const ScreenWidth_1 = require("../../../styles/ScreenWidth");
|
|
32
|
+
const boxShadow_1 = __importDefault(require("../../../styles/mixins/boxShadow"));
|
|
33
|
+
const boxTransform_1 = __importDefault(require("../../../styles/mixins/boxTransform"));
|
|
34
|
+
const SkeletonLabel_1 = __importDefault(require("../SkeletonLabel"));
|
|
35
|
+
const constants_1 = require("@ludo.ninja/core/build/constants");
|
|
36
|
+
const _4k_1 = require("@ludo.ninja/ui/build/utils/4k");
|
|
37
|
+
const image_1 = __importDefault(require("next/image"));
|
|
38
|
+
const link_1 = __importDefault(require("next/link"));
|
|
39
|
+
const styled_components_1 = __importStar(require("styled-components"));
|
|
40
|
+
const CreditsLabelStyles = () => (0, styled_components_1.css) `
|
|
41
|
+
${boxShadow_1.default};
|
|
42
|
+
display: flex;
|
|
43
|
+
gap: 8px;
|
|
44
|
+
user-select: none;
|
|
45
|
+
justify-content: flex-start;
|
|
46
|
+
align-items: center;
|
|
47
|
+
padding: 5px 16px;
|
|
48
|
+
max-width: max-content;
|
|
49
|
+
min-width: 80px;
|
|
50
|
+
min-height: 32px;
|
|
51
|
+
border-radius: 24px;
|
|
52
|
+
background: ${({ theme }) => theme.colors?.inviteCodesGradientLabel?.gradient};
|
|
53
|
+
|
|
54
|
+
.value {
|
|
55
|
+
font-family: ${vars_1.poppinsFontVarCss.css};
|
|
56
|
+
font-size: 1.6em;
|
|
57
|
+
font-weight: 600;
|
|
58
|
+
line-height: 1.3;
|
|
59
|
+
color: ${({ theme }) => theme.colors?.inviteCodesGradientLabel?.color};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
${ScreenWidth_1.mediaQuery.minWidthFourK} {
|
|
63
|
+
gap: ${(0, _4k_1.adaptiveValueCalc)(8)};
|
|
64
|
+
padding: ${(0, _4k_1.adaptiveValueCalc)(5)} ${(0, _4k_1.adaptiveValueCalc)(16)};
|
|
65
|
+
min-width: ${(0, _4k_1.adaptiveValueCalc)(80)};
|
|
66
|
+
min-height: ${(0, _4k_1.adaptiveValueCalc)(32)};
|
|
67
|
+
border-radius: ${(0, _4k_1.adaptiveValueCalc)(24)};
|
|
68
|
+
|
|
69
|
+
.value {
|
|
70
|
+
font-size: ${(0, _4k_1.adaptiveValueCalc)(16)};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
const StyledCreditsLink = (0, styled_components_1.default)(link_1.default) `
|
|
75
|
+
${boxTransform_1.default};
|
|
76
|
+
${CreditsLabelStyles};
|
|
77
|
+
`;
|
|
78
|
+
const StyledCreditsTab = styled_components_1.default.div `
|
|
79
|
+
${CreditsLabelStyles};
|
|
80
|
+
`;
|
|
81
|
+
const CreditsLabel = ({ value = 0, link, loading, className, style, withIcon = false, }) => {
|
|
82
|
+
if (loading)
|
|
83
|
+
return (0, jsx_runtime_1.jsx)(SkeletonLabel_1.default, {});
|
|
84
|
+
return link ? ((0, jsx_runtime_1.jsx)(StyledCreditsLink, { href: link, className: className, style: style, children: (0, jsx_runtime_1.jsx)(LabelContent, { value: value, withIcon: withIcon }) })) : ((0, jsx_runtime_1.jsx)(StyledCreditsTab, { className: className, style: style, children: (0, jsx_runtime_1.jsx)(LabelContent, { value: value, withIcon: withIcon }) }));
|
|
85
|
+
};
|
|
86
|
+
const LabelContent = ({ value, withIcon }) => {
|
|
87
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [withIcon && (0, jsx_runtime_1.jsx)(image_1.default, { src: `${constants_1.staticLink}/public/credits_icon.svg`, alt: "Credits icon", width: 20, height: 20 }), (0, jsx_runtime_1.jsx)("p", { className: `value `, children: `${value} credit${value !== 1 ? 's' : ''}` })] }));
|
|
88
|
+
};
|
|
89
|
+
exports.default = CreditsLabel;
|