@selfcommunity/react-ui 0.10.5-payments.169 → 0.10.5-payments.175
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/lib/cjs/components/CourseForm/CourseForm.js +25 -4
- package/lib/cjs/components/EventForm/EventForm.js +10 -6
- package/lib/cjs/components/EventFormDialog/EventFormDialog.js +7 -1
- package/lib/cjs/components/GroupForm/GroupForm.js +12 -6
- package/lib/cjs/components/UserAddPaymentMethodDialog/UserAddPaymentMethodDialog.d.ts +41 -0
- package/lib/cjs/components/UserAddPaymentMethodDialog/UserAddPaymentMethodDialog.js +94 -0
- package/lib/cjs/components/UserAddPaymentMethodDialog/constants.d.ts +1 -0
- package/lib/cjs/components/UserAddPaymentMethodDialog/constants.js +4 -0
- package/lib/cjs/components/UserAddPaymentMethodDialog/index.d.ts +3 -0
- package/lib/cjs/components/UserAddPaymentMethodDialog/index.js +5 -0
- package/lib/cjs/components/UserAddPaymentMethodForm/UserAddPaymentMethodForm.d.ts +40 -0
- package/lib/cjs/components/UserAddPaymentMethodForm/UserAddPaymentMethodForm.js +143 -0
- package/lib/cjs/components/UserAddPaymentMethodForm/constants.d.ts +1 -0
- package/lib/cjs/components/UserAddPaymentMethodForm/constants.js +4 -0
- package/lib/cjs/components/UserAddPaymentMethodForm/index.d.ts +3 -0
- package/lib/cjs/components/UserAddPaymentMethodForm/index.js +5 -0
- package/lib/cjs/components/UserBillingInfo/Skeleton.d.ts +25 -0
- package/lib/cjs/components/UserBillingInfo/Skeleton.js +14 -0
- package/lib/cjs/components/UserBillingInfo/UserBillingInfo.d.ts +35 -0
- package/lib/cjs/components/UserBillingInfo/UserBillingInfo.js +492 -0
- package/lib/cjs/components/UserBillingInfo/constants.d.ts +1 -0
- package/lib/cjs/components/UserBillingInfo/constants.js +4 -0
- package/lib/cjs/components/UserBillingInfo/index.d.ts +4 -0
- package/lib/cjs/components/UserBillingInfo/index.js +8 -0
- package/lib/cjs/components/UserBillingInfo/reducer.d.ts +77 -0
- package/lib/cjs/components/UserBillingInfo/reducer.js +96 -0
- package/lib/cjs/components/UserChangeAddressDialog/UserChangeAddressDialog.d.ts +44 -0
- package/lib/cjs/components/UserChangeAddressDialog/UserChangeAddressDialog.js +85 -0
- package/lib/cjs/components/UserChangeAddressDialog/constants.d.ts +1 -0
- package/lib/cjs/components/UserChangeAddressDialog/constants.js +4 -0
- package/lib/cjs/components/UserChangeAddressDialog/index.d.ts +3 -0
- package/lib/cjs/components/UserChangeAddressDialog/index.js +5 -0
- package/lib/cjs/components/UserPaymentMethods/Skeleton.d.ts +15 -22
- package/lib/cjs/components/UserPaymentMethods/Skeleton.js +17 -4
- package/lib/cjs/components/UserPaymentMethods/UserPaymentMethods.d.ts +6 -31
- package/lib/cjs/components/UserPaymentMethods/UserPaymentMethods.js +264 -29
- package/lib/cjs/components/UserPaymentMethodsPortal/Skeleton.d.ts +22 -0
- package/lib/cjs/components/UserPaymentMethodsPortal/Skeleton.js +38 -0
- package/lib/cjs/components/UserPaymentMethodsPortal/UserPaymentMethodsPortal.d.ts +44 -0
- package/lib/cjs/components/UserPaymentMethodsPortal/UserPaymentMethodsPortal.js +104 -0
- package/lib/cjs/components/UserPaymentMethodsPortal/constants.d.ts +1 -0
- package/lib/cjs/components/UserPaymentMethodsPortal/constants.js +4 -0
- package/lib/cjs/components/UserPaymentMethodsPortal/index.d.ts +4 -0
- package/lib/cjs/components/UserPaymentMethodsPortal/index.js +8 -0
- package/lib/cjs/constants/Billing.d.ts +10 -0
- package/lib/cjs/constants/Billing.js +60 -0
- package/lib/cjs/constants/Country.d.ts +5 -0
- package/lib/cjs/constants/Country.js +271 -0
- package/lib/cjs/index.d.ts +6 -1
- package/lib/cjs/index.js +14 -2
- package/lib/cjs/types/index.d.ts +2 -1
- package/lib/cjs/types/index.js +5 -1
- package/lib/cjs/types/payment.d.ts +25 -0
- package/lib/cjs/types/payment.js +29 -0
- package/lib/cjs/utils/address.d.ts +10 -0
- package/lib/cjs/utils/address.js +24 -0
- package/lib/esm/components/CourseForm/CourseForm.js +27 -6
- package/lib/esm/components/EventForm/EventForm.js +10 -6
- package/lib/esm/components/EventFormDialog/EventFormDialog.js +7 -1
- package/lib/esm/components/GroupForm/GroupForm.js +12 -6
- package/lib/esm/components/UserAddPaymentMethodDialog/UserAddPaymentMethodDialog.d.ts +41 -0
- package/lib/esm/components/UserAddPaymentMethodDialog/UserAddPaymentMethodDialog.js +91 -0
- package/lib/esm/components/UserAddPaymentMethodDialog/constants.d.ts +1 -0
- package/lib/esm/components/UserAddPaymentMethodDialog/constants.js +1 -0
- package/lib/esm/components/UserAddPaymentMethodDialog/index.d.ts +3 -0
- package/lib/esm/components/UserAddPaymentMethodDialog/index.js +2 -0
- package/lib/esm/components/UserAddPaymentMethodForm/UserAddPaymentMethodForm.d.ts +40 -0
- package/lib/esm/components/UserAddPaymentMethodForm/UserAddPaymentMethodForm.js +140 -0
- package/lib/esm/components/UserAddPaymentMethodForm/constants.d.ts +1 -0
- package/lib/esm/components/UserAddPaymentMethodForm/constants.js +1 -0
- package/lib/esm/components/UserAddPaymentMethodForm/index.d.ts +3 -0
- package/lib/esm/components/UserAddPaymentMethodForm/index.js +2 -0
- package/lib/esm/components/UserBillingInfo/Skeleton.d.ts +25 -0
- package/lib/esm/components/UserBillingInfo/Skeleton.js +10 -0
- package/lib/esm/components/UserBillingInfo/UserBillingInfo.d.ts +35 -0
- package/lib/esm/components/UserBillingInfo/UserBillingInfo.js +490 -0
- package/lib/esm/components/UserBillingInfo/constants.d.ts +1 -0
- package/lib/esm/components/UserBillingInfo/constants.js +1 -0
- package/lib/esm/components/UserBillingInfo/index.d.ts +4 -0
- package/lib/esm/components/UserBillingInfo/index.js +4 -0
- package/lib/esm/components/UserBillingInfo/reducer.d.ts +77 -0
- package/lib/esm/components/UserBillingInfo/reducer.js +91 -0
- package/lib/esm/components/UserChangeAddressDialog/UserChangeAddressDialog.d.ts +44 -0
- package/lib/esm/components/UserChangeAddressDialog/UserChangeAddressDialog.js +82 -0
- package/lib/esm/components/UserChangeAddressDialog/constants.d.ts +1 -0
- package/lib/esm/components/UserChangeAddressDialog/constants.js +1 -0
- package/lib/esm/components/UserChangeAddressDialog/index.d.ts +3 -0
- package/lib/esm/components/UserChangeAddressDialog/index.js +2 -0
- package/lib/esm/components/UserPaymentMethods/Skeleton.d.ts +15 -22
- package/lib/esm/components/UserPaymentMethods/Skeleton.js +19 -6
- package/lib/esm/components/UserPaymentMethods/UserPaymentMethods.d.ts +6 -31
- package/lib/esm/components/UserPaymentMethods/UserPaymentMethods.js +268 -32
- package/lib/esm/components/UserPaymentMethodsPortal/Skeleton.d.ts +22 -0
- package/lib/esm/components/UserPaymentMethodsPortal/Skeleton.js +36 -0
- package/lib/esm/components/UserPaymentMethodsPortal/UserPaymentMethodsPortal.d.ts +44 -0
- package/lib/esm/components/UserPaymentMethodsPortal/UserPaymentMethodsPortal.js +101 -0
- package/lib/esm/components/UserPaymentMethodsPortal/constants.d.ts +1 -0
- package/lib/esm/components/UserPaymentMethodsPortal/constants.js +1 -0
- package/lib/esm/components/UserPaymentMethodsPortal/index.d.ts +4 -0
- package/lib/esm/components/UserPaymentMethodsPortal/index.js +4 -0
- package/lib/esm/constants/Billing.d.ts +10 -0
- package/lib/esm/constants/Billing.js +57 -0
- package/lib/esm/constants/Country.d.ts +5 -0
- package/lib/esm/constants/Country.js +268 -0
- package/lib/esm/index.d.ts +6 -1
- package/lib/esm/index.js +6 -1
- package/lib/esm/types/index.d.ts +2 -1
- package/lib/esm/types/index.js +2 -1
- package/lib/esm/types/payment.d.ts +25 -0
- package/lib/esm/types/payment.js +26 -0
- package/lib/esm/utils/address.d.ts +10 -0
- package/lib/esm/utils/address.js +19 -0
- package/lib/umd/465.js +2 -0
- package/lib/umd/react-ui.js +1 -1
- package/package.json +9 -10
- package/lib/umd/401.js +0 -20
- /package/lib/umd/{401.js.LICENSE.txt → 465.js.LICENSE.txt} +0 -0
|
@@ -22,6 +22,7 @@ const Course_1 = require("../../constants/Course");
|
|
|
22
22
|
const CategoryAutocomplete_1 = tslib_1.__importDefault(require("../CategoryAutocomplete"));
|
|
23
23
|
const Edit_1 = tslib_1.__importDefault(require("./Edit"));
|
|
24
24
|
const Dialog_1 = tslib_1.__importDefault(require("./Dialog"));
|
|
25
|
+
const PaywallsConfigurator_1 = tslib_1.__importDefault(require("../PaywallsConfigurator"));
|
|
25
26
|
const messages = (0, react_intl_1.defineMessages)({
|
|
26
27
|
name: {
|
|
27
28
|
id: 'ui.courseForm.name.placeholder',
|
|
@@ -60,7 +61,8 @@ const classes = {
|
|
|
60
61
|
stepCustomization: `${constants_1.PREFIX}-step-customization`,
|
|
61
62
|
cardTitle: `${constants_1.PREFIX}-card-title`,
|
|
62
63
|
title: `${constants_1.PREFIX}-title`,
|
|
63
|
-
contrastColor: `${constants_1.PREFIX}-contrast-color
|
|
64
|
+
contrastColor: `${constants_1.PREFIX}-contrast-color`,
|
|
65
|
+
paywallsConfiguratorWrap: `${constants_1.PREFIX}-paywalls-configurator-wrap`
|
|
64
66
|
};
|
|
65
67
|
const Root = (0, styles_1.styled)(material_1.Box, {
|
|
66
68
|
name: constants_1.PREFIX,
|
|
@@ -101,7 +103,7 @@ const Root = (0, styles_1.styled)(material_1.Box, {
|
|
|
101
103
|
* @param inProps
|
|
102
104
|
*/
|
|
103
105
|
function CourseForm(inProps) {
|
|
104
|
-
var _a, _b, _c;
|
|
106
|
+
var _a, _b, _c, _d;
|
|
105
107
|
//PROPS
|
|
106
108
|
const props = (0, system_1.useThemeProps)({
|
|
107
109
|
props: inProps,
|
|
@@ -118,6 +120,7 @@ function CourseForm(inProps) {
|
|
|
118
120
|
description: course ? course.description : '',
|
|
119
121
|
categories: course ? course.categories : [],
|
|
120
122
|
privacy: course ? course.privacy : '',
|
|
123
|
+
product_ids: ((_a = course === null || course === void 0 ? void 0 : course.paywalls) === null || _a === void 0 ? void 0 : _a.map((p) => p.id)) || [],
|
|
121
124
|
isSubmitting: false
|
|
122
125
|
};
|
|
123
126
|
// STATE
|
|
@@ -125,8 +128,13 @@ function CourseForm(inProps) {
|
|
|
125
128
|
const [_step, setStep] = (0, react_1.useState)(step);
|
|
126
129
|
const [error, setError] = (0, react_1.useState)({});
|
|
127
130
|
const [openDialog, setOpenDialog] = (0, react_1.useState)(false);
|
|
131
|
+
// CONTEXT
|
|
132
|
+
const scUserContext = (0, react_core_1.useSCUser)();
|
|
128
133
|
// PREFERENCES
|
|
129
134
|
const { preferences } = (0, react_core_1.useSCPreferences)();
|
|
135
|
+
// PAYMENTS
|
|
136
|
+
const { isPaymentsEnabled } = (0, react_core_1.useSCPaymentsEnabled)();
|
|
137
|
+
const isStaff = (0, react_1.useMemo)(() => scUserContext.user && react_core_1.UserUtils.isStaff(scUserContext.user), [scUserContext.user]);
|
|
130
138
|
const courseAdvancedEnabled = (0, react_1.useMemo)(() => preferences[react_core_1.SCPreferences.CONFIGURATIONS_COURSES_ADVANCED_ENABLED].value, [preferences]);
|
|
131
139
|
const _backgroundCover = Object.assign({}, (field.imageOriginal
|
|
132
140
|
? { background: `url('${field.imageOriginal}') center / cover` }
|
|
@@ -187,6 +195,7 @@ function CourseForm(inProps) {
|
|
|
187
195
|
* Handles the form submission for create/update action
|
|
188
196
|
*/
|
|
189
197
|
const handleSubmit = (0, react_1.useCallback)(() => {
|
|
198
|
+
var _a;
|
|
190
199
|
setField((prev) => (Object.assign(Object.assign({}, prev), { isSubmitting: true })));
|
|
191
200
|
const formData = new FormData();
|
|
192
201
|
if (field.imageOriginalFile) {
|
|
@@ -203,6 +212,11 @@ function CourseForm(inProps) {
|
|
|
203
212
|
formData.append(key, field.categories[key]);
|
|
204
213
|
}
|
|
205
214
|
}
|
|
215
|
+
if (field.product_ids && (isStaff || ((_a = course.paywalls) === null || _a === void 0 ? void 0 : _a.length))) {
|
|
216
|
+
field.product_ids.forEach((p, i) => {
|
|
217
|
+
formData.append(`product_ids[${i}]`, p.toString());
|
|
218
|
+
});
|
|
219
|
+
}
|
|
206
220
|
let courseService;
|
|
207
221
|
if (course) {
|
|
208
222
|
courseService = api_services_1.CourseService.patchCourse(course.id, formData, {
|
|
@@ -244,6 +258,13 @@ function CourseForm(inProps) {
|
|
|
244
258
|
setError(error);
|
|
245
259
|
}
|
|
246
260
|
}, [setField, error]);
|
|
261
|
+
/**
|
|
262
|
+
* Handle change payment products
|
|
263
|
+
* @param products
|
|
264
|
+
*/
|
|
265
|
+
const handleChangePaymentsProducts = (products) => {
|
|
266
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { product_ids: products.map((product) => product.id) })));
|
|
267
|
+
};
|
|
247
268
|
/**
|
|
248
269
|
* Handles for closing confirm dialog
|
|
249
270
|
*/
|
|
@@ -256,8 +277,8 @@ function CourseForm(inProps) {
|
|
|
256
277
|
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className) }, rest, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ className: _step === Course_1.SCCourseFormStepType.GENERAL ? classes.stepOne : classes.stepTwo }, { children: [_step === Course_1.SCCourseFormStepType.GENERAL && ((0, jsx_runtime_1.jsx)(react_1.Fragment, { children: Object.values(types_1.SCCourseTypologyType).map((option, index) => ((0, jsx_runtime_1.jsx)(material_1.Card, Object.assign({ className: (0, classnames_1.default)(classes.card, { [classes.selected]: option === field.type }, { [classes.disabled]: !courseAdvancedEnabled && option !== types_1.SCCourseTypologyType.SELF }) }, { children: (0, jsx_runtime_1.jsx)(material_1.CardActionArea, Object.assign({ onClick: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['type']: option }))) }, { children: (0, jsx_runtime_1.jsxs)(material_1.CardContent, { children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, Object.assign({ variant: "subtitle2", className: classes.cardTitle }, { children: [(0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: `ui.courseForm.${option}.title`, defaultMessage: `ui.courseForm.${option}.title` }), !courseAdvancedEnabled && option !== types_1.SCCourseTypologyType.SELF && ((0, jsx_runtime_1.jsx)(material_1.Chip, { variant: "outlined", color: "warning", size: "small", label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.courseForm.comingSoon.chip", defaultMessage: "ui.courseForm.comingSoon.chip" }) }))] })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: `ui.courseForm.${option}.info`, defaultMessage: `ui.courseForm.${option}.info` }) }))] }) })) }), index))) })), _step === Course_1.SCCourseFormStepType.CUSTOMIZATION && ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [course && ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "h5", className: classes.contrastColor }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.courseForm.edit.title.general", defaultMessage: "ui.courseForm.edit.title.general" }) }))), (0, jsx_runtime_1.jsxs)(material_1.FormGroup, Object.assign({ className: (0, classnames_1.default)(classes.form, _step === Course_1.SCCourseFormStepType.CUSTOMIZATION && course ? classes.stepCustomization : undefined) }, { children: [(0, jsx_runtime_1.jsx)(material_1.Paper, Object.assign({ style: _backgroundCover, classes: { root: classes.cover } }, { children: (0, jsx_runtime_1.jsx)(UploadCourseCover_1.default, { isUploading: field.isSubmitting, onChange: handleChangeCover }) })), (0, jsx_runtime_1.jsx)(material_1.TextField, { required: true, className: classes.name, placeholder: `${intl.formatMessage(messages.name)}`, margin: "normal", value: field.name, name: "name", onChange: handleChange, InputProps: {
|
|
257
278
|
endAdornment: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: Course_1.COURSE_TITLE_MAX_LENGTH - field.name.length }))
|
|
258
279
|
}, error: Boolean(field.name.length > Course_1.COURSE_TITLE_MAX_LENGTH) || Boolean(error['nameError']), helperText: field.name.length > Course_1.COURSE_TITLE_MAX_LENGTH ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.courseForm.name.error.maxLength", defaultMessage: "ui.courseForm.name.error.maxLength" })) : error['nameError'] ? (error['nameError']) : null }), (0, jsx_runtime_1.jsx)(material_1.TextField, { multiline: true, className: classes.description, placeholder: `${intl.formatMessage(messages.description)}`, margin: "normal", value: field.description, name: "description", onChange: handleChange, InputProps: {
|
|
259
|
-
endAdornment: ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: ((
|
|
260
|
-
}, error: Boolean(((
|
|
280
|
+
endAdornment: ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: ((_b = field.description) === null || _b === void 0 ? void 0 : _b.length) ? Course_1.COURSE_DESCRIPTION_MAX_LENGTH - field.description.length : Course_1.COURSE_DESCRIPTION_MAX_LENGTH })))
|
|
281
|
+
}, error: Boolean(((_c = field.description) === null || _c === void 0 ? void 0 : _c.length) > Course_1.COURSE_DESCRIPTION_MAX_LENGTH), helperText: ((_d = field.description) === null || _d === void 0 ? void 0 : _d.length) > Course_1.COURSE_DESCRIPTION_MAX_LENGTH ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.courseForm.description.error.maxLength", defaultMessage: "ui.courseForm.description.error.maxLength" })) : null }), (0, jsx_runtime_1.jsx)(CategoryAutocomplete_1.default, { defaultValue: field.categories, TextFieldProps: { label: intl.formatMessage(Object.keys(field.categories).length ? messages.category : messages.categoryEmpty) }, multiple: true, onChange: handleOnChangeCategory }), course && (0, jsx_runtime_1.jsx)(Edit_1.default, { course: course, onPrivacyChange: (privacy) => setField((prev) => (Object.assign(Object.assign({}, prev), { ['privacy']: privacy }))) }), isPaymentsEnabled && isStaff && ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.paywallsConfiguratorWrap }, { children: (0, jsx_runtime_1.jsx)(PaywallsConfigurator_1.default, Object.assign({}, (course && { contentId: course.id }), { contentType: types_1.SCContentType.COURSE, onChange: handleChangePaymentsProducts })) })))] }))] })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: (0, classnames_1.default)(classes.actions, _step === Course_1.SCCourseFormStepType.CUSTOMIZATION && course ? classes.stepCustomization : undefined) }, { children: (0, jsx_runtime_1.jsx)(lab_1.LoadingButton, Object.assign({ size: "small", loading: field.isSubmitting, disabled: _step === Course_1.SCCourseFormStepType.GENERAL
|
|
261
282
|
? !field.type || Object.keys(error).length !== 0
|
|
262
283
|
: _step === Course_1.SCCourseFormStepType.CUSTOMIZATION &&
|
|
263
284
|
(!field.name ||
|
|
@@ -123,7 +123,7 @@ const Root = (0, styles_1.styled)(material_1.Box, {
|
|
|
123
123
|
* @param inProps
|
|
124
124
|
*/
|
|
125
125
|
function EventForm(inProps) {
|
|
126
|
-
var _a, _b, _c, _d, _e, _f;
|
|
126
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
127
127
|
//PROPS
|
|
128
128
|
const props = (0, system_1.useThemeProps)({
|
|
129
129
|
props: inProps,
|
|
@@ -165,7 +165,7 @@ function EventForm(inProps) {
|
|
|
165
165
|
liveStreamSettings: (event === null || event === void 0 ? void 0 : event.live_stream) ? event === null || event === void 0 ? void 0 : event.live_stream.settings : null,
|
|
166
166
|
recurring: (event === null || event === void 0 ? void 0 : event.recurring) || types_1.SCEventRecurrenceType.NEVER,
|
|
167
167
|
isPublic: (event === null || event === void 0 ? void 0 : event.privacy) === types_1.SCEventPrivacyType.PUBLIC || true,
|
|
168
|
-
product_ids: (event === null || event === void 0 ? void 0 : event.paywalls.map((p) => p.id)) || [],
|
|
168
|
+
product_ids: ((_b = event === null || event === void 0 ? void 0 : event.paywalls) === null || _b === void 0 ? void 0 : _b.map((p) => p.id)) || [],
|
|
169
169
|
isSubmitting: false
|
|
170
170
|
};
|
|
171
171
|
// STATE
|
|
@@ -179,7 +179,7 @@ function EventForm(inProps) {
|
|
|
179
179
|
scPreferences.features.includes(types_1.SCFeatureName.LIVE_STREAM) &&
|
|
180
180
|
react_core_1.SCPreferences.CONFIGURATIONS_LIVE_STREAM_ENABLED in scPreferences.preferences &&
|
|
181
181
|
scPreferences.preferences[react_core_1.SCPreferences.CONFIGURATIONS_LIVE_STREAM_ENABLED].value, [scPreferences.preferences, scPreferences.features]);
|
|
182
|
-
const canCreateLiveStream = (0, react_1.useMemo)(() => { var _a, _b; return (_b = (_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.permission) === null || _b === void 0 ? void 0 : _b.create_live_stream; }, [(
|
|
182
|
+
const canCreateLiveStream = (0, react_1.useMemo)(() => { var _a, _b; return (_b = (_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.permission) === null || _b === void 0 ? void 0 : _b.create_live_stream; }, [(_c = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _c === void 0 ? void 0 : _c.permission]);
|
|
183
183
|
const privateEnabled = (0, react_1.useMemo)(() => scPreferences.preferences[react_core_1.SCPreferences.CONFIGURATIONS_EVENTS_PRIVATE_ENABLED].value, [scPreferences.preferences]);
|
|
184
184
|
const visibilityEnabled = (0, react_1.useMemo)(() => scPreferences.preferences[react_core_1.SCPreferences.CONFIGURATIONS_EVENTS_VISIBILITY_ENABLED].value, [scPreferences.preferences]);
|
|
185
185
|
const disablePastStartTime = (0, react_1.useMemo)(() => field.startDate.getDate() === (0, utils_2.getNewDate)().getDate(), [field]);
|
|
@@ -332,6 +332,10 @@ function EventForm(inProps) {
|
|
|
332
332
|
}
|
|
333
333
|
setGenericError(null);
|
|
334
334
|
}, [error, setField, setGenericError]);
|
|
335
|
+
/**
|
|
336
|
+
* Handle change payment products
|
|
337
|
+
* @param products
|
|
338
|
+
*/
|
|
335
339
|
const handleChangePaymentsProducts = (products) => {
|
|
336
340
|
setField((prev) => (Object.assign(Object.assign({}, prev), { product_ids: products.map((product) => product.id) })));
|
|
337
341
|
};
|
|
@@ -408,7 +412,7 @@ function EventForm(inProps) {
|
|
|
408
412
|
start_date: field.startDate,
|
|
409
413
|
location: field.location,
|
|
410
414
|
geolocation: field.geolocation,
|
|
411
|
-
live_stream: Object.assign(Object.assign({ title: field.name || `${intl.formatMessage(messages.name)}` }, (event && ((
|
|
415
|
+
live_stream: Object.assign(Object.assign({ title: field.name || `${intl.formatMessage(messages.name)}` }, (event && ((_d = event.live_stream) === null || _d === void 0 ? void 0 : _d.created_at) && { created_at: field.startDate })), { settings: field.liveStreamSettings })
|
|
412
416
|
}) }, EventAddressComponentProps)), privateEnabled && ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ className: classes.privacySection }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ direction: "row", spacing: 1, alignItems: "center", justifyContent: "center" }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, Object.assign({ className: (0, classnames_1.default)(classes.switchLabel, { [classes.active]: !field.isPublic }) }, { children: [(0, jsx_runtime_1.jsx)(material_1.Icon, { children: "private" }), (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.privacy.private", defaultMessage: "ui.eventForm.privacy.private" })] })), (0, jsx_runtime_1.jsx)(material_1.Switch, { className: classes.switch, checked: field.isPublic, onChange: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['isPublic']: !field.isPublic }))), disabled: event && !field.isPublic }), (0, jsx_runtime_1.jsxs)(material_1.Typography, Object.assign({ className: (0, classnames_1.default)(classes.switchLabel, { [classes.active]: field.isPublic }) }, { children: [(0, jsx_runtime_1.jsx)(material_1.Icon, { children: "public" }), (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.privacy.public", defaultMessage: "ui.eventForm.privacy.public" })] }))] })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2", textAlign: "center", className: classes.privacySectionInfo }, { children: field.isPublic ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.privacy.public.info", defaultMessage: "ui.eventForm.privacy.public.info", values: {
|
|
413
417
|
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
|
|
414
418
|
// @ts-ignores
|
|
@@ -418,8 +422,8 @@ function EventForm(inProps) {
|
|
|
418
422
|
// @ts-ignore
|
|
419
423
|
b: (chunks) => (0, jsx_runtime_1.jsx)("strong", { children: chunks })
|
|
420
424
|
} })) }))] }))), (0, jsx_runtime_1.jsx)(material_1.TextField, { multiline: true, className: classes.description, placeholder: `${intl.formatMessage(messages.description)}`, margin: "normal", value: field.description, name: "description", onChange: handleChange, InputProps: {
|
|
421
|
-
endAdornment: ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: ((
|
|
422
|
-
}, error: Boolean(((
|
|
425
|
+
endAdornment: ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: ((_e = field.description) === null || _e === void 0 ? void 0 : _e.length) ? Event_1.EVENT_DESCRIPTION_MAX_LENGTH - field.description.length : Event_1.EVENT_DESCRIPTION_MAX_LENGTH })))
|
|
426
|
+
}, error: Boolean(((_f = field.description) === null || _f === void 0 ? void 0 : _f.length) > Event_1.EVENT_DESCRIPTION_MAX_LENGTH), helperText: ((_g = field.description) === null || _g === void 0 ? void 0 : _g.length) > Event_1.EVENT_DESCRIPTION_MAX_LENGTH ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.description.error.maxLength", defaultMessage: "ui.eventForm.description.error.maxLength" })) : null }), isPaymentsEnabled && isStaff && ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.paywallsConfiguratorWrap }, { children: (0, jsx_runtime_1.jsx)(PaywallsConfigurator_1.default, Object.assign({}, (event && { contentId: event.id }), { contentType: types_1.SCContentType.EVENT, onChange: handleChangePaymentsProducts })) }))), genericError && ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.genericError }, { children: (0, jsx_runtime_1.jsx)(material_1.Alert, Object.assign({ variant: "filled", severity: "error" }, { children: genericError })) }))), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.actions }, { children: (0, jsx_runtime_1.jsx)(lab_1.LoadingButton, Object.assign({ loading: field.isSubmitting, disabled: !field.name ||
|
|
423
427
|
!field.startDate ||
|
|
424
428
|
!field.startTime ||
|
|
425
429
|
!field.endDate ||
|
|
@@ -48,9 +48,15 @@ function EventFormDialog(inProps) {
|
|
|
48
48
|
(_a = EventFormComponentProps.onSuccess) === null || _a === void 0 ? void 0 : _a.call(EventFormComponentProps, event);
|
|
49
49
|
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
50
50
|
}, [onClose, EventFormComponentProps]);
|
|
51
|
+
const handleClose = (_event, reason) => {
|
|
52
|
+
if (reason === 'backdropClick' || reason === 'escapeKeyDown') {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
56
|
+
};
|
|
51
57
|
/**
|
|
52
58
|
* Renders root object
|
|
53
59
|
*/
|
|
54
|
-
return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ DialogContentProps: { dividers: false }, title: (EventFormComponentProps === null || EventFormComponentProps === void 0 ? void 0 : EventFormComponentProps.event) ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.title.edit", defaultMessage: "ui.eventForm.title.edit" })) : ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.title", defaultMessage: "ui.eventForm.title" })), open: open, onClose:
|
|
60
|
+
return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ DialogContentProps: { dividers: false }, disableEscapeKeyDown: true, title: (EventFormComponentProps === null || EventFormComponentProps === void 0 ? void 0 : EventFormComponentProps.event) ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.title.edit", defaultMessage: "ui.eventForm.title.edit" })) : ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.title", defaultMessage: "ui.eventForm.title" })), open: open, onClose: handleClose, className: (0, classnames_1.default)(classes.root, className) }, rest, { children: (0, jsx_runtime_1.jsx)(EventForm_1.default, Object.assign({}, EventFormComponentProps, { onSuccess: handleSuccess })) })));
|
|
55
61
|
}
|
|
56
62
|
exports.default = EventFormDialog;
|
|
@@ -95,7 +95,7 @@ const Root = (0, styles_1.styled)(BaseDialog_1.default, {
|
|
|
95
95
|
* @param inProps
|
|
96
96
|
*/
|
|
97
97
|
function GroupForm(inProps) {
|
|
98
|
-
var _a, _b, _c, _d, _e;
|
|
98
|
+
var _a, _b, _c, _d, _e, _f;
|
|
99
99
|
//PROPS
|
|
100
100
|
const props = (0, system_1.useThemeProps)({
|
|
101
101
|
props: inProps,
|
|
@@ -113,7 +113,7 @@ function GroupForm(inProps) {
|
|
|
113
113
|
isVisible: group ? group.visible : true,
|
|
114
114
|
invitedUsers: null,
|
|
115
115
|
isSubmitting: false,
|
|
116
|
-
product_ids: (group === null || group === void 0 ? void 0 : group.paywalls.map((p) => p.id)) || []
|
|
116
|
+
product_ids: ((_a = group === null || group === void 0 ? void 0 : group.paywalls) === null || _a === void 0 ? void 0 : _a.map((p) => p.id)) || []
|
|
117
117
|
};
|
|
118
118
|
// CONTEXT
|
|
119
119
|
const scUserContext = (0, react_core_1.useSCUser)();
|
|
@@ -235,17 +235,23 @@ function GroupForm(inProps) {
|
|
|
235
235
|
const handleChangePaymentsProducts = (products) => {
|
|
236
236
|
setField((prev) => (Object.assign(Object.assign({}, prev), { product_ids: products.map((product) => product.id) })));
|
|
237
237
|
};
|
|
238
|
+
const handleClose = (_event, reason) => {
|
|
239
|
+
if (reason === 'backdropClick' || reason === 'escapeKeyDown') {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
243
|
+
};
|
|
238
244
|
/**
|
|
239
245
|
* Renders root object
|
|
240
246
|
*/
|
|
241
|
-
return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ DialogContentProps: { dividers: false }, title: group ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.groupForm.title.edit", defaultMessage: "ui.groupForm.title.edit" })) : ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.groupForm.title", defaultMessage: "ui.groupForm.title" })), open: open, onClose:
|
|
247
|
+
return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ DialogContentProps: { dividers: false }, title: group ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.groupForm.title.edit", defaultMessage: "ui.groupForm.title.edit" })) : ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.groupForm.title", defaultMessage: "ui.groupForm.title" })), open: open, disableEscapeKeyDown: true, onClose: handleClose, className: (0, classnames_1.default)(classes.root, className), actions: (0, jsx_runtime_1.jsx)(lab_1.LoadingButton, Object.assign({ loading: field.isSubmitting, disabled: !field.name ||
|
|
242
248
|
Object.keys(error).length !== 0 ||
|
|
243
249
|
field.name.length > Group_1.GROUP_TITLE_MAX_LENGTH ||
|
|
244
250
|
field.name.description > Group_1.GROUP_DESCRIPTION_MAX_LENGTH, variant: "contained", onClick: handleSubmit, color: "secondary" }, { children: group ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.groupForm.button.edit", defaultMessage: "ui.groupForm.button.edit" })) : ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.groupForm.button.create", defaultMessage: "ui.groupForm.button.create" })) })) }, rest, { children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(material_1.Paper, Object.assign({ style: _backgroundCover, classes: { root: classes.cover } }, { children: [(0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.avatar }, { children: (0, jsx_runtime_1.jsx)(material_1.Avatar, { children: field.imageOriginal ? (0, jsx_runtime_1.jsx)("img", { src: field.imageOriginal, alt: "avatar" }) : (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "icon_image" }) }) })), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(ChangeGroupPicture_1.default, { isCreationMode: true, onChange: handleChangeAvatar }), (0, jsx_runtime_1.jsx)(ChangeGroupCover_1.default, { isCreationMode: true, onChange: handleChangeCover })] })] })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ className: (0, classnames_1.default)(classes.header, { [classes.error]: error.emotionalImageOriginalError || error.imageOriginalError }), align: "center" }, { children: error.emotionalImageOriginalError || error.imageOriginalError ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.groupForm.header.error", defaultMessage: "ui.groupForm.header.error" })) : ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.groupForm.header", defaultMessage: "ui.groupForm.header" })) }))] }), (0, jsx_runtime_1.jsxs)(material_1.FormGroup, Object.assign({ className: classes.form }, { children: [(0, jsx_runtime_1.jsx)(material_1.TextField, { required: true, className: classes.name, placeholder: `${intl.formatMessage(messages.name)}`, margin: "normal", value: field.name, name: "name", onChange: handleChange, InputProps: {
|
|
245
251
|
endAdornment: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: Group_1.GROUP_TITLE_MAX_LENGTH - field.name.length }))
|
|
246
|
-
}, error: Boolean(((
|
|
247
|
-
endAdornment: ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: ((
|
|
248
|
-
}, error: Boolean(((
|
|
252
|
+
}, error: Boolean(((_b = field === null || field === void 0 ? void 0 : field.name) === null || _b === void 0 ? void 0 : _b.length) > Group_1.GROUP_TITLE_MAX_LENGTH), helperText: ((_c = field === null || field === void 0 ? void 0 : field.name) === null || _c === void 0 ? void 0 : _c.length) > Group_1.GROUP_TITLE_MAX_LENGTH ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.groupForm.name.error.maxLength", defaultMessage: "ui.groupForm.name.error.maxLength" })) : null }), (0, jsx_runtime_1.jsx)(material_1.TextField, { multiline: true, className: classes.description, placeholder: `${intl.formatMessage(messages.description)}`, margin: "normal", value: field.description, name: "description", onChange: handleChange, InputProps: {
|
|
253
|
+
endAdornment: ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: ((_d = field.description) === null || _d === void 0 ? void 0 : _d.length) ? Group_1.GROUP_DESCRIPTION_MAX_LENGTH - field.description.length : Group_1.GROUP_DESCRIPTION_MAX_LENGTH })))
|
|
254
|
+
}, error: Boolean(((_e = field.description) === null || _e === void 0 ? void 0 : _e.length) > Group_1.GROUP_DESCRIPTION_MAX_LENGTH), helperText: ((_f = field.description) === null || _f === void 0 ? void 0 : _f.length) > Group_1.GROUP_DESCRIPTION_MAX_LENGTH ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.groupForm.description.error.maxLength", defaultMessage: "ui.groupForm.description.error.maxLength" })) : null }), privateEnabled && ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ className: classes.privacySection }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "h4" }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.groupForm.privacy.title", defaultMessage: "ui.groupForm.privacy.title", values: {
|
|
249
255
|
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
250
256
|
// @ts-ignore
|
|
251
257
|
b: (chunks) => (0, jsx_runtime_1.jsx)("strong", { children: chunks })
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BaseDialogProps } from '../../shared/BaseDialog';
|
|
2
|
+
import { PaymentMethod as StripePaymentMethod } from '@stripe/stripe-js';
|
|
3
|
+
export interface UserAddPaymentMethodDialogProps extends BaseDialogProps {
|
|
4
|
+
/**
|
|
5
|
+
* Overrides or extends the styles applied to the component.
|
|
6
|
+
* @default null
|
|
7
|
+
*/
|
|
8
|
+
className?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Callback handle address
|
|
11
|
+
* @param address
|
|
12
|
+
*/
|
|
13
|
+
handlePaymentMethod?: (paymentMethod: StripePaymentMethod) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Any other properties
|
|
16
|
+
*/
|
|
17
|
+
[p: string]: any;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* > API documentation for the Community-JS User Add Payment Method Dialog. Learn about the available props and the CSS API.
|
|
21
|
+
|
|
22
|
+
#### Import
|
|
23
|
+
|
|
24
|
+
```jsx
|
|
25
|
+
import {UserAddPaymentMethodDialog} from '@selfcommunity/react-ui';
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
#### Component Name
|
|
29
|
+
|
|
30
|
+
The name `SCUserAddPaymentMethodDialog` can be used when providing style overrides in the theme.
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
#### CSS
|
|
34
|
+
|
|
35
|
+
|Rule Name|Global class|Description|
|
|
36
|
+
|---|---|---|
|
|
37
|
+
|root|.SCUserAddPaymentMethodDialog-root|Styles applied to the root element.|
|
|
38
|
+
|
|
39
|
+
* @param inProps
|
|
40
|
+
*/
|
|
41
|
+
export default function UserAddPaymentMethodDialog(inProps: UserAddPaymentMethodDialogProps): JSX.Element;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
6
|
+
const styles_1 = require("@mui/material/styles");
|
|
7
|
+
const react_core_1 = require("@selfcommunity/react-core");
|
|
8
|
+
const system_1 = require("@mui/system");
|
|
9
|
+
const constants_1 = require("./constants");
|
|
10
|
+
const BaseDialog_1 = tslib_1.__importDefault(require("../../shared/BaseDialog"));
|
|
11
|
+
const react_intl_1 = require("react-intl");
|
|
12
|
+
const stripe_js_1 = require("@stripe/stripe-js");
|
|
13
|
+
const payment_1 = require("../../types/payment");
|
|
14
|
+
const material_1 = require("@mui/material");
|
|
15
|
+
const react_stripe_js_1 = require("@stripe/react-stripe-js");
|
|
16
|
+
const payment_2 = require("../../utils/payment");
|
|
17
|
+
const UserAddPaymentMethodForm_1 = tslib_1.__importDefault(require("../UserAddPaymentMethodForm"));
|
|
18
|
+
const classes = {
|
|
19
|
+
root: `${constants_1.PREFIX}-root`,
|
|
20
|
+
loading: `${constants_1.PREFIX}-loading`
|
|
21
|
+
};
|
|
22
|
+
const Root = (0, styles_1.styled)(BaseDialog_1.default, {
|
|
23
|
+
name: constants_1.PREFIX,
|
|
24
|
+
slot: 'Root'
|
|
25
|
+
})(() => ({
|
|
26
|
+
[`& .MuiDialogContent-root`]: {
|
|
27
|
+
overflowX: 'hidden'
|
|
28
|
+
},
|
|
29
|
+
[`& .${classes.loading}`]: {
|
|
30
|
+
marginTop: '200px'
|
|
31
|
+
}
|
|
32
|
+
}));
|
|
33
|
+
/**
|
|
34
|
+
* > API documentation for the Community-JS User Add Payment Method Dialog. Learn about the available props and the CSS API.
|
|
35
|
+
|
|
36
|
+
#### Import
|
|
37
|
+
|
|
38
|
+
```jsx
|
|
39
|
+
import {UserAddPaymentMethodDialog} from '@selfcommunity/react-ui';
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
#### Component Name
|
|
43
|
+
|
|
44
|
+
The name `SCUserAddPaymentMethodDialog` can be used when providing style overrides in the theme.
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
#### CSS
|
|
48
|
+
|
|
49
|
+
|Rule Name|Global class|Description|
|
|
50
|
+
|---|---|---|
|
|
51
|
+
|root|.SCUserAddPaymentMethodDialog-root|Styles applied to the root element.|
|
|
52
|
+
|
|
53
|
+
* @param inProps
|
|
54
|
+
*/
|
|
55
|
+
function UserAddPaymentMethodDialog(inProps) {
|
|
56
|
+
// PROPS
|
|
57
|
+
const props = (0, system_1.useThemeProps)({
|
|
58
|
+
props: inProps,
|
|
59
|
+
name: constants_1.PREFIX
|
|
60
|
+
});
|
|
61
|
+
const { className = null, handlePaymentMethod, open = false } = props, rest = tslib_1.__rest(props, ["className", "handlePaymentMethod", "open"]);
|
|
62
|
+
// CONTEXT
|
|
63
|
+
const scUserContext = (0, react_core_1.useSCUser)();
|
|
64
|
+
// STATE
|
|
65
|
+
const [isLoadingInit, setIsLoadingInit] = react_1.default.useState(true);
|
|
66
|
+
const [customer, setCustomer] = (0, react_1.useState)(null);
|
|
67
|
+
// HOOKS
|
|
68
|
+
const { isPaymentsEnabled, stripePublicKey, stripeConnectedAccountId } = (0, react_core_1.useSCPaymentsEnabled)();
|
|
69
|
+
const intl = (0, react_intl_1.useIntl)();
|
|
70
|
+
const stripePromise = isPaymentsEnabled && stripePublicKey && stripeConnectedAccountId && stripe_js_1.loadStripe
|
|
71
|
+
? (0, stripe_js_1.loadStripe)(stripePublicKey, { stripeAccount: stripeConnectedAccountId, locale: (0, payment_2.getDefaultLocale)(intl).locale })
|
|
72
|
+
: null;
|
|
73
|
+
const theme = (0, styles_1.useTheme)();
|
|
74
|
+
const elementsOptions = Object.assign(Object.assign({ mode: 'setup', currency: payment_1.StripeCurrency.EUR, paymentMethodCreation: 'manual', loader: 'always' }, (0, payment_2.getDefaultAppearanceStyle)(theme)), (0, payment_2.getDefaultLocale)(intl));
|
|
75
|
+
const handleClose = () => {
|
|
76
|
+
handlePaymentMethod === null || handlePaymentMethod === void 0 ? void 0 : handlePaymentMethod(null);
|
|
77
|
+
};
|
|
78
|
+
const handleSuccess = (paymentMethod) => {
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
handlePaymentMethod === null || handlePaymentMethod === void 0 ? void 0 : handlePaymentMethod(paymentMethod);
|
|
82
|
+
};
|
|
83
|
+
(0, react_1.useEffect)(() => {
|
|
84
|
+
/* getAccountCustomer().then((customer) => {
|
|
85
|
+
setCustomer(customer);
|
|
86
|
+
setIsLoadingInit(false);
|
|
87
|
+
}); */
|
|
88
|
+
}, []);
|
|
89
|
+
if (!isPaymentsEnabled || !scUserContext.user) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ title: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { defaultMessage: "ui.userAddPaymentMethodDialog.title", id: "ui.userAddPaymentMethodDialog.title" }), open: open }, { children: isLoadingInit ? ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.loading }, { children: (0, jsx_runtime_1.jsx)(material_1.CircularProgress, {}) }))) : ((0, jsx_runtime_1.jsx)(react_stripe_js_1.Elements, Object.assign({ stripe: stripePromise, options: elementsOptions }, { children: (0, jsx_runtime_1.jsx)(UserAddPaymentMethodForm_1.default, { customer: customer, handleSuccess: handleSuccess, handleClose: handleClose }) }))) })));
|
|
93
|
+
}
|
|
94
|
+
exports.default = UserAddPaymentMethodDialog;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PREFIX = "SCUserAddPaymentMethodDialog";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const UserAddPaymentMethodDialog_1 = tslib_1.__importDefault(require("./UserAddPaymentMethodDialog"));
|
|
5
|
+
exports.default = UserAddPaymentMethodDialog_1.default;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BaseDialogProps } from '../../shared/BaseDialog';
|
|
2
|
+
import { PaymentMethod as StripePaymentMethod } from '@stripe/stripe-js';
|
|
3
|
+
export interface UserAddPaymentMethodFormProps extends BaseDialogProps {
|
|
4
|
+
/**
|
|
5
|
+
* Overrides or extends the styles applied to the component.
|
|
6
|
+
* @default null
|
|
7
|
+
*/
|
|
8
|
+
className?: string;
|
|
9
|
+
customer: any;
|
|
10
|
+
collectBillingAddress?: boolean;
|
|
11
|
+
handleSuccess?: (paymentMethod: StripePaymentMethod) => void;
|
|
12
|
+
handleClose?: () => void;
|
|
13
|
+
/**
|
|
14
|
+
* Any other properties
|
|
15
|
+
*/
|
|
16
|
+
[p: string]: any;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* > API documentation for the Community-JS User Add Payment Method Form. Learn about the available props and the CSS API.
|
|
20
|
+
|
|
21
|
+
#### Import
|
|
22
|
+
|
|
23
|
+
```jsx
|
|
24
|
+
import {UserAddPaymentMethodForm} from '@selfcommunity/react-ui';
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
#### Component Name
|
|
28
|
+
|
|
29
|
+
The name `SCUserAddPaymentMethodForm` can be used when providing style overrides in the theme.
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
#### CSS
|
|
33
|
+
|
|
34
|
+
|Rule Name|Global class|Description|
|
|
35
|
+
|---|---|---|
|
|
36
|
+
|root|.SCUserAddPaymentMethodForm-root|Styles applied to the root element.|
|
|
37
|
+
|
|
38
|
+
* @param inProps
|
|
39
|
+
*/
|
|
40
|
+
export default function UserAddPaymentMethodForm(inProps: UserAddPaymentMethodFormProps): JSX.Element;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
6
|
+
const styles_1 = require("@mui/material/styles");
|
|
7
|
+
const react_core_1 = require("@selfcommunity/react-core");
|
|
8
|
+
const system_1 = require("@mui/system");
|
|
9
|
+
const constants_1 = require("./constants");
|
|
10
|
+
const BaseDialog_1 = tslib_1.__importDefault(require("../../shared/BaseDialog"));
|
|
11
|
+
const react_intl_1 = require("react-intl");
|
|
12
|
+
const stripe_js_1 = require("@stripe/stripe-js");
|
|
13
|
+
const material_1 = require("@mui/material");
|
|
14
|
+
const react_stripe_js_1 = require("@stripe/react-stripe-js");
|
|
15
|
+
const payment_1 = require("../../utils/payment");
|
|
16
|
+
const lab_1 = require("@mui/lab");
|
|
17
|
+
const notistack_1 = require("notistack");
|
|
18
|
+
const classes = {
|
|
19
|
+
root: `${constants_1.PREFIX}-root`,
|
|
20
|
+
address: `${constants_1.PREFIX}-loading`
|
|
21
|
+
};
|
|
22
|
+
const Root = (0, styles_1.styled)(BaseDialog_1.default, {
|
|
23
|
+
name: constants_1.PREFIX,
|
|
24
|
+
slot: 'Root'
|
|
25
|
+
})(() => ({
|
|
26
|
+
[`& .${classes.address}`]: {
|
|
27
|
+
padding: 10,
|
|
28
|
+
borderRadius: 5,
|
|
29
|
+
margin: '20px 0px'
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
32
|
+
/**
|
|
33
|
+
* > API documentation for the Community-JS User Add Payment Method Form. Learn about the available props and the CSS API.
|
|
34
|
+
|
|
35
|
+
#### Import
|
|
36
|
+
|
|
37
|
+
```jsx
|
|
38
|
+
import {UserAddPaymentMethodForm} from '@selfcommunity/react-ui';
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
#### Component Name
|
|
42
|
+
|
|
43
|
+
The name `SCUserAddPaymentMethodForm` can be used when providing style overrides in the theme.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
#### CSS
|
|
47
|
+
|
|
48
|
+
|Rule Name|Global class|Description|
|
|
49
|
+
|---|---|---|
|
|
50
|
+
|root|.SCUserAddPaymentMethodForm-root|Styles applied to the root element.|
|
|
51
|
+
|
|
52
|
+
* @param inProps
|
|
53
|
+
*/
|
|
54
|
+
function UserAddPaymentMethodForm(inProps) {
|
|
55
|
+
// PROPS
|
|
56
|
+
const props = (0, system_1.useThemeProps)({
|
|
57
|
+
props: inProps,
|
|
58
|
+
name: constants_1.PREFIX
|
|
59
|
+
});
|
|
60
|
+
const { className = null, customer, collectBillingAddress = false, handleSuccess, handleClose } = props, rest = tslib_1.__rest(props, ["className", "customer", "collectBillingAddress", "handleSuccess", "handleClose"]);
|
|
61
|
+
// CONTEXT
|
|
62
|
+
const scUserContext = (0, react_core_1.useSCUser)();
|
|
63
|
+
// STATE
|
|
64
|
+
const [errorMessage, setErrorMessage] = (0, react_1.useState)(null);
|
|
65
|
+
const [ready, setReady] = (0, react_1.useState)(false);
|
|
66
|
+
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
67
|
+
const [addressState, setAddressState] = (0, react_1.useState)({ name: customer.name, address: customer.address });
|
|
68
|
+
const [isEditingBillingAddress, setIsEditingBillingAddress] = react_1.default.useState(false);
|
|
69
|
+
const { enqueueSnackbar } = (0, notistack_1.useSnackbar)();
|
|
70
|
+
// HOOKS
|
|
71
|
+
const { isPaymentsEnabled, stripePublicKey, stripeConnectedAccountId } = (0, react_core_1.useSCPaymentsEnabled)();
|
|
72
|
+
const intl = (0, react_intl_1.useIntl)();
|
|
73
|
+
const stripePromise = isPaymentsEnabled && stripePublicKey && stripeConnectedAccountId && stripe_js_1.loadStripe
|
|
74
|
+
? (0, stripe_js_1.loadStripe)(stripePublicKey, { stripeAccount: stripeConnectedAccountId, locale: (0, payment_1.getDefaultLocale)(intl).locale })
|
|
75
|
+
: null;
|
|
76
|
+
const elements = (0, react_stripe_js_1.useElements)();
|
|
77
|
+
const handleError = (error) => {
|
|
78
|
+
setLoading(false);
|
|
79
|
+
enqueueSnackbar((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.common.error", defaultMessage: "ui.common.error" }), {
|
|
80
|
+
variant: 'error',
|
|
81
|
+
autoHideDuration: 3000
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
const handleSubmit = (event) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
/*
|
|
86
|
+
|
|
87
|
+
// We don't want to let default form submission happen here,
|
|
88
|
+
// which would refresh the page.
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
|
|
91
|
+
if (!stripePromise || !elements) {
|
|
92
|
+
// Stripe.js hasn't yet loaded.
|
|
93
|
+
// Make sure to disable form submission until Stripe.js has loaded.
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
setLoading(true);
|
|
98
|
+
|
|
99
|
+
// Trigger form validation and wallet collection
|
|
100
|
+
const {error: submitError} = await elements.submit();
|
|
101
|
+
if (submitError) {
|
|
102
|
+
handleError(submitError);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Create the PaymentMethod using the details collected by the Payment Element
|
|
107
|
+
const {error, paymentMethod} = await stripe.createPaymentMethod({
|
|
108
|
+
elements,
|
|
109
|
+
params: {billing_details: addressState}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (error) {
|
|
113
|
+
// This point is only reached if there's an immediate error when
|
|
114
|
+
// creating the PaymentMethod. Show the error to your customer (for example, payment details incomplete)
|
|
115
|
+
handleError(error);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const res = await attachPaymentMethodToCustomer(paymentMethod.id);
|
|
120
|
+
if (res.error) {
|
|
121
|
+
handleError(res.error);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
handleSuccess?.(paymentMethod as StripePaymentMethod); */
|
|
126
|
+
});
|
|
127
|
+
const onHandleClose = () => {
|
|
128
|
+
handleClose === null || handleClose === void 0 ? void 0 : handleClose();
|
|
129
|
+
};
|
|
130
|
+
const paymentElementOptions = {
|
|
131
|
+
defaultValues: Object.assign({}, (collectBillingAddress && { billingDetails: addressState }))
|
|
132
|
+
};
|
|
133
|
+
if (!isPaymentsEnabled || !scUserContext.user) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ className: classes.root }, { children: (0, jsx_runtime_1.jsxs)("form", Object.assign({ onSubmit: handleSubmit }, { children: [(0, jsx_runtime_1.jsx)(react_stripe_js_1.PaymentElement, { id: "payment-element", options: paymentElementOptions, onReady: () => setReady(true) }), collectBillingAddress && ((0, jsx_runtime_1.jsx)(material_1.Paper, Object.assign({ variant: "outlined", className: classes.address }, { children: Object.keys(addressState).length && !isEditingBillingAddress ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: 'body1' }, { children: addressState.name })), (0, jsx_runtime_1.jsxs)(material_1.Typography, Object.assign({ variant: 'body1' }, { children: [addressState.address.line1, (0, jsx_runtime_1.jsx)("br", {}), addressState.address.line2] })), (0, jsx_runtime_1.jsxs)(material_1.Typography, Object.assign({ variant: 'body1' }, { children: [addressState.address.postal_code, " - ", addressState.address.city, " - ", addressState.address.country] })), (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ sx: { mt: 1 }, variant: 'contained', disabled: !elements, onClick: () => setIsEditingBillingAddress(!isEditingBillingAddress) }, { children: "Change" }))] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_stripe_js_1.AddressElement, { onChange: (event) => {
|
|
137
|
+
setAddressState(event.value);
|
|
138
|
+
}, options: {
|
|
139
|
+
mode: 'billing',
|
|
140
|
+
defaultValues: addressState
|
|
141
|
+
} }), (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ sx: { mt: 1 }, variant: 'contained', disabled: !elements || loading || !ready, onClick: () => setIsEditingBillingAddress(!isEditingBillingAddress) }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: 'ui.userAddPaymentMethodForm.useDefaultMethod', defaultMessage: 'ui.userAddPaymentMethodForm.useDefaultMethod' }) }))] })) }))), (0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ direction: "row", justifyContent: "flex-end", alignItems: "center", spacing: 2, mt: 3 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ onClick: onHandleClose, variant: "outlined" }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.userAddPaymentMethodForm.cancelButton", defaultMessage: "ui.userAddPaymentMethodForm.cancelButton" }) })), (0, jsx_runtime_1.jsx)(lab_1.LoadingButton, Object.assign({ disabled: !ready, loading: loading, type: "submit", variant: "contained" }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.userAddPaymentMethodForm.addButton", defaultMessage: "ui.userAddPaymentMethodForm.addButton" }) }))] })), errorMessage && (0, jsx_runtime_1.jsx)("div", { children: errorMessage })] })) })));
|
|
142
|
+
}
|
|
143
|
+
exports.default = UserAddPaymentMethodForm;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PREFIX = "SCUserAddPaymentMethodForm";
|