@greatapps/common 1.1.505 → 1.1.507
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,7 +9,16 @@ function useCreateCard() {
|
|
|
9
9
|
const cardsKey = useAuthQueryKey([...CARDS_QUERY_KEY]);
|
|
10
10
|
return useMutation({
|
|
11
11
|
mutationFn: (data) => withAction(createCardAction)(data),
|
|
12
|
-
onSuccess: () => {
|
|
12
|
+
onSuccess: (result) => {
|
|
13
|
+
if (result?.data) {
|
|
14
|
+
queryClient.setQueriesData(
|
|
15
|
+
{ queryKey: cardsKey },
|
|
16
|
+
(old) => {
|
|
17
|
+
if (!old?.data) return old;
|
|
18
|
+
return { ...old, data: [...old.data, result.data] };
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
}
|
|
13
22
|
queryClient.invalidateQueries({ queryKey: cardsKey });
|
|
14
23
|
}
|
|
15
24
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/cards/hooks/create-card.hook.ts"],"sourcesContent":["'use client';\n\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { withAction } from '../../../utils/withAction';\nimport { createCardAction } from '../actions/create-card.action';\nimport { CreateCardRequest } from '../types';\nimport { CARDS_QUERY_KEY } from './cards.hook';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\n\nexport function useCreateCard() {\n const queryClient = useQueryClient();\n const cardsKey = useAuthQueryKey([...CARDS_QUERY_KEY]);\n\n return useMutation({\n mutationFn: (data: CreateCardRequest) => withAction(createCardAction)(data),\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: cardsKey });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,aAAa,sBAAsB;AAC5C,SAAS,kBAAkB;AAC3B,SAAS,wBAAwB;
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/cards/hooks/create-card.hook.ts"],"sourcesContent":["'use client';\n\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { withAction } from '../../../utils/withAction';\nimport { createCardAction } from '../actions/create-card.action';\nimport type { CreateCardRequest, Card } from '../types';\nimport type { PaginatedSuccessResult } from '../../../infra/api/types';\nimport { CARDS_QUERY_KEY } from './cards.hook';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\n\nexport function useCreateCard() {\n const queryClient = useQueryClient();\n const cardsKey = useAuthQueryKey([...CARDS_QUERY_KEY]);\n\n return useMutation({\n mutationFn: (data: CreateCardRequest) => withAction(createCardAction)(data),\n onSuccess: (result) => {\n if (result?.data) {\n queryClient.setQueriesData<PaginatedSuccessResult<Card>>(\n { queryKey: cardsKey },\n (old) => {\n if (!old?.data) return old;\n return { ...old, data: [...old.data, result.data!] };\n }\n );\n }\n queryClient.invalidateQueries({ queryKey: cardsKey });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,aAAa,sBAAsB;AAC5C,SAAS,kBAAkB;AAC3B,SAAS,wBAAwB;AAGjC,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAEzB,SAAS,gBAAgB;AAC9B,QAAM,cAAc,eAAe;AACnC,QAAM,WAAW,gBAAgB,CAAC,GAAG,eAAe,CAAC;AAErD,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,SAA4B,WAAW,gBAAgB,EAAE,IAAI;AAAA,IAC1E,WAAW,CAAC,WAAW;AACrB,UAAI,QAAQ,MAAM;AAChB,oBAAY;AAAA,UACV,EAAE,UAAU,SAAS;AAAA,UACrB,CAAC,QAAQ;AACP,gBAAI,CAAC,KAAK,KAAM,QAAO;AACvB,mBAAO,EAAE,GAAG,KAAK,MAAM,CAAC,GAAG,IAAI,MAAM,OAAO,IAAK,EAAE;AAAA,UACrD;AAAA,QACF;AAAA,MACF;AACA,kBAAY,kBAAkB,EAAE,UAAU,SAAS,CAAC;AAAA,IACtD;AAAA,EACF,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
4
4
|
import { withAction } from '../../../utils/withAction';
|
|
5
5
|
import { createCardAction } from '../actions/create-card.action';
|
|
6
|
-
import { CreateCardRequest } from '../types';
|
|
6
|
+
import type { CreateCardRequest, Card } from '../types';
|
|
7
|
+
import type { PaginatedSuccessResult } from '../../../infra/api/types';
|
|
7
8
|
import { CARDS_QUERY_KEY } from './cards.hook';
|
|
8
9
|
import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
|
|
9
10
|
|
|
@@ -13,7 +14,16 @@ export function useCreateCard() {
|
|
|
13
14
|
|
|
14
15
|
return useMutation({
|
|
15
16
|
mutationFn: (data: CreateCardRequest) => withAction(createCardAction)(data),
|
|
16
|
-
onSuccess: () => {
|
|
17
|
+
onSuccess: (result) => {
|
|
18
|
+
if (result?.data) {
|
|
19
|
+
queryClient.setQueriesData<PaginatedSuccessResult<Card>>(
|
|
20
|
+
{ queryKey: cardsKey },
|
|
21
|
+
(old) => {
|
|
22
|
+
if (!old?.data) return old;
|
|
23
|
+
return { ...old, data: [...old.data, result.data!] };
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
}
|
|
17
27
|
queryClient.invalidateQueries({ queryKey: cardsKey });
|
|
18
28
|
},
|
|
19
29
|
});
|