richie-education 2.29.2 → 2.29.3-dev48
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/i18n/locales/ar-SA.json +193 -125
- package/i18n/locales/es-ES.json +193 -125
- package/i18n/locales/fa-IR.json +193 -125
- package/i18n/locales/fr-CA.json +193 -125
- package/i18n/locales/fr-FR.json +193 -125
- package/i18n/locales/ko-KR.json +193 -125
- package/i18n/locales/pt-PT.json +193 -125
- package/i18n/locales/ru-RU.json +193 -125
- package/i18n/locales/vi-VN.json +193 -125
- package/js/api/joanie.ts +42 -17
- package/js/api/lms/dummy.ts +1 -12
- package/js/components/ContractFrame/AbstractContractFrame.spec.tsx +16 -9
- package/js/components/ContractFrame/AbstractContractFrame.tsx +28 -23
- package/js/components/ContractFrame/LearnerContractFrame.tsx +2 -2
- package/js/components/ContractFrame/_styles.scss +6 -14
- package/js/components/ContractStatus/index.spec.tsx +1 -1
- package/js/components/ContractStatus/index.tsx +1 -1
- package/js/components/{SaleTunnel/CreditCardSelector → CreditCardSelector}/index.spec.tsx +15 -45
- package/js/components/{SaleTunnel/CreditCardSelector → CreditCardSelector}/index.tsx +19 -26
- package/js/components/DownloadContractButton/index.spec.tsx +1 -1
- package/js/components/Form/utils.ts +2 -1
- package/js/components/OpenEdxFullNameForm/index.spec.tsx +229 -0
- package/js/components/OpenEdxFullNameForm/index.tsx +7 -7
- package/js/components/PaymentInterfaces/LyraPopIn.tsx +2 -2
- package/js/components/PaymentInterfaces/PayplugLightbox.tsx +1 -1
- package/js/components/PaymentInterfaces/__mocks__/index.tsx +1 -4
- package/js/components/PaymentInterfaces/types.ts +5 -2
- package/js/components/PaymentScheduleGrid/_styles.scss +13 -0
- package/js/components/PaymentScheduleGrid/index.tsx +50 -70
- package/js/components/PurchaseButton/index.spec.tsx +84 -37
- package/js/components/PurchaseButton/index.tsx +9 -27
- package/js/components/SaleTunnel/AddressSelector/index.spec.tsx +2 -2
- package/js/components/SaleTunnel/CertificateSaleTunnel/index.tsx +2 -2
- package/js/components/SaleTunnel/CredentialSaleTunnel/index.tsx +6 -10
- package/js/components/SaleTunnel/GenericSaleTunnel.tsx +105 -48
- package/js/components/SaleTunnel/SaleTunnelInformation/index.tsx +16 -20
- package/js/components/SaleTunnel/SaleTunnelSavePaymentMethod/_styles.scss +12 -0
- package/js/components/SaleTunnel/SaleTunnelSavePaymentMethod/index.tsx +157 -0
- package/js/components/SaleTunnel/SaleTunnelSuccess/index.tsx +15 -29
- package/js/components/SaleTunnel/Sponsors/SaleTunnelSponsors.scss +4 -5
- package/js/components/SaleTunnel/Sponsors/SaleTunnelSponsors.tsx +39 -11
- package/js/components/SaleTunnel/SubscriptionButton/_styles.scss +7 -0
- package/js/components/SaleTunnel/SubscriptionButton/index.tsx +202 -0
- package/js/components/SaleTunnel/_styles.scss +16 -5
- package/js/components/SaleTunnel/hooks/useTerms.tsx +0 -77
- package/js/components/SaleTunnel/index.credential.spec.tsx +14 -25
- package/js/components/SaleTunnel/index.full-process.spec.tsx +114 -48
- package/js/components/SaleTunnel/index.spec.tsx +333 -717
- package/js/components/SaleTunnel/index.tsx +2 -1
- package/js/components/SignContractButton/index.omniscientOrders.spec.tsx +16 -11
- package/js/components/SignContractButton/index.spec.tsx +16 -20
- package/js/components/SignContractButton/index.tsx +3 -1
- package/js/hooks/useCreditCards/index.spec.tsx +70 -6
- package/js/hooks/useCreditCards/index.ts +49 -11
- package/js/hooks/useOrders/index.spec.tsx +322 -0
- package/js/hooks/{useOrders.ts → useOrders/index.ts} +40 -14
- package/js/hooks/usePaymentSchedule.tsx +23 -0
- package/js/hooks/useProductOrder/index.spec.tsx +77 -60
- package/js/hooks/useProductOrder/index.tsx +2 -2
- package/js/hooks/useResources/useResourcesRoot.ts +4 -3
- package/js/index.tsx +2 -0
- package/js/pages/DashboardCreditCardsManagement/CreditCardBrandLogo.spec.tsx +1 -1
- package/js/pages/DashboardCreditCardsManagement/CreditCardBrandLogo.tsx +4 -2
- package/js/pages/DashboardOrderLayout/index.spec.tsx +10 -1
- package/js/pages/TeacherDashboardContractsLayout/components/ContractActionsBar/index.spec.tsx +8 -5
- package/js/pages/TeacherDashboardContractsLayout/components/SignOrganizationContractButton/index.spec.tsx +8 -9
- package/js/pages/TeacherDashboardCourseLearnersLayout/components/CourseLearnerDataGrid/index.spec.tsx +1 -1
- package/js/pages/TeacherDashboardCourseLearnersLayout/components/CourseLearnerDataGrid/index.tsx +1 -6
- package/js/settings/settings.prod.ts +0 -2
- package/js/settings/settings.test.ts +16 -2
- package/js/translations/ar-SA.json +1 -1
- package/js/translations/es-ES.json +1 -1
- package/js/translations/fa-IR.json +1 -1
- package/js/translations/fr-CA.json +1 -1
- package/js/translations/fr-FR.json +1 -1
- package/js/translations/ko-KR.json +1 -1
- package/js/translations/pt-PT.json +1 -1
- package/js/translations/ru-RU.json +1 -1
- package/js/translations/vi-VN.json +1 -1
- package/js/types/Joanie.ts +81 -32
- package/js/utils/OrderHelper/index.ts +46 -38
- package/js/utils/PaymentScheduleHelper/index.spec.tsx +78 -0
- package/js/utils/PaymentScheduleHelper/index.ts +30 -0
- package/js/utils/ProductHelper/index.spec.ts +322 -166
- package/js/utils/ProductHelper/index.ts +32 -0
- package/js/utils/test/factories/joanie.ts +72 -69
- package/js/widgets/Dashboard/components/DashboardItem/Contract/index.spec.tsx +2 -2
- package/js/widgets/Dashboard/components/DashboardItem/CourseEnrolling/index.tsx +8 -18
- package/js/widgets/Dashboard/components/DashboardItem/Enrollment/DashboardItemEnrollment.spec.tsx +23 -0
- package/js/widgets/Dashboard/components/DashboardItem/Enrollment/DashboardItemEnrollment.tsx +23 -1
- package/js/widgets/Dashboard/components/DashboardItem/Enrollment/ProductCertificateFooter/index.spec.tsx +145 -34
- package/js/widgets/Dashboard/components/DashboardItem/Enrollment/ProductCertificateFooter/index.tsx +175 -37
- package/js/widgets/Dashboard/components/DashboardItem/Order/CertificateItem/index.tsx +51 -0
- package/js/widgets/Dashboard/components/DashboardItem/Order/ContractItem/index.tsx +52 -0
- package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemNotResumable.spec.tsx +109 -0
- package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemOrder.spec.tsx +219 -5
- package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemOrder.tsx +111 -245
- package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemOrderContract.spec.tsx +61 -8
- package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemOrderContract.useUnionResource.cache.spec.tsx +17 -7
- package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemSavePaymentMethod.spec.tsx +116 -0
- package/js/widgets/Dashboard/components/DashboardItem/Order/Installment/index.tsx +175 -0
- package/js/widgets/Dashboard/components/DashboardItem/Order/OrderPaymentDetailsModal/_styles.scss +7 -0
- package/js/widgets/Dashboard/components/DashboardItem/Order/OrderPaymentDetailsModal/index.tsx +127 -0
- package/js/widgets/Dashboard/components/DashboardItem/Order/OrderPaymentRetryModal/index.tsx +216 -0
- package/js/widgets/Dashboard/components/DashboardItem/Order/OrderStateLearnerMessage/index.spec.tsx +18 -71
- package/js/widgets/Dashboard/components/DashboardItem/Order/OrderStateLearnerMessage/index.tsx +40 -25
- package/js/widgets/Dashboard/components/DashboardItem/Order/OrderStateMessage/index.tsx +28 -22
- package/js/widgets/Dashboard/components/DashboardItem/Order/OrderStateTeacherMessage/index.spec.tsx +18 -73
- package/js/widgets/Dashboard/components/DashboardItem/Order/OrderStateTeacherMessage/index.tsx +32 -16
- package/js/widgets/Dashboard/components/DashboardItem/Order/OrganizationBlock/index.tsx +150 -0
- package/js/widgets/Dashboard/components/DashboardOrderLoader/index.tsx +32 -14
- package/js/widgets/Dashboard/components/Signature/SignatureDummy.tsx +25 -3
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/components/CourseProductCourseRuns/EnrollableCourseRunList.tsx +2 -6
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/components/CourseProductCourseRuns/index.spec.tsx +7 -14
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/components/CourseRunItem/index.spec.tsx +7 -5
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/components/CourseRunItem/index.tsx +5 -7
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.spec.tsx +242 -332
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.stories.tsx +12 -13
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.tsx +10 -21
- package/js/widgets/SyllabusCourseRunsList/components/CourseRunEnrollment/index.joanie.spec.tsx +2 -2
- package/package.json +45 -44
- package/scss/components/_index.scss +4 -2
- package/js/components/PaymentButton/_styles.scss +0 -27
- package/js/components/SaleTunnel/GenericPaymentButton/index.tsx +0 -340
- package/js/components/SaleTunnel/SaleTunnelNotValidated/index.tsx +0 -70
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/components/ProductSignatureHeader/index.tsx +0 -41
- /package/js/components/{SaleTunnel/CreditCardSelector → CreditCardSelector}/_styles.scss +0 -0
package/js/widgets/Dashboard/components/DashboardItem/Enrollment/ProductCertificateFooter/index.tsx
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
|
-
import { FormattedMessage,
|
|
2
|
-
import { useState } from 'react';
|
|
1
|
+
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { Button, useModal } from '@openfun/cunningham-react';
|
|
3
4
|
import PurchaseButton from 'components/PurchaseButton';
|
|
4
5
|
import { Icon, IconTypeEnum } from 'components/Icon';
|
|
5
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
CertificateProduct,
|
|
8
|
+
Enrollment,
|
|
9
|
+
Order,
|
|
10
|
+
OrderEnrollment,
|
|
11
|
+
OrderState,
|
|
12
|
+
ProductType,
|
|
13
|
+
} from 'types/Joanie';
|
|
6
14
|
import DownloadCertificateButton from 'components/DownloadCertificateButton';
|
|
7
15
|
import { useCertificate } from 'hooks/useCertificates';
|
|
8
16
|
import { isOpenedCourseRunCertificate } from 'utils/CourseRuns';
|
|
9
17
|
import { OrderHelper } from 'utils/OrderHelper';
|
|
18
|
+
import { OrderPaymentRetryModal } from 'widgets/Dashboard/components/DashboardItem/Order/OrderPaymentRetryModal';
|
|
19
|
+
import PaymentScheduleHelper from 'utils/PaymentScheduleHelper';
|
|
20
|
+
import { useOrder } from 'hooks/useOrders';
|
|
21
|
+
import useDateFormat from 'hooks/useDateFormat';
|
|
10
22
|
import CertificateStatus from '../../CertificateStatus';
|
|
11
23
|
|
|
12
24
|
const messages = defineMessages({
|
|
@@ -25,6 +37,27 @@ const messages = defineMessages({
|
|
|
25
37
|
description: 'Label on the enrollment when a product of type certificate have been bought',
|
|
26
38
|
defaultMessage: 'Finish this course to obtain your certificate.',
|
|
27
39
|
},
|
|
40
|
+
failedInstallmentMessage: {
|
|
41
|
+
id: 'components.ProductCertificateFooter.failedInstallmentMessage',
|
|
42
|
+
description: 'Message displayed when the last installment has failed',
|
|
43
|
+
defaultMessage:
|
|
44
|
+
'Last direct debit has failed. Please resolve your situation as soon as possible.',
|
|
45
|
+
},
|
|
46
|
+
examAccessBlocked: {
|
|
47
|
+
id: 'components.ProductCertificateFooter.examAccessBlocked',
|
|
48
|
+
description: 'Message displayed when the exam access is blocked',
|
|
49
|
+
defaultMessage: 'You will be able to pass the exam once the installment has been paid.',
|
|
50
|
+
},
|
|
51
|
+
nextInstallmentMessage: {
|
|
52
|
+
id: 'components.ProductCertificateFooter.nextInstallmentMessage',
|
|
53
|
+
description: 'Message displayed when an installment is pending',
|
|
54
|
+
defaultMessage: 'The next installment ({amount}) will be withdrawn on the {due_date}.',
|
|
55
|
+
},
|
|
56
|
+
paymentNeededButton: {
|
|
57
|
+
id: 'components.ProductCertificateFooter.paymentNeededButton',
|
|
58
|
+
description: 'Button label for the payment needed message',
|
|
59
|
+
defaultMessage: 'Pay {amount}',
|
|
60
|
+
},
|
|
28
61
|
});
|
|
29
62
|
|
|
30
63
|
export interface ProductCertificateFooterProps {
|
|
@@ -33,59 +66,164 @@ export interface ProductCertificateFooterProps {
|
|
|
33
66
|
}
|
|
34
67
|
|
|
35
68
|
const ProductCertificateFooter = ({ product, enrollment }: ProductCertificateFooterProps) => {
|
|
36
|
-
if (product.type !== ProductType.CERTIFICATE) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
69
|
const [order, setOrder] = useState(
|
|
40
70
|
OrderHelper.getActiveEnrollmentOrder(enrollment.orders || [], product.id),
|
|
41
71
|
);
|
|
42
|
-
const
|
|
72
|
+
const isOrderActive = OrderHelper.isActive(order);
|
|
73
|
+
const isPurchasable =
|
|
74
|
+
OrderHelper.isPurchasable(order) && isOpenedCourseRunCertificate(enrollment.course_run.state);
|
|
75
|
+
const isCertificateIssued = isOrderActive && Boolean(order!.certificate_id);
|
|
76
|
+
const hasError =
|
|
77
|
+
isOrderActive && [OrderState.NO_PAYMENT, OrderState.FAILED_PAYMENT].includes(order!.state);
|
|
78
|
+
|
|
79
|
+
if (product.type !== ProductType.CERTIFICATE) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
43
82
|
|
|
44
83
|
// The course run is no longer available
|
|
45
84
|
// and no product certificate had been bought therefore there isn't any certificate to download.
|
|
46
|
-
if (!
|
|
85
|
+
if (!isPurchasable && !order) {
|
|
47
86
|
return null;
|
|
48
87
|
}
|
|
49
88
|
|
|
50
89
|
return (
|
|
51
90
|
<div className="dashboard-item__course-enrolling__infos">
|
|
52
|
-
|
|
53
|
-
<
|
|
54
|
-
|
|
91
|
+
{!isOrderActive ? (
|
|
92
|
+
<ProductCertificateStatus />
|
|
93
|
+
) : (
|
|
94
|
+
<OrderCertificateStatus order={order!} product={product} hasError={hasError} />
|
|
95
|
+
)}
|
|
96
|
+
{isCertificateIssued && (
|
|
97
|
+
<DownloadCertificateButton
|
|
98
|
+
className="dashboard-item__button"
|
|
99
|
+
certificateId={order!.certificate_id!}
|
|
100
|
+
/>
|
|
101
|
+
)}
|
|
102
|
+
<PurchaseButton
|
|
103
|
+
className="dashboard-item__button"
|
|
104
|
+
product={product}
|
|
105
|
+
enrollment={enrollment}
|
|
106
|
+
buttonProps={{ size: 'small' }}
|
|
107
|
+
disabled={!isPurchasable}
|
|
108
|
+
onFinish={(o) => {
|
|
109
|
+
/**
|
|
110
|
+
* As we do not refetch enrollments in DashboardCourses after SaleTunnel cache invalidation (to avoid
|
|
111
|
+
* scroll reset - and SaleTunnel modal unmounting too early caused by list reset) we need to manually
|
|
112
|
+
* update the active order in the enrollment in order to hide the buy button and display the download button.
|
|
113
|
+
*/
|
|
114
|
+
setOrder(o);
|
|
115
|
+
}}
|
|
116
|
+
/>
|
|
117
|
+
{hasError && <FailedInstallmentManager order={order!} updateOrder={setOrder} />}
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const ProductCertificateStatus = () => (
|
|
123
|
+
<div className="dashboard-item__block__status">
|
|
124
|
+
<Icon name={IconTypeEnum.CERTIFICATE} />
|
|
125
|
+
<FormattedMessage {...messages.buyProductCertificateLabel} />
|
|
126
|
+
</div>
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
type OrderCertificateStatusProps = {
|
|
130
|
+
order: OrderEnrollment;
|
|
131
|
+
product: CertificateProduct;
|
|
132
|
+
hasError: boolean;
|
|
133
|
+
};
|
|
134
|
+
const OrderCertificateStatus = ({ order, product, hasError }: OrderCertificateStatusProps) => {
|
|
135
|
+
const { item: certificate } = useCertificate(order?.certificate_id);
|
|
136
|
+
const intl = useIntl();
|
|
137
|
+
const formatDate = useDateFormat();
|
|
138
|
+
const nextInstallment = PaymentScheduleHelper.getPendingInstallment(order?.payment_schedule);
|
|
139
|
+
const canAccessToExam = ![OrderState.PENDING, OrderState.NO_PAYMENT].includes(order.state);
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<div className="dashboard-item__block__status">
|
|
143
|
+
<Icon name={hasError ? IconTypeEnum.WARNING : IconTypeEnum.CERTIFICATE} />
|
|
144
|
+
<p>
|
|
145
|
+
{hasError && (
|
|
146
|
+
<>
|
|
147
|
+
<strong>
|
|
148
|
+
<FormattedMessage {...messages.failedInstallmentMessage} />
|
|
149
|
+
</strong>
|
|
150
|
+
<br />
|
|
151
|
+
</>
|
|
152
|
+
)}
|
|
153
|
+
{canAccessToExam ? (
|
|
55
154
|
<>
|
|
56
155
|
{product.certificate_definition.title + '. '}
|
|
57
156
|
<CertificateStatus certificate={certificate} productType={product.type} />
|
|
58
157
|
</>
|
|
59
158
|
) : (
|
|
60
|
-
<FormattedMessage {...messages.
|
|
159
|
+
<FormattedMessage {...messages.examAccessBlocked} />
|
|
61
160
|
)}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* As we do not refetch enrollments in DashboardCourses after SaleTunnel cache invalidation (to avoid
|
|
80
|
-
* scroll reset - and SaleTunnel modal unmounting too early caused by list reset) we need to manually
|
|
81
|
-
* update the active order in the enrollment in order to hide the buy button and display the download button.
|
|
82
|
-
*/
|
|
83
|
-
setOrder(o);
|
|
84
|
-
}}
|
|
85
|
-
/>
|
|
86
|
-
)}
|
|
161
|
+
{!hasError && nextInstallment && (
|
|
162
|
+
<>
|
|
163
|
+
<br />
|
|
164
|
+
<FormattedMessage
|
|
165
|
+
{...messages.nextInstallmentMessage}
|
|
166
|
+
values={{
|
|
167
|
+
amount: intl.formatNumber(nextInstallment.amount, {
|
|
168
|
+
style: 'currency',
|
|
169
|
+
currency: nextInstallment.currency,
|
|
170
|
+
}),
|
|
171
|
+
due_date: formatDate(nextInstallment.due_date),
|
|
172
|
+
}}
|
|
173
|
+
/>
|
|
174
|
+
</>
|
|
175
|
+
)}
|
|
176
|
+
</p>
|
|
87
177
|
</div>
|
|
88
178
|
);
|
|
89
179
|
};
|
|
90
180
|
|
|
181
|
+
type FailedInstallmentManagerProps = {
|
|
182
|
+
order: OrderEnrollment;
|
|
183
|
+
updateOrder: (order: Order) => void;
|
|
184
|
+
};
|
|
185
|
+
const FailedInstallmentManager = ({ order, updateOrder }: FailedInstallmentManagerProps) => {
|
|
186
|
+
const intl = useIntl();
|
|
187
|
+
const failedInstallment = PaymentScheduleHelper.getFailedInstallment(order!.payment_schedule);
|
|
188
|
+
const installmentRetryModal = useModal();
|
|
189
|
+
const orderQuery = useOrder(order.id);
|
|
190
|
+
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
/**
|
|
193
|
+
* As we do not refetch enrollments in DashboardCourses after SaleTunnel cache invalidation (to avoid
|
|
194
|
+
* scroll reset - and SaleTunnel modal unmounting too early caused by list reset) we need to manually
|
|
195
|
+
* update the active order in the enrollment in order to hide the installment manager.
|
|
196
|
+
*/
|
|
197
|
+
if (orderQuery.item) {
|
|
198
|
+
updateOrder(orderQuery.item);
|
|
199
|
+
}
|
|
200
|
+
}, [orderQuery.item]);
|
|
201
|
+
|
|
202
|
+
if (!failedInstallment) return null;
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
<>
|
|
206
|
+
<div className="dashboard-splitted-card__item__actions">
|
|
207
|
+
<Button size="small" color="primary" onClick={installmentRetryModal.open}>
|
|
208
|
+
<FormattedMessage
|
|
209
|
+
{...messages.paymentNeededButton}
|
|
210
|
+
values={{
|
|
211
|
+
amount: intl.formatNumber(failedInstallment.amount, {
|
|
212
|
+
style: 'currency',
|
|
213
|
+
currency: failedInstallment.currency,
|
|
214
|
+
}),
|
|
215
|
+
}}
|
|
216
|
+
/>
|
|
217
|
+
</Button>
|
|
218
|
+
</div>
|
|
219
|
+
<OrderPaymentRetryModal
|
|
220
|
+
{...installmentRetryModal}
|
|
221
|
+
installment={failedInstallment}
|
|
222
|
+
order={order!}
|
|
223
|
+
onClose={orderQuery.methods.invalidate}
|
|
224
|
+
/>
|
|
225
|
+
</>
|
|
226
|
+
);
|
|
227
|
+
};
|
|
228
|
+
|
|
91
229
|
export default ProductCertificateFooter;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { defineMessages, FormattedMessage } from 'react-intl';
|
|
2
|
+
import { CredentialOrder, Product } from 'types/Joanie';
|
|
3
|
+
import { DashboardItemCertificate } from 'widgets/Dashboard/components/DashboardItem/Certificate';
|
|
4
|
+
import { useCertificate } from 'hooks/useCertificates';
|
|
5
|
+
import { Spinner } from 'components/Spinner';
|
|
6
|
+
|
|
7
|
+
const messages = defineMessages({
|
|
8
|
+
loadingCertificate: {
|
|
9
|
+
id: 'components.DashboardItemOrder.CertificateItem.loadingCertificate',
|
|
10
|
+
description: 'Accessible label displayed while certificate is being fetched on the dashboard.',
|
|
11
|
+
defaultMessage: 'Loading certificate...',
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
interface DashboardItemOrderCertificateProps {
|
|
16
|
+
order: CredentialOrder;
|
|
17
|
+
product: Product;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const CertificateItem = ({ order, product }: DashboardItemOrderCertificateProps) => {
|
|
21
|
+
if (!order.certificate_id) {
|
|
22
|
+
return (
|
|
23
|
+
<DashboardItemCertificate
|
|
24
|
+
certificateDefinition={product.certificate_definition}
|
|
25
|
+
productType={product.type}
|
|
26
|
+
mode="compact"
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
const certificate = useCertificate(order.certificate_id);
|
|
31
|
+
return (
|
|
32
|
+
<>
|
|
33
|
+
{certificate.states.fetching && (
|
|
34
|
+
<Spinner aria-labelledby="loading-certificate">
|
|
35
|
+
<span id="loading-certificate">
|
|
36
|
+
<FormattedMessage {...messages.loadingCertificate} />
|
|
37
|
+
</span>
|
|
38
|
+
</Spinner>
|
|
39
|
+
)}
|
|
40
|
+
{certificate.item && (
|
|
41
|
+
<DashboardItemCertificate
|
|
42
|
+
certificate={certificate.item}
|
|
43
|
+
productType={product.type}
|
|
44
|
+
mode="compact"
|
|
45
|
+
/>
|
|
46
|
+
)}
|
|
47
|
+
</>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export default CertificateItem;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { defineMessages, FormattedMessage } from 'react-intl';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { CredentialOrder, Product } from 'types/Joanie';
|
|
4
|
+
import { OrderHelper } from 'utils/OrderHelper';
|
|
5
|
+
import ContractStatus from 'components/ContractStatus';
|
|
6
|
+
import SignContractButton from 'components/SignContractButton';
|
|
7
|
+
|
|
8
|
+
const messages = defineMessages({
|
|
9
|
+
trainingContractTitle: {
|
|
10
|
+
id: 'components.DashboardItemOrder.ContractItem.trainingContractTitle',
|
|
11
|
+
description: 'Title of the training contract section',
|
|
12
|
+
defaultMessage: 'Training contract',
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const ContractItem = ({ order, product }: { order: CredentialOrder; product: Product }) => {
|
|
17
|
+
if (!product?.contract_definition) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const needsSignature = OrderHelper.orderNeedsSignature(order);
|
|
22
|
+
return (
|
|
23
|
+
<div
|
|
24
|
+
id="dashboard-item-contract"
|
|
25
|
+
className="dashboard-splitted-card__item"
|
|
26
|
+
data-testid={`dashboard-item-contract-${order.id}`}
|
|
27
|
+
>
|
|
28
|
+
<div
|
|
29
|
+
className={classNames('dashboard-splitted-card__item__title', {
|
|
30
|
+
'dashboard-splitted-card__item__title--dot': needsSignature,
|
|
31
|
+
})}
|
|
32
|
+
>
|
|
33
|
+
<span>
|
|
34
|
+
<FormattedMessage {...messages.trainingContractTitle} />
|
|
35
|
+
</span>
|
|
36
|
+
</div>
|
|
37
|
+
<div className="dashboard-splitted-card__item__description">
|
|
38
|
+
<ContractStatus contract={order.contract} />
|
|
39
|
+
</div>
|
|
40
|
+
<div className="dashboard-splitted-card__item__actions">
|
|
41
|
+
<SignContractButton
|
|
42
|
+
order={order}
|
|
43
|
+
contract={order.contract}
|
|
44
|
+
writable={true}
|
|
45
|
+
className="dashboard-item__button"
|
|
46
|
+
/>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default ContractItem;
|
package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemNotResumable.spec.tsx
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test suite for DashboardItem component with a non-resumable order (inactive and related product
|
|
3
|
+
* is no more purchasable (no remaining seats if order group, some target courses are not opened)).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import fetchMock from 'fetch-mock';
|
|
7
|
+
import { render, screen, within } from '@testing-library/react';
|
|
8
|
+
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
|
|
9
|
+
import { setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper';
|
|
10
|
+
import { CredentialOrderFactory } from 'utils/test/factories/joanie';
|
|
11
|
+
import { OrderState } from 'types/Joanie';
|
|
12
|
+
import { mockCourseProductWithOrder } from 'utils/test/mockCourseProductWithOrder';
|
|
13
|
+
import { DashboardTest } from 'widgets/Dashboard/components/DashboardTest';
|
|
14
|
+
import { LearnerDashboardPaths } from 'widgets/Dashboard/utils/learnerRoutesPaths';
|
|
15
|
+
import { BaseJoanieAppWrapper } from 'utils/test/wrappers/BaseJoanieAppWrapper';
|
|
16
|
+
|
|
17
|
+
jest.mock('utils/context', () => ({
|
|
18
|
+
__esModule: true,
|
|
19
|
+
default: mockRichieContextFactory({
|
|
20
|
+
authentication: { backend: 'fonzie', endpoint: 'https://demo.endpoint' },
|
|
21
|
+
joanie_backend: { endpoint: 'https://joanie.endpoint' },
|
|
22
|
+
}).one(),
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
describe('DashboardItemOrder / Not resumable', () => {
|
|
26
|
+
setupJoanieSession();
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
fetchMock.get(
|
|
29
|
+
'begin:https://joanie.endpoint/api/v1.0/enrollments/',
|
|
30
|
+
{ results: [], next: null, previous: null, count: null },
|
|
31
|
+
{ overwriteRoutes: true },
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
fetchMock.restore();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('non-writable', () => {
|
|
39
|
+
it('renders elements to explain that the order process is not resumable', async () => {
|
|
40
|
+
const order = CredentialOrderFactory({
|
|
41
|
+
state: OrderState.TO_SIGN,
|
|
42
|
+
}).one();
|
|
43
|
+
|
|
44
|
+
fetchMock.get('begin:https://joanie.endpoint/api/v1.0/orders/', {
|
|
45
|
+
results: [order],
|
|
46
|
+
next: null,
|
|
47
|
+
previous: null,
|
|
48
|
+
count: null,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const { product } = mockCourseProductWithOrder(order);
|
|
52
|
+
// Make product no more purchasable
|
|
53
|
+
product.remaining_order_count = 0;
|
|
54
|
+
|
|
55
|
+
render(<DashboardTest initialRoute={LearnerDashboardPaths.COURSES} />, {
|
|
56
|
+
wrapper: BaseJoanieAppWrapper,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const dashboardItem = await screen.findByTestId(`dashboard-item-order-${order.id}`);
|
|
60
|
+
within(dashboardItem).getByRole('heading', { level: 5, name: product.title });
|
|
61
|
+
within(dashboardItem).getByText(
|
|
62
|
+
'The subscription process cannot be resumed. The related training is no more purchasable.',
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
// No subitem should be displayed (target course details)
|
|
66
|
+
expect(within(dashboardItem).queryAllByTestId('dashboard-sub-item')).toHaveLength(0);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('writable', () => {
|
|
71
|
+
it('renders elements to explain that the order process is not resumable', async () => {
|
|
72
|
+
const order = CredentialOrderFactory({
|
|
73
|
+
state: OrderState.TO_SAVE_PAYMENT_METHOD,
|
|
74
|
+
}).one();
|
|
75
|
+
|
|
76
|
+
fetchMock.get(
|
|
77
|
+
'https://joanie.endpoint/api/v1.0/orders/',
|
|
78
|
+
{ results: [order], next: null, previous: null, count: null },
|
|
79
|
+
{ overwriteRoutes: true },
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const url = `begin:https://joanie.endpoint/api/v1.0/orders/?`;
|
|
83
|
+
fetchMock.get(url, [order]);
|
|
84
|
+
|
|
85
|
+
const { product } = mockCourseProductWithOrder(order);
|
|
86
|
+
// Make product no more purchasable
|
|
87
|
+
product.remaining_order_count = 0;
|
|
88
|
+
|
|
89
|
+
render(
|
|
90
|
+
<DashboardTest initialRoute={LearnerDashboardPaths.ORDER.replace(':orderId', order.id)} />,
|
|
91
|
+
{
|
|
92
|
+
wrapper: BaseJoanieAppWrapper,
|
|
93
|
+
},
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const dashboardItem = await screen.findByTestId(`dashboard-item-order-${order.id}`);
|
|
97
|
+
within(dashboardItem).getByRole('heading', { level: 5, name: product.title });
|
|
98
|
+
within(dashboardItem).getByText(
|
|
99
|
+
'The subscription process cannot be resumed. The related training is no more purchasable.',
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// No subitem should be displayed (target course details)
|
|
103
|
+
expect(within(dashboardItem).queryAllByTestId('dashboard-sub-item')).toHaveLength(0);
|
|
104
|
+
|
|
105
|
+
// Organization block should not be displayed
|
|
106
|
+
expect(within(dashboardItem).queryByTestId('organization-block')).toBeNull();
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|