Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.

feat(refactor): update ShortLink types from SDK #979

Merged
merged 1 commit into from
Nov 6, 2024
Merged
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
feat(refactor): update ShortLink types from SDK
  • Loading branch information
ReidyT committed Nov 6, 2024
commit 1b90d1f4e019532eddea6aeb73b16046fb21323a
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@eslint/compat": "1.2.0",
"@eslint/eslintrc": "3.1.0",
"@eslint/js": "9.12.0",
"@graasp/sdk": "4.33.0",
"@graasp/sdk": "4.35.0",
"@graasp/translations": "1.40.0",
"@testing-library/dom": "10.4.0",
"@testing-library/react": "16.0.1",
Expand Down
23 changes: 12 additions & 11 deletions src/api/shortLink.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
ShortLink,
ShortLinkAvailable,
ShortLinkPatchPayload,
ShortLinkPostPayload,
ShortLinksOfItem,
UpdateShortLink,
} from '@graasp/sdk';

import {
Expand Down Expand Up @@ -33,7 +33,9 @@ export const getShortLinksItem = (
) =>
verifyAuthentication(() =>
axios
.get<ShortLink[]>(`${API_HOST}/${buildGetShortLinksItemRoute(itemId)}`)
.get<ShortLinksOfItem>(
`${API_HOST}/${buildGetShortLinksItemRoute(itemId)}`,
)
.then(({ data }) => data),
);

Expand All @@ -48,26 +50,25 @@ export const deleteShortLink = (
);

export const postShortLink = async (
shortLink: ShortLinkPostPayload,
shortLink: ShortLink,
{ API_HOST, axios }: PartialQueryConfigForApi,
) =>
verifyAuthentication(() =>
axios
.post<ShortLink>(`${API_HOST}/${buildPostShortLinkRoute()}`, {
...shortLink,
})
.post<ShortLink>(`${API_HOST}/${buildPostShortLinkRoute()}`, shortLink)
.then(({ data }) => data),
);

export const patchShortLink = (
alias: string,
updatedPayload: ShortLinkPatchPayload,
updatedPayload: UpdateShortLink,
{ API_HOST, axios }: PartialQueryConfigForApi,
) =>
verifyAuthentication(() =>
axios
.patch<ShortLink>(`${API_HOST}/${buildPatchShortLinkRoute(alias)}`, {
...updatedPayload,
})
.patch<ShortLink>(
`${API_HOST}/${buildPatchShortLinkRoute(alias)}`,
updatedPayload,
)
.then(({ data }) => data),
);
2 changes: 1 addition & 1 deletion src/hooks/shortLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default (queryConfig: QueryClientConfig) => {
useQuery({
queryKey: itemKeys.single(itemId).shortLinks,
queryFn: () => Api.getShortLinksItem(itemId, queryConfig),
enabled: true,
enabled: Boolean(itemId),
...defaultQueryOptions,
}),
};
Expand Down
2 changes: 1 addition & 1 deletion src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const itemKeys = {
geolocation: [...singleBaseKey, 'geolocation'] as const,

// short links
shortLinks: [...singleBaseKey, 'shortLink'] as const,
shortLinks: [...singleBaseKey, 'shortLinks'] as const,

// likes
likes: [...singleBaseKey, 'likes'] as const,
Expand Down
10 changes: 5 additions & 5 deletions src/mutations/shortLink.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ShortLinkPatchPayload, ShortLinkPostPayload } from '@graasp/sdk';
import { ShortLink, UpdateShortLink } from '@graasp/sdk';
import { SUCCESS_MESSAGES } from '@graasp/translations';

import { useMutation, useQueryClient } from '@tanstack/react-query';
Expand All @@ -18,7 +18,7 @@ export default (queryConfig: QueryClientConfig) => {
const usePostShortLink = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async (shortLink: ShortLinkPostPayload) =>
mutationFn: async (shortLink: ShortLink) =>
Api.postShortLink(shortLink, queryConfig),
onSuccess: (_data, variables) => {
notifier?.({
Expand Down Expand Up @@ -49,15 +49,15 @@ export default (queryConfig: QueryClientConfig) => {
shortLink,
}: {
alias: string;
shortLink: ShortLinkPatchPayload;
shortLink: UpdateShortLink;
}) => Api.patchShortLink(alias, shortLink, queryConfig),
onSuccess: (data) => {
notifier?.({
type: patchShortLinkRoutine.SUCCESS,
payload: { message: SUCCESS_MESSAGES.EDIT_SHORT_LINK },
});
queryClient.invalidateQueries({
queryKey: itemKeys.single(data.item.id).shortLinks,
queryKey: itemKeys.single(data.itemId).shortLinks,
});
queryClient.invalidateQueries({
queryKey: buildShortLinkKey(data.alias),
Expand All @@ -83,7 +83,7 @@ export default (queryConfig: QueryClientConfig) => {
payload: { message: SUCCESS_MESSAGES.DELETE_SHORT_LINK },
});
queryClient.invalidateQueries({
queryKey: itemKeys.single(data.item.id).shortLinks,
queryKey: itemKeys.single(data.itemId).shortLinks,
});
queryClient.invalidateQueries({
queryKey: buildShortLinkKey(data.alias),
Expand Down
30 changes: 11 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,10 @@ __metadata:
languageName: node
linkType: hard

"@faker-js/faker@npm:9.0.3":
version: 9.0.3
resolution: "@faker-js/faker@npm:9.0.3"
checksum: 10/60ea71c31d6bd6317184736de17daee415e229cab5e10a4146a19622f3eb22f49f42345ff339dc9261f0214ca1f9b019c63fd9aac842a2d359f135102788ec90
"@faker-js/faker@npm:9.2.0":
version: 9.2.0
resolution: "@faker-js/faker@npm:9.2.0"
checksum: 10/c233aaa41ebc4f4bed36c1304c399c424b9e5abca9cb8fe54ce73d4162ec7acd66f294b90c85ed7a5df774400e44f0a10364bdd41f49e72cb519a48b5948939f
languageName: node
linkType: hard

Expand All @@ -636,7 +636,7 @@ __metadata:
"@eslint/compat": "npm:1.2.0"
"@eslint/eslintrc": "npm:3.1.0"
"@eslint/js": "npm:9.12.0"
"@graasp/sdk": "npm:4.33.0"
"@graasp/sdk": "npm:4.35.0"
"@graasp/translations": "npm:1.40.0"
"@tanstack/react-query": "npm:5.59.8"
"@tanstack/react-query-devtools": "npm:5.59.8"
Expand Down Expand Up @@ -683,18 +683,17 @@ __metadata:
languageName: unknown
linkType: soft

"@graasp/sdk@npm:4.33.0":
version: 4.33.0
resolution: "@graasp/sdk@npm:4.33.0"
"@graasp/sdk@npm:4.35.0":
version: 4.35.0
resolution: "@graasp/sdk@npm:4.35.0"
dependencies:
"@faker-js/faker": "npm:9.0.3"
"@faker-js/faker": "npm:9.2.0"
filesize: "npm:10.1.6"
js-cookie: "npm:3.0.5"
validator: "npm:13.12.0"
peerDependencies:
date-fns: ^3 || ^4.0.0
uuid: ^9 || ^10
checksum: 10/6e0b0f661f52e1ca97b48c4b90ddc3c18e2afe7b8d3bf7818010b24bbc57f3c1ddc9bfa90c6fe2a1c05535f73ffe15956523b2557906b4a21a9a9f8b61d1647a
uuid: ^9 || ^10 || ^11.0.0
checksum: 10/72f4ad5c689f94fb0bd99696b7b18d7a7d893df5117b6b39e019d7943cd48c909e11a80bc5de0c0cf66fd4f0f7ffb79fc29fad244ff5070d9a1699538c8ea5d2
languageName: node
linkType: hard

Expand Down Expand Up @@ -6157,13 +6156,6 @@ __metadata:
languageName: node
linkType: hard

"validator@npm:13.12.0":
version: 13.12.0
resolution: "validator@npm:13.12.0"
checksum: 10/db6eb0725e2b67d60d30073ae8573982713b5903195d031dc3c7db7e82df8b74e8c13baef8e2106d146d979599fd61a06cde1fec5c148e4abd53d52817ff0fd9
languageName: node
linkType: hard

"vite-node@npm:2.1.2":
version: 2.1.2
resolution: "vite-node@npm:2.1.2"
Expand Down