@@ -8,22 +8,23 @@ import ShopContext from '../contexts';
88import ShopSchemas from "../schemas" ;
99
1010const QUERY_KEYS = {
11- USER : [ "query" , "user" ] ,
12- PRODUCT_LIST : [ "query" , "products" ] ,
13- CART_INFO : [ "query" , "cart" ] ,
14- ORDER_LIST : [ "query" , "orders" ] ,
11+ BASE : [ "query" , "shop" ] ,
12+ USER : [ "query" , "shop" , "user" ] ,
13+ PRODUCT_LIST : [ "query" , "shop" , "products" ] ,
14+ CART_INFO : [ "query" , "shop" , "cart" ] ,
15+ ORDER_LIST : [ "query" , "shop" , "orders" ] ,
1516} ;
1617
1718const MUTATION_KEYS = {
18- USER_SIGN_IN_EMAIL : [ "mutation" , "user" , "sign_in" , "email" ] ,
19- USER_SIGN_IN_SNS : [ "mutation" , "user" , "sign_in" , "sns" ] ,
20- USER_SIGN_OUT : [ "mutation" , "user" , "sign_out" ] ,
21- CART_ITEM_APPEND : [ "mutation" , "cart" , "item" , "append" ] ,
22- CART_ITEM_REMOVE : [ "mutation" , "cart" , "item" , "remove" ] ,
23- CART_ORDER_START : [ "mutation" , "cart_order" , "start" ] ,
24- ONE_ITEM_ORDER_START : [ "mutation" , "one_item_order" , "start" ] ,
25- ALL_ORDER_REFUND : [ "mutation" , "all_order_refund" ] ,
26- ONE_ITEM_REFUND : [ "mutation" , "one_item_refund" ] ,
19+ USER_SIGN_IN_EMAIL : [ "mutation" , "shop" , " user", "sign_in" , "email" ] ,
20+ USER_SIGN_IN_SNS : [ "mutation" , "shop" , " user", "sign_in" , "sns" ] ,
21+ USER_SIGN_OUT : [ "mutation" , "shop" , " user", "sign_out" ] ,
22+ CART_ITEM_APPEND : [ "mutation" , "shop" , " cart", "item" , "append" ] ,
23+ CART_ITEM_REMOVE : [ "mutation" , "shop" , " cart", "item" , "remove" ] ,
24+ CART_ORDER_START : [ "mutation" , "shop" , " cart_order", "start" ] ,
25+ ONE_ITEM_ORDER_START : [ "mutation" , "shop" , " one_item_order", "start" ] ,
26+ ALL_ORDER_REFUND : [ "mutation" , "shop" , " all_order_refund"] ,
27+ ONE_ITEM_REFUND : [ "mutation" , "shop" , " one_item_refund"] ,
2728} ;
2829
2930namespace ShopHooks {
@@ -43,59 +44,29 @@ namespace ShopHooks {
4344 export const useUserStatus = ( ) =>
4445 useSuspenseQuery ( {
4546 queryKey : QUERY_KEYS . USER ,
46- queryFn : async ( ) => {
47- try {
48- const userInfo = await clientDecorator ( ShopAPIs . retrieveUserInfo ) ( ) ;
49- return userInfo . meta . is_authenticated === true ? userInfo : null ;
50- } catch ( e ) {
51- return null ;
52- }
53- } ,
47+ queryFn : clientDecorator ( ShopAPIs . retrieveUserInfo ) ,
48+ retry : 3 ,
5449 } ) ;
5550
5651 export const useSignInWithEmailMutation = ( ) =>
5752 useMutation ( {
5853 mutationKey : MUTATION_KEYS . USER_SIGN_IN_EMAIL ,
5954 mutationFn : clientDecorator ( ShopAPIs . signInWithEmail ) ,
60- meta : {
61- invalidates : [
62- QUERY_KEYS . USER ,
63- QUERY_KEYS . CART_INFO ,
64- QUERY_KEYS . ORDER_LIST ,
65- ] ,
66- } ,
55+ meta : { invalidates : [ QUERY_KEYS . BASE ] } ,
6756 } ) ;
6857
6958 export const useSignInWithSNSMutation = ( ) =>
7059 useMutation ( {
7160 mutationKey : MUTATION_KEYS . USER_SIGN_IN_SNS ,
7261 mutationFn : clientDecorator ( ShopAPIs . signInWithSNS ) ,
73- meta : {
74- invalidates : [
75- QUERY_KEYS . USER ,
76- QUERY_KEYS . CART_INFO ,
77- QUERY_KEYS . ORDER_LIST ,
78- ] ,
79- } ,
62+ meta : { invalidates : [ QUERY_KEYS . BASE ] } ,
8063 } ) ;
8164
8265 export const useSignOutMutation = ( ) =>
8366 useMutation ( {
8467 mutationKey : MUTATION_KEYS . USER_SIGN_OUT ,
85- mutationFn : async ( ) => {
86- try {
87- return await clientDecorator ( ShopAPIs . signOut ) ( ) ;
88- } catch ( e ) {
89- return null ;
90- }
91- } ,
92- meta : {
93- invalidates : [
94- QUERY_KEYS . USER ,
95- QUERY_KEYS . CART_INFO ,
96- QUERY_KEYS . ORDER_LIST ,
97- ] ,
98- } ,
68+ mutationFn : clientDecorator ( ShopAPIs . signOut ) ,
69+ meta : { invalidates : [ QUERY_KEYS . BASE ] } ,
9970 } ) ;
10071
10172 export const useProducts = ( qs ?: ShopSchemas . ProductListQueryParams ) =>
0 commit comments