richie-education 3.1.3-dev11 → 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.
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 +2 -2
  9. package/js/components/SaleTunnel/index.full-process.spec.tsx +3 -3
  10. package/js/components/SaleTunnel/index.spec.tsx +5 -5
  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 +17 -19
  52. package/js/utils/test/factories/joanie.ts +3 -3
  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 +9 -13
  68. package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.spec.tsx +63 -87
  69. package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.stories.tsx +2 -2
  70. package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.tsx +20 -34
  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
@@ -1,5 +1,5 @@
1
1
  import { defineMessages } from 'react-intl';
2
- import { API, CourseProductQueryFilters, CourseProductRelation, Product } from 'types/Joanie';
2
+ import { API, CourseProductQueryFilters, Offer, Product } from 'types/Joanie';
3
3
  import { QueryOptions, useResourcesCustom, UseResourcesProps } from 'hooks/useResources';
4
4
  import { useJoanieApi } from 'contexts/JoanieApiContext';
5
5
 
@@ -19,11 +19,7 @@ export const messages = defineMessages({
19
19
  /**
20
20
  * Joanie Api hook to retrieve a product through its id and a course code.
21
21
  */
22
- const props: UseResourcesProps<
23
- CourseProductRelation,
24
- CourseProductQueryFilters,
25
- API['courses']['products']
26
- > = {
22
+ const props: UseResourcesProps<Offer, CourseProductQueryFilters, API['courses']['products']> = {
27
23
  queryKey: ['courses-products'],
28
24
  apiInterface: () => useJoanieApi().courses.products,
29
25
  messages,
@@ -31,11 +27,11 @@ const props: UseResourcesProps<
31
27
 
32
28
  export const useCourseProduct = (
33
29
  filters: Omit<CourseProductQueryFilters, 'id'> & { product_id: Product['id'] },
34
- queryOptions?: QueryOptions<CourseProductRelation>,
30
+ queryOptions?: QueryOptions<Offer>,
35
31
  ) => {
36
32
  const { product_id: productId, ...queryfilters } = filters;
37
33
  const enabled = !!productId && !!queryfilters.course_id;
38
- const resources = useResourcesCustom<CourseProductRelation, CourseProductQueryFilters>({
34
+ const resources = useResourcesCustom<Offer, CourseProductQueryFilters>({
39
35
  ...props,
40
36
  filters: { id: productId, ...queryfilters },
41
37
  queryOptions: { ...queryOptions, enabled },
@@ -1,6 +1,6 @@
1
1
  import { useParams, useSearchParams } from 'react-router';
2
2
  import { useOrganizations } from 'hooks/useOrganizations';
3
- import { CourseProductRelation, Organization } from 'types/Joanie';
3
+ import { Offer, Organization } from 'types/Joanie';
4
4
 
5
5
  /**
6
6
  * return organization id with this priority:
@@ -9,17 +9,14 @@ import { CourseProductRelation, Organization } from 'types/Joanie';
9
9
  * * first organization of user's organizations
10
10
  */
11
11
  const useDefaultOrganizationId = () => {
12
- const {
13
- organizationId: routeOrganizationId,
14
- courseProductRelationId: routeCourseProductRelationId,
15
- } = useParams<{
12
+ const { organizationId: routeOrganizationId, offerId: routeOfferId } = useParams<{
16
13
  organizationId?: Organization['id'];
17
- courseProductRelationId: CourseProductRelation['id'];
14
+ offerId: Offer['id'];
18
15
  }>();
19
16
  const [searchParams] = useSearchParams();
20
17
  const queryOrganizationId = searchParams.get('organization_id') || undefined;
21
18
  const { items: organizations } = useOrganizations(
22
- { course_product_relation_id: routeCourseProductRelationId },
19
+ { offer_id: routeOfferId },
23
20
  {
24
21
  enabled: !routeOrganizationId && !queryOrganizationId,
25
22
  },
@@ -0,0 +1,32 @@
1
+ import { defineMessages } from 'react-intl';
2
+ import { useJoanieApi } from 'contexts/JoanieApiContext';
3
+ import { API, Offer, OfferQueryFilters } from 'types/Joanie';
4
+ import { useResource, useResources, UseResourcesProps } from 'hooks/useResources';
5
+
6
+ const messages = defineMessages({
7
+ errorGet: {
8
+ id: 'hooks.useOffers.errorGet',
9
+ description: 'Error message shown to the user when offer fetch request fails.',
10
+ defaultMessage: 'An error occurred while fetching trainings. Please retry later.',
11
+ },
12
+ errorNotFound: {
13
+ id: 'hooks.useOffers.errorNotFound',
14
+ description: 'Error message shown to the user when no offer matches.',
15
+ defaultMessage: 'Cannot find the training.',
16
+ },
17
+ });
18
+
19
+ /**
20
+ * Joanie Api hook to retrieve/create/update/delete course
21
+ * owned by the authenticated user.
22
+ */
23
+ const props: UseResourcesProps<Offer, OfferQueryFilters, API['offers']> = {
24
+ queryKey: ['offers'],
25
+ apiInterface: () => useJoanieApi().offers,
26
+ session: true,
27
+ messages,
28
+ };
29
+
30
+ export const useOffers = useResources<Offer, OfferQueryFilters, API['offers']>(props);
31
+
32
+ export const useOffer = useResource<Offer, OfferQueryFilters>(props);
@@ -1,16 +1,16 @@
1
1
  import { useEffect, useState } from 'react';
2
2
  import { useParams, useSearchParams } from 'react-router';
3
3
  import { useCourseProductUnion } from 'hooks/useCourseProductUnion';
4
- import { CourseListItem, CourseProductRelationLight, ProductType } from 'types/Joanie';
4
+ import { CourseListItem, OfferLight, ProductType } from 'types/Joanie';
5
5
  import { Maybe, Nullable } from 'types/utils';
6
6
 
7
7
  const useTeacherCoursesSearch = () => {
8
8
  const { organizationId } = useParams<{ organizationId: string }>();
9
9
  const [searchParams, setSearchParams] = useSearchParams();
10
10
  const [count, setCount] = useState<Maybe<number>>(0);
11
- const [courseAndProductList, setCourseAndProductList] = useState<
12
- (CourseListItem | CourseProductRelationLight)[]
13
- >([]);
11
+ const [courseAndProductList, setCourseAndProductList] = useState<(CourseListItem | OfferLight)[]>(
12
+ [],
13
+ );
14
14
  const [isNewSearchLoading, setIsNewSearchLoading] = useState(false);
15
15
  const query = searchParams.get('query') || undefined;
16
16
  const {
@@ -1,19 +1,19 @@
1
1
  import { useOrganizationContracts } from 'hooks/useContracts';
2
2
  import { PER_PAGE } from 'settings';
3
- import { ContractState, CourseProductRelation, Organization } from 'types/Joanie';
3
+ import { ContractState, Offer, Organization } from 'types/Joanie';
4
4
 
5
5
  interface UseTeacherPendingContractsCountProps {
6
6
  organizationId?: Organization['id'];
7
- courseProductRelationId?: CourseProductRelation['id'];
7
+ offerId?: Offer['id'];
8
8
  }
9
9
 
10
10
  const useTeacherPendingContractsCount = ({
11
11
  organizationId,
12
- courseProductRelationId,
12
+ offerId,
13
13
  }: UseTeacherPendingContractsCountProps) => {
14
14
  const { items: contracts, meta } = useOrganizationContracts({
15
15
  organization_id: organizationId,
16
- course_product_relation_id: courseProductRelationId,
16
+ offer_id: offerId,
17
17
  signature_state: ContractState.LEARNER_SIGNED,
18
18
  page: 1,
19
19
  page_size: PER_PAGE.teacherContractList,
@@ -5,12 +5,12 @@ import userEvent from '@testing-library/user-event';
5
5
  import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
6
6
  import { DashboardTest } from 'widgets/Dashboard/components/DashboardTest';
7
7
  import {
8
- CourseProductRelationFactory,
8
+ OfferFactory,
9
9
  EnrollmentFactory,
10
10
  CredentialOrderFactory,
11
11
  } from 'utils/test/factories/joanie';
12
12
  import { createTestQueryClient } from 'utils/test/createTestQueryClient';
13
- import { CourseLight, CourseProductRelation, Enrollment, CredentialOrder } from 'types/Joanie';
13
+ import { CourseLight, Offer, Enrollment, CredentialOrder } from 'types/Joanie';
14
14
  import { expectNoSpinner, expectSpinner } from 'utils/test/expectSpinner';
15
15
  import { expectBannerError, expectBannerInfo, expectNoBannerInfo } from 'utils/test/expectBanner';
16
16
  import { Deferred } from 'utils/test/deferred';
@@ -54,15 +54,15 @@ describe('<DashboardCourses/>', () => {
54
54
  const perPage = PER_PAGE.useOrdersEnrollments;
55
55
 
56
56
  const mockOrders = (orders: CredentialOrder[], client?: QueryClient) => {
57
- const relations: Record<string, CourseProductRelation> = {};
57
+ const offers: Record<string, Offer> = {};
58
58
  orders.forEach((order) => {
59
59
  const productId = order.product_id;
60
60
  const courseCode = (order.course as CourseLight).code;
61
- const relation = CourseProductRelationFactory().one();
61
+ const offer = OfferFactory().one();
62
62
 
63
63
  fetchMock.get(
64
64
  `https://joanie.endpoint/api/v1.0/courses/${courseCode}/products/${productId}/`,
65
- relation,
65
+ offer,
66
66
  );
67
67
 
68
68
  // Allowing this option boosts the test performances. Without it, the tests case with 200+
@@ -70,28 +70,28 @@ describe('<DashboardCourses/>', () => {
70
70
  if (client) {
71
71
  client.setQueryData(
72
72
  ['courses-products', JSON.stringify({ id: courseCode, productId })],
73
- relation,
73
+ offer,
74
74
  );
75
75
  }
76
- relations[order.id] = relation;
76
+ offers[order.id] = offer;
77
77
  });
78
78
  orders.sort((a, b) => {
79
79
  const aDate = new Date(a.created_on);
80
80
  const bDate = new Date(b.created_on);
81
81
  return bDate.getTime() - aDate.getTime();
82
82
  });
83
- return { orders, relations };
83
+ return { orders, offers };
84
84
  };
85
85
 
86
86
  const expectList = (
87
87
  entities: (CredentialOrder | Enrollment)[],
88
- relations: Record<string, CourseProductRelation>,
88
+ offers: Record<string, Offer>,
89
89
  ) => {
90
90
  const itemElements = document.querySelectorAll<HTMLElement>('.dashboard__courses__list__item');
91
91
  expect(itemElements.length).toBe(entities.length);
92
92
  entities.forEach((entity, i) => {
93
93
  const title = isOrder(entity)
94
- ? relations[entity.id].product.title
94
+ ? offers[entity.id].product.title
95
95
  : entity.course_run.course?.title;
96
96
  getByRole(itemElements[i], 'heading', {
97
97
  name: title,
@@ -146,10 +146,7 @@ describe('<DashboardCourses/>', () => {
146
146
 
147
147
  it('should render the list of entities', async () => {
148
148
  const client = createTestQueryClient({ user: true });
149
- const { orders, relations } = mockOrders(
150
- CredentialOrderFactory().many(perPage * 2 + 1),
151
- client,
152
- );
149
+ const { orders, offers } = mockOrders(CredentialOrderFactory().many(perPage * 2 + 1), client);
153
150
  fetchMock.get(
154
151
  'https://joanie.endpoint/api/v1.0/orders/' +
155
152
  '?product_type=credential' +
@@ -255,18 +252,18 @@ describe('<DashboardCourses/>', () => {
255
252
  await expectNoBannerInfo('You have no enrollments nor orders yet');
256
253
  let loadMoreButton = await screen.findByRole('button', { name: 'Load more' });
257
254
  expect(loadMoreButton).toBeEnabled();
258
- await waitFor(() => expectList(entities.slice(0, perPage), relations), { interval: 200 });
255
+ await waitFor(() => expectList(entities.slice(0, perPage), offers), { interval: 200 });
259
256
 
260
257
  // Click on load more button to load slice 2.
261
258
  await act(async () => userEvent.click(loadMoreButton));
262
- await waitFor(() => expectList(entities.slice(0, perPage * 2), relations));
259
+ await waitFor(() => expectList(entities.slice(0, perPage * 2), offers));
263
260
  loadMoreButton = await screen.findByRole('button', { name: 'Load more' });
264
261
  expect(loadMoreButton).toBeEnabled();
265
262
 
266
263
  // Activate intersection observe to load slice 3.
267
264
  const { onIntersect } = (globalThis as any).__intersection_observer_props__;
268
265
  await waitFor(async () => onIntersect());
269
- await waitFor(() => expectList(entities.slice(0, perPage * 3), relations), { timeout: 30000 });
266
+ await waitFor(() => expectList(entities.slice(0, perPage * 3), offers), { timeout: 30000 });
270
267
  loadMoreButton = await screen.findByRole('button', { name: 'Load more' });
271
268
  expect(loadMoreButton).toBeEnabled();
272
269
  }, 15000);
@@ -3,11 +3,7 @@ import { screen } from '@testing-library/react';
3
3
  import { getAllByRole } from '@testing-library/dom';
4
4
  import userEvent from '@testing-library/user-event';
5
5
  import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
6
- import {
7
- ContractFactory,
8
- CourseProductRelationFactory,
9
- OrganizationFactory,
10
- } from 'utils/test/factories/joanie';
6
+ import { ContractFactory, OfferFactory, OrganizationFactory } from 'utils/test/factories/joanie';
11
7
  import { expectNoSpinner } from 'utils/test/expectSpinner';
12
8
  import { expectBannerError } from 'utils/test/expectBanner';
13
9
  import { HttpStatusCode } from 'utils/errors/HttpError';
@@ -37,8 +33,8 @@ jest.mock('components/ContractFrame', () => ({
37
33
  describe('pages/TeacherDashboardContracts', () => {
38
34
  setupJoanieSession();
39
35
 
40
- it('should render a list of contracts for a course product relation', async () => {
41
- const courseProductRelation = CourseProductRelationFactory().one();
36
+ it('should render a list of contracts for a offer', async () => {
37
+ const offer = OfferFactory().one();
42
38
  const contracts = ContractFactory({
43
39
  student_signed_on: Date.toString(),
44
40
  organization_signed_on: Date.toString(),
@@ -48,26 +44,24 @@ describe('pages/TeacherDashboardContracts', () => {
48
44
 
49
45
  // OrganizationContractFilter request all organizations forwho the user have access
50
46
  fetchMock.get(
51
- `https://joanie.endpoint/api/v1.0/organizations/?course_product_relation_id=${courseProductRelation.id}`,
47
+ `https://joanie.endpoint/api/v1.0/organizations/?offer_id=${offer.id}`,
52
48
  organizations,
53
49
  );
54
50
  // TeacherDashboardContracts request a paginated list of contracts to display
55
51
  fetchMock.get(
56
- `https://joanie.endpoint/api/v1.0/organizations/${defaultOrganization.id}/contracts/?course_product_relation_id=${courseProductRelation.id}&signature_state=signed&page=1&page_size=25`,
52
+ `https://joanie.endpoint/api/v1.0/organizations/${defaultOrganization.id}/contracts/?offer_id=${offer.id}&signature_state=signed&page=1&page_size=25`,
57
53
  { results: contracts, count: 0, previous: null, next: null },
58
54
  );
59
55
  // useTeacherContractsToSign request all contract to sign, without pagination
60
56
  fetchMock.get(
61
- `https://joanie.endpoint/api/v1.0/organizations/${defaultOrganization.id}/contracts/?signature_state=half_signed&course_product_relation_id=${courseProductRelation.id}`,
57
+ `https://joanie.endpoint/api/v1.0/organizations/${defaultOrganization.id}/contracts/?signature_state=half_signed&offer_id=${offer.id}`,
62
58
  { results: [], count: 0, previous: null, next: null },
63
59
  );
64
60
 
65
61
  render(<TeacherDashboardContracts />, {
66
62
  routerOptions: {
67
- path: '/courses/:courseId/products/:courseProductRelationId/contracts',
68
- initialEntries: [
69
- `/courses/${courseProductRelation.course.id}/products/${courseProductRelation.id}/contracts`,
70
- ],
63
+ path: '/courses/:courseId/products/:offerId/contracts',
64
+ initialEntries: [`/courses/${offer.course.id}/products/${offer.id}/contracts`],
71
65
  },
72
66
  });
73
67
 
@@ -42,20 +42,15 @@ const TeacherDashboardContracts = () => {
42
42
  defaultPage: page ? parseInt(page, 10) : 1,
43
43
  pageSize: PER_PAGE.teacherContractList,
44
44
  });
45
- const {
46
- organizationId: routeOrganizationId,
47
- courseProductRelationId: routeCourseProductRelationId,
48
- } = useParams<TeacherDashboardContractsParams>();
45
+ const { organizationId: routeOrganizationId, offerId: routeofferId } =
46
+ useParams<TeacherDashboardContractsParams>();
49
47
  // organization list is used to show/hide organization filter.
50
48
  // when organizationId is in route's params this filter is always hidden.
51
49
  // therefore we don't need to enable this query.
52
50
  const {
53
51
  items: organizationList,
54
52
  states: { isFetched: isOrganizationListFetched },
55
- } = useOrganizations(
56
- { course_product_relation_id: routeCourseProductRelationId },
57
- { enabled: !routeOrganizationId },
58
- );
53
+ } = useOrganizations({ offer_id: routeofferId }, { enabled: !routeOrganizationId });
59
54
  const hasMultipleOrganizations = isOrganizationListFetched && organizationList.length > 1;
60
55
  const { initialFilters, filters, setFilters } = useTeacherContractFilters();
61
56
  const {
@@ -96,10 +91,7 @@ const TeacherDashboardContracts = () => {
96
91
  return (
97
92
  <div className="teacher-contract-page">
98
93
  <div className="dashboard__page__actions">
99
- <ContractActionsBar
100
- organizationId={filters.organization_id!}
101
- courseProductRelationId={filters.course_product_relation_id}
102
- />
94
+ <ContractActionsBar organizationId={filters.organization_id!} offerId={filters.offer_id} />
103
95
  <ContractFiltersBar
104
96
  defaultValues={initialFilters}
105
97
  onFiltersChange={handleFiltersChange}
@@ -9,7 +9,7 @@ import JoanieApiProvider from 'contexts/JoanieApiContext';
9
9
  import { createTestQueryClient } from 'utils/test/createTestQueryClient';
10
10
  import { ContractDownloadStatus } from 'pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive';
11
11
 
12
- import { CourseProductRelationFactory, OrganizationFactory } from 'utils/test/factories/joanie';
12
+ import { OfferFactory, OrganizationFactory } from 'utils/test/factories/joanie';
13
13
  import { unstoreContractArchiveId } from 'pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/contractArchiveLocalStorage';
14
14
  import BulkDownloadContractButton from '.';
15
15
 
@@ -44,26 +44,26 @@ describe.each([
44
44
  {
45
45
  testLabel: 'for all organization and all trainings',
46
46
  organization: undefined,
47
- courseProductRelation: undefined,
47
+ offer: undefined,
48
48
  },
49
49
  {
50
50
  testLabel: 'for a training in an organization',
51
51
  organization: OrganizationFactory().one(),
52
- courseProductRelation: CourseProductRelationFactory().one(),
52
+ offer: OfferFactory().one(),
53
53
  },
54
54
  {
55
55
  testLabel: 'for an organization',
56
56
  organization: OrganizationFactory().one(),
57
- courseProductRelation: undefined,
57
+ offer: undefined,
58
58
  },
59
59
  {
60
60
  testLabel: 'for a training',
61
61
  organization: undefined,
62
- courseProductRelation: CourseProductRelationFactory().one(),
62
+ offer: OfferFactory().one(),
63
63
  },
64
64
  ])(
65
65
  'TeacherDashboardContractsLayout/BulkDownloadContractButton $testLabel',
66
- ({ organization, courseProductRelation }) => {
66
+ ({ organization, offer }) => {
67
67
  const Wrapper = ({ children }: PropsWithChildren) => {
68
68
  return (
69
69
  <IntlProvider locale="en">
@@ -86,7 +86,7 @@ describe.each([
86
86
  jest.resetAllMocks();
87
87
  unstoreContractArchiveId({
88
88
  organizationId: organization ? organization.id : undefined,
89
- courseProductRelationId: courseProductRelation ? courseProductRelation.id : undefined,
89
+ offerId: offer ? offer.id : undefined,
90
90
  });
91
91
  });
92
92
 
@@ -97,7 +97,7 @@ describe.each([
97
97
  <Wrapper>
98
98
  <BulkDownloadContractButton
99
99
  organizationId={organization?.id ?? undefined}
100
- courseProductRelationId={courseProductRelation?.id ?? undefined}
100
+ offerId={offer?.id ?? undefined}
101
101
  />
102
102
  </Wrapper>,
103
103
  );
@@ -118,7 +118,7 @@ describe.each([
118
118
  <Wrapper>
119
119
  <BulkDownloadContractButton
120
120
  organizationId={organization?.id ?? undefined}
121
- courseProductRelationId={courseProductRelation?.id ?? undefined}
121
+ offerId={offer?.id ?? undefined}
122
122
  />
123
123
  </Wrapper>,
124
124
  );
@@ -139,7 +139,7 @@ describe.each([
139
139
  <Wrapper>
140
140
  <BulkDownloadContractButton
141
141
  organizationId={organization?.id ?? undefined}
142
- courseProductRelationId={courseProductRelation?.id ?? undefined}
142
+ offerId={offer?.id ?? undefined}
143
143
  />
144
144
  </Wrapper>,
145
145
  );
@@ -160,7 +160,7 @@ describe.each([
160
160
  <Wrapper>
161
161
  <BulkDownloadContractButton
162
162
  organizationId={organization?.id ?? undefined}
163
- courseProductRelationId={courseProductRelation?.id ?? undefined}
163
+ offerId={offer?.id ?? undefined}
164
164
  />
165
165
  </Wrapper>,
166
166
  );
@@ -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
  )