@selfcommunity/react-ui 0.10.5-payments.158 → 0.10.5-payments.162

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.
@@ -32,7 +32,7 @@ function PaymentProduct(inProps) {
32
32
  const { scPaymentProduct } = (0, react_core_1.useSCFetchPaymentProduct)({ id: paymentProductId, paymentProduct });
33
33
  // CONST
34
34
  const productPaymentPriceIds = (0, react_1.useMemo)(() => {
35
- if (scPaymentProduct) {
35
+ if (scPaymentProduct && scPaymentProduct.payment_prices) {
36
36
  return scPaymentProduct.payment_prices.map((p) => p.id);
37
37
  }
38
38
  return [];
@@ -45,6 +45,7 @@ function PaymentProduct(inProps) {
45
45
  return (0, jsx_runtime_1.jsx)(Skeleton_1.default, {});
46
46
  }
47
47
  return ((0, jsx_runtime_1.jsxs)(Root, Object.assign({ disabled: !productPaymentPriceIds.length, defaultExpanded: isProductExpanded && productPaymentPriceIds.length > 0, square: true, className: (0, classnames_1.default)(classes.root, className) }, (expanded && { expanded }), rest, { children: [(0, jsx_runtime_1.jsxs)(material_1.AccordionSummary, Object.assign({ "aria-controls": "panel1-content", id: "panel1-header" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "h5", component: "div" }, { children: (0, jsx_runtime_1.jsx)("b", { children: scPaymentProduct.name && scPaymentProduct.name }) })), scPaymentProduct.description && ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body1", component: "div" }, { children: scPaymentProduct.description })))] })), (0, jsx_runtime_1.jsx)(material_1.AccordionDetails, { children: !hidePaymentProductPrices &&
48
+ scPaymentProduct.payment_prices &&
48
49
  scPaymentProduct.payment_prices.map((price, index) => ((0, jsx_runtime_1.jsx)(PaymentProductPrice_1.default, Object.assign({ price: price }, PaymentProductPriceComponentProps, (contentType && { contentType }), (content ? { content } : { contentId }), (paymentOrder && { paymentOrder, onHandleActionBuy: onUpdatePaymentOrder })), index))) })] })));
49
50
  }
50
51
  exports.default = PaymentProduct;
@@ -6,13 +6,13 @@ const react_1 = require("react");
6
6
  const material_1 = require("@mui/material");
7
7
  const styles_1 = require("@mui/material/styles");
8
8
  const system_1 = require("@mui/system");
9
- const types_1 = require("@selfcommunity/types");
10
9
  const constants_1 = require("./constants");
11
10
  const Skeleton_1 = tslib_1.__importDefault(require("./Skeleton"));
12
11
  const react_intl_1 = require("react-intl");
13
12
  const react_core_1 = require("@selfcommunity/react-core");
14
13
  const BaseItem_1 = tslib_1.__importDefault(require("../../shared/BaseItem"));
15
14
  const classnames_1 = tslib_1.__importDefault(require("classnames"));
15
+ const payment_1 = require("../../utils/payment");
16
16
  const classes = {
17
17
  root: `${constants_1.PREFIX}-root`,
18
18
  image: `${constants_1.PREFIX}-image`,
@@ -41,9 +41,6 @@ function PaymentProductPrice(inProps) {
41
41
  const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('sm'));
42
42
  const intl = (0, react_intl_1.useIntl)();
43
43
  const { isPaymentsEnabled } = (0, react_core_1.useSCPaymentsEnabled)();
44
- const formattedPrice = (0, react_1.useMemo)(() => {
45
- return ((0, jsx_runtime_1.jsxs)("b", { children: [(price.unit_amount / 100).toFixed(2), price.currency === types_1.SCPaymentPriceCurrencyType.EUR && '€'] }));
46
- }, [price]);
47
44
  const handleActionBuy = (0, react_1.useCallback)((e) => {
48
45
  e.preventDefault();
49
46
  e.stopPropagation();
@@ -55,8 +52,8 @@ function PaymentProductPrice(inProps) {
55
52
  if (!price) {
56
53
  return (0, jsx_runtime_1.jsx)(Skeleton_1.default, {});
57
54
  }
58
- return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ disableTypography: true, className: classes.root, image: (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.image }, { children: (0, jsx_runtime_1.jsx)(material_1.Avatar, Object.assign({ variant: "square", alt: 'price.name', className: classes.image }, { children: (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "card_giftcard" }) })) })), primary: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body1" }, { children: formattedPrice })), secondary: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [!isMobile && ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ component: "p", variant: "body2", className: classes.secondary }, { children: price.description }))), (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: !isMobile && paymentOrder && paymentOrder.payment_price.id === price.id && ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ component: "p", variant: "body2", className: (0, classnames_1.default)(classes.secondary, classes.purchasedAt) }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { defaultMessage: "ui.paymentProduct.action.purchasedAt", id: "ui.paymentProduct.action.purchasedAt", values: {
59
- purchasedAt: intl.formatDate(new Date(), { day: 'numeric', year: 'numeric', month: 'long' })
55
+ return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ disableTypography: true, className: classes.root, image: (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.image }, { children: (0, jsx_runtime_1.jsx)(material_1.Avatar, Object.assign({ variant: "square", alt: 'price.name', className: classes.image }, { children: (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "card_giftcard" }) })) })), primary: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body1" }, { children: (0, jsx_runtime_1.jsx)("b", { children: (0, payment_1.getConvertedAmount)(price) }) })), secondary: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [!isMobile && ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ component: "p", variant: "body2", className: classes.secondary }, { children: price.description }))), (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: !isMobile && paymentOrder && paymentOrder.payment_price.id === price.id && ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ component: "p", variant: "body2", className: (0, classnames_1.default)(classes.secondary, classes.purchasedAt) }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { defaultMessage: "ui.paymentProduct.action.purchasedAt", id: "ui.paymentProduct.action.purchasedAt", values: {
56
+ purchasedAt: intl.formatDate(new Date(paymentOrder.created_at), { day: 'numeric', year: 'numeric', month: 'long' })
60
57
  } }) }))) })] }), actions: actions !== null && actions !== void 0 ? actions : ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.action }, { children: (0, jsx_runtime_1.jsx)(material_1.Zoom, Object.assign({ in: true, style: { transitionDelay: '200ms' } }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ size: "small", color: paymentOrder && paymentOrder.payment_price.id === price.id ? 'secondary' : 'error', className: (0, classnames_1.default)(classes.button, { [classes.buttonPurchased]: paymentOrder && paymentOrder.payment_price.id === price.id }) }, (paymentOrder && { disabled: true }), { variant: "contained", component: react_core_1.Link, startIcon: (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "card_giftcard" }) }, (onHandleActionBuy && { onClick: handleActionBuy }), { to: `${scRoutingContext.url(react_core_1.SCRoutes.CHECKOUT_PAYMENT, {
61
58
  content_type: contentType.toLowerCase(),
62
59
  content_id: content ? content.id : contentId,
@@ -15,6 +15,8 @@ const utils_1 = require("@selfcommunity/utils");
15
15
  const Errors_1 = require("../../constants/Errors");
16
16
  const PaymentProducts_1 = tslib_1.__importDefault(require("../PaymentProducts"));
17
17
  const react_intl_1 = require("react-intl");
18
+ const PaymentProduct_1 = tslib_1.__importDefault(require("../PaymentProduct"));
19
+ const payment_1 = require("../../utils/payment");
18
20
  const classes = {
19
21
  root: `${constants_1.PREFIX}-root`,
20
22
  error: `${constants_1.PREFIX}-error`
@@ -37,6 +39,7 @@ function Paywalls(inProps) {
37
39
  // HOOKS
38
40
  const { isPaymentsEnabled } = (0, react_core_1.useSCPaymentsEnabled)();
39
41
  const isMountedRef = (0, react_core_1.useIsComponentMountedRef)();
42
+ const intl = (0, react_intl_1.useIntl)();
40
43
  // Check if the payment price of the purchase is in the current list
41
44
  const isPricePurchasedIncluded = (0, react_1.useMemo)(() => {
42
45
  let _included = false;
@@ -84,6 +87,9 @@ function Paywalls(inProps) {
84
87
  if (!isPaymentsEnabled) {
85
88
  return null;
86
89
  }
87
- return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className) }, rest, { children: loading ? ((0, jsx_runtime_1.jsx)(Skeleton_1.default, {})) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(PaymentProducts_1.default, Object.assign({ contentType: contentType }, (content ? { content } : { contentId }), { prefetchedProducts: products, paymentOrder: paymentOrder }, (paymentOrder && { paymentOrder, onUpdatePaymentOrder }))), paymentOrder && !isPricePurchasedIncluded && ((0, jsx_runtime_1.jsx)(material_1.Alert, Object.assign({ severity: "error", className: classes.error }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.paywalls.priceNotIncluded", defaultMessage: "ui.paywalls.priceNotIncluded" }) })))] })) })));
90
+ return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className) }, rest, { children: loading ? ((0, jsx_runtime_1.jsx)(Skeleton_1.default, {})) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(PaymentProducts_1.default, Object.assign({ contentType: contentType }, (content ? { content } : { contentId }), { prefetchedProducts: products, paymentOrder: paymentOrder }, (paymentOrder && { paymentOrder, onUpdatePaymentOrder }))), paymentOrder && !isPricePurchasedIncluded && ((0, jsx_runtime_1.jsxs)(material_1.Alert, Object.assign({ severity: "error", className: classes.error }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ component: "p", variant: "body2" }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.paywalls.priceNotIncluded", defaultMessage: "ui.paywalls.priceNotIncluded" }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ component: "p", variant: "body2" }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { defaultMessage: "ui.paywalls.contentPurchasedAt", id: "ui.paywalls.contentPurchasedAt", values: {
91
+ purchasedAt: intl.formatDate(new Date(paymentOrder.created_at), { day: 'numeric', year: 'numeric', month: 'long' }),
92
+ price: (0, payment_1.getConvertedAmount)(paymentOrder.payment_price)
93
+ } }) })), (0, jsx_runtime_1.jsx)(PaymentProduct_1.default, Object.assign({ paymentProduct: paymentOrder.payment_price.payment_product, contentType: contentType }, (content ? { content } : { contentId })))] })))] })) })));
88
94
  }
89
95
  exports.default = Paywalls;
@@ -30,7 +30,7 @@ export default function PaymentProduct(inProps) {
30
30
  const { scPaymentProduct } = useSCFetchPaymentProduct({ id: paymentProductId, paymentProduct });
31
31
  // CONST
32
32
  const productPaymentPriceIds = useMemo(() => {
33
- if (scPaymentProduct) {
33
+ if (scPaymentProduct && scPaymentProduct.payment_prices) {
34
34
  return scPaymentProduct.payment_prices.map((p) => p.id);
35
35
  }
36
36
  return [];
@@ -43,5 +43,6 @@ export default function PaymentProduct(inProps) {
43
43
  return _jsx(PaymentProductSkeleton, {});
44
44
  }
45
45
  return (_jsxs(Root, Object.assign({ disabled: !productPaymentPriceIds.length, defaultExpanded: isProductExpanded && productPaymentPriceIds.length > 0, square: true, className: classNames(classes.root, className) }, (expanded && { expanded }), rest, { children: [_jsxs(AccordionSummary, Object.assign({ "aria-controls": "panel1-content", id: "panel1-header" }, { children: [_jsx(Typography, Object.assign({ variant: "h5", component: "div" }, { children: _jsx("b", { children: scPaymentProduct.name && scPaymentProduct.name }) })), scPaymentProduct.description && (_jsx(Typography, Object.assign({ variant: "body1", component: "div" }, { children: scPaymentProduct.description })))] })), _jsx(AccordionDetails, { children: !hidePaymentProductPrices &&
46
+ scPaymentProduct.payment_prices &&
46
47
  scPaymentProduct.payment_prices.map((price, index) => (_jsx(PaymentProductPrice, Object.assign({ price: price }, PaymentProductPriceComponentProps, (contentType && { contentType }), (content ? { content } : { contentId }), (paymentOrder && { paymentOrder, onHandleActionBuy: onUpdatePaymentOrder })), index))) })] })));
47
48
  }
@@ -1,16 +1,16 @@
1
1
  import { __rest } from "tslib";
2
- import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { useCallback, useMemo } from 'react';
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useCallback } from 'react';
4
4
  import { Avatar, Box, Button, Icon, Typography, useMediaQuery, useTheme, Zoom } from '@mui/material';
5
5
  import { styled } from '@mui/material/styles';
6
6
  import { useThemeProps } from '@mui/system';
7
- import { SCPaymentPriceCurrencyType } from '@selfcommunity/types';
8
7
  import { PREFIX } from './constants';
9
8
  import PaymentProductPriceSkeleton from './Skeleton';
10
9
  import { FormattedMessage, useIntl } from 'react-intl';
11
10
  import { Link, SCRoutes, useSCPaymentsEnabled, useSCRouting } from '@selfcommunity/react-core';
12
11
  import BaseItem from '../../shared/BaseItem';
13
12
  import classNames from 'classnames';
13
+ import { getConvertedAmount } from '../../utils/payment';
14
14
  const classes = {
15
15
  root: `${PREFIX}-root`,
16
16
  image: `${PREFIX}-image`,
@@ -39,9 +39,6 @@ export default function PaymentProductPrice(inProps) {
39
39
  const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
40
40
  const intl = useIntl();
41
41
  const { isPaymentsEnabled } = useSCPaymentsEnabled();
42
- const formattedPrice = useMemo(() => {
43
- return (_jsxs("b", { children: [(price.unit_amount / 100).toFixed(2), price.currency === SCPaymentPriceCurrencyType.EUR && '€'] }));
44
- }, [price]);
45
42
  const handleActionBuy = useCallback((e) => {
46
43
  e.preventDefault();
47
44
  e.stopPropagation();
@@ -53,8 +50,8 @@ export default function PaymentProductPrice(inProps) {
53
50
  if (!price) {
54
51
  return _jsx(PaymentProductPriceSkeleton, {});
55
52
  }
56
- return (_jsx(Root, Object.assign({ disableTypography: true, className: classes.root, image: _jsx(Box, Object.assign({ className: classes.image }, { children: _jsx(Avatar, Object.assign({ variant: "square", alt: 'price.name', className: classes.image }, { children: _jsx(Icon, { children: "card_giftcard" }) })) })), primary: _jsx(Typography, Object.assign({ variant: "body1" }, { children: formattedPrice })), secondary: _jsxs(_Fragment, { children: [!isMobile && (_jsx(Typography, Object.assign({ component: "p", variant: "body2", className: classes.secondary }, { children: price.description }))), _jsx(_Fragment, { children: !isMobile && paymentOrder && paymentOrder.payment_price.id === price.id && (_jsx(Typography, Object.assign({ component: "p", variant: "body2", className: classNames(classes.secondary, classes.purchasedAt) }, { children: _jsx(FormattedMessage, { defaultMessage: "ui.paymentProduct.action.purchasedAt", id: "ui.paymentProduct.action.purchasedAt", values: {
57
- purchasedAt: intl.formatDate(new Date(), { day: 'numeric', year: 'numeric', month: 'long' })
53
+ return (_jsx(Root, Object.assign({ disableTypography: true, className: classes.root, image: _jsx(Box, Object.assign({ className: classes.image }, { children: _jsx(Avatar, Object.assign({ variant: "square", alt: 'price.name', className: classes.image }, { children: _jsx(Icon, { children: "card_giftcard" }) })) })), primary: _jsx(Typography, Object.assign({ variant: "body1" }, { children: _jsx("b", { children: getConvertedAmount(price) }) })), secondary: _jsxs(_Fragment, { children: [!isMobile && (_jsx(Typography, Object.assign({ component: "p", variant: "body2", className: classes.secondary }, { children: price.description }))), _jsx(_Fragment, { children: !isMobile && paymentOrder && paymentOrder.payment_price.id === price.id && (_jsx(Typography, Object.assign({ component: "p", variant: "body2", className: classNames(classes.secondary, classes.purchasedAt) }, { children: _jsx(FormattedMessage, { defaultMessage: "ui.paymentProduct.action.purchasedAt", id: "ui.paymentProduct.action.purchasedAt", values: {
54
+ purchasedAt: intl.formatDate(new Date(paymentOrder.created_at), { day: 'numeric', year: 'numeric', month: 'long' })
58
55
  } }) }))) })] }), actions: actions !== null && actions !== void 0 ? actions : (_jsx(Box, Object.assign({ className: classes.action }, { children: _jsx(Zoom, Object.assign({ in: true, style: { transitionDelay: '200ms' } }, { children: _jsx(Button, Object.assign({ size: "small", color: paymentOrder && paymentOrder.payment_price.id === price.id ? 'secondary' : 'error', className: classNames(classes.button, { [classes.buttonPurchased]: paymentOrder && paymentOrder.payment_price.id === price.id }) }, (paymentOrder && { disabled: true }), { variant: "contained", component: Link, startIcon: _jsx(Icon, { children: "card_giftcard" }) }, (onHandleActionBuy && { onClick: handleActionBuy }), { to: `${scRoutingContext.url(SCRoutes.CHECKOUT_PAYMENT, {
59
56
  content_type: contentType.toLowerCase(),
60
57
  content_id: content ? content.id : contentId,
@@ -1,7 +1,7 @@
1
1
  import { __rest } from "tslib";
2
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { useEffect, useMemo, useState } from 'react';
4
- import { Alert, Box } from '@mui/material';
4
+ import { Alert, Box, Typography } from '@mui/material';
5
5
  import { styled } from '@mui/material/styles';
6
6
  import { useThemeProps } from '@mui/system';
7
7
  import classNames from 'classnames';
@@ -12,7 +12,9 @@ import PaymentProductsSkeleton from './Skeleton';
12
12
  import { Logger } from '@selfcommunity/utils';
13
13
  import { SCOPE_SC_UI } from '../../constants/Errors';
14
14
  import PaymentProducts from '../PaymentProducts';
15
- import { FormattedMessage } from 'react-intl';
15
+ import { FormattedMessage, useIntl } from 'react-intl';
16
+ import PaymentProduct from '../PaymentProduct';
17
+ import { getConvertedAmount } from '../../utils/payment';
16
18
  const classes = {
17
19
  root: `${PREFIX}-root`,
18
20
  error: `${PREFIX}-error`
@@ -35,6 +37,7 @@ export default function Paywalls(inProps) {
35
37
  // HOOKS
36
38
  const { isPaymentsEnabled } = useSCPaymentsEnabled();
37
39
  const isMountedRef = useIsComponentMountedRef();
40
+ const intl = useIntl();
38
41
  // Check if the payment price of the purchase is in the current list
39
42
  const isPricePurchasedIncluded = useMemo(() => {
40
43
  let _included = false;
@@ -82,5 +85,8 @@ export default function Paywalls(inProps) {
82
85
  if (!isPaymentsEnabled) {
83
86
  return null;
84
87
  }
85
- return (_jsx(Root, Object.assign({ className: classNames(classes.root, className) }, rest, { children: loading ? (_jsx(PaymentProductsSkeleton, {})) : (_jsxs(_Fragment, { children: [_jsx(PaymentProducts, Object.assign({ contentType: contentType }, (content ? { content } : { contentId }), { prefetchedProducts: products, paymentOrder: paymentOrder }, (paymentOrder && { paymentOrder, onUpdatePaymentOrder }))), paymentOrder && !isPricePurchasedIncluded && (_jsx(Alert, Object.assign({ severity: "error", className: classes.error }, { children: _jsx(FormattedMessage, { id: "ui.paywalls.priceNotIncluded", defaultMessage: "ui.paywalls.priceNotIncluded" }) })))] })) })));
88
+ return (_jsx(Root, Object.assign({ className: classNames(classes.root, className) }, rest, { children: loading ? (_jsx(PaymentProductsSkeleton, {})) : (_jsxs(_Fragment, { children: [_jsx(PaymentProducts, Object.assign({ contentType: contentType }, (content ? { content } : { contentId }), { prefetchedProducts: products, paymentOrder: paymentOrder }, (paymentOrder && { paymentOrder, onUpdatePaymentOrder }))), paymentOrder && !isPricePurchasedIncluded && (_jsxs(Alert, Object.assign({ severity: "error", className: classes.error }, { children: [_jsx(Typography, Object.assign({ component: "p", variant: "body2" }, { children: _jsx(FormattedMessage, { id: "ui.paywalls.priceNotIncluded", defaultMessage: "ui.paywalls.priceNotIncluded" }) })), _jsx(Typography, Object.assign({ component: "p", variant: "body2" }, { children: _jsx(FormattedMessage, { defaultMessage: "ui.paywalls.contentPurchasedAt", id: "ui.paywalls.contentPurchasedAt", values: {
89
+ purchasedAt: intl.formatDate(new Date(paymentOrder.created_at), { day: 'numeric', year: 'numeric', month: 'long' }),
90
+ price: getConvertedAmount(paymentOrder.payment_price)
91
+ } }) })), _jsx(PaymentProduct, Object.assign({ paymentProduct: paymentOrder.payment_price.payment_product, contentType: contentType }, (content ? { content } : { contentId })))] })))] })) })));
86
92
  }