Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/chatbox/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SuggestionDataItem } from 'react-mentions';

import { PartialMemberDisplay } from './types.js';
import { Account } from '@graasp/sdk';

export const SCROLL_SAFETY_MARGIN = 64;
export const CONTAINER_HEIGHT_SAFETY_MARGIN = 16;
Expand All @@ -25,7 +25,7 @@ export const ALL_MEMBERS_SUGGESTION: SuggestionDataItem = {
id: ALL_MEMBERS_ID,
display: ALL_MEMBERS_DISPLAY,
};
export const ALL_MEMBERS_MEMBER: PartialMemberDisplay = {
export const ALL_MEMBERS_MEMBER: Account = {
id: ALL_MEMBERS_ID,
name: ALL_MEMBERS_DISPLAY,
};
3 changes: 0 additions & 3 deletions src/components/chatbox/types.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/components/chatbox/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PartialMemberDisplay } from './types.js';
import { Account } from '@graasp/sdk';

export const getIdMention = (textContent: string): RegExpMatchArray | null =>
/<!@(?<id>[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12})>/i.exec(
Expand All @@ -23,7 +23,7 @@ export const LEGACY_MENTION_MARKUP = '`<!@__display__>[__id__]`';
export const MENTION_MARKUP = '`<!@__id__>[__display__]`';

export const getMentionMarkupFromMember = (
member: PartialMemberDisplay,
member: Account,
templateMarkup = MENTION_MARKUP,
): string =>
Object.entries(reactMentionsMarkup).reduce(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,25 @@ import {
getFileExtra,
} from '@graasp/sdk';

import { useQuery } from '@tanstack/react-query';

import { NS } from '@/config/constants';
import { hooks } from '@/config/queryClient';
import { ITEM_PANEL_NAME_ID, ITEM_PANEL_TABLE_ID } from '@/config/selectors';
import { getOneMemberOptions } from '@/openapi/client/@tanstack/react-query.gen';

import { useOutletContext } from '~builder/contexts/OutletContext';

import { BUILDER } from '../../../langs';
import LanguageSelect from './LanguageSelect';

const { useMember } = hooks;

const ItemMetadataContent = (): JSX.Element => {
const { t: translateBuilder, i18n } = useTranslation(NS.Builder);
const { t: translateCommon } = useTranslation(NS.Common);
const { item } = useOutletContext();

const { data: creator } = useMember(item?.creator?.id);
const { data: creator } = useQuery(
getOneMemberOptions({ path: { id: item.creator?.id ?? '' } }),
);

let size = null;
let mimetype = null;
Expand Down
6 changes: 0 additions & 6 deletions src/modules/builder/utils/member.ts

This file was deleted.

11 changes: 5 additions & 6 deletions src/modules/player/access/RequestAccessContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import { useTranslation } from 'react-i18next';

import { Button, Stack, Typography } from '@mui/material';

import {
DiscriminatedItem,
Member,
MembershipRequestStatus,
} from '@graasp/sdk';
import { DiscriminatedItem, MembershipRequestStatus } from '@graasp/sdk';

import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { Check, Lock } from 'lucide-react';
Expand All @@ -17,17 +13,20 @@ import {
MEMBERSHIP_REQUEST_PENDING_SCREEN_SELECTOR,
REQUEST_MEMBERSHIP_BUTTON_ID,
} from '@/config/selectors';
import { CurrentAccount } from '@/openapi/client';
import {
createMembershipRequestMutation,
getOwnMembershipRequestByItemIdOptions,
getOwnMembershipRequestByItemIdQueryKey,
} from '@/openapi/client/@tanstack/react-query.gen';

type CurrentMember = Exclude<CurrentAccount, { type: 'guest' }>;

export function RequestAccessContent({
member,
itemId,
}: Readonly<{
member: Member;
member: CurrentMember;
itemId: DiscriminatedItem['id'];
}>): JSX.Element {
const { t: translatePlayer } = useTranslation(NS.Player);
Expand Down
7 changes: 0 additions & 7 deletions src/query/member/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
CurrentAccount,
Member,
MemberStorage,
MemberStorageItem,
Paginated,
Expand All @@ -22,18 +21,12 @@ import {
buildDownloadAvatarRoute,
buildExportMemberDataRoute,
buildGetCurrentMemberRoute,
buildGetMemberRoute,
buildGetMemberStorageFilesRoute,
buildGetMemberStorageRoute,
buildPostMemberEmailUpdateRoute,
buildUploadAvatarRoute,
} from './routes.js';

export const getMember = async ({ id }: { id: UUID }) =>
axios
.get<Member>(`${API_HOST}/${buildGetMemberRoute(id)}`)
.then(({ data }) => data);

export const getCurrentMember = async () =>
verifyAuthentication(() =>
axios
Expand Down
50 changes: 0 additions & 50 deletions src/query/member/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { MEMBER_STORAGE_ITEM_RESPONSE } from './fixtures.js';
import {
buildDownloadAvatarRoute,
buildGetCurrentMemberRoute,
buildGetMemberRoute,
buildGetMemberStorageFilesRoute,
buildGetMemberStorageRoute,
} from './routes.js';
Expand Down Expand Up @@ -71,55 +70,6 @@ describe('Member Hooks', () => {
});
});

describe('useMember', () => {
const id = 'member-id';
const response = AccountFactory();

it(`Receive member id = ${id}`, async () => {
const endpoints = [
{
route: `/${buildGetMemberRoute(id)}`,
response,
},
];
const hook = () => hooks.useMember(id);
const { data } = await mockHook({
hook,
wrapper,
endpoints,
});

expect(data).toMatchObject(response);
// verify cache keys
expect(
queryClient.getQueryData(memberKeys.single(id).content),
).toMatchObject(data!);
});

it(`Unauthorized`, async () => {
const hook = () => hooks.useMember(id);
const endpoints = [
{
route: `/${buildGetMemberRoute(id)}`,
response: UNAUTHORIZED_RESPONSE,
statusCode: StatusCodes.UNAUTHORIZED,
},
];
const { data, isError } = await mockHook({
hook,
wrapper,
endpoints,
});

expect(data).toBeFalsy();
expect(isError).toBeTruthy();
// verify cache keys
expect(
queryClient.getQueryData(memberKeys.single(id).content),
).toBeFalsy();
});
});

describe('useAvatarUrl', () => {
const member = AccountFactory();
const replyUrl = true;
Expand Down
13 changes: 0 additions & 13 deletions src/query/member/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,6 @@ export default (queryConfig: QueryClientConfig) => {
...defaultQueryOptions,
}),

useMember: (id?: UUID) =>
useQuery({
queryKey: memberKeys.single(id).content,
queryFn: () => {
if (!id) {
throw new UndefinedArgument();
}
return Api.getMember({ id });
},
enabled: Boolean(id),
...defaultQueryOptions,
}),

// use another hook because of key content
useAvatarUrl: ({
id,
Expand Down
4 changes: 2 additions & 2 deletions src/ui/items/AppItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { type JSX, memo, useMemo, useRef, useState } from 'react';
import { Skeleton, styled } from '@mui/material';

import {
Account,
AppItemType,
Member,
appendQueryParamToUrl,
getAppExtra,
} from '@graasp/sdk';
Expand Down Expand Up @@ -75,7 +75,7 @@ type AppItemProps = {
/**
* id of the member currently signed in
*/
memberId?: Member['id'];
memberId?: Account['id'];
/**
* Whether the caption is shown
*/
Expand Down
Loading