richie-education 3.1.2 → 3.1.3-dev12
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/js/api/joanie.ts +8 -8
- package/js/components/ContractFrame/OrganizationContractFrame.spec.tsx +11 -20
- package/js/components/ContractFrame/OrganizationContractFrame.tsx +4 -4
- package/js/components/CourseGlimpse/utils.ts +22 -35
- package/js/components/CourseGlimpseList/utils.ts +2 -2
- package/js/components/PurchaseButton/index.tsx +3 -3
- package/js/components/SaleTunnel/CredentialSaleTunnel/index.tsx +1 -3
- package/js/components/SaleTunnel/GenericSaleTunnel.tsx +3 -1
- package/js/components/SaleTunnel/SaleTunnelInformation/index.tsx +2 -2
- package/js/components/SaleTunnel/SubscriptionButton/index.tsx +1 -2
- package/js/components/SaleTunnel/index.credential.spec.tsx +5 -19
- package/js/components/SaleTunnel/index.full-process.spec.tsx +3 -3
- package/js/components/SaleTunnel/index.spec.tsx +75 -0
- package/js/components/SaleTunnel/index.stories.tsx +0 -1
- package/js/components/SaleTunnel/index.tsx +2 -2
- package/js/components/TeacherDashboardCourseList/index.spec.tsx +3 -3
- package/js/components/TeacherDashboardCourseList/index.tsx +2 -2
- package/js/hooks/useContractArchive/index.ts +3 -3
- package/js/hooks/useCourseProductUnion/index.spec.tsx +16 -18
- package/js/hooks/useCourseProductUnion/index.ts +7 -7
- package/js/hooks/useCourseProducts.ts +4 -8
- package/js/hooks/useDefaultOrganizationId/index.tsx +4 -7
- package/js/hooks/useOffer/index.ts +32 -0
- package/js/hooks/useTeacherCoursesSearch/index.tsx +4 -4
- package/js/hooks/useTeacherPendingContractsCount/index.ts +4 -4
- package/js/pages/DashboardCourses/index.spec.tsx +14 -17
- package/js/pages/TeacherDashboardContractsLayout/TeacherDashboardContracts/index.spec.tsx +8 -14
- package/js/pages/TeacherDashboardContractsLayout/TeacherDashboardContracts/index.tsx +4 -12
- package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.spec.tsx +11 -11
- package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.timer.spec.tsx +10 -13
- package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.tsx +4 -4
- package/js/pages/TeacherDashboardContractsLayout/components/ContractActionsBar/index.spec.tsx +20 -28
- package/js/pages/TeacherDashboardContractsLayout/components/ContractActionsBar/index.tsx +8 -11
- package/js/pages/TeacherDashboardContractsLayout/components/SignOrganizationContractButton/index.spec.tsx +6 -6
- package/js/pages/TeacherDashboardContractsLayout/components/SignOrganizationContractButton/index.tsx +4 -4
- package/js/pages/TeacherDashboardContractsLayout/hooks/useCheckContractArchiveExists/index.spec.tsx +7 -7
- package/js/pages/TeacherDashboardContractsLayout/hooks/useCheckContractArchiveExists/index.tsx +5 -5
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/contractArchiveLocalStorage.spec.ts +21 -28
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/contractArchiveLocalStorage.ts +13 -23
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/index.spec.tsx +11 -13
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/index.tsx +6 -6
- package/js/pages/TeacherDashboardContractsLayout/hooks/useHasContractToDownload/index.tsx +3 -6
- package/js/pages/TeacherDashboardContractsLayout/hooks/useTeacherContractFilters/index.spec.tsx +16 -16
- package/js/pages/TeacherDashboardContractsLayout/hooks/useTeacherContractFilters/index.tsx +4 -4
- package/js/pages/TeacherDashboardContractsLayout/hooks/useTeacherContractsToSign.tsx +4 -7
- package/js/pages/TeacherDashboardCourseLearnersLayout/hooks/useCourseLearnersFilters/index.spec.tsx +21 -21
- package/js/pages/TeacherDashboardCourseLearnersLayout/hooks/useCourseLearnersFilters/index.ts +5 -10
- package/js/pages/TeacherDashboardCourseLearnersLayout/index.spec.tsx +61 -79
- package/js/pages/TeacherDashboardCourseLearnersLayout/index.tsx +1 -1
- package/js/pages/TeacherDashboardCoursesLoader/index.spec.tsx +11 -11
- package/js/pages/TeacherDashboardOrganizationCourseLoader/index.spec.tsx +11 -11
- package/js/pages/TeacherDashboardTraining/TeacherDashboardTrainingLoader.tsx +7 -7
- package/js/pages/TeacherDashboardTraining/index.spec.tsx +25 -33
- package/js/pages/TeacherDashboardTraining/index.tsx +12 -20
- package/js/types/Joanie.ts +26 -30
- package/js/utils/ProductHelper/index.ts +1 -5
- package/js/utils/test/factories/joanie.ts +12 -25
- package/js/utils/test/mockCourseProductWithOrder.ts +4 -4
- package/js/widgets/Dashboard/components/DashboardItem/Enrollment/DashboardItemEnrollment.tsx +1 -1
- package/js/widgets/Dashboard/components/DashboardItem/Enrollment/ProductCertificateFooter/index.spec.tsx +1 -1
- package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemOrder.tsx +3 -3
- package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemOrderContract.useUnionResource.cache.spec.tsx +1 -1
- package/js/widgets/Dashboard/components/DashboardItem/Order/Installment/index.tsx +4 -4
- package/js/widgets/Dashboard/components/DashboardItem/stories.mock.ts +1 -1
- package/js/widgets/Dashboard/components/DashboardSidebar/components/ContractNavLink/index.spec.tsx +23 -28
- package/js/widgets/Dashboard/components/DashboardSidebar/components/ContractNavLink/index.tsx +4 -8
- package/js/widgets/Dashboard/components/TeacherDashboardCourseSidebar/index.spec.tsx +17 -27
- package/js/widgets/Dashboard/components/TeacherDashboardCourseSidebar/index.tsx +16 -25
- package/js/widgets/Dashboard/components/TeacherDashboardCourseSidebar/utils.ts +4 -4
- package/js/widgets/Dashboard/components/TeacherDashboardOrganizationSidebar/index.tsx +3 -7
- package/js/widgets/Dashboard/utils/teacherDashboardPaths.tsx +4 -4
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/CourseProductItemFooter/index.tsx +23 -38
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/_styles.scss +27 -7
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/components/CourseProductCourseRuns/CourseRunList.tsx +1 -1
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.spec.tsx +174 -158
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.stories.tsx +9 -2
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.tsx +108 -28
- package/js/widgets/SyllabusCourseRunsList/index.spec.tsx +8 -8
- package/package.json +1 -1
- package/js/hooks/useCourseProductRelation/index.ts +0 -44
package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import { useEffect } from 'react';
|
|
|
4
4
|
import useDownloadContractArchive, {
|
|
5
5
|
ContractDownloadStatus,
|
|
6
6
|
} from 'pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive';
|
|
7
|
-
import {
|
|
7
|
+
import { Offer, Organization } from 'types/Joanie';
|
|
8
8
|
|
|
9
9
|
const messages = defineMessages({
|
|
10
10
|
bulkDownloadButtonDownloadLabel: {
|
|
@@ -26,16 +26,16 @@ const messages = defineMessages({
|
|
|
26
26
|
|
|
27
27
|
interface BulkDownloadContractButtonProps {
|
|
28
28
|
organizationId?: Organization['id'];
|
|
29
|
-
|
|
29
|
+
offerId?: Offer['id'];
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
const BulkDownloadContractButton = ({
|
|
33
33
|
organizationId,
|
|
34
|
-
|
|
34
|
+
offerId,
|
|
35
35
|
}: BulkDownloadContractButtonProps) => {
|
|
36
36
|
const { downloadContractArchive, createContractArchive, status } = useDownloadContractArchive({
|
|
37
37
|
organizationId,
|
|
38
|
-
|
|
38
|
+
offerId,
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
useEffect(() => {
|
package/js/pages/TeacherDashboardContractsLayout/components/ContractActionsBar/index.spec.tsx
CHANGED
|
@@ -97,38 +97,30 @@ describe('TeacherDashboardContractsLayout/ContractActionsBar', () => {
|
|
|
97
97
|
{
|
|
98
98
|
label: "doesn't have contract to download",
|
|
99
99
|
hasContractToDownload: false,
|
|
100
|
-
|
|
100
|
+
offerId: undefined,
|
|
101
101
|
},
|
|
102
102
|
{
|
|
103
|
-
label: "doesn't have contract to download and
|
|
103
|
+
label: "doesn't have contract to download and offerId",
|
|
104
104
|
hasContractToDownload: false,
|
|
105
|
-
|
|
105
|
+
offerId: faker.string.uuid(),
|
|
106
106
|
},
|
|
107
|
-
])(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
expect(
|
|
125
|
-
screen.getByRole('button', { name: /Sign all pending contracts/ }),
|
|
126
|
-
).toBeInTheDocument();
|
|
127
|
-
expect(
|
|
128
|
-
screen.queryByRole('button', { name: /Request contracts archive/ }),
|
|
129
|
-
).not.toBeInTheDocument();
|
|
130
|
-
},
|
|
131
|
-
);
|
|
107
|
+
])('should only display sign button when $label', ({ hasContractToDownload, offerId }) => {
|
|
108
|
+
mockHasContractToDownload = hasContractToDownload;
|
|
109
|
+
mockCanSignContracts = true;
|
|
110
|
+
mockContractsToSignCount = 1;
|
|
111
|
+
|
|
112
|
+
render(
|
|
113
|
+
<Wrapper>
|
|
114
|
+
<ContractActionsBar offerId={offerId} organizationId={faker.string.uuid()} />
|
|
115
|
+
</Wrapper>,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
expect(screen.getByTestId('teacher-contracts-list-actionsBar')).toBeInTheDocument();
|
|
119
|
+
expect(screen.getByRole('button', { name: /Sign all pending contracts/ })).toBeInTheDocument();
|
|
120
|
+
expect(
|
|
121
|
+
screen.queryByRole('button', { name: /Request contracts archive/ }),
|
|
122
|
+
).not.toBeInTheDocument();
|
|
123
|
+
});
|
|
132
124
|
|
|
133
125
|
it("shouldn't only display download button", () => {
|
|
134
126
|
mockHasContractToDownload = true;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
|
-
import { Organization,
|
|
2
|
+
import { Organization, Offer } from 'types/Joanie';
|
|
3
3
|
import useTeacherContractsToSign from 'pages/TeacherDashboardContractsLayout/hooks/useTeacherContractsToSign';
|
|
4
4
|
import useHasContractToDownload from 'pages/TeacherDashboardContractsLayout/hooks/useHasContractToDownload';
|
|
5
5
|
import SignOrganizationContractButton from '../SignOrganizationContractButton';
|
|
@@ -7,18 +7,18 @@ import BulkDownloadContractButton from '../BulkDownloadContractButton';
|
|
|
7
7
|
|
|
8
8
|
interface ContractActionsProps {
|
|
9
9
|
organizationId: Organization['id'];
|
|
10
|
-
|
|
10
|
+
offerId?: Offer['id'];
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const ContractActionsBar = ({ organizationId,
|
|
13
|
+
const ContractActionsBar = ({ organizationId, offerId }: ContractActionsProps) => {
|
|
14
14
|
const { canSignContracts, contractsToSignCount } = useTeacherContractsToSign({
|
|
15
15
|
organizationId,
|
|
16
|
-
|
|
16
|
+
offerId,
|
|
17
17
|
});
|
|
18
|
-
const hasContractToDownload = useHasContractToDownload(organizationId,
|
|
18
|
+
const hasContractToDownload = useHasContractToDownload(organizationId, offerId);
|
|
19
19
|
|
|
20
20
|
const nbAvailableActions = [canSignContracts, hasContractToDownload].filter((val) => val).length;
|
|
21
|
-
const
|
|
21
|
+
const offerIds = offerId ? [offerId] : undefined;
|
|
22
22
|
return (
|
|
23
23
|
nbAvailableActions > 0 && (
|
|
24
24
|
<div
|
|
@@ -31,17 +31,14 @@ const ContractActionsBar = ({ organizationId, courseProductRelationId }: Contrac
|
|
|
31
31
|
{canSignContracts && (
|
|
32
32
|
<div>
|
|
33
33
|
<SignOrganizationContractButton
|
|
34
|
-
|
|
34
|
+
offerIds={offerIds}
|
|
35
35
|
organizationId={organizationId}
|
|
36
36
|
contractToSignCount={contractsToSignCount}
|
|
37
37
|
/>
|
|
38
38
|
</div>
|
|
39
39
|
)}
|
|
40
40
|
{hasContractToDownload && (
|
|
41
|
-
<BulkDownloadContractButton
|
|
42
|
-
organizationId={organizationId}
|
|
43
|
-
courseProductRelationId={courseProductRelationId}
|
|
44
|
-
/>
|
|
41
|
+
<BulkDownloadContractButton organizationId={organizationId} offerId={offerId} />
|
|
45
42
|
)}
|
|
46
43
|
</div>
|
|
47
44
|
)
|
|
@@ -70,19 +70,19 @@ describe('TeacherDashboardContractsLayout/SignOrganizationContractButton', () =>
|
|
|
70
70
|
{
|
|
71
71
|
label: "organization's contracts",
|
|
72
72
|
organizationId: faker.string.uuid(),
|
|
73
|
-
|
|
73
|
+
offerIds: undefined,
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
76
|
label: "organization's training contracts",
|
|
77
77
|
organizationId: faker.string.uuid(),
|
|
78
|
-
|
|
78
|
+
offerIds: [faker.string.uuid()],
|
|
79
79
|
},
|
|
80
|
-
])('should open $label frame on click', async ({ organizationId,
|
|
80
|
+
])('should open $label frame on click', async ({ organizationId, offerIds }) => {
|
|
81
81
|
render(
|
|
82
82
|
<Wrapper>
|
|
83
83
|
<SignOrganizationContractButton
|
|
84
84
|
organizationId={organizationId}
|
|
85
|
-
|
|
85
|
+
offerIds={offerIds}
|
|
86
86
|
contractToSignCount={12}
|
|
87
87
|
/>
|
|
88
88
|
</Wrapper>,
|
|
@@ -92,8 +92,8 @@ describe('TeacherDashboardContractsLayout/SignOrganizationContractButton', () =>
|
|
|
92
92
|
const user = userEvent.setup();
|
|
93
93
|
|
|
94
94
|
let getInvitationLinkUrl = `https://joanie.test/api/v1.0/organizations/${organizationId}/contracts-signature-link/`;
|
|
95
|
-
if (
|
|
96
|
-
getInvitationLinkUrl += `?
|
|
95
|
+
if (offerIds) {
|
|
96
|
+
getInvitationLinkUrl += `?offer_ids=${offerIds[0]}`;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
fetchMock.get(getInvitationLinkUrl, {
|
package/js/pages/TeacherDashboardContractsLayout/components/SignOrganizationContractButton/index.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import { defineMessages, FormattedMessage } from 'react-intl';
|
|
|
3
3
|
import { Button } from '@openfun/cunningham-react';
|
|
4
4
|
import { OrganizationContractFrame } from 'components/ContractFrame';
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { Offer, Organization } from 'types/Joanie';
|
|
7
7
|
|
|
8
8
|
const messages = defineMessages({
|
|
9
9
|
signAllPendingContracts: {
|
|
@@ -14,7 +14,7 @@ const messages = defineMessages({
|
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
interface Props {
|
|
17
|
-
|
|
17
|
+
offerIds?: Offer['id'][];
|
|
18
18
|
organizationId: Organization['id'];
|
|
19
19
|
contractToSignCount: number;
|
|
20
20
|
}
|
|
@@ -22,7 +22,7 @@ interface Props {
|
|
|
22
22
|
const SignOrganizationContractButton = ({
|
|
23
23
|
organizationId,
|
|
24
24
|
contractToSignCount,
|
|
25
|
-
|
|
25
|
+
offerIds = [],
|
|
26
26
|
}: Props) => {
|
|
27
27
|
const [contractFrameOpened, setContractFrameOpened] = useState(false);
|
|
28
28
|
const hasContractToSign = contractToSignCount > 0;
|
|
@@ -48,7 +48,7 @@ const SignOrganizationContractButton = ({
|
|
|
48
48
|
</Button>
|
|
49
49
|
)}
|
|
50
50
|
<OrganizationContractFrame
|
|
51
|
-
|
|
51
|
+
offerIds={offerIds}
|
|
52
52
|
organizationId={organizationId}
|
|
53
53
|
isOpen={contractFrameOpened}
|
|
54
54
|
onClose={() => setContractFrameOpened(false)}
|
package/js/pages/TeacherDashboardContractsLayout/hooks/useCheckContractArchiveExists/index.spec.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import { IntlProvider } from 'react-intl';
|
|
|
5
5
|
import { PropsWithChildren } from 'react';
|
|
6
6
|
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
|
|
7
7
|
import JoanieApiProvider from 'contexts/JoanieApiContext';
|
|
8
|
-
import {
|
|
8
|
+
import { OfferFactory, OrganizationFactory } from 'utils/test/factories/joanie';
|
|
9
9
|
import {
|
|
10
10
|
LocalStorageArchiveFilters,
|
|
11
11
|
storeContractArchiveId,
|
|
@@ -41,24 +41,24 @@ describe.each([
|
|
|
41
41
|
{
|
|
42
42
|
testLabel: 'for all organization and all trainings',
|
|
43
43
|
organization: undefined,
|
|
44
|
-
|
|
44
|
+
offer: undefined,
|
|
45
45
|
},
|
|
46
46
|
{
|
|
47
47
|
testLabel: 'for a training in an organization',
|
|
48
48
|
organization: OrganizationFactory().one(),
|
|
49
|
-
|
|
49
|
+
offer: OfferFactory().one(),
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
52
|
testLabel: 'for an organization',
|
|
53
53
|
organization: OrganizationFactory().one(),
|
|
54
|
-
|
|
54
|
+
offer: undefined,
|
|
55
55
|
},
|
|
56
56
|
{
|
|
57
57
|
testLabel: 'for a training',
|
|
58
58
|
organization: undefined,
|
|
59
|
-
|
|
59
|
+
offer: OfferFactory().one(),
|
|
60
60
|
},
|
|
61
|
-
])('useCheckContractArchiveExists $testLabel', ({ organization,
|
|
61
|
+
])('useCheckContractArchiveExists $testLabel', ({ organization, offer }) => {
|
|
62
62
|
const Wrapper = ({ children }: PropsWithChildren) => {
|
|
63
63
|
return (
|
|
64
64
|
<IntlProvider locale="en">
|
|
@@ -71,7 +71,7 @@ describe.each([
|
|
|
71
71
|
beforeEach(() => {
|
|
72
72
|
localStorageArchiveFilters = {
|
|
73
73
|
organizationId: organization ? organization.id : undefined,
|
|
74
|
-
|
|
74
|
+
offerId: offer ? offer.id : undefined,
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
// Joanie providers calls
|
package/js/pages/TeacherDashboardContractsLayout/hooks/useCheckContractArchiveExists/index.tsx
CHANGED
|
@@ -2,17 +2,17 @@ import { useEffect, useRef, useState } from 'react';
|
|
|
2
2
|
import useContractArchive from 'hooks/useContractArchive';
|
|
3
3
|
import { CONTRACT_DOWNLOAD_SETTINGS } from 'settings';
|
|
4
4
|
import { Nullable } from 'types/utils';
|
|
5
|
-
import {
|
|
5
|
+
import { Offer, Organization } from 'types/Joanie';
|
|
6
6
|
import { getStoredContractArchiveId } from '../useDownloadContractArchive/contractArchiveLocalStorage';
|
|
7
7
|
|
|
8
8
|
export interface UseCheckContractArchiveExistsProps {
|
|
9
9
|
organizationId?: Organization['id'];
|
|
10
|
-
|
|
10
|
+
offerId?: Offer['id'];
|
|
11
11
|
enable?: boolean;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const useCheckContractArchiveExist = (
|
|
15
|
-
{ organizationId,
|
|
15
|
+
{ organizationId, offerId, enable = true }: UseCheckContractArchiveExistsProps = {
|
|
16
16
|
enable: true,
|
|
17
17
|
},
|
|
18
18
|
) => {
|
|
@@ -55,7 +55,7 @@ const useCheckContractArchiveExist = (
|
|
|
55
55
|
useEffect(() => {
|
|
56
56
|
const storedContractArchiveId = getStoredContractArchiveId({
|
|
57
57
|
organizationId,
|
|
58
|
-
|
|
58
|
+
offerId,
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
if (enable && storedContractArchiveId) {
|
|
@@ -63,7 +63,7 @@ const useCheckContractArchiveExist = (
|
|
|
63
63
|
} else {
|
|
64
64
|
setIsContractArchiveExists(false);
|
|
65
65
|
}
|
|
66
|
-
}, [enable, organizationId,
|
|
66
|
+
}, [enable, organizationId, offerId]);
|
|
67
67
|
|
|
68
68
|
// Be sure to clear any timeout before unmouting the hook.
|
|
69
69
|
useEffect(() => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { faker } from '@faker-js/faker';
|
|
2
2
|
import { CONTRACT_DOWNLOAD_SETTINGS } from 'settings';
|
|
3
|
-
import {
|
|
3
|
+
import { OfferFactory, OrganizationFactory } from 'utils/test/factories/joanie';
|
|
4
4
|
import {
|
|
5
5
|
LocalStorageArchiveFilters,
|
|
6
6
|
generateLocalStorageKey,
|
|
@@ -14,56 +14,56 @@ describe.each([
|
|
|
14
14
|
{
|
|
15
15
|
testLabel: 'for all organization and all trainings',
|
|
16
16
|
organization: undefined,
|
|
17
|
-
|
|
17
|
+
offer: undefined,
|
|
18
18
|
existingOrganization: undefined,
|
|
19
|
-
|
|
19
|
+
existingOffer: undefined,
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
22
|
testLabel: 'for a training in an organization',
|
|
23
23
|
organization: OrganizationFactory().one(),
|
|
24
|
-
|
|
24
|
+
offer: OfferFactory().one(),
|
|
25
25
|
existingOrganization: undefined,
|
|
26
|
-
|
|
26
|
+
existingOffer: undefined,
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
29
|
testLabel: 'for an organization',
|
|
30
30
|
organization: OrganizationFactory().one(),
|
|
31
|
-
|
|
31
|
+
offer: undefined,
|
|
32
32
|
existingOrganization: undefined,
|
|
33
|
-
|
|
33
|
+
existingOffer: undefined,
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
testLabel: 'for a training',
|
|
37
37
|
organization: undefined,
|
|
38
|
-
|
|
38
|
+
offer: OfferFactory().one(),
|
|
39
39
|
existingOrganization: undefined,
|
|
40
|
-
|
|
40
|
+
existingOffer: undefined,
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
43
|
testLabel: 'for all organization and all trainings, with a other id already stored',
|
|
44
44
|
organization: undefined,
|
|
45
|
-
|
|
45
|
+
offer: undefined,
|
|
46
46
|
existingOrganization: OrganizationFactory().one(),
|
|
47
|
-
|
|
47
|
+
existingOffer: OfferFactory().one(),
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
50
|
testLabel: 'for a training in an organization, with a other id already stored',
|
|
51
51
|
organization: OrganizationFactory().one(),
|
|
52
|
-
|
|
52
|
+
offer: OfferFactory().one(),
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
55
|
testLabel: 'for an organization, with a other id already stored',
|
|
56
56
|
organization: OrganizationFactory().one(),
|
|
57
|
-
|
|
57
|
+
offer: undefined,
|
|
58
58
|
existingOrganization: OrganizationFactory().one(),
|
|
59
|
-
|
|
59
|
+
existingOffer: OfferFactory().one(),
|
|
60
60
|
},
|
|
61
61
|
{
|
|
62
62
|
testLabel: 'for a training, with a other id already stored',
|
|
63
63
|
organization: undefined,
|
|
64
|
-
|
|
64
|
+
offer: OfferFactory().one(),
|
|
65
65
|
existingOrganization: OrganizationFactory().one(),
|
|
66
|
-
|
|
66
|
+
existingOffer: OfferFactory().one(),
|
|
67
67
|
},
|
|
68
68
|
|
|
69
69
|
{
|
|
@@ -72,16 +72,11 @@ describe.each([
|
|
|
72
72
|
{
|
|
73
73
|
testLabel: 'Testing with a other id already stored',
|
|
74
74
|
existingOrganization: OrganizationFactory().one(),
|
|
75
|
-
|
|
75
|
+
existingOffer: OfferFactory().one(),
|
|
76
76
|
},
|
|
77
77
|
])(
|
|
78
78
|
'contractArchiveLocalStorage $testLabel',
|
|
79
|
-
({
|
|
80
|
-
organization,
|
|
81
|
-
courseProductRelation,
|
|
82
|
-
existingOrganization,
|
|
83
|
-
existingCourseProductRelation,
|
|
84
|
-
}) => {
|
|
79
|
+
({ organization, offer, existingOrganization, existingOffer }) => {
|
|
85
80
|
let localStorageArchiveFilters: LocalStorageArchiveFilters;
|
|
86
81
|
let localStorageExistingArchiveFilters: LocalStorageArchiveFilters;
|
|
87
82
|
let exsitingContractId: string;
|
|
@@ -89,17 +84,15 @@ describe.each([
|
|
|
89
84
|
beforeEach(() => {
|
|
90
85
|
localStorageArchiveFilters = {
|
|
91
86
|
organizationId: organization ? organization.id : undefined,
|
|
92
|
-
|
|
87
|
+
offerId: offer ? offer.id : undefined,
|
|
93
88
|
};
|
|
94
89
|
localStorageExistingArchiveFilters = {
|
|
95
90
|
organizationId: existingOrganization ? existingOrganization.id : undefined,
|
|
96
|
-
|
|
97
|
-
? existingCourseProductRelation.id
|
|
98
|
-
: undefined,
|
|
91
|
+
offerId: existingOffer ? existingOffer.id : undefined,
|
|
99
92
|
};
|
|
100
93
|
exsitingContractId = faker.string.uuid();
|
|
101
94
|
|
|
102
|
-
if (
|
|
95
|
+
if (existingOffer && existingOrganization) {
|
|
103
96
|
// everything should work fine with multiple archive stored
|
|
104
97
|
storeContractArchiveId({
|
|
105
98
|
...localStorageExistingArchiveFilters,
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { CONTRACT_DOWNLOAD_SETTINGS } from 'settings';
|
|
2
|
-
import {
|
|
2
|
+
import { Offer, Organization } from 'types/Joanie';
|
|
3
3
|
|
|
4
4
|
export interface LocalStorageArchiveFilters {
|
|
5
5
|
organizationId?: Organization['id'];
|
|
6
|
-
|
|
6
|
+
offerId?: Offer['id'];
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
const generateLocalStorageKey = ({
|
|
10
|
-
organizationId
|
|
11
|
-
courseProductRelationId,
|
|
12
|
-
}: LocalStorageArchiveFilters = {}) => {
|
|
13
|
-
return `${CONTRACT_DOWNLOAD_SETTINGS.contractArchiveLocalStorageKey}::${organizationId ?? 'all'}::${courseProductRelationId ?? 'all'}`;
|
|
9
|
+
const generateLocalStorageKey = ({ organizationId, offerId }: LocalStorageArchiveFilters = {}) => {
|
|
10
|
+
return `${CONTRACT_DOWNLOAD_SETTINGS.contractArchiveLocalStorageKey}::${organizationId ?? 'all'}::${offerId ?? 'all'}`;
|
|
14
11
|
};
|
|
15
12
|
|
|
16
13
|
const generateLocalStorageId = (contractArchiveId: string) => {
|
|
@@ -20,32 +17,27 @@ const generateLocalStorageId = (contractArchiveId: string) => {
|
|
|
20
17
|
const storeContractArchiveId = ({
|
|
21
18
|
contractArchiveId,
|
|
22
19
|
organizationId,
|
|
23
|
-
|
|
20
|
+
offerId,
|
|
24
21
|
}: {
|
|
25
22
|
contractArchiveId: string;
|
|
26
23
|
organizationId?: Organization['id'];
|
|
27
|
-
|
|
24
|
+
offerId?: Offer['id'];
|
|
28
25
|
}) => {
|
|
29
26
|
localStorage.setItem(
|
|
30
|
-
generateLocalStorageKey({ organizationId,
|
|
27
|
+
generateLocalStorageKey({ organizationId, offerId }),
|
|
31
28
|
generateLocalStorageId(contractArchiveId),
|
|
32
29
|
);
|
|
33
30
|
};
|
|
34
31
|
|
|
35
|
-
const unstoreContractArchiveId = ({
|
|
36
|
-
organizationId,
|
|
37
|
-
courseProductRelationId,
|
|
38
|
-
}: LocalStorageArchiveFilters = {}) => {
|
|
39
|
-
localStorage.removeItem(generateLocalStorageKey({ organizationId, courseProductRelationId }));
|
|
32
|
+
const unstoreContractArchiveId = ({ organizationId, offerId }: LocalStorageArchiveFilters = {}) => {
|
|
33
|
+
localStorage.removeItem(generateLocalStorageKey({ organizationId, offerId }));
|
|
40
34
|
};
|
|
41
35
|
|
|
42
36
|
const getStoredContractArchiveId = ({
|
|
43
37
|
organizationId,
|
|
44
|
-
|
|
38
|
+
offerId,
|
|
45
39
|
}: LocalStorageArchiveFilters = {}) => {
|
|
46
|
-
const value = localStorage.getItem(
|
|
47
|
-
generateLocalStorageKey({ organizationId, courseProductRelationId }),
|
|
48
|
-
);
|
|
40
|
+
const value = localStorage.getItem(generateLocalStorageKey({ organizationId, offerId }));
|
|
49
41
|
if (value === null) {
|
|
50
42
|
return value;
|
|
51
43
|
}
|
|
@@ -56,11 +48,9 @@ const getStoredContractArchiveId = ({
|
|
|
56
48
|
|
|
57
49
|
const isStoredContractArchiveIdExpired = ({
|
|
58
50
|
organizationId,
|
|
59
|
-
|
|
51
|
+
offerId,
|
|
60
52
|
}: LocalStorageArchiveFilters = {}) => {
|
|
61
|
-
const value = localStorage.getItem(
|
|
62
|
-
generateLocalStorageKey({ organizationId, courseProductRelationId }),
|
|
63
|
-
);
|
|
53
|
+
const value = localStorage.getItem(generateLocalStorageKey({ organizationId, offerId }));
|
|
64
54
|
if (value === null) {
|
|
65
55
|
return false;
|
|
66
56
|
}
|
package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/index.spec.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import { PropsWithChildren } from 'react';
|
|
|
5
5
|
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
|
|
6
6
|
import JoanieApiProvider from 'contexts/JoanieApiContext';
|
|
7
7
|
import { CONTRACT_DOWNLOAD_SETTINGS } from 'settings';
|
|
8
|
-
import {
|
|
8
|
+
import { OfferFactory, OrganizationFactory } from 'utils/test/factories/joanie';
|
|
9
9
|
import {
|
|
10
10
|
LocalStorageArchiveFilters,
|
|
11
11
|
getStoredContractArchiveId,
|
|
@@ -50,30 +50,30 @@ describe.each([
|
|
|
50
50
|
{
|
|
51
51
|
testLabel: 'for all organization and all trainings',
|
|
52
52
|
organization: undefined,
|
|
53
|
-
|
|
53
|
+
offer: undefined,
|
|
54
54
|
},
|
|
55
55
|
{
|
|
56
56
|
testLabel: 'for a training in an organization',
|
|
57
57
|
organization: OrganizationFactory().one(),
|
|
58
|
-
|
|
58
|
+
offer: OfferFactory().one(),
|
|
59
59
|
},
|
|
60
60
|
{
|
|
61
61
|
testLabel: 'for an organization',
|
|
62
62
|
organization: OrganizationFactory().one(),
|
|
63
|
-
|
|
63
|
+
offer: undefined,
|
|
64
64
|
},
|
|
65
65
|
{
|
|
66
66
|
testLabel: 'for a training',
|
|
67
67
|
organization: undefined,
|
|
68
|
-
|
|
68
|
+
offer: OfferFactory().one(),
|
|
69
69
|
},
|
|
70
|
-
])('useDownloadContractArchive $testLabel', ({ organization,
|
|
70
|
+
])('useDownloadContractArchive $testLabel', ({ organization, offer }) => {
|
|
71
71
|
let localStorageArchiveFilters: LocalStorageArchiveFilters;
|
|
72
72
|
|
|
73
73
|
beforeEach(() => {
|
|
74
74
|
localStorageArchiveFilters = {
|
|
75
75
|
organizationId: organization ? organization.id : undefined,
|
|
76
|
-
|
|
76
|
+
offerId: offer ? offer.id : undefined,
|
|
77
77
|
};
|
|
78
78
|
});
|
|
79
79
|
|
|
@@ -97,22 +97,20 @@ describe.each([
|
|
|
97
97
|
{
|
|
98
98
|
testLabel: 'Testing with a other id already stored',
|
|
99
99
|
existingOrganization: OrganizationFactory().one(),
|
|
100
|
-
|
|
100
|
+
existingOffer: OfferFactory().one(),
|
|
101
101
|
},
|
|
102
|
-
])('$testLabel', ({ existingOrganization,
|
|
102
|
+
])('$testLabel', ({ existingOrganization, existingOffer }) => {
|
|
103
103
|
let localStorageExistingArchiveFilters: LocalStorageArchiveFilters;
|
|
104
104
|
let exsitingContractId: string;
|
|
105
105
|
|
|
106
106
|
beforeEach(() => {
|
|
107
107
|
localStorageExistingArchiveFilters = {
|
|
108
108
|
organizationId: existingOrganization ? existingOrganization.id : undefined,
|
|
109
|
-
|
|
110
|
-
? existingCourseProductRelation.id
|
|
111
|
-
: undefined,
|
|
109
|
+
offerId: existingOffer ? existingOffer.id : undefined,
|
|
112
110
|
};
|
|
113
111
|
exsitingContractId = faker.string.uuid();
|
|
114
112
|
|
|
115
|
-
if (
|
|
113
|
+
if (existingOffer && existingOrganization) {
|
|
116
114
|
// everything should work fine with multiple archive stored
|
|
117
115
|
storeContractArchiveId({
|
|
118
116
|
...localStorageExistingArchiveFilters,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import useContractArchive from 'hooks/useContractArchive';
|
|
3
|
-
import {
|
|
3
|
+
import { Offer, Organization } from 'types/Joanie';
|
|
4
4
|
import useCheckContractArchiveExists from '../useCheckContractArchiveExists';
|
|
5
5
|
import useHasContractToDownload from '../useHasContractToDownload';
|
|
6
6
|
import {
|
|
@@ -19,16 +19,16 @@ export enum ContractDownloadStatus {
|
|
|
19
19
|
|
|
20
20
|
interface UseTeacherContractsBulkDownloadProps {
|
|
21
21
|
organizationId?: Organization['id'];
|
|
22
|
-
|
|
22
|
+
offerId?: Offer['id'];
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const useDownloadContractArchive = ({
|
|
26
26
|
organizationId,
|
|
27
|
-
|
|
27
|
+
offerId,
|
|
28
28
|
}: UseTeacherContractsBulkDownloadProps) => {
|
|
29
29
|
const localstorageArchiveFilters = {
|
|
30
30
|
organizationId,
|
|
31
|
-
|
|
31
|
+
offerId,
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
// Contract's archive api interface
|
|
@@ -37,7 +37,7 @@ const useDownloadContractArchive = ({
|
|
|
37
37
|
} = useContractArchive();
|
|
38
38
|
|
|
39
39
|
// Simple hook that verifiy if current user have some fully signed contracts to download.
|
|
40
|
-
const hasContractToDownload = useHasContractToDownload(organizationId,
|
|
40
|
+
const hasContractToDownload = useHasContractToDownload(organizationId, offerId);
|
|
41
41
|
|
|
42
42
|
// Component state of the localstorage contract's archive id
|
|
43
43
|
const [contractArchiveId, setContractArchiveId] = useState<string | null>(
|
|
@@ -116,7 +116,7 @@ const useDownloadContractArchive = ({
|
|
|
116
116
|
const createContractArchive = async () => {
|
|
117
117
|
let newContractArchiveId;
|
|
118
118
|
if (contractArchiveId === null) {
|
|
119
|
-
newContractArchiveId = await createArchive(organizationId,
|
|
119
|
+
newContractArchiveId = await createArchive(organizationId, offerId);
|
|
120
120
|
setContractArchiveId(newContractArchiveId);
|
|
121
121
|
storeContractArchiveId({
|
|
122
122
|
...localstorageArchiveFilters,
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { useOrganizationContracts } from 'hooks/useContracts';
|
|
2
2
|
import { PER_PAGE } from 'settings';
|
|
3
|
-
import { ContractState,
|
|
3
|
+
import { ContractState, Offer, Organization } from 'types/Joanie';
|
|
4
4
|
|
|
5
|
-
const useHasContractToDownload = (
|
|
6
|
-
organizationId?: Organization['id'],
|
|
7
|
-
courseProductRelationId?: CourseProductRelation['id'],
|
|
8
|
-
) => {
|
|
5
|
+
const useHasContractToDownload = (organizationId?: Organization['id'], offerId?: Offer['id']) => {
|
|
9
6
|
const {
|
|
10
7
|
items: contracts,
|
|
11
8
|
states: { isFetched },
|
|
12
9
|
} = useOrganizationContracts({
|
|
13
10
|
organization_id: organizationId,
|
|
14
|
-
|
|
11
|
+
offer_id: offerId,
|
|
15
12
|
signature_state: ContractState.SIGNED,
|
|
16
13
|
page: 1,
|
|
17
14
|
page_size: PER_PAGE.teacherContractList,
|