richie-education 3.1.3-dev11 → 3.1.3-dev15
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/GenericSaleTunnel.tsx +3 -10
- 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 -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 +25 -22
- 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 -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 +10 -18
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.spec.tsx +81 -99
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.stories.tsx +6 -4
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.tsx +20 -31
- package/js/widgets/SyllabusCourseRunsList/index.spec.tsx +8 -8
- package/package.json +1 -1
- package/js/hooks/useCourseProductRelation/index.ts +0 -44
|
@@ -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,
|
package/js/pages/TeacherDashboardContractsLayout/hooks/useTeacherContractFilters/index.spec.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import { MemoryRouter, Route, Routes } from 'react-router';
|
|
|
7
7
|
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
|
|
8
8
|
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
|
|
9
9
|
import JoanieSessionProvider from 'contexts/SessionContext/JoanieSessionProvider';
|
|
10
|
-
import {
|
|
10
|
+
import { OfferFactory, OrganizationFactory } from 'utils/test/factories/joanie';
|
|
11
11
|
import { ContractState } from 'types/Joanie';
|
|
12
12
|
import useTeacherContractFilters from '.';
|
|
13
13
|
|
|
@@ -67,13 +67,13 @@ describe('useTeacherContractFilters', () => {
|
|
|
67
67
|
expect(result.current.initialFilters).toStrictEqual({
|
|
68
68
|
contract_ids: [],
|
|
69
69
|
organization_id: defaultOrganization.id,
|
|
70
|
-
|
|
70
|
+
offer_id: undefined,
|
|
71
71
|
signature_state: ContractState.SIGNED,
|
|
72
72
|
});
|
|
73
73
|
expect(result.current.filters).toStrictEqual({
|
|
74
74
|
contract_ids: [],
|
|
75
75
|
organization_id: defaultOrganization.id,
|
|
76
|
-
|
|
76
|
+
offer_id: undefined,
|
|
77
77
|
signature_state: ContractState.SIGNED,
|
|
78
78
|
});
|
|
79
79
|
});
|
|
@@ -83,7 +83,7 @@ describe('useTeacherContractFilters', () => {
|
|
|
83
83
|
const defaultOrganization = OrganizationFactory({ id: 'default' }).one();
|
|
84
84
|
const filteredOrganization = OrganizationFactory({ id: 'filtered' }).one();
|
|
85
85
|
const routeOrganization = OrganizationFactory({ id: 'route' }).one();
|
|
86
|
-
const
|
|
86
|
+
const routeOffer = OfferFactory().one();
|
|
87
87
|
// fetching user's organizations to initialize default organizationId.
|
|
88
88
|
fetchMock.get('https://joanie.test/api/v1.0/organizations/', [
|
|
89
89
|
defaultOrganization,
|
|
@@ -92,8 +92,8 @@ describe('useTeacherContractFilters', () => {
|
|
|
92
92
|
const { result } = renderHook(useTeacherContractFilters, {
|
|
93
93
|
wrapper: ({ children }) => (
|
|
94
94
|
<Wrapper
|
|
95
|
-
routePath="/:organizationId/:
|
|
96
|
-
initialEntry={`/${routeOrganization.id}/${
|
|
95
|
+
routePath="/:organizationId/:offerId"
|
|
96
|
+
initialEntry={`/${routeOrganization.id}/${routeOffer.id}?organization_id=${filteredOrganization.id}&signature_state=${ContractState?.UNSIGNED}&contract_ids=1&contract_ids=2`}
|
|
97
97
|
>
|
|
98
98
|
{children}
|
|
99
99
|
</Wrapper>
|
|
@@ -104,13 +104,13 @@ describe('useTeacherContractFilters', () => {
|
|
|
104
104
|
expect(result.current.initialFilters).toStrictEqual({
|
|
105
105
|
contract_ids: ['1', '2'],
|
|
106
106
|
organization_id: routeOrganization.id,
|
|
107
|
-
|
|
107
|
+
offer_id: routeOffer.id,
|
|
108
108
|
signature_state: ContractState.UNSIGNED,
|
|
109
109
|
});
|
|
110
110
|
expect(result.current.filters).toStrictEqual({
|
|
111
111
|
contract_ids: ['1', '2'],
|
|
112
112
|
organization_id: routeOrganization.id,
|
|
113
|
-
|
|
113
|
+
offer_id: routeOffer.id,
|
|
114
114
|
signature_state: ContractState.UNSIGNED,
|
|
115
115
|
});
|
|
116
116
|
});
|
|
@@ -119,7 +119,7 @@ describe('useTeacherContractFilters', () => {
|
|
|
119
119
|
it("should use organizationId from query parameters when it's not in route params", async () => {
|
|
120
120
|
const defaultOrganization = OrganizationFactory({ id: 'default' }).one();
|
|
121
121
|
const filteredOrganization = OrganizationFactory({ id: 'filtered' }).one();
|
|
122
|
-
const
|
|
122
|
+
const routeOffer = OfferFactory({ id: 'route' }).one();
|
|
123
123
|
// fetching user's organizations to initialize default organizationId.
|
|
124
124
|
fetchMock.get('https://joanie.test/api/v1.0/organizations/', [
|
|
125
125
|
defaultOrganization,
|
|
@@ -128,8 +128,8 @@ describe('useTeacherContractFilters', () => {
|
|
|
128
128
|
const { result } = renderHook(useTeacherContractFilters, {
|
|
129
129
|
wrapper: ({ children }) => (
|
|
130
130
|
<Wrapper
|
|
131
|
-
routePath="/:
|
|
132
|
-
initialEntry={`/${
|
|
131
|
+
routePath="/:offerId"
|
|
132
|
+
initialEntry={`/${routeOffer.id}/?organization_id=${filteredOrganization.id}&signature_state=${ContractState?.UNSIGNED}&contract_ids=1&contract_ids=2`}
|
|
133
133
|
>
|
|
134
134
|
{children}
|
|
135
135
|
</Wrapper>
|
|
@@ -140,13 +140,13 @@ describe('useTeacherContractFilters', () => {
|
|
|
140
140
|
expect(result.current.initialFilters).toStrictEqual({
|
|
141
141
|
contract_ids: ['1', '2'],
|
|
142
142
|
organization_id: filteredOrganization.id,
|
|
143
|
-
|
|
143
|
+
offer_id: routeOffer.id,
|
|
144
144
|
signature_state: ContractState.UNSIGNED,
|
|
145
145
|
});
|
|
146
146
|
expect(result.current.filters).toStrictEqual({
|
|
147
147
|
contract_ids: ['1', '2'],
|
|
148
148
|
organization_id: filteredOrganization.id,
|
|
149
|
-
|
|
149
|
+
offer_id: routeOffer.id,
|
|
150
150
|
signature_state: ContractState.UNSIGNED,
|
|
151
151
|
});
|
|
152
152
|
});
|
|
@@ -155,7 +155,7 @@ describe('useTeacherContractFilters', () => {
|
|
|
155
155
|
it('setFilters should update filter state', async () => {
|
|
156
156
|
const defaultOrganization = OrganizationFactory({ id: 'default' }).one();
|
|
157
157
|
const routeOrganization = OrganizationFactory({ id: 'route' }).one();
|
|
158
|
-
const
|
|
158
|
+
const routeOffer = OfferFactory().one();
|
|
159
159
|
// fetching user's organizations to initialize default organizationId.
|
|
160
160
|
fetchMock.get('https://joanie.test/api/v1.0/organizations/', [defaultOrganization]);
|
|
161
161
|
const { result } = renderHook(useTeacherContractFilters, {
|
|
@@ -169,7 +169,7 @@ describe('useTeacherContractFilters', () => {
|
|
|
169
169
|
const expectedInitialFilters = {
|
|
170
170
|
contract_ids: [],
|
|
171
171
|
organization_id: defaultOrganization.id,
|
|
172
|
-
|
|
172
|
+
offer_id: undefined,
|
|
173
173
|
signature_state: ContractState.SIGNED,
|
|
174
174
|
};
|
|
175
175
|
await waitFor(() => {
|
|
@@ -179,7 +179,7 @@ describe('useTeacherContractFilters', () => {
|
|
|
179
179
|
const newFilters = {
|
|
180
180
|
contract_ids: ['1', '2'],
|
|
181
181
|
organization_id: routeOrganization.id,
|
|
182
|
-
|
|
182
|
+
offer_id: routeOffer.id,
|
|
183
183
|
signature_state: ContractState.UNSIGNED,
|
|
184
184
|
};
|
|
185
185
|
act(() => {
|
|
@@ -5,16 +5,16 @@ import { ContractResourceQuery, ContractState } from 'types/Joanie';
|
|
|
5
5
|
|
|
6
6
|
export type TeacherDashboardContractsParams = {
|
|
7
7
|
organizationId?: string;
|
|
8
|
-
|
|
8
|
+
offerId?: string;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
const useTeacherContractFilters = () => {
|
|
12
|
-
const {
|
|
12
|
+
const { offerId } = useParams<TeacherDashboardContractsParams>();
|
|
13
13
|
const [searchParams] = useSearchParams();
|
|
14
14
|
const searchFilters: ContractResourceQuery = useMemo(() => {
|
|
15
15
|
return {
|
|
16
16
|
organization_id: searchParams.get('organization_id') || undefined,
|
|
17
|
-
|
|
17
|
+
offer_id: searchParams.get('offer_id') || undefined,
|
|
18
18
|
contract_ids: searchParams.getAll('contract_ids') || undefined,
|
|
19
19
|
signature_state:
|
|
20
20
|
(searchParams.get('signature_state') as ContractState) || ContractState.SIGNED,
|
|
@@ -28,7 +28,7 @@ const useTeacherContractFilters = () => {
|
|
|
28
28
|
return {
|
|
29
29
|
...searchFilters,
|
|
30
30
|
organization_id: defaultOrganizationId,
|
|
31
|
-
|
|
31
|
+
offer_id: offerId,
|
|
32
32
|
};
|
|
33
33
|
}, [defaultOrganizationId]);
|
|
34
34
|
const [filters, setFilters] = useState<ContractResourceQuery>(initialFilters);
|
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import useContractAbilities from 'hooks/useContractAbilities';
|
|
2
2
|
import { useOrganizationContracts } from 'hooks/useContracts';
|
|
3
|
-
import { ContractState, Organization,
|
|
3
|
+
import { ContractState, Organization, Offer } from 'types/Joanie';
|
|
4
4
|
import { ContractActions } from 'utils/AbilitiesHelper/types';
|
|
5
5
|
|
|
6
6
|
interface UseTeacherContractsToSignProps {
|
|
7
7
|
organizationId?: Organization['id'];
|
|
8
|
-
|
|
8
|
+
offerId?: Offer['id'];
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
const useTeacherContractsToSign = ({
|
|
12
|
-
organizationId,
|
|
13
|
-
courseProductRelationId,
|
|
14
|
-
}: UseTeacherContractsToSignProps) => {
|
|
11
|
+
const useTeacherContractsToSign = ({ organizationId, offerId }: UseTeacherContractsToSignProps) => {
|
|
15
12
|
const { items: contractsToSign, meta: contractsToSignMeta } = useOrganizationContracts(
|
|
16
13
|
{
|
|
17
14
|
signature_state: ContractState.LEARNER_SIGNED,
|
|
18
15
|
organization_id: organizationId,
|
|
19
|
-
|
|
16
|
+
offer_id: offerId,
|
|
20
17
|
},
|
|
21
18
|
{ enabled: !!organizationId },
|
|
22
19
|
);
|
package/js/pages/TeacherDashboardCourseLearnersLayout/hooks/useCourseLearnersFilters/index.spec.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fetchMock from 'fetch-mock';
|
|
2
2
|
import { renderHook, waitFor, act } from '@testing-library/react';
|
|
3
3
|
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
|
|
4
|
-
import {
|
|
4
|
+
import { OfferFactory, OrganizationFactory } from 'utils/test/factories/joanie';
|
|
5
5
|
import { JoanieAppWrapper, setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper';
|
|
6
6
|
import useCourseLearnersFilters from '.';
|
|
7
7
|
|
|
@@ -32,12 +32,12 @@ describe('useCourseLearnersFilters', () => {
|
|
|
32
32
|
expect(result.current.initialFilters).toStrictEqual({
|
|
33
33
|
organization_id: undefined,
|
|
34
34
|
course_id: undefined,
|
|
35
|
-
|
|
35
|
+
offer_id: undefined,
|
|
36
36
|
});
|
|
37
37
|
expect(result.current.filters).toStrictEqual({
|
|
38
38
|
organization_id: undefined,
|
|
39
39
|
course_id: undefined,
|
|
40
|
-
|
|
40
|
+
offer_id: undefined,
|
|
41
41
|
});
|
|
42
42
|
});
|
|
43
43
|
});
|
|
@@ -46,7 +46,7 @@ describe('useCourseLearnersFilters', () => {
|
|
|
46
46
|
const defaultOrganization = OrganizationFactory().one();
|
|
47
47
|
const filteredOrganization = OrganizationFactory({ id: 'filtered' }).one();
|
|
48
48
|
const routeOrganization = OrganizationFactory({ id: 'route' }).one();
|
|
49
|
-
const
|
|
49
|
+
const routeOffer = OfferFactory().one();
|
|
50
50
|
// fetching user's organizations to initialize default organizationId.
|
|
51
51
|
fetchMock.get('https://joanie.endpoint/api/v1.0/organizations/', [
|
|
52
52
|
defaultOrganization,
|
|
@@ -56,9 +56,9 @@ describe('useCourseLearnersFilters', () => {
|
|
|
56
56
|
wrapper: ({ children }) => (
|
|
57
57
|
<JoanieAppWrapper
|
|
58
58
|
routerOptions={{
|
|
59
|
-
path: '/:organizationId/:courseId/:
|
|
59
|
+
path: '/:organizationId/:courseId/:offerId',
|
|
60
60
|
initialEntries: [
|
|
61
|
-
`/${routeOrganization.id}/${
|
|
61
|
+
`/${routeOrganization.id}/${routeOffer.course.id}/${routeOffer.id}?organization_id=${filteredOrganization.id}`,
|
|
62
62
|
],
|
|
63
63
|
}}
|
|
64
64
|
>
|
|
@@ -70,13 +70,13 @@ describe('useCourseLearnersFilters', () => {
|
|
|
70
70
|
await waitFor(() => {
|
|
71
71
|
expect(result.current.initialFilters).toStrictEqual({
|
|
72
72
|
organization_id: routeOrganization.id,
|
|
73
|
-
course_id:
|
|
74
|
-
|
|
73
|
+
course_id: routeOffer.course.id,
|
|
74
|
+
offer_id: routeOffer.id,
|
|
75
75
|
});
|
|
76
76
|
expect(result.current.filters).toStrictEqual({
|
|
77
77
|
organization_id: routeOrganization.id,
|
|
78
|
-
course_id:
|
|
79
|
-
|
|
78
|
+
course_id: routeOffer.course.id,
|
|
79
|
+
offer_id: routeOffer.id,
|
|
80
80
|
});
|
|
81
81
|
});
|
|
82
82
|
});
|
|
@@ -84,7 +84,7 @@ describe('useCourseLearnersFilters', () => {
|
|
|
84
84
|
it("should use organizationId from query parameters when it's not in route params", async () => {
|
|
85
85
|
const defaultOrganization = OrganizationFactory().one();
|
|
86
86
|
const filteredOrganization = OrganizationFactory({ id: 'filtered' }).one();
|
|
87
|
-
const
|
|
87
|
+
const routeOffer = OfferFactory({ id: 'route' }).one();
|
|
88
88
|
// fetching user's organizations to initialize default organizationId.
|
|
89
89
|
fetchMock.get('https://joanie.endpoint/api/v1.0/organizations/', [
|
|
90
90
|
defaultOrganization,
|
|
@@ -94,9 +94,9 @@ describe('useCourseLearnersFilters', () => {
|
|
|
94
94
|
wrapper: ({ children }) => (
|
|
95
95
|
<JoanieAppWrapper
|
|
96
96
|
routerOptions={{
|
|
97
|
-
path: '/:courseId/:
|
|
97
|
+
path: '/:courseId/:offerId',
|
|
98
98
|
initialEntries: [
|
|
99
|
-
`/${
|
|
99
|
+
`/${routeOffer.course.id}/${routeOffer.id}/?organization_id=${filteredOrganization.id}`,
|
|
100
100
|
],
|
|
101
101
|
}}
|
|
102
102
|
>
|
|
@@ -108,13 +108,13 @@ describe('useCourseLearnersFilters', () => {
|
|
|
108
108
|
await waitFor(() => {
|
|
109
109
|
expect(result.current.initialFilters).toStrictEqual({
|
|
110
110
|
organization_id: filteredOrganization.id,
|
|
111
|
-
course_id:
|
|
112
|
-
|
|
111
|
+
course_id: routeOffer.course.id,
|
|
112
|
+
offer_id: routeOffer.id,
|
|
113
113
|
});
|
|
114
114
|
expect(result.current.filters).toStrictEqual({
|
|
115
115
|
organization_id: filteredOrganization.id,
|
|
116
|
-
course_id:
|
|
117
|
-
|
|
116
|
+
course_id: routeOffer.course.id,
|
|
117
|
+
offer_id: routeOffer.id,
|
|
118
118
|
});
|
|
119
119
|
});
|
|
120
120
|
});
|
|
@@ -122,7 +122,7 @@ describe('useCourseLearnersFilters', () => {
|
|
|
122
122
|
it('setFilters should update filter state', async () => {
|
|
123
123
|
const defaultOrganization = OrganizationFactory({ id: 'all' }).one();
|
|
124
124
|
const routeOrganization = OrganizationFactory({ id: 'route' }).one();
|
|
125
|
-
const
|
|
125
|
+
const routeOffer = OfferFactory().one();
|
|
126
126
|
// fetching user's organizations to initialize default organizationId.
|
|
127
127
|
fetchMock.get('https://joanie.endpoint/api/v1.0/organizations/', [defaultOrganization]);
|
|
128
128
|
const { result } = renderHook(useCourseLearnersFilters, {
|
|
@@ -136,7 +136,7 @@ describe('useCourseLearnersFilters', () => {
|
|
|
136
136
|
const expectedInitialFilters = {
|
|
137
137
|
organization_id: defaultOrganization.id,
|
|
138
138
|
course_id: undefined,
|
|
139
|
-
|
|
139
|
+
offer_id: undefined,
|
|
140
140
|
};
|
|
141
141
|
await waitFor(() => {
|
|
142
142
|
expect(result.current.initialFilters).toStrictEqual(expectedInitialFilters);
|
|
@@ -144,8 +144,8 @@ describe('useCourseLearnersFilters', () => {
|
|
|
144
144
|
|
|
145
145
|
const newFilters = {
|
|
146
146
|
organization_id: routeOrganization.id,
|
|
147
|
-
course_id:
|
|
148
|
-
|
|
147
|
+
course_id: routeOffer.course.id,
|
|
148
|
+
offer_id: routeOffer.id,
|
|
149
149
|
};
|
|
150
150
|
act(() => {
|
|
151
151
|
result.current.setFilters(newFilters);
|
package/js/pages/TeacherDashboardCourseLearnersLayout/hooks/useCourseLearnersFilters/index.ts
CHANGED
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { useParams, useSearchParams } from 'react-router';
|
|
3
3
|
import useDefaultOrganizationId from 'hooks/useDefaultOrganizationId';
|
|
4
|
-
import {
|
|
5
|
-
CourseListItem,
|
|
6
|
-
CourseOrderResourceQuery,
|
|
7
|
-
CourseProductRelation,
|
|
8
|
-
Organization,
|
|
9
|
-
} from 'types/Joanie';
|
|
4
|
+
import { CourseListItem, CourseOrderResourceQuery, Offer, Organization } from 'types/Joanie';
|
|
10
5
|
|
|
11
6
|
export type CourseLearnersParams = {
|
|
12
7
|
courseId: CourseListItem['id'];
|
|
13
|
-
|
|
8
|
+
offerId?: Offer['id'];
|
|
14
9
|
organizationId?: Organization['id'];
|
|
15
10
|
};
|
|
16
11
|
|
|
17
12
|
const useCourseLearnersFilters = () => {
|
|
18
|
-
const { courseId,
|
|
13
|
+
const { courseId, offerId } = useParams<CourseLearnersParams>();
|
|
19
14
|
const [searchParams] = useSearchParams();
|
|
20
15
|
const searchFilters: CourseOrderResourceQuery = useMemo(() => {
|
|
21
16
|
return {
|
|
22
17
|
course_id: courseId,
|
|
23
18
|
organization_id: searchParams.get('organization_id') || undefined,
|
|
24
|
-
|
|
19
|
+
offer_id: searchParams.get('offer_id') || undefined,
|
|
25
20
|
};
|
|
26
21
|
}, Array.from(searchParams.entries()));
|
|
27
22
|
|
|
@@ -32,7 +27,7 @@ const useCourseLearnersFilters = () => {
|
|
|
32
27
|
return {
|
|
33
28
|
...searchFilters,
|
|
34
29
|
organization_id: defaultOrganizationId,
|
|
35
|
-
|
|
30
|
+
offer_id: offerId,
|
|
36
31
|
};
|
|
37
32
|
}, [defaultOrganizationId]);
|
|
38
33
|
const [filters, setFilters] = useState<CourseOrderResourceQuery>(initialFilters);
|