🤡(app-desk) mock endpoint teams/:teamId/accesses/
We intercept the request to the endpoint teams/:teamId/accesses/ and return a json with dummy accesses of the team.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
"test:watch": "jest --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"@faker-js/faker": "8.4.1",
|
||||
"@openfun/cunningham-react": "2.4.0",
|
||||
"@tanstack/react-query": "5.24.8",
|
||||
"i18next": "23.10.0",
|
||||
|
||||
24
src/frontend/apps/desk/src/features/teams/api/data/teams.ts
Normal file
24
src/frontend/apps/desk/src/features/teams/api/data/teams.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { faker } from '@faker-js/faker';
|
||||
|
||||
import { Access, Role } from '../types';
|
||||
|
||||
function createRandomAccess(): Access {
|
||||
return {
|
||||
id: faker.string.uuid(),
|
||||
user: {
|
||||
id: faker.string.uuid(),
|
||||
email: faker.internet.email(),
|
||||
name: faker.person.fullName(),
|
||||
},
|
||||
role: faker.helpers.enumValue(Role),
|
||||
};
|
||||
}
|
||||
|
||||
export const dummyDataAPITeamAccesses = (count: number, pageSize: number) => {
|
||||
return {
|
||||
count,
|
||||
next: null,
|
||||
previous: null,
|
||||
results: faker.helpers.multiple(createRandomAccess, { count: pageSize }),
|
||||
};
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
enum Role {
|
||||
export enum Role {
|
||||
MEMBER = 'member',
|
||||
ADMIN = 'administrator',
|
||||
OWNER = 'owner',
|
||||
|
||||
@@ -2,6 +2,9 @@ import { UseQueryOptions, useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { APIError, APIList, errorCauses, fetchAPI } from '@/api';
|
||||
|
||||
import { PAGE_SIZE } from '../conf';
|
||||
|
||||
import { dummyDataAPITeamAccesses } from './data/teams';
|
||||
import { Access } from './types';
|
||||
|
||||
export type TeamAccessesAPIParams = {
|
||||
@@ -15,6 +18,15 @@ export const getTeamAccesses = async ({
|
||||
page,
|
||||
teamId,
|
||||
}: TeamAccessesAPIParams): Promise<AccessesResponse> => {
|
||||
/**
|
||||
* TODO: Remove this block when the API endpoint is ready
|
||||
*/
|
||||
return await new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve(dummyDataAPITeamAccesses(100, PAGE_SIZE));
|
||||
}, 500);
|
||||
});
|
||||
|
||||
const response = await fetchAPI(`teams/${teamId}/accesses/?page=${page}`);
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
1
src/frontend/apps/desk/src/features/teams/conf.ts
Normal file
1
src/frontend/apps/desk/src/features/teams/conf.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const PAGE_SIZE = 20;
|
||||
@@ -1318,6 +1318,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.0.tgz#a5417ae8427873f1dd08b70b3574b453e67b5f7f"
|
||||
integrity sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==
|
||||
|
||||
"@faker-js/faker@8.4.1":
|
||||
version "8.4.1"
|
||||
resolved "https://registry.yarnpkg.com/@faker-js/faker/-/faker-8.4.1.tgz#5d5e8aee8fce48f5e189bf730ebd1f758f491451"
|
||||
integrity sha512-XQ3cU+Q8Uqmrbf2e0cIC/QN43sTBSC8KF12u29Mb47tWrt2hAgBXSgpZMj4Ao8Uk0iJcU99QsOCaIL8934obCg==
|
||||
|
||||
"@fontsource-variable/roboto-flex@5.0.8":
|
||||
version "5.0.8"
|
||||
resolved "https://registry.yarnpkg.com/@fontsource-variable/roboto-flex/-/roboto-flex-5.0.8.tgz#d6685dbcdb9ba939717f995dfeb77cd22f7d82a3"
|
||||
|
||||
Reference in New Issue
Block a user