Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(chore) generate joanie api client #1901

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
✨(frontend) useEnrollments with generated api client
rlecellier committed Mar 6, 2023
commit 25a051be7863d7594c645093f2c0622f334e5b3d
24 changes: 20 additions & 4 deletions src/frontend/js/hooks/useEnrollments.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { defineMessages } from 'react-intl';
import { useJoanieApi } from 'data/JoanieApiProvider';
import { Enrollment } from 'api/joanie/gen';
import { ResourcesQuery, useResources, UseResourcesProps } from 'hooks/useResources';
import { API, Enrollment } from 'types/Joanie';
import { ApiResourceInterface } from 'types/Joanie';
import { joanieApi } from 'api/joanie';

const messages = defineMessages({
errorUpdate: {
@@ -31,9 +32,24 @@ const messages = defineMessages({
},
});

const props: UseResourcesProps<Enrollment, ResourcesQuery, API['user']['enrollments']> = {
const props: UseResourcesProps<Enrollment, ResourcesQuery, ApiResourceInterface<Enrollment>> = {
queryKey: ['enrollments'],
apiInterface: () => useJoanieApi().user.enrollments,
apiInterface: () => ({
get: async (filters?: ResourcesQuery) => {
if (filters?.id) {
return joanieApi.enrollments.enrollmentsRead(filters?.id);
}
return joanieApi.enrollments.enrollmentsList();
},
create: (data: Enrollment) => joanieApi.enrollments.enrollmentsCreate(data),
update: (data: Enrollment) => {
const { id, ...updatedData } = data;
if (id) {
return joanieApi.enrollments.enrollmentsUpdate(id, updatedData);
}
throw new Error('api.enrollmentsUpdate need a id.');
},
}),
session: true,
messages,
onMutationSuccess: async (queryClient) => {