richie-education 3.1.3-dev12 → 3.1.3-dev17
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 +12 -11
- package/js/components/ContractFrame/OrganizationContractFrame.tsx +4 -4
- package/js/components/CourseGlimpse/utils.ts +28 -22
- package/js/components/CourseGlimpseList/utils.ts +2 -2
- package/js/components/PurchaseButton/index.tsx +3 -3
- package/js/components/SaleTunnel/GenericSaleTunnel.tsx +3 -3
- package/js/components/SaleTunnel/SaleTunnelInformation/index.tsx +5 -3
- package/js/components/SaleTunnel/index.full-process.spec.tsx +3 -3
- package/js/components/SaleTunnel/index.spec.tsx +76 -63
- 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 -16
- package/js/hooks/useCourseProductUnion/index.ts +7 -7
- package/js/hooks/useCourseProducts.ts +4 -4
- package/js/hooks/useDefaultOrganizationId/index.tsx +4 -4
- package/js/hooks/useOffering/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 +17 -14
- package/js/pages/TeacherDashboardContractsLayout/TeacherDashboardContracts/index.spec.tsx +11 -8
- package/js/pages/TeacherDashboardContractsLayout/TeacherDashboardContracts/index.tsx +6 -3
- package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.spec.tsx +11 -11
- package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.timer.spec.tsx +10 -10
- package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.tsx +4 -4
- package/js/pages/TeacherDashboardContractsLayout/components/ContractActionsBar/index.spec.tsx +5 -5
- package/js/pages/TeacherDashboardContractsLayout/components/ContractActionsBar/index.tsx +8 -8
- 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 -21
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/contractArchiveLocalStorage.ts +19 -13
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/index.spec.tsx +11 -11
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/index.tsx +6 -6
- package/js/pages/TeacherDashboardContractsLayout/hooks/useHasContractToDownload/index.tsx +6 -3
- 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 +7 -4
- package/js/pages/TeacherDashboardCourseLearnersLayout/hooks/useCourseLearnersFilters/index.spec.tsx +21 -21
- package/js/pages/TeacherDashboardCourseLearnersLayout/hooks/useCourseLearnersFilters/index.ts +5 -5
- package/js/pages/TeacherDashboardCourseLearnersLayout/index.spec.tsx +55 -55
- 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 -25
- package/js/pages/TeacherDashboardTraining/index.tsx +16 -12
- package/js/types/Joanie.ts +27 -20
- package/js/utils/test/factories/joanie.ts +14 -11
- 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 -23
- package/js/widgets/Dashboard/components/DashboardSidebar/components/ContractNavLink/index.tsx +4 -4
- package/js/widgets/Dashboard/components/TeacherDashboardCourseSidebar/index.spec.tsx +20 -17
- package/js/widgets/Dashboard/components/TeacherDashboardCourseSidebar/index.tsx +22 -16
- package/js/widgets/Dashboard/components/TeacherDashboardCourseSidebar/utils.ts +4 -4
- package/js/widgets/Dashboard/components/TeacherDashboardOrganizationSidebar/index.tsx +3 -3
- package/js/widgets/Dashboard/utils/teacherDashboardPaths.tsx +4 -4
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/CourseProductItemFooter/index.tsx +14 -14
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.spec.tsx +105 -75
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.stories.tsx +6 -4
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.tsx +27 -20
- package/js/widgets/SyllabusCourseRunsList/index.spec.tsx +8 -8
- package/package.json +1 -1
- package/js/hooks/useOffer/index.ts +0 -32
package/js/pages/TeacherDashboardContractsLayout/components/ContractActionsBar/index.spec.tsx
CHANGED
|
@@ -97,21 +97,21 @@ describe('TeacherDashboardContractsLayout/ContractActionsBar', () => {
|
|
|
97
97
|
{
|
|
98
98
|
label: "doesn't have contract to download",
|
|
99
99
|
hasContractToDownload: false,
|
|
100
|
-
|
|
100
|
+
offeringId: undefined,
|
|
101
101
|
},
|
|
102
102
|
{
|
|
103
|
-
label: "doesn't have contract to download
|
|
103
|
+
label: "doesn't have contract to download and offeringId",
|
|
104
104
|
hasContractToDownload: false,
|
|
105
|
-
|
|
105
|
+
offeringId: faker.string.uuid(),
|
|
106
106
|
},
|
|
107
|
-
])('should only display sign button when $label', ({ hasContractToDownload,
|
|
107
|
+
])('should only display sign button when $label', ({ hasContractToDownload, offeringId }) => {
|
|
108
108
|
mockHasContractToDownload = hasContractToDownload;
|
|
109
109
|
mockCanSignContracts = true;
|
|
110
110
|
mockContractsToSignCount = 1;
|
|
111
111
|
|
|
112
112
|
render(
|
|
113
113
|
<Wrapper>
|
|
114
|
-
<ContractActionsBar
|
|
114
|
+
<ContractActionsBar offeringId={offeringId} organizationId={faker.string.uuid()} />
|
|
115
115
|
</Wrapper>,
|
|
116
116
|
);
|
|
117
117
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
|
-
import { Organization,
|
|
2
|
+
import { Organization, Offering } 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
|
+
offeringId?: Offering['id'];
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const ContractActionsBar = ({ organizationId,
|
|
13
|
+
const ContractActionsBar = ({ organizationId, offeringId }: ContractActionsProps) => {
|
|
14
14
|
const { canSignContracts, contractsToSignCount } = useTeacherContractsToSign({
|
|
15
15
|
organizationId,
|
|
16
|
-
|
|
16
|
+
offeringId,
|
|
17
17
|
});
|
|
18
|
-
const hasContractToDownload = useHasContractToDownload(organizationId,
|
|
18
|
+
const hasContractToDownload = useHasContractToDownload(organizationId, offeringId);
|
|
19
19
|
|
|
20
20
|
const nbAvailableActions = [canSignContracts, hasContractToDownload].filter((val) => val).length;
|
|
21
|
-
const
|
|
21
|
+
const offeringIds = offeringId ? [offeringId] : undefined;
|
|
22
22
|
return (
|
|
23
23
|
nbAvailableActions > 0 && (
|
|
24
24
|
<div
|
|
@@ -31,14 +31,14 @@ const ContractActionsBar = ({ organizationId, offerId }: ContractActionsProps) =
|
|
|
31
31
|
{canSignContracts && (
|
|
32
32
|
<div>
|
|
33
33
|
<SignOrganizationContractButton
|
|
34
|
-
|
|
34
|
+
offeringIds={offeringIds}
|
|
35
35
|
organizationId={organizationId}
|
|
36
36
|
contractToSignCount={contractsToSignCount}
|
|
37
37
|
/>
|
|
38
38
|
</div>
|
|
39
39
|
)}
|
|
40
40
|
{hasContractToDownload && (
|
|
41
|
-
<BulkDownloadContractButton organizationId={organizationId}
|
|
41
|
+
<BulkDownloadContractButton organizationId={organizationId} offeringId={offeringId} />
|
|
42
42
|
)}
|
|
43
43
|
</div>
|
|
44
44
|
)
|
|
@@ -70,19 +70,19 @@ describe('TeacherDashboardContractsLayout/SignOrganizationContractButton', () =>
|
|
|
70
70
|
{
|
|
71
71
|
label: "organization's contracts",
|
|
72
72
|
organizationId: faker.string.uuid(),
|
|
73
|
-
|
|
73
|
+
offeringIds: undefined,
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
76
|
label: "organization's training contracts",
|
|
77
77
|
organizationId: faker.string.uuid(),
|
|
78
|
-
|
|
78
|
+
offeringIds: [faker.string.uuid()],
|
|
79
79
|
},
|
|
80
|
-
])('should open $label frame on click', async ({ organizationId,
|
|
80
|
+
])('should open $label frame on click', async ({ organizationId, offeringIds }) => {
|
|
81
81
|
render(
|
|
82
82
|
<Wrapper>
|
|
83
83
|
<SignOrganizationContractButton
|
|
84
84
|
organizationId={organizationId}
|
|
85
|
-
|
|
85
|
+
offeringIds={offeringIds}
|
|
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 (offeringIds) {
|
|
96
|
+
getInvitationLinkUrl += `?offering_ids=${offeringIds[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 { Offering, 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
|
+
offeringIds?: Offering['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
|
+
offeringIds = [],
|
|
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
|
+
offeringIds={offeringIds}
|
|
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 { OfferingFactory, 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
|
+
offering: undefined,
|
|
45
45
|
},
|
|
46
46
|
{
|
|
47
47
|
testLabel: 'for a training in an organization',
|
|
48
48
|
organization: OrganizationFactory().one(),
|
|
49
|
-
|
|
49
|
+
offering: OfferingFactory().one(),
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
52
|
testLabel: 'for an organization',
|
|
53
53
|
organization: OrganizationFactory().one(),
|
|
54
|
-
|
|
54
|
+
offering: undefined,
|
|
55
55
|
},
|
|
56
56
|
{
|
|
57
57
|
testLabel: 'for a training',
|
|
58
58
|
organization: undefined,
|
|
59
|
-
|
|
59
|
+
offering: OfferingFactory().one(),
|
|
60
60
|
},
|
|
61
|
-
])('useCheckContractArchiveExists $testLabel', ({ organization,
|
|
61
|
+
])('useCheckContractArchiveExists $testLabel', ({ organization, offering }) => {
|
|
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
|
+
offeringId: offering ? offering.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 { Offering, 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
|
+
offeringId?: Offering['id'];
|
|
11
11
|
enable?: boolean;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const useCheckContractArchiveExist = (
|
|
15
|
-
{ organizationId,
|
|
15
|
+
{ organizationId, offeringId, 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
|
+
offeringId,
|
|
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, offeringId]);
|
|
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 { OfferingFactory, 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
|
+
offering: undefined,
|
|
18
18
|
existingOrganization: undefined,
|
|
19
|
-
|
|
19
|
+
existingOffering: undefined,
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
22
|
testLabel: 'for a training in an organization',
|
|
23
23
|
organization: OrganizationFactory().one(),
|
|
24
|
-
|
|
24
|
+
offering: OfferingFactory().one(),
|
|
25
25
|
existingOrganization: undefined,
|
|
26
|
-
|
|
26
|
+
existingOffering: undefined,
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
29
|
testLabel: 'for an organization',
|
|
30
30
|
organization: OrganizationFactory().one(),
|
|
31
|
-
|
|
31
|
+
offering: undefined,
|
|
32
32
|
existingOrganization: undefined,
|
|
33
|
-
|
|
33
|
+
existingOffering: undefined,
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
testLabel: 'for a training',
|
|
37
37
|
organization: undefined,
|
|
38
|
-
|
|
38
|
+
offering: OfferingFactory().one(),
|
|
39
39
|
existingOrganization: undefined,
|
|
40
|
-
|
|
40
|
+
existingOffering: 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
|
+
offering: undefined,
|
|
46
46
|
existingOrganization: OrganizationFactory().one(),
|
|
47
|
-
|
|
47
|
+
existingOffering: OfferingFactory().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
|
+
offering: OfferingFactory().one(),
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
55
|
testLabel: 'for an organization, with a other id already stored',
|
|
56
56
|
organization: OrganizationFactory().one(),
|
|
57
|
-
|
|
57
|
+
offering: undefined,
|
|
58
58
|
existingOrganization: OrganizationFactory().one(),
|
|
59
|
-
|
|
59
|
+
existingOffering: OfferingFactory().one(),
|
|
60
60
|
},
|
|
61
61
|
{
|
|
62
62
|
testLabel: 'for a training, with a other id already stored',
|
|
63
63
|
organization: undefined,
|
|
64
|
-
|
|
64
|
+
offering: OfferingFactory().one(),
|
|
65
65
|
existingOrganization: OrganizationFactory().one(),
|
|
66
|
-
|
|
66
|
+
existingOffering: OfferingFactory().one(),
|
|
67
67
|
},
|
|
68
68
|
|
|
69
69
|
{
|
|
@@ -72,11 +72,11 @@ describe.each([
|
|
|
72
72
|
{
|
|
73
73
|
testLabel: 'Testing with a other id already stored',
|
|
74
74
|
existingOrganization: OrganizationFactory().one(),
|
|
75
|
-
|
|
75
|
+
existingOffering: OfferingFactory().one(),
|
|
76
76
|
},
|
|
77
77
|
])(
|
|
78
78
|
'contractArchiveLocalStorage $testLabel',
|
|
79
|
-
({ organization,
|
|
79
|
+
({ organization, offering, existingOrganization, existingOffering }) => {
|
|
80
80
|
let localStorageArchiveFilters: LocalStorageArchiveFilters;
|
|
81
81
|
let localStorageExistingArchiveFilters: LocalStorageArchiveFilters;
|
|
82
82
|
let exsitingContractId: string;
|
|
@@ -84,15 +84,15 @@ describe.each([
|
|
|
84
84
|
beforeEach(() => {
|
|
85
85
|
localStorageArchiveFilters = {
|
|
86
86
|
organizationId: organization ? organization.id : undefined,
|
|
87
|
-
|
|
87
|
+
offeringId: offering ? offering.id : undefined,
|
|
88
88
|
};
|
|
89
89
|
localStorageExistingArchiveFilters = {
|
|
90
90
|
organizationId: existingOrganization ? existingOrganization.id : undefined,
|
|
91
|
-
|
|
91
|
+
offeringId: existingOffering ? existingOffering.id : undefined,
|
|
92
92
|
};
|
|
93
93
|
exsitingContractId = faker.string.uuid();
|
|
94
94
|
|
|
95
|
-
if (
|
|
95
|
+
if (existingOffering && existingOrganization) {
|
|
96
96
|
// everything should work fine with multiple archive stored
|
|
97
97
|
storeContractArchiveId({
|
|
98
98
|
...localStorageExistingArchiveFilters,
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { CONTRACT_DOWNLOAD_SETTINGS } from 'settings';
|
|
2
|
-
import {
|
|
2
|
+
import { Offering, Organization } from 'types/Joanie';
|
|
3
3
|
|
|
4
4
|
export interface LocalStorageArchiveFilters {
|
|
5
5
|
organizationId?: Organization['id'];
|
|
6
|
-
|
|
6
|
+
offeringId?: Offering['id'];
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
const generateLocalStorageKey = ({
|
|
10
|
-
|
|
9
|
+
const generateLocalStorageKey = ({
|
|
10
|
+
organizationId,
|
|
11
|
+
offeringId,
|
|
12
|
+
}: LocalStorageArchiveFilters = {}) => {
|
|
13
|
+
return `${CONTRACT_DOWNLOAD_SETTINGS.contractArchiveLocalStorageKey}::${organizationId ?? 'all'}::${offeringId ?? 'all'}`;
|
|
11
14
|
};
|
|
12
15
|
|
|
13
16
|
const generateLocalStorageId = (contractArchiveId: string) => {
|
|
@@ -17,27 +20,30 @@ const generateLocalStorageId = (contractArchiveId: string) => {
|
|
|
17
20
|
const storeContractArchiveId = ({
|
|
18
21
|
contractArchiveId,
|
|
19
22
|
organizationId,
|
|
20
|
-
|
|
23
|
+
offeringId,
|
|
21
24
|
}: {
|
|
22
25
|
contractArchiveId: string;
|
|
23
26
|
organizationId?: Organization['id'];
|
|
24
|
-
|
|
27
|
+
offeringId?: Offering['id'];
|
|
25
28
|
}) => {
|
|
26
29
|
localStorage.setItem(
|
|
27
|
-
generateLocalStorageKey({ organizationId,
|
|
30
|
+
generateLocalStorageKey({ organizationId, offeringId }),
|
|
28
31
|
generateLocalStorageId(contractArchiveId),
|
|
29
32
|
);
|
|
30
33
|
};
|
|
31
34
|
|
|
32
|
-
const unstoreContractArchiveId = ({
|
|
33
|
-
|
|
35
|
+
const unstoreContractArchiveId = ({
|
|
36
|
+
organizationId,
|
|
37
|
+
offeringId,
|
|
38
|
+
}: LocalStorageArchiveFilters = {}) => {
|
|
39
|
+
localStorage.removeItem(generateLocalStorageKey({ organizationId, offeringId }));
|
|
34
40
|
};
|
|
35
41
|
|
|
36
42
|
const getStoredContractArchiveId = ({
|
|
37
43
|
organizationId,
|
|
38
|
-
|
|
44
|
+
offeringId,
|
|
39
45
|
}: LocalStorageArchiveFilters = {}) => {
|
|
40
|
-
const value = localStorage.getItem(generateLocalStorageKey({ organizationId,
|
|
46
|
+
const value = localStorage.getItem(generateLocalStorageKey({ organizationId, offeringId }));
|
|
41
47
|
if (value === null) {
|
|
42
48
|
return value;
|
|
43
49
|
}
|
|
@@ -48,9 +54,9 @@ const getStoredContractArchiveId = ({
|
|
|
48
54
|
|
|
49
55
|
const isStoredContractArchiveIdExpired = ({
|
|
50
56
|
organizationId,
|
|
51
|
-
|
|
57
|
+
offeringId,
|
|
52
58
|
}: LocalStorageArchiveFilters = {}) => {
|
|
53
|
-
const value = localStorage.getItem(generateLocalStorageKey({ organizationId,
|
|
59
|
+
const value = localStorage.getItem(generateLocalStorageKey({ organizationId, offeringId }));
|
|
54
60
|
if (value === null) {
|
|
55
61
|
return false;
|
|
56
62
|
}
|
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 { OfferingFactory, 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
|
+
offering: undefined,
|
|
54
54
|
},
|
|
55
55
|
{
|
|
56
56
|
testLabel: 'for a training in an organization',
|
|
57
57
|
organization: OrganizationFactory().one(),
|
|
58
|
-
|
|
58
|
+
offering: OfferingFactory().one(),
|
|
59
59
|
},
|
|
60
60
|
{
|
|
61
61
|
testLabel: 'for an organization',
|
|
62
62
|
organization: OrganizationFactory().one(),
|
|
63
|
-
|
|
63
|
+
offering: undefined,
|
|
64
64
|
},
|
|
65
65
|
{
|
|
66
66
|
testLabel: 'for a training',
|
|
67
67
|
organization: undefined,
|
|
68
|
-
|
|
68
|
+
offering: OfferingFactory().one(),
|
|
69
69
|
},
|
|
70
|
-
])('useDownloadContractArchive $testLabel', ({ organization,
|
|
70
|
+
])('useDownloadContractArchive $testLabel', ({ organization, offering }) => {
|
|
71
71
|
let localStorageArchiveFilters: LocalStorageArchiveFilters;
|
|
72
72
|
|
|
73
73
|
beforeEach(() => {
|
|
74
74
|
localStorageArchiveFilters = {
|
|
75
75
|
organizationId: organization ? organization.id : undefined,
|
|
76
|
-
|
|
76
|
+
offeringId: offering ? offering.id : undefined,
|
|
77
77
|
};
|
|
78
78
|
});
|
|
79
79
|
|
|
@@ -97,20 +97,20 @@ describe.each([
|
|
|
97
97
|
{
|
|
98
98
|
testLabel: 'Testing with a other id already stored',
|
|
99
99
|
existingOrganization: OrganizationFactory().one(),
|
|
100
|
-
|
|
100
|
+
existingOffering: OfferingFactory().one(),
|
|
101
101
|
},
|
|
102
|
-
])('$testLabel', ({ existingOrganization,
|
|
102
|
+
])('$testLabel', ({ existingOrganization, existingOffering }) => {
|
|
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
|
-
|
|
109
|
+
offeringId: existingOffering ? existingOffering.id : undefined,
|
|
110
110
|
};
|
|
111
111
|
exsitingContractId = faker.string.uuid();
|
|
112
112
|
|
|
113
|
-
if (
|
|
113
|
+
if (existingOffering && existingOrganization) {
|
|
114
114
|
// everything should work fine with multiple archive stored
|
|
115
115
|
storeContractArchiveId({
|
|
116
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 { Offering, 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
|
+
offeringId?: Offering['id'];
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const useDownloadContractArchive = ({
|
|
26
26
|
organizationId,
|
|
27
|
-
|
|
27
|
+
offeringId,
|
|
28
28
|
}: UseTeacherContractsBulkDownloadProps) => {
|
|
29
29
|
const localstorageArchiveFilters = {
|
|
30
30
|
organizationId,
|
|
31
|
-
|
|
31
|
+
offeringId,
|
|
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, offeringId);
|
|
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, offeringId);
|
|
120
120
|
setContractArchiveId(newContractArchiveId);
|
|
121
121
|
storeContractArchiveId({
|
|
122
122
|
...localstorageArchiveFilters,
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { useOrganizationContracts } from 'hooks/useContracts';
|
|
2
2
|
import { PER_PAGE } from 'settings';
|
|
3
|
-
import { ContractState,
|
|
3
|
+
import { ContractState, Offering, Organization } from 'types/Joanie';
|
|
4
4
|
|
|
5
|
-
const useHasContractToDownload = (
|
|
5
|
+
const useHasContractToDownload = (
|
|
6
|
+
organizationId?: Organization['id'],
|
|
7
|
+
offeringId?: Offering['id'],
|
|
8
|
+
) => {
|
|
6
9
|
const {
|
|
7
10
|
items: contracts,
|
|
8
11
|
states: { isFetched },
|
|
9
12
|
} = useOrganizationContracts({
|
|
10
13
|
organization_id: organizationId,
|
|
11
|
-
|
|
14
|
+
offering_id: offeringId,
|
|
12
15
|
signature_state: ContractState.SIGNED,
|
|
13
16
|
page: 1,
|
|
14
17
|
page_size: PER_PAGE.teacherContractList,
|