From 47fcd2af276d6d4af8ec1be7ae682cf1382105e6 Mon Sep 17 00:00:00 2001 From: JeanMarc RAJAONARIVELONA <127597326+JeanMarc-RAJAONARIVELONA@users.noreply.github.com> Date: Wed, 20 Nov 2024 15:03:47 +0300 Subject: [PATCH] feat: teachers can create letters now --- cypress/e2e/download.cy.tsx | 34 +-- cypress/e2e/letter.event.cy.tsx | 8 +- .../{letters.cy.tsx => letters.users.cy.tsx} | 64 +++--- cypress/e2e/student.docs.cy.tsx | 32 +-- cypress/e2e/student.fees.mpbs.cy.tsx | 4 +- cypress/fixtures/api_mocks/letters-mocks.ts | 208 ++++++++++++++++++ package-lock.json | 8 +- package.json | 2 +- src/App.jsx | 2 +- .../common/components/ProfileLayout.jsx | 99 ++++----- .../events/EventParticipantList.tsx | 2 +- src/operations/events/components/Actions.tsx | 10 +- .../fees/components/StudentFeeList.tsx | 2 +- src/operations/letters/CreateLetters.tsx | 14 +- ...entLettersList.tsx => UserLettersList.tsx} | 14 +- .../letters/components/AcceptWithConfirm.tsx | 2 +- .../letters/components/LettersFilter.tsx | 4 +- .../letters/components/RefuseButton.tsx | 2 +- src/operations/letters/types.tsx | 2 +- ...ersProvider.ts => UsersLettersProvider.ts} | 14 +- src/providers/dataProvider.ts | 4 +- src/providers/docsProvider.ts | 14 +- 22 files changed, 375 insertions(+), 170 deletions(-) rename cypress/e2e/{letters.cy.tsx => letters.users.cy.tsx} (72%) rename src/operations/letters/{StudentLettersList.tsx => UserLettersList.tsx} (91%) rename src/providers/{studentLettersProvider.ts => UsersLettersProvider.ts} (84%) diff --git a/cypress/e2e/download.cy.tsx b/cypress/e2e/download.cy.tsx index fe2e2272..6cd620ee 100644 --- a/cypress/e2e/download.cy.tsx +++ b/cypress/e2e/download.cy.tsx @@ -25,7 +25,7 @@ describe("Manager.Work.Docs.Download", () => { ); cy.intercept( "POST", - `/students/${student1Mock.id}/work_files/raw?filename=new_document&work_study_status=WORKING*`, + `/users/${student1Mock.id}/work_files/raw?filename=new_document&work_study_status=WORKING*`, newWorkerDoc ); @@ -60,32 +60,32 @@ describe("Student.Transcript.Docs.Download", () => { cy.intercept("GET", `/students/${student1Mock.id}`, student1Mock); cy.intercept( "GET", - `/students/${student1Mock.id}/files?file_type=TRANSCRIPT*`, + `/users/${student1Mock.id}/files?file_type=TRANSCRIPT*`, transcriptsMock ); cy.intercept( "GET", - `/students/${student1Mock.id}/files?file_type=OTHER*`, + `/users/${student1Mock.id}/files?file_type=OTHER*`, otherDocsMocks ); cy.intercept( "GET", - `/students/${student1Mock.id}/files/${transcript1.id}`, + `/users/${student1Mock.id}/files/${transcript1.id}`, transcript1 ); cy.intercept( "GET", - `/students/${student1Mock.id}/files/${otherDoc1.id}`, + `/users/${student1Mock.id}/files/${otherDoc1.id}`, otherDoc1 ); cy.intercept( "GET", - `/students/${student1Mock.id}/work_files?*`, + `/users/${student1Mock.id}/work_files?*`, workDocsMocks ); cy.intercept( "GET", - `/students/${student1Mock.id}/work_files/${workDoc1.id}`, + `/users/${student1Mock.id}/work_files/${workDoc1.id}`, workDoc1 ); @@ -110,22 +110,22 @@ describe("Student.Work.Docs.Download", () => { cy.intercept("GET", `/students/${student1Mock.id}`, student1Mock); cy.intercept( "GET", - `/students/${student1Mock.id}/files?file_type=TRANSCRIPT*`, + `/users/${student1Mock.id}/files?file_type=TRANSCRIPT*`, transcriptsMock ); cy.intercept( "GET", - `/students/${student1Mock.id}/files?file_type=OTHER*`, + `/users/${student1Mock.id}/files?file_type=OTHER*`, otherDocsMocks ); cy.intercept( "GET", - `/students/${student1Mock.id}/files/${transcript1.id}`, + `/users/${student1Mock.id}/files/${transcript1.id}`, transcript1 ); cy.intercept( "GET", - `/students/${student1Mock.id}/files/${otherDoc1.id}`, + `/users/${student1Mock.id}/files/${otherDoc1.id}`, otherDoc1 ); cy.intercept( @@ -160,32 +160,32 @@ describe("Student.Other.Docs.Download", () => { cy.intercept("GET", `/students/${student1Mock.id}`, student1Mock); cy.intercept( "GET", - `/students/${student1Mock.id}/files?file_type=TRANSCRIPT*`, + `/users/${student1Mock.id}/files?file_type=TRANSCRIPT*`, transcriptsMock ); cy.intercept( "GET", - `/students/${student1Mock.id}/files?file_type=OTHER*`, + `/users/${student1Mock.id}/files?file_type=OTHER*`, otherDocsMocks ); cy.intercept( "GET", - `/students/${student1Mock.id}/files/${transcript1.id}`, + `/users/${student1Mock.id}/files/${transcript1.id}`, transcript1 ); cy.intercept( "GET", - `/students/${student1Mock.id}/files/${otherDoc1.id}`, + `/users/${student1Mock.id}/files/${otherDoc1.id}`, otherDoc1 ); cy.intercept( "GET", - `/students/${student1Mock.id}/work_files?*`, + `/users/${student1Mock.id}/work_files?*`, workDocsMocks ); cy.intercept( "GET", - `/students/${student1Mock.id}/work_files/${workDoc1.id}`, + `/users/${student1Mock.id}/work_files/${workDoc1.id}`, workDoc1 ); diff --git a/cypress/e2e/letter.event.cy.tsx b/cypress/e2e/letter.event.cy.tsx index 2b66b18b..0e538187 100644 --- a/cypress/e2e/letter.event.cy.tsx +++ b/cypress/e2e/letter.event.cy.tsx @@ -12,11 +12,9 @@ describe("Letter.event", () => { `/events/${event1mock.id}/participants?page=1&page_size=10`, eventParticipantsMock ).as("getEventParticipantPage1"); - cy.intercept( - "POST", - `/students/${student1Mock.id}/letters?*`, - newLetter - ).as("createLetter"); + cy.intercept("POST", `/users/${student1Mock.id}/letters?*`, newLetter).as( + "createLetter" + ); cy.intercept("GET", `/events/${event1mock.id}`, event1mock); }); diff --git a/cypress/e2e/letters.cy.tsx b/cypress/e2e/letters.users.cy.tsx similarity index 72% rename from cypress/e2e/letters.cy.tsx rename to cypress/e2e/letters.users.cy.tsx index 8f39bffc..a95c8bef 100644 --- a/cypress/e2e/letters.cy.tsx +++ b/cypress/e2e/letters.users.cy.tsx @@ -1,43 +1,43 @@ import { newLetter, - statsMocks, student1LettersMocks, + teacher1LettersMocks, } from "../fixtures/api_mocks/letters-mocks"; import {student1Mock, studentsMock} from "../fixtures/api_mocks/students-mocks"; +import {teacher1Mock} from "../fixtures/api_mocks/teachers-mocks"; const ITEM_PER_LIST = 10; -describe("Student.Letters", () => { +const testLettersFunctionality = ( + role: string, + id: string, + letterMocks: any +) => { beforeEach(() => { - cy.login({role: "STUDENT"}); - cy.intercept( - "GET", - `/students/${student1Mock.id}/letters?page=1&page_size=10`, - student1LettersMocks.slice(0, ITEM_PER_LIST) - ).as("getStudent1LettersPage1"); - cy.intercept( - "POST", - `/students/${student1Mock.id}/letters?*`, - newLetter - ).as("createLetter"); - cy.intercept("GET", `/students/${newLetter.id}`); - cy.intercept("GET", `letters/stats`, statsMocks).as("getStats"); + cy.login({role}); + + const userId = id; + expect(userId).to.exist; + cy.intercept( "GET", - `/students/${student1Mock.id}/letters?page=1&page_size=10&status=PENDING`, - student1LettersMocks - ).as("getStudent1LettersPending"); + `/users/${userId}/letters?page=1&page_size=10`, + letterMocks.slice(0, ITEM_PER_LIST) + ).as("getusers1LettersPage1"); + cy.intercept("POST", `/users/${userId}/letters?*`, newLetter).as( + "createLetter" + ); }); - it("student can list his letters", () => { + it("can list letters", () => { cy.getByTestid("letters-list-tab").click(); - cy.wait("@getStudent1LettersPage1"); + cy.wait("@getusers1LettersPage1"); cy.getByTestid("letter-list-wrapper") .children() .should("have.length", ITEM_PER_LIST); }); - it("student can create his letters", () => { + it("can create letters", () => { cy.getByTestid("letters-list-tab").click(); cy.getByTestid("letter-create-button").click(); cy.get("#description").type(newLetter.description!); @@ -50,6 +50,14 @@ describe("Student.Letters", () => { expect(interception.response!.statusCode).to.eq(200); }); }); +}; + +describe("Student.Letters", () => { + testLettersFunctionality("STUDENT", student1Mock.id, student1LettersMocks); +}); + +describe("Teacher.Letters", () => { + testLettersFunctionality("TEACHER", teacher1Mock.id, teacher1LettersMocks); }); describe("Manager.Letters.student", () => { @@ -83,22 +91,20 @@ describe("Manager.Letters.student", () => { it("manager can list student letter", () => { cy.intercept( "GET", - `/students/${student1Mock.id}/letters?page=1&page_size=10`, + `/users/${student1Mock.id}/letters?page=1&page_size=10`, student1LettersMocks.slice(0, ITEM_PER_LIST) - ).as("getStudent1LettersPage1"); + ).as("getusers1LettersPage1"); cy.getByTestid("letters-list-tab").click(); - cy.wait("@getStudent1LettersPage1"); + cy.wait("@getusers1LettersPage1"); cy.getByTestid("letter-list-wrapper") .children() .should("have.length", ITEM_PER_LIST); }); it("manager can create letters for student", () => { - cy.intercept( - "POST", - `/students/${student1Mock.id}/letters?*`, - newLetter - ).as("createLetter"); + cy.intercept("POST", `/users/${student1Mock.id}/letters?*`, newLetter).as( + "createLetter" + ); cy.getByTestid("letters-list-tab").click(); cy.getByTestid("letter-create-button").click(); cy.get("#description").type(newLetter.description!); diff --git a/cypress/e2e/student.docs.cy.tsx b/cypress/e2e/student.docs.cy.tsx index 98a12f6e..de26544d 100644 --- a/cypress/e2e/student.docs.cy.tsx +++ b/cypress/e2e/student.docs.cy.tsx @@ -14,32 +14,32 @@ describe("Transcript.Docs", () => { cy.intercept("GET", `/students/${student1Mock.id}`, student1Mock); cy.intercept( "GET", - `/students/${student1Mock.id}/files?file_type=TRANSCRIPT*`, + `/users/${student1Mock.id}/files?file_type=TRANSCRIPT*`, transcriptsMock ); cy.intercept( "GET", - `/students/${student1Mock.id}/files?file_type=OTHER*`, + `/users/${student1Mock.id}/files?file_type=OTHER*`, otherDocsMocks ); cy.intercept( "GET", - `/students/${student1Mock.id}/files/${transcript1.id}`, + `/users/${student1Mock.id}/files/${transcript1.id}`, transcript1 ); cy.intercept( "GET", - `/students/${student1Mock.id}/files/${otherDoc1.id}`, + `/users/${student1Mock.id}/files/${otherDoc1.id}`, otherDoc1 ); cy.intercept( "GET", - `/students/${student1Mock.id}/work_files?*`, + `/users/${student1Mock.id}/work_files?*`, workDocsMocks ); cy.intercept( "GET", - `/students/${student1Mock.id}/work_files/${workDoc1.id}`, + `/users/${student1Mock.id}/work_files/${workDoc1.id}`, workDoc1 ); @@ -63,22 +63,22 @@ describe("Work.Docs", () => { cy.intercept("GET", `/students/${student1Mock.id}`, student1Mock); cy.intercept( "GET", - `/students/${student1Mock.id}/files?file_type=TRANSCRIPT*`, + `/users/${student1Mock.id}/files?file_type=TRANSCRIPT*`, transcriptsMock ); cy.intercept( "GET", - `/students/${student1Mock.id}/files?file_type=OTHER*`, + `/users/${student1Mock.id}/files?file_type=OTHER*`, otherDocsMocks ); cy.intercept( "GET", - `/students/${student1Mock.id}/files/${transcript1.id}`, + `/users/${student1Mock.id}/files/${transcript1.id}`, transcript1 ); cy.intercept( "GET", - `/students/${student1Mock.id}/files/${otherDoc1.id}`, + `/users/${student1Mock.id}/files/${otherDoc1.id}`, otherDoc1 ); cy.intercept( @@ -112,32 +112,32 @@ describe("Other.Docs", () => { cy.intercept("GET", `/students/${student1Mock.id}`, student1Mock); cy.intercept( "GET", - `/students/${student1Mock.id}/files?file_type=TRANSCRIPT*`, + `/users/${student1Mock.id}/files?file_type=TRANSCRIPT*`, transcriptsMock ); cy.intercept( "GET", - `/students/${student1Mock.id}/files?file_type=OTHER*`, + `/users/${student1Mock.id}/files?file_type=OTHER*`, otherDocsMocks ); cy.intercept( "GET", - `/students/${student1Mock.id}/files/${transcript1.id}`, + `/users/${student1Mock.id}/files/${transcript1.id}`, transcript1 ); cy.intercept( "GET", - `/students/${student1Mock.id}/files/${otherDoc1.id}`, + `/users/${student1Mock.id}/files/${otherDoc1.id}`, otherDoc1 ); cy.intercept( "GET", - `/students/${student1Mock.id}/work_files?*`, + `/users/${student1Mock.id}/work_files?*`, workDocsMocks ); cy.intercept( "GET", - `/students/${student1Mock.id}/work_files/${workDoc1.id}`, + `/users/${student1Mock.id}/work_files/${workDoc1.id}`, workDoc1 ); diff --git a/cypress/e2e/student.fees.mpbs.cy.tsx b/cypress/e2e/student.fees.mpbs.cy.tsx index de716b26..e8949ce6 100644 --- a/cypress/e2e/student.fees.mpbs.cy.tsx +++ b/cypress/e2e/student.fees.mpbs.cy.tsx @@ -33,7 +33,7 @@ describe("Mobile payment by student", () => { ).should("exist"); }); - it("can create a mpbs", () => { + it.only("can create a mpbs", () => { const [fee1Mock, ...fees] = feesMock; cy.intercept( @@ -52,7 +52,7 @@ describe("Mobile payment by student", () => { ).click({force: true}); cy.get("#psp_id").click().type("MP240726.1541.D88425"); - cy.get('[data-testid="SaveIcon"]').click(); + cy.contains("Enregistrer").click(); cy.contains("Frais créés avec succès"); diff --git a/cypress/fixtures/api_mocks/letters-mocks.ts b/cypress/fixtures/api_mocks/letters-mocks.ts index 836c5964..9b175040 100644 --- a/cypress/fixtures/api_mocks/letters-mocks.ts +++ b/cypress/fixtures/api_mocks/letters-mocks.ts @@ -1,5 +1,6 @@ import {Letter, LetterStats, LetterStatus} from "@haapi/typescript-client"; import {student1Mock, studentsMock} from "./students-mocks"; +import {teacher1Mock} from "../api_mocks/teachers-mocks"; export const newLetter: Letter = { id: "id_14", @@ -454,3 +455,210 @@ export const lettersMocks: Required[] = [ reason_for_refusal: "incomplete application form", }, ]; + +export const teacher1LettersMocks: Required[] = [ + { + id: "id_1", + description: "invoice letter", + creation_datetime: new Date("2024-02-01T00:00:00Z"), + approval_datetime: new Date("2024-02-01T00:00:00Z"), + ref: "ref_1", + status: LetterStatus.PENDING, + file_url: `https://www.example.com/path/to/test_file_1.pdf`, + fee: { + id: "string", + comment: "string", + amount: 0, + type: "TUITION", + }, + student: teacher1Mock, + reason_for_refusal: "", + }, + { + id: "id_2", + description: "scholarship slip document", + creation_datetime: new Date("2024-02-01T00:00:00Z"), + approval_datetime: new Date("2024-02-01T00:00:00Z"), + ref: "ref_2", + status: LetterStatus.RECEIVED, + file_url: `https://www.example.com/path/to/test_file_2.pdf`, + fee: { + id: "string", + comment: "string", + amount: 0, + type: "TUITION", + }, + student: teacher1Mock, + reason_for_refusal: "", + }, + { + id: "id_3", + description: "scholarship reimbursement request", + creation_datetime: new Date("2024-02-01T00:00:00Z"), + approval_datetime: new Date("2024-02-01T00:00:00Z"), + ref: "ref_3", + status: LetterStatus.REJECTED, + file_url: `https://www.example.com/path/to/test_file_3.pdf`, + fee: { + id: "string", + comment: "string", + amount: 0, + type: "TUITION", + }, + student: teacher1Mock, + reason_for_refusal: "your request does not respect the rules", + }, + { + id: "id_4", + description: "internship confirmation", + creation_datetime: new Date("2024-02-10T10:30:00Z"), + approval_datetime: new Date("2024-02-12T12:00:00Z"), + ref: "ref_4", + status: LetterStatus.RECEIVED, + file_url: `https://www.example.com/path/to/test_file_4.pdf`, + fee: { + id: "string", + comment: "string", + amount: 0, + type: "TUITION", + }, + student: teacher1Mock, + reason_for_refusal: "", + }, + { + id: "id_5", + description: "graduation certificate", + creation_datetime: new Date("2024-03-01T09:45:00Z"), + approval_datetime: new Date("2024-03-02T15:30:00Z"), + ref: "ref_5", + status: LetterStatus.PENDING, + file_url: `https://www.example.com/path/to/test_file_5.pdf`, + fee: { + id: "string", + comment: "string", + amount: 0, + type: "TUITION", + }, + student: teacher1Mock, + reason_for_refusal: "", + }, + { + id: "id_6", + description: "study abroad approval letter", + creation_datetime: new Date("2024-03-10T13:15:00Z"), + approval_datetime: new Date("2024-03-11T11:20:00Z"), + ref: "ref_6", + status: LetterStatus.RECEIVED, + file_url: `https://www.example.com/path/to/test_file_6.pdf`, + fee: { + id: "string", + comment: "string", + amount: 0, + type: "TUITION", + }, + student: teacher1Mock, + reason_for_refusal: "", + }, + { + id: "id_7", + description: "student exchange request", + creation_datetime: new Date("2024-04-01T08:00:00Z"), + approval_datetime: new Date("2024-04-05T16:40:00Z"), + ref: "ref_7", + status: LetterStatus.REJECTED, + file_url: `https://www.example.com/path/to/test_file_7.pdf`, + fee: { + id: "string", + comment: "string", + amount: 0, + type: "TUITION", + }, + student: teacher1Mock, + reason_for_refusal: "insufficient academic performance", + }, + { + id: "id_8", + description: "tuition fee waiver application", + creation_datetime: new Date("2024-04-15T09:00:00Z"), + approval_datetime: new Date("2024-04-16T14:30:00Z"), + ref: "ref_8", + status: LetterStatus.RECEIVED, + file_url: `https://www.example.com/path/to/test_file_8.pdf`, + fee: { + id: "string", + comment: "string", + amount: 0, + type: "TUITION", + }, + student: teacher1Mock, + reason_for_refusal: "", + }, + { + id: "id_9", + description: "change of program request", + creation_datetime: new Date("2024-05-01T11:25:00Z"), + approval_datetime: new Date("2024-05-02T10:00:00Z"), + ref: "ref_9", + status: LetterStatus.PENDING, + file_url: `https://www.example.com/path/to/test_file_9.pdf`, + fee: { + id: "string", + comment: "string", + amount: 0, + type: "TUITION", + }, + student: teacher1Mock, + reason_for_refusal: "", + }, + { + id: "id_10", + description: "academic leave request", + creation_datetime: new Date("2024-05-12T14:10:00Z"), + approval_datetime: new Date("2024-05-13T09:45:00Z"), + ref: "ref_10", + status: LetterStatus.RECEIVED, + file_url: `https://www.example.com/path/to/test_file_10.pdf`, + fee: { + id: "string", + comment: "string", + amount: 0, + type: "TUITION", + }, + student: teacher1Mock, + reason_for_refusal: "", + }, + { + id: "id_11", + description: "attendance confirmation", + creation_datetime: new Date("2024-06-01T07:50:00Z"), + approval_datetime: new Date("2024-06-02T12:30:00Z"), + ref: "ref_11", + status: LetterStatus.RECEIVED, + file_url: `https://www.example.com/path/to/test_file_11.pdf`, + fee: { + id: "string", + comment: "string", + amount: 0, + type: "TUITION", + }, + student: teacher1Mock, + reason_for_refusal: "", + }, + { + id: "id_12", + description: "academic transcript request", + creation_datetime: new Date("2024-06-20T15:05:00Z"), + approval_datetime: new Date("2024-06-21T10:15:00Z"), + ref: "ref_12", + status: LetterStatus.REJECTED, + file_url: `https://www.example.com/path/to/test_file_12.pdf`, + fee: { + id: "string", + comment: "string", + amount: 0, + type: "TUITION", + }, + student: teacher1Mock, + reason_for_refusal: "incomplete application form", + }, +]; diff --git a/package-lock.json b/package-lock.json index c48ac511..ef47c190 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "hei-admin-ui", "version": "0.2.0", "dependencies": { - "@haapi/typescript-client": "^1.77.1", + "@haapi/typescript-client": "^1.79.0", "@mui/x-date-pickers": "^7.21.0", "@react-admin/ra-calendar": "^4.0.1", "@react-admin/ra-enterprise": "^7.0.0", @@ -3901,9 +3901,9 @@ "integrity": "sha512-I7xWjLs2YSVMc5gGx1Z3ZG1lgFpITPndpi8Ku55GeEIKpACCPQNS/OTqQbxgTCfq0Ncvcc+CrFov96itVh6Qvw==" }, "node_modules/@haapi/typescript-client": { - "version": "1.77.1", - "resolved": "https://npm-hei-lab-057045785189.d.codeartifact.eu-west-3.amazonaws.com/npm/hei-store/@haapi/typescript-client/-/typescript-client-1.77.1.tgz", - "integrity": "sha512-/104iPwT3gNpgZ7Ot/ijuaVfn9TM8hQ27e0fz4bpkREFf132StKppqFF7kTTDHJlHxDXX6XAVnTGOXPo0Ah4ZQ==", + "version": "1.79.0", + "resolved": "https://npm-hei-lab-057045785189.d.codeartifact.eu-west-3.amazonaws.com/npm/hei-store/@haapi/typescript-client/-/typescript-client-1.79.0.tgz", + "integrity": "sha512-EjYSu2/RHjibLUTdbFErKq+KTrV3sN02rSEmQ/yjNsXW8GPChbPz1VWWCYBbwO92yCy96XmoCosNPZengLcc4g==", "license": "Unlicense", "peerDependencies": { "axios": "^1.6.1" diff --git a/package.json b/package.json index ce8e769d..5b928b65 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "test:merge:reports": "srm ./dist/test-reports.xml \"./dist/**/!(*test-reports).xml\"" }, "dependencies": { - "@haapi/typescript-client": "^1.77.1", + "@haapi/typescript-client": "^1.79.0", "@mui/x-date-pickers": "^7.21.0", "@react-admin/ra-calendar": "^4.0.1", "@react-admin/ra-enterprise": "^7.0.0", diff --git a/src/App.jsx b/src/App.jsx index d86453e7..b5af8243 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -58,7 +58,7 @@ function AppBase() { - + ); } - - const shouldSyncTab = - !role.isStudent() && !role.isManager() && !role.isMonitor(); + const isViewerManager = + !isTeacherProfile && + !isStudentProfile && + !isMonitorProfile && + role.isManager(); return ( } - syncWithLocation={ - !role.isStudent() && !role.isManager() && !role.isMonitor() - } + syncWithLocation={false} > } /> )} - {isStudentProfile && (role.isManager() || role.isStudent()) && ( + {!isViewerManager && !role.isMonitor() && !isMonitorProfile && ( } + children={} + data-testid="letters-list-tab" + sx={{ + position: "relative", + fontSize: "0.7rem", + }} + /> + )} + {isViewerManager && ( + + {letterStats.pending} + + } + sx={{ + position: "relative", + fontSize: "0.7rem", + }} + > + Boîte aux lettres + + ) : null + } + children={} + style={{paddingTop: "1rem", width: "10vw"}} data-testid="letters-list-tab" /> )} - {!isTeacherProfile && - !isStudentProfile && - !isMonitorProfile && - role.isManager() && ( - - {letterStats.pending} - - } - sx={{ - position: "relative", - fontSize: "0.7rem", - }} - > - Boîte aux lettres - - ) : null - } - children={} - style={{paddingTop: "1rem", width: "10vw"}} - data-testid="letters-list-tab" - /> - )} ); }; diff --git a/src/operations/events/EventParticipantList.tsx b/src/operations/events/EventParticipantList.tsx index 8d8f5b05..91583309 100644 --- a/src/operations/events/EventParticipantList.tsx +++ b/src/operations/events/EventParticipantList.tsx @@ -168,7 +168,7 @@ const ListContent = ({eventId}: {eventId: string}) => { return (statusMap.get(record.id!) || record.event_status) === "MISSING" ? ( diff --git a/src/operations/events/components/Actions.tsx b/src/operations/events/components/Actions.tsx index a771f8fb..bd0cda26 100644 --- a/src/operations/events/components/Actions.tsx +++ b/src/operations/events/components/Actions.tsx @@ -16,13 +16,13 @@ import {LETTER_ICON} from "@/operations/fees/components/letterIcon"; interface LetterActionProps { eventParticipantId: string; - studentId: string; + userId: string; letters: EventParticipantLetter[]; } export const LetterActions = ({ eventParticipantId, - studentId, + userId, letters, }: LetterActionProps) => { const [show, _, toggle] = useToggle(); @@ -31,12 +31,12 @@ export const LetterActions = ({ const {data} = useGetIdentity(); const disableAttach = - (data?.id as string) !== studentId || + (data?.id as string) !== userId || letters.some( (letter) => letter.status === "RECEIVED" || letter.status === "PENDING" ); const disableView = - (!isManager() && (data?.id as string) !== studentId) || !letters[0]; + (!isManager() && (data?.id as string) !== userId) || !letters[0]; return ( @@ -63,7 +63,7 @@ export const LetterActions = ({ toggle(); refresh(); }} - studentId={studentId} + userId={userId} eventParticipantId={eventParticipantId} title="Justificatif d'absence" /> diff --git a/src/operations/fees/components/StudentFeeList.tsx b/src/operations/fees/components/StudentFeeList.tsx index a0f79844..36974544 100644 --- a/src/operations/fees/components/StudentFeeList.tsx +++ b/src/operations/fees/components/StudentFeeList.tsx @@ -285,7 +285,7 @@ const ListActionButtons: FC<{studentId: string}> = ({studentId}) => { toggle4(); refresh(); }} - studentId={studentId} + userId={studentId} feeAmount={total_amount} feeId={id} title="Payer mon frais par ajout d'un bordereau" diff --git a/src/operations/letters/CreateLetters.tsx b/src/operations/letters/CreateLetters.tsx index b2a0a4b0..de399260 100644 --- a/src/operations/letters/CreateLetters.tsx +++ b/src/operations/letters/CreateLetters.tsx @@ -55,7 +55,7 @@ const CustomToolbar: React.FC<{handleSave: () => void; isloading: boolean}> = ({ export const CreateLettersDialog: FC = ({ isOpen, onClose, - studentId, + userId, feeId, feeAmount, title, @@ -74,10 +74,10 @@ export const CreateLettersDialog: FC = ({ setConfirmOpen(false); if (letterRef.current) { create( - "student-letters", + "users-letters", { data: letterRef.current, - meta: {studentId, feeId, feeAmount, eventParticipantId}, + meta: {userId, feeId, feeAmount, eventParticipantId}, }, { onSuccess: () => { @@ -152,7 +152,7 @@ export const CreateLettersDialog: FC = ({ /> = ({ } }} > - + {fileInfo && ( { +export const UserLettersList: FC = () => { const [isOpen, , onToggle] = useToggle(); const [anchorEl, setAnchorEl] = useState(null); @@ -40,9 +40,9 @@ export const StudentLettersList: FC = () => { setAnchorEl(null); }; - const student = useRecordContext(); + const user = useRecordContext(); - if (!student) return null; + if (!user) return null; return ( { }} > @@ -114,7 +114,7 @@ export const StudentLettersList: FC = () => { ); diff --git a/src/operations/letters/components/AcceptWithConfirm.tsx b/src/operations/letters/components/AcceptWithConfirm.tsx index 66ce62b8..210de857 100644 --- a/src/operations/letters/components/AcceptWithConfirm.tsx +++ b/src/operations/letters/components/AcceptWithConfirm.tsx @@ -15,7 +15,7 @@ export const AcceptWithConfirm: FC<{letterId: string}> = ({letterId}) => { const onConfirm = () => { update( - "student-letters", + "users-letters", { id: letterId, data: { diff --git a/src/operations/letters/components/LettersFilter.tsx b/src/operations/letters/components/LettersFilter.tsx index 8d85f4ef..3f077120 100644 --- a/src/operations/letters/components/LettersFilter.tsx +++ b/src/operations/letters/components/LettersFilter.tsx @@ -5,7 +5,7 @@ import {LetterStatus} from "@haapi/typescript-client"; export const LettersFilter: FC = () => { return ( - + { /> = ({letterId}) => { return; } update( - "student-letters", + "users-letters", { id: letterId, data: { diff --git a/src/operations/letters/types.tsx b/src/operations/letters/types.tsx index cebd1efc..cb1e95f9 100644 --- a/src/operations/letters/types.tsx +++ b/src/operations/letters/types.tsx @@ -6,7 +6,7 @@ import {Letter} from "@haapi/typescript-client"; export interface CreateLettersDialogProps { isOpen: boolean; onClose: () => void; - studentId: Identifier; + userId: Identifier; feeId?: Identifier; feeAmount?: number; title?: string; diff --git a/src/providers/studentLettersProvider.ts b/src/providers/UsersLettersProvider.ts similarity index 84% rename from src/providers/studentLettersProvider.ts rename to src/providers/UsersLettersProvider.ts index f2237578..3e06fb43 100644 --- a/src/providers/studentLettersProvider.ts +++ b/src/providers/UsersLettersProvider.ts @@ -5,19 +5,19 @@ import {toApiIds} from "./feeProvider"; type Params = { meta: { method: "CREATE" | "UPDATE"; - studentId: string; + userId: string; feeId: string; feeAmount: number; eventParticipantId: string; }; }; -const studentLettersProvider: HaDataProviderType = { +const usersLettersProvider: HaDataProviderType = { getList: async (page, perPage, filter, meta) => { - const {studentId} = meta; + const {userId} = meta; const {status} = filter; return lettersApi() - .getLettersByStudentId(studentId, page, perPage, status) + .getLettersByUserId(userId, page, perPage, status) .then((result) => ({data: result.data})); }, getOne: async (id: string) => { @@ -28,7 +28,7 @@ const studentLettersProvider: HaDataProviderType = { saveOrUpdate: async (payload: any, {meta}: Params) => { const { method, - studentId, + userId, feeId: raId, feeAmount, eventParticipantId, @@ -45,7 +45,7 @@ const studentLettersProvider: HaDataProviderType = { const {title, rawFile} = filename; return lettersApi() .createLetter( - studentId, + userId, title, description, feeId, @@ -60,4 +60,4 @@ const studentLettersProvider: HaDataProviderType = { }, }; -export default studentLettersProvider; +export default usersLettersProvider; diff --git a/src/providers/dataProvider.ts b/src/providers/dataProvider.ts index 779eb579..37ef30aa 100644 --- a/src/providers/dataProvider.ts +++ b/src/providers/dataProvider.ts @@ -21,7 +21,7 @@ import announcementProvider from "@/providers/announcementProvider"; import courseProvider from "@/providers/courseProvider"; import statsProvider from "@/providers/statsProvider"; import heiDocsProvider from "@/providers/heiDocsProvider"; -import studentLettersProvider from "@/providers/studentLettersProvider"; +import usersLettersProvider from "@/providers/UsersLettersProvider"; import lettersProvider from "@/providers/lettersProvider"; import lettersStatsProvider from "./letterStatsProvider"; import receiptProvider from "./receiptProvider"; @@ -55,7 +55,7 @@ const getProvider = (resourceType: string): HaDataProviderType => { if (resourceType === "course") return courseProvider; if (resourceType === "stats") return statsProvider; if (resourceType === "hei-docs") return heiDocsProvider; - if (resourceType === "student-letters") return studentLettersProvider; + if (resourceType === "users-letters") return usersLettersProvider; if (resourceType === "letters") return lettersProvider; if (resourceType === "letters-stats") return lettersStatsProvider; if (resourceType === "receipts") return receiptProvider; diff --git a/src/providers/docsProvider.ts b/src/providers/docsProvider.ts index fde9d38f..fc7d321c 100644 --- a/src/providers/docsProvider.ts +++ b/src/providers/docsProvider.ts @@ -20,7 +20,7 @@ const docsProvider: HaDataProviderType = { } if (meta.type in FileType) { return filesApi() - .getStudentFiles(meta?.studentId, page, perPage, meta.type) + .getUserFiles(meta?.studentId, page, perPage, meta.type) .then((result) => ({data: result.data})); } return {data: []}; @@ -42,7 +42,7 @@ const docsProvider: HaDataProviderType = { .then((result) => result.data); } return filesApi() - .getStudentFilesById(meta.studentId, id) + .getUserFilesById(meta.studentId, id) .then((result) => result.data); default: return []; @@ -77,13 +77,9 @@ const docsProvider: HaDataProviderType = { } if (doc.type in FileType) { return filesApi() - .uploadStudentFile( - doc.studentId, - doc.type, - doc.title, - raw.rawFile, - {headers: MULTIPART_HEADERS} - ) + .uploadUserFile(doc.studentId, doc.type, doc.title, raw.rawFile, { + headers: MULTIPART_HEADERS, + }) .then((result) => [result.data]); } return [];