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.
Files changed (73) hide show
  1. package/js/api/joanie.ts +8 -8
  2. package/js/components/ContractFrame/OrganizationContractFrame.spec.tsx +11 -20
  3. package/js/components/ContractFrame/OrganizationContractFrame.tsx +4 -4
  4. package/js/components/CourseGlimpse/utils.ts +22 -35
  5. package/js/components/CourseGlimpseList/utils.ts +2 -2
  6. package/js/components/PurchaseButton/index.tsx +3 -3
  7. package/js/components/SaleTunnel/GenericSaleTunnel.tsx +3 -10
  8. package/js/components/SaleTunnel/SaleTunnelInformation/index.tsx +5 -3
  9. package/js/components/SaleTunnel/index.full-process.spec.tsx +3 -3
  10. package/js/components/SaleTunnel/index.spec.tsx +76 -63
  11. package/js/components/SaleTunnel/index.tsx +2 -2
  12. package/js/components/TeacherDashboardCourseList/index.spec.tsx +3 -3
  13. package/js/components/TeacherDashboardCourseList/index.tsx +2 -2
  14. package/js/hooks/useContractArchive/index.ts +3 -3
  15. package/js/hooks/useCourseProductUnion/index.spec.tsx +16 -18
  16. package/js/hooks/useCourseProductUnion/index.ts +7 -7
  17. package/js/hooks/useCourseProducts.ts +4 -8
  18. package/js/hooks/useDefaultOrganizationId/index.tsx +4 -7
  19. package/js/hooks/useOffer/index.ts +32 -0
  20. package/js/hooks/useTeacherCoursesSearch/index.tsx +4 -4
  21. package/js/hooks/useTeacherPendingContractsCount/index.ts +4 -4
  22. package/js/pages/DashboardCourses/index.spec.tsx +14 -17
  23. package/js/pages/TeacherDashboardContractsLayout/TeacherDashboardContracts/index.spec.tsx +8 -14
  24. package/js/pages/TeacherDashboardContractsLayout/TeacherDashboardContracts/index.tsx +4 -12
  25. package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.spec.tsx +11 -11
  26. package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.timer.spec.tsx +10 -13
  27. package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.tsx +4 -4
  28. package/js/pages/TeacherDashboardContractsLayout/components/ContractActionsBar/index.spec.tsx +20 -28
  29. package/js/pages/TeacherDashboardContractsLayout/components/ContractActionsBar/index.tsx +8 -11
  30. package/js/pages/TeacherDashboardContractsLayout/components/SignOrganizationContractButton/index.spec.tsx +6 -6
  31. package/js/pages/TeacherDashboardContractsLayout/components/SignOrganizationContractButton/index.tsx +4 -4
  32. package/js/pages/TeacherDashboardContractsLayout/hooks/useCheckContractArchiveExists/index.spec.tsx +7 -7
  33. package/js/pages/TeacherDashboardContractsLayout/hooks/useCheckContractArchiveExists/index.tsx +5 -5
  34. package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/contractArchiveLocalStorage.spec.ts +21 -28
  35. package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/contractArchiveLocalStorage.ts +13 -23
  36. package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/index.spec.tsx +11 -13
  37. package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/index.tsx +6 -6
  38. package/js/pages/TeacherDashboardContractsLayout/hooks/useHasContractToDownload/index.tsx +3 -6
  39. package/js/pages/TeacherDashboardContractsLayout/hooks/useTeacherContractFilters/index.spec.tsx +16 -16
  40. package/js/pages/TeacherDashboardContractsLayout/hooks/useTeacherContractFilters/index.tsx +4 -4
  41. package/js/pages/TeacherDashboardContractsLayout/hooks/useTeacherContractsToSign.tsx +4 -7
  42. package/js/pages/TeacherDashboardCourseLearnersLayout/hooks/useCourseLearnersFilters/index.spec.tsx +21 -21
  43. package/js/pages/TeacherDashboardCourseLearnersLayout/hooks/useCourseLearnersFilters/index.ts +5 -10
  44. package/js/pages/TeacherDashboardCourseLearnersLayout/index.spec.tsx +61 -79
  45. package/js/pages/TeacherDashboardCourseLearnersLayout/index.tsx +1 -1
  46. package/js/pages/TeacherDashboardCoursesLoader/index.spec.tsx +11 -11
  47. package/js/pages/TeacherDashboardOrganizationCourseLoader/index.spec.tsx +11 -11
  48. package/js/pages/TeacherDashboardTraining/TeacherDashboardTrainingLoader.tsx +7 -7
  49. package/js/pages/TeacherDashboardTraining/index.spec.tsx +25 -33
  50. package/js/pages/TeacherDashboardTraining/index.tsx +12 -20
  51. package/js/types/Joanie.ts +25 -22
  52. package/js/utils/test/factories/joanie.ts +14 -11
  53. package/js/utils/test/mockCourseProductWithOrder.ts +4 -4
  54. package/js/widgets/Dashboard/components/DashboardItem/Enrollment/DashboardItemEnrollment.tsx +1 -1
  55. package/js/widgets/Dashboard/components/DashboardItem/Enrollment/ProductCertificateFooter/index.spec.tsx +1 -1
  56. package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemOrder.tsx +3 -3
  57. package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemOrderContract.useUnionResource.cache.spec.tsx +1 -1
  58. package/js/widgets/Dashboard/components/DashboardItem/Order/Installment/index.tsx +4 -4
  59. package/js/widgets/Dashboard/components/DashboardItem/stories.mock.ts +1 -1
  60. package/js/widgets/Dashboard/components/DashboardSidebar/components/ContractNavLink/index.spec.tsx +23 -28
  61. package/js/widgets/Dashboard/components/DashboardSidebar/components/ContractNavLink/index.tsx +4 -8
  62. package/js/widgets/Dashboard/components/TeacherDashboardCourseSidebar/index.spec.tsx +17 -27
  63. package/js/widgets/Dashboard/components/TeacherDashboardCourseSidebar/index.tsx +16 -25
  64. package/js/widgets/Dashboard/components/TeacherDashboardCourseSidebar/utils.ts +4 -4
  65. package/js/widgets/Dashboard/components/TeacherDashboardOrganizationSidebar/index.tsx +3 -7
  66. package/js/widgets/Dashboard/utils/teacherDashboardPaths.tsx +4 -4
  67. package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/CourseProductItemFooter/index.tsx +10 -18
  68. package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.spec.tsx +81 -99
  69. package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.stories.tsx +6 -4
  70. package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.tsx +20 -31
  71. package/js/widgets/SyllabusCourseRunsList/index.spec.tsx +8 -8
  72. package/package.json +1 -1
  73. package/js/hooks/useCourseProductRelation/index.ts +0 -44
@@ -14,7 +14,7 @@ import {
14
14
  unstoreContractArchiveId,
15
15
  } from 'pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/contractArchiveLocalStorage';
16
16
  import { CONTRACT_DOWNLOAD_SETTINGS } from 'settings';
17
- import { CourseProductRelationFactory, OrganizationFactory } from 'utils/test/factories/joanie';
17
+ import { OfferFactory, OrganizationFactory } from 'utils/test/factories/joanie';
18
18
  import BulkDownloadContractButton from '.';
19
19
 
20
20
  jest.mock('utils/context', () => ({
@@ -45,26 +45,26 @@ describe.each([
45
45
  {
46
46
  testLabel: 'for all organization and all trainings',
47
47
  organization: undefined,
48
- courseProductRelation: undefined,
48
+ offer: undefined,
49
49
  },
50
50
  {
51
51
  testLabel: 'for a training in an organization',
52
52
  organization: OrganizationFactory().one(),
53
- courseProductRelation: CourseProductRelationFactory().one(),
53
+ offer: OfferFactory().one(),
54
54
  },
55
55
  {
56
56
  testLabel: 'for an organization',
57
57
  organization: OrganizationFactory().one(),
58
- courseProductRelation: undefined,
58
+ offer: undefined,
59
59
  },
60
60
  {
61
61
  testLabel: 'for a training',
62
62
  organization: undefined,
63
- courseProductRelation: CourseProductRelationFactory().one(),
63
+ offer: OfferFactory().one(),
64
64
  },
65
65
  ])(
66
66
  'TeacherDashboardContractsLayout/BulkDownloadContractButton with fake timer, $testLabel',
67
- ({ organization, courseProductRelation }) => {
67
+ ({ organization, offer }) => {
68
68
  let localStorageArchiveFilters: LocalStorageArchiveFilters;
69
69
 
70
70
  const Wrapper = ({ children }: PropsWithChildren) => {
@@ -81,7 +81,7 @@ describe.each([
81
81
  beforeEach(() => {
82
82
  localStorageArchiveFilters = {
83
83
  organizationId: organization ? organization.id : undefined,
84
- courseProductRelationId: courseProductRelation ? courseProductRelation.id : undefined,
84
+ offerId: offer ? offer.id : undefined,
85
85
  };
86
86
  mockHasContractToDownload = true;
87
87
 
@@ -102,7 +102,7 @@ describe.each([
102
102
  jest.clearAllMocks();
103
103
  unstoreContractArchiveId({
104
104
  organizationId: organization ? organization.id : undefined,
105
- courseProductRelationId: courseProductRelation ? courseProductRelation.id : undefined,
105
+ offerId: offer ? offer.id : undefined,
106
106
  });
107
107
  });
108
108
 
@@ -114,7 +114,7 @@ describe.each([
114
114
  <Wrapper>
115
115
  <BulkDownloadContractButton
116
116
  organizationId={organization?.id ?? undefined}
117
- courseProductRelationId={courseProductRelation?.id ?? undefined}
117
+ offerId={offer?.id ?? undefined}
118
118
  />
119
119
  </Wrapper>,
120
120
  );
@@ -151,10 +151,7 @@ describe.each([
151
151
 
152
152
  render(
153
153
  <Wrapper>
154
- <BulkDownloadContractButton
155
- organizationId={organization?.id}
156
- courseProductRelationId={courseProductRelation?.id}
157
- />
154
+ <BulkDownloadContractButton organizationId={organization?.id} offerId={offer?.id} />
158
155
  </Wrapper>,
159
156
  );
160
157
 
@@ -4,7 +4,7 @@ import { useEffect } from 'react';
4
4
  import useDownloadContractArchive, {
5
5
  ContractDownloadStatus,
6
6
  } from 'pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive';
7
- import { CourseProductRelation, Organization } from 'types/Joanie';
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
- courseProductRelationId?: CourseProductRelation['id'];
29
+ offerId?: Offer['id'];
30
30
  }
31
31
 
32
32
  const BulkDownloadContractButton = ({
33
33
  organizationId,
34
- courseProductRelationId,
34
+ offerId,
35
35
  }: BulkDownloadContractButtonProps) => {
36
36
  const { downloadContractArchive, createContractArchive, status } = useDownloadContractArchive({
37
37
  organizationId,
38
- courseProductRelationId,
38
+ offerId,
39
39
  });
40
40
 
41
41
  useEffect(() => {
@@ -97,38 +97,30 @@ describe('TeacherDashboardContractsLayout/ContractActionsBar', () => {
97
97
  {
98
98
  label: "doesn't have contract to download",
99
99
  hasContractToDownload: false,
100
- courseProductRelationId: undefined,
100
+ offerId: undefined,
101
101
  },
102
102
  {
103
- label: "doesn't have contract to download and courseProductRelationId",
103
+ label: "doesn't have contract to download and offerId",
104
104
  hasContractToDownload: false,
105
- courseProductRelationId: faker.string.uuid(),
105
+ offerId: faker.string.uuid(),
106
106
  },
107
- ])(
108
- 'should only display sign button when $label',
109
- ({ hasContractToDownload, courseProductRelationId }) => {
110
- mockHasContractToDownload = hasContractToDownload;
111
- mockCanSignContracts = true;
112
- mockContractsToSignCount = 1;
113
-
114
- render(
115
- <Wrapper>
116
- <ContractActionsBar
117
- courseProductRelationId={courseProductRelationId}
118
- organizationId={faker.string.uuid()}
119
- />
120
- </Wrapper>,
121
- );
122
-
123
- expect(screen.getByTestId('teacher-contracts-list-actionsBar')).toBeInTheDocument();
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, CourseProductRelation } from 'types/Joanie';
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
- courseProductRelationId?: CourseProductRelation['id'];
10
+ offerId?: Offer['id'];
11
11
  }
12
12
 
13
- const ContractActionsBar = ({ organizationId, courseProductRelationId }: ContractActionsProps) => {
13
+ const ContractActionsBar = ({ organizationId, offerId }: ContractActionsProps) => {
14
14
  const { canSignContracts, contractsToSignCount } = useTeacherContractsToSign({
15
15
  organizationId,
16
- courseProductRelationId,
16
+ offerId,
17
17
  });
18
- const hasContractToDownload = useHasContractToDownload(organizationId, courseProductRelationId);
18
+ const hasContractToDownload = useHasContractToDownload(organizationId, offerId);
19
19
 
20
20
  const nbAvailableActions = [canSignContracts, hasContractToDownload].filter((val) => val).length;
21
- const courseProductRelationIds = courseProductRelationId ? [courseProductRelationId] : undefined;
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
- courseProductRelationIds={courseProductRelationIds}
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
- courseProductRelationIds: undefined,
73
+ offerIds: undefined,
74
74
  },
75
75
  {
76
76
  label: "organization's training contracts",
77
77
  organizationId: faker.string.uuid(),
78
- courseProductRelationIds: [faker.string.uuid()],
78
+ offerIds: [faker.string.uuid()],
79
79
  },
80
- ])('should open $label frame on click', async ({ organizationId, courseProductRelationIds }) => {
80
+ ])('should open $label frame on click', async ({ organizationId, offerIds }) => {
81
81
  render(
82
82
  <Wrapper>
83
83
  <SignOrganizationContractButton
84
84
  organizationId={organizationId}
85
- courseProductRelationIds={courseProductRelationIds}
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 (courseProductRelationIds) {
96
- getInvitationLinkUrl += `?course_product_relation_ids=${courseProductRelationIds[0]}`;
95
+ if (offerIds) {
96
+ getInvitationLinkUrl += `?offer_ids=${offerIds[0]}`;
97
97
  }
98
98
 
99
99
  fetchMock.get(getInvitationLinkUrl, {
@@ -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 { CourseProductRelation, Organization } from 'types/Joanie';
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
- courseProductRelationIds?: CourseProductRelation['id'][];
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
- courseProductRelationIds = [],
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
- courseProductRelationIds={courseProductRelationIds}
51
+ offerIds={offerIds}
52
52
  organizationId={organizationId}
53
53
  isOpen={contractFrameOpened}
54
54
  onClose={() => setContractFrameOpened(false)}
@@ -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 { CourseProductRelationFactory, OrganizationFactory } from 'utils/test/factories/joanie';
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
- courseProductRelation: undefined,
44
+ offer: undefined,
45
45
  },
46
46
  {
47
47
  testLabel: 'for a training in an organization',
48
48
  organization: OrganizationFactory().one(),
49
- courseProductRelation: CourseProductRelationFactory().one(),
49
+ offer: OfferFactory().one(),
50
50
  },
51
51
  {
52
52
  testLabel: 'for an organization',
53
53
  organization: OrganizationFactory().one(),
54
- courseProductRelation: undefined,
54
+ offer: undefined,
55
55
  },
56
56
  {
57
57
  testLabel: 'for a training',
58
58
  organization: undefined,
59
- courseProductRelation: CourseProductRelationFactory().one(),
59
+ offer: OfferFactory().one(),
60
60
  },
61
- ])('useCheckContractArchiveExists $testLabel', ({ organization, courseProductRelation }) => {
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
- courseProductRelationId: courseProductRelation ? courseProductRelation.id : undefined,
74
+ offerId: offer ? offer.id : undefined,
75
75
  };
76
76
 
77
77
  // Joanie providers calls
@@ -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 { CourseProductRelation, Organization } from 'types/Joanie';
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
- courseProductRelationId?: CourseProductRelation['id'];
10
+ offerId?: Offer['id'];
11
11
  enable?: boolean;
12
12
  }
13
13
 
14
14
  const useCheckContractArchiveExist = (
15
- { organizationId, courseProductRelationId, enable = true }: UseCheckContractArchiveExistsProps = {
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
- courseProductRelationId,
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, courseProductRelationId]);
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 { CourseProductRelationFactory, OrganizationFactory } from 'utils/test/factories/joanie';
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
- courseProductRelation: undefined,
17
+ offer: undefined,
18
18
  existingOrganization: undefined,
19
- existingCourseProductRelation: undefined,
19
+ existingOffer: undefined,
20
20
  },
21
21
  {
22
22
  testLabel: 'for a training in an organization',
23
23
  organization: OrganizationFactory().one(),
24
- courseProductRelation: CourseProductRelationFactory().one(),
24
+ offer: OfferFactory().one(),
25
25
  existingOrganization: undefined,
26
- existingCourseProductRelation: undefined,
26
+ existingOffer: undefined,
27
27
  },
28
28
  {
29
29
  testLabel: 'for an organization',
30
30
  organization: OrganizationFactory().one(),
31
- courseProductRelation: undefined,
31
+ offer: undefined,
32
32
  existingOrganization: undefined,
33
- existingCourseProductRelation: undefined,
33
+ existingOffer: undefined,
34
34
  },
35
35
  {
36
36
  testLabel: 'for a training',
37
37
  organization: undefined,
38
- courseProductRelation: CourseProductRelationFactory().one(),
38
+ offer: OfferFactory().one(),
39
39
  existingOrganization: undefined,
40
- existingCourseProductRelation: undefined,
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
- courseProductRelation: undefined,
45
+ offer: undefined,
46
46
  existingOrganization: OrganizationFactory().one(),
47
- existingCourseProductRelation: CourseProductRelationFactory().one(),
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
- courseProductRelation: CourseProductRelationFactory().one(),
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
- courseProductRelation: undefined,
57
+ offer: undefined,
58
58
  existingOrganization: OrganizationFactory().one(),
59
- existingCourseProductRelation: CourseProductRelationFactory().one(),
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
- courseProductRelation: CourseProductRelationFactory().one(),
64
+ offer: OfferFactory().one(),
65
65
  existingOrganization: OrganizationFactory().one(),
66
- existingCourseProductRelation: CourseProductRelationFactory().one(),
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
- existingCourseProductRelation: CourseProductRelationFactory().one(),
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
- courseProductRelationId: courseProductRelation ? courseProductRelation.id : undefined,
87
+ offerId: offer ? offer.id : undefined,
93
88
  };
94
89
  localStorageExistingArchiveFilters = {
95
90
  organizationId: existingOrganization ? existingOrganization.id : undefined,
96
- courseProductRelationId: existingCourseProductRelation
97
- ? existingCourseProductRelation.id
98
- : undefined,
91
+ offerId: existingOffer ? existingOffer.id : undefined,
99
92
  };
100
93
  exsitingContractId = faker.string.uuid();
101
94
 
102
- if (existingCourseProductRelation && existingOrganization) {
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 { CourseProductRelation, Organization } from 'types/Joanie';
2
+ import { Offer, Organization } from 'types/Joanie';
3
3
 
4
4
  export interface LocalStorageArchiveFilters {
5
5
  organizationId?: Organization['id'];
6
- courseProductRelationId?: CourseProductRelation['id'];
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
- courseProductRelationId,
20
+ offerId,
24
21
  }: {
25
22
  contractArchiveId: string;
26
23
  organizationId?: Organization['id'];
27
- courseProductRelationId?: CourseProductRelation['id'];
24
+ offerId?: Offer['id'];
28
25
  }) => {
29
26
  localStorage.setItem(
30
- generateLocalStorageKey({ organizationId, courseProductRelationId }),
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
- courseProductRelationId,
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
- courseProductRelationId,
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
  }
@@ -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 { CourseProductRelationFactory, OrganizationFactory } from 'utils/test/factories/joanie';
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
- courseProductRelation: undefined,
53
+ offer: undefined,
54
54
  },
55
55
  {
56
56
  testLabel: 'for a training in an organization',
57
57
  organization: OrganizationFactory().one(),
58
- courseProductRelation: CourseProductRelationFactory().one(),
58
+ offer: OfferFactory().one(),
59
59
  },
60
60
  {
61
61
  testLabel: 'for an organization',
62
62
  organization: OrganizationFactory().one(),
63
- courseProductRelation: undefined,
63
+ offer: undefined,
64
64
  },
65
65
  {
66
66
  testLabel: 'for a training',
67
67
  organization: undefined,
68
- courseProductRelation: CourseProductRelationFactory().one(),
68
+ offer: OfferFactory().one(),
69
69
  },
70
- ])('useDownloadContractArchive $testLabel', ({ organization, courseProductRelation }) => {
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
- courseProductRelationId: courseProductRelation ? courseProductRelation.id : undefined,
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
- existingCourseProductRelation: CourseProductRelationFactory().one(),
100
+ existingOffer: OfferFactory().one(),
101
101
  },
102
- ])('$testLabel', ({ existingOrganization, existingCourseProductRelation }) => {
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
- courseProductRelationId: existingCourseProductRelation
110
- ? existingCourseProductRelation.id
111
- : undefined,
109
+ offerId: existingOffer ? existingOffer.id : undefined,
112
110
  };
113
111
  exsitingContractId = faker.string.uuid();
114
112
 
115
- if (existingCourseProductRelation && existingOrganization) {
113
+ if (existingOffer && existingOrganization) {
116
114
  // everything should work fine with multiple archive stored
117
115
  storeContractArchiveId({
118
116
  ...localStorageExistingArchiveFilters,