buymeua-api-fe 0.14.0 → 0.15.0

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +6 -3
  3. package/dist/entities/ad/api/adApi.js +1 -1
  4. package/dist/entities/ad/api/adApi.js.map +1 -1
  5. package/dist/entities/cart/api/cartApi.js +2 -2
  6. package/dist/entities/cart/api/cartApi.js.map +1 -1
  7. package/dist/entities/category/api/categoryApi.js +1 -1
  8. package/dist/entities/category/api/categoryApi.js.map +1 -1
  9. package/dist/entities/chat/api/chatApi.js +1 -1
  10. package/dist/entities/chat/api/chatApi.js.map +1 -1
  11. package/dist/entities/country/api/countryApi.js +1 -1
  12. package/dist/entities/country/api/countryApi.js.map +1 -1
  13. package/dist/entities/favorite/api/favoriteApi.d.ts +40 -41
  14. package/dist/entities/favorite/api/favoriteApi.d.ts.map +1 -1
  15. package/dist/entities/favorite/api/favoriteApi.js +287 -269
  16. package/dist/entities/favorite/api/favoriteApi.js.map +1 -1
  17. package/dist/entities/favorite/model/types.d.ts +5 -16
  18. package/dist/entities/favorite/model/types.d.ts.map +1 -1
  19. package/dist/entities/notification/api/notificationApi.js +1 -1
  20. package/dist/entities/notification/api/notificationApi.js.map +1 -1
  21. package/dist/entities/novaposhta/api/novaposhtaApi.js +3 -3
  22. package/dist/entities/novaposhta/api/novaposhtaApi.js.map +1 -1
  23. package/dist/entities/product/api/productApi.d.ts +132 -317
  24. package/dist/entities/product/api/productApi.d.ts.map +1 -1
  25. package/dist/entities/product/api/productApi.js +54 -13
  26. package/dist/entities/product/api/productApi.js.map +1 -1
  27. package/dist/entities/product/model/types.d.ts +0 -6
  28. package/dist/entities/product/model/types.d.ts.map +1 -1
  29. package/dist/entities/referral/api/referralApi.js +2 -2
  30. package/dist/entities/referral/api/referralApi.js.map +1 -1
  31. package/dist/entities/stories/api/storiesApi.js +1 -1
  32. package/dist/entities/stories/api/storiesApi.js.map +1 -1
  33. package/package.json +1 -1
@@ -1,6 +1,5 @@
1
1
  import { productApi } from '../../product';
2
2
  import { getNextPageParam } from '../../../shared/lib';
3
- // TODO: optimistic
4
3
  export const favoriteApi = productApi
5
4
  .injectEndpoints({
6
5
  endpoints: (build) => ({
@@ -17,8 +16,8 @@ export const favoriteApi = productApi
17
16
  query: (arg) => ({
18
17
  url: 'v1/favorite/merchants',
19
18
  params: {
20
- page: arg.pageParam,
21
19
  ...arg.queryArg,
20
+ page: arg.pageParam,
22
21
  },
23
22
  }),
24
23
  }),
@@ -30,8 +29,8 @@ export const favoriteApi = productApi
30
29
  query: (arg) => ({
31
30
  url: 'v1/favorite/merchant-items',
32
31
  params: {
33
- page: arg.pageParam,
34
32
  ...arg.queryArg,
33
+ page: arg.pageParam,
35
34
  },
36
35
  }),
37
36
  }),
@@ -39,269 +38,264 @@ export const favoriteApi = productApi
39
38
  query: (arg) => ({
40
39
  url: 'v1/favorite',
41
40
  method: 'POST',
42
- body: { ...arg },
41
+ body: arg,
43
42
  }),
44
- // onQueryStarted: async (queryArgument, mutationLifeCycleApi) => {
45
- // const patchResult = mutationLifeCycleApi.dispatch(
46
- // favoriteApi.util.updateQueryData(
47
- // 'getFavoriteMerchantItems',
48
- // { merchant_id: 0 }, // TODO
49
- // (draft) => {
50
- // draft.pages[draft.pages.length - 1].push(queryArgument.merchant_id);
51
- // },
52
- // ),
53
- // );
54
- // const favoriteCountPatchResult = mutationLifeCycleApi.dispatch(
55
- // favoriteApi.util.updateQueryData(
56
- // 'getFavoriteCount',
57
- // undefined,
58
- // (draft) => {
59
- // draft.total_quantity += 1;
60
- // },
61
- // ),
62
- // );
63
- // let productPatchResult;
64
- // let supplierProductPatchResult;
65
- // let productDetailsPatchResult;
66
- // let supplierProductDetailsPatchResult;
67
- // for (const {
68
- // endpointName,
69
- // originalArgs,
70
- // } of favoriteApi.util.selectInvalidatedBy(
71
- // mutationLifeCycleApi.getState(),
72
- // [{ type: 'Product', id: queryArgument.product.id }],
73
- // )) {
74
- // if (endpointName !== 'getProductsSearch') continue;
75
- // productPatchResult = mutationLifeCycleApi.dispatch(
76
- // favoriteApi.util.updateQueryData(
77
- // 'getProductsSearch',
78
- // originalArgs,
79
- // (draft) => {
80
- // draft.pages.forEach((page) => {
81
- // page.forEach((product) => {
82
- // if (product.id === queryArgument.product.id) {
83
- // product.in_favorite = true;
84
- // }
85
- // });
86
- // });
87
- // },
88
- // ),
89
- // );
90
- // }
91
- // for (const {
92
- // endpointName,
93
- // originalArgs,
94
- // } of favoriteApi.util.selectInvalidatedBy(
95
- // mutationLifeCycleApi.getState(),
96
- // [{ type: 'SupplierProduct', id: queryArgument.product.id }],
97
- // )) {
98
- // if (endpointName !== 'getSupplierProducts') continue;
99
- // supplierProductPatchResult = mutationLifeCycleApi.dispatch(
100
- // favoriteApi.util.updateQueryData(
101
- // 'getSupplierProducts',
102
- // originalArgs,
103
- // (draft) => {
104
- // draft.pages.forEach((page) => {
105
- // page.data.forEach((product) => {
106
- // if (product.id === queryArgument.product.id) {
107
- // product.in_favorite = true;
108
- // }
109
- // });
110
- // });
111
- // },
112
- // ),
113
- // );
114
- // }
115
- // for (const {
116
- // endpointName,
117
- // originalArgs,
118
- // } of favoriteApi.util.selectInvalidatedBy(
119
- // mutationLifeCycleApi.getState(),
120
- // [{ type: 'ProductDetails', id: queryArgument.product.id }],
121
- // )) {
122
- // if (endpointName !== 'getProductDetails') continue;
123
- // productDetailsPatchResult = mutationLifeCycleApi.dispatch(
124
- // favoriteApi.util.updateQueryData(
125
- // 'getProductDetails',
126
- // originalArgs,
127
- // (draft) => {
128
- // draft.in_favorite = true;
129
- // },
130
- // ),
131
- // );
132
- // }
133
- // for (const {
134
- // endpointName,
135
- // originalArgs,
136
- // } of favoriteApi.util.selectInvalidatedBy(
137
- // mutationLifeCycleApi.getState(),
138
- // [{ type: 'SupplierProductDetails', id: queryArgument.product.id }],
139
- // )) {
140
- // if (endpointName !== 'getSupplierProductDetails') continue;
141
- // supplierProductDetailsPatchResult = mutationLifeCycleApi.dispatch(
142
- // favoriteApi.util.updateQueryData(
143
- // 'getSupplierProductDetails',
144
- // originalArgs,
145
- // (draft) => {
146
- // draft.in_favorite = true;
147
- // },
148
- // ),
149
- // );
150
- // }
151
- // try {
152
- // await mutationLifeCycleApi.queryFulfilled;
153
- // } catch {
154
- // patchResult.undo();
155
- // favoriteCountPatchResult.undo();
156
- // if (productPatchResult) productPatchResult.undo();
157
- // if (supplierProductPatchResult) supplierProductPatchResult.undo();
158
- // if (productDetailsPatchResult) productDetailsPatchResult.undo();
159
- // if (supplierProductDetailsPatchResult)
160
- // supplierProductDetailsPatchResult.undo();
161
- // }
162
- // },
43
+ // TODO: Review, refactor, standalone func to this and deleteFavoriteMerchantItem
44
+ onQueryStarted: async (queryArgument, mutationLifeCycleApi) => {
45
+ if (!queryArgument.optimisticUpdate)
46
+ return;
47
+ const patchResult = mutationLifeCycleApi.dispatch(favoriteApi.util.updateQueryData('getFavoriteMerchantItems', {
48
+ merchant_id: queryArgument.optimisticUpdate.product.merchant_id,
49
+ }, (draft) => {
50
+ const firstPage = draft.pages[0];
51
+ if (!firstPage || !queryArgument.optimisticUpdate?.product)
52
+ return;
53
+ const favoriteItem = {
54
+ ...queryArgument.optimisticUpdate.product,
55
+ favorite_item_id: performance.now() + Math.random() * 1000,
56
+ };
57
+ firstPage.data.push(favoriteItem);
58
+ }));
59
+ const favoriteCountPatchResult = mutationLifeCycleApi.dispatch(favoriteApi.util.updateQueryData('getFavoriteCount', undefined, (draft) => {
60
+ draft.total_quantity += 1;
61
+ }));
62
+ let productPatchResult;
63
+ let bestsellerProductPatchResult;
64
+ let supplierProductPatchResult;
65
+ let productDetailsPatchResult;
66
+ let supplierProductDetailsPatchResult;
67
+ for (const { endpointName, originalArgs, } of favoriteApi.util.selectInvalidatedBy(mutationLifeCycleApi.getState(), [
68
+ {
69
+ type: 'Product',
70
+ id: queryArgument.optimisticUpdate.product.id,
71
+ },
72
+ ])) {
73
+ if (endpointName !== 'getProducts')
74
+ continue;
75
+ productPatchResult = mutationLifeCycleApi.dispatch(favoriteApi.util.updateQueryData('getProducts', originalArgs, (draft) => {
76
+ draft.pages.forEach((page) => {
77
+ page.data.forEach((product) => {
78
+ if (product.id ===
79
+ queryArgument.optimisticUpdate?.product.id) {
80
+ product.in_favorite = true;
81
+ }
82
+ });
83
+ });
84
+ }));
85
+ }
86
+ for (const { endpointName, originalArgs, } of favoriteApi.util.selectInvalidatedBy(mutationLifeCycleApi.getState(), [
87
+ {
88
+ type: 'BestsellerProduct',
89
+ id: queryArgument.optimisticUpdate.product.id,
90
+ },
91
+ ])) {
92
+ if (endpointName !== 'getBestSellers')
93
+ continue;
94
+ bestsellerProductPatchResult = mutationLifeCycleApi.dispatch(favoriteApi.util.updateQueryData('getBestSellers', originalArgs, (draft) => {
95
+ draft.data.forEach((bestsellerProduct) => {
96
+ if (bestsellerProduct.id ===
97
+ queryArgument.optimisticUpdate?.product.id) {
98
+ bestsellerProduct.in_favorite = true;
99
+ }
100
+ });
101
+ }));
102
+ }
103
+ for (const { endpointName, originalArgs, } of favoriteApi.util.selectInvalidatedBy(mutationLifeCycleApi.getState(), [
104
+ {
105
+ type: 'SupplierProduct',
106
+ id: queryArgument.optimisticUpdate.product.id,
107
+ },
108
+ ])) {
109
+ if (endpointName !== 'getSupplierProducts')
110
+ continue;
111
+ supplierProductPatchResult = mutationLifeCycleApi.dispatch(favoriteApi.util.updateQueryData('getSupplierProducts', originalArgs, (draft) => {
112
+ draft.pages.forEach((page) => {
113
+ page.data.forEach((product) => {
114
+ if (product.id ===
115
+ queryArgument.optimisticUpdate?.product.id) {
116
+ product.in_favorite = true;
117
+ }
118
+ });
119
+ });
120
+ }));
121
+ }
122
+ for (const { endpointName, originalArgs, } of favoriteApi.util.selectInvalidatedBy(mutationLifeCycleApi.getState(), [
123
+ {
124
+ type: 'ProductDetails',
125
+ id: queryArgument.optimisticUpdate.product.id,
126
+ },
127
+ ])) {
128
+ if (endpointName !== 'getProductDetails')
129
+ continue;
130
+ productDetailsPatchResult = mutationLifeCycleApi.dispatch(favoriteApi.util.updateQueryData('getProductDetails', originalArgs, (draft) => {
131
+ draft.data.in_favorite = true;
132
+ }));
133
+ }
134
+ for (const { endpointName, originalArgs, } of favoriteApi.util.selectInvalidatedBy(mutationLifeCycleApi.getState(), [
135
+ {
136
+ type: 'SupplierProductDetails',
137
+ id: queryArgument.optimisticUpdate.product.id,
138
+ },
139
+ ])) {
140
+ if (endpointName !== 'getSupplierProductDetails')
141
+ continue;
142
+ supplierProductDetailsPatchResult = mutationLifeCycleApi.dispatch(favoriteApi.util.updateQueryData('getSupplierProductDetails', originalArgs, (draft) => {
143
+ draft.data.in_favorite = true;
144
+ }));
145
+ }
146
+ try {
147
+ await mutationLifeCycleApi.queryFulfilled;
148
+ }
149
+ catch {
150
+ patchResult.undo();
151
+ favoriteCountPatchResult.undo();
152
+ if (productPatchResult)
153
+ productPatchResult.undo();
154
+ if (bestsellerProductPatchResult)
155
+ bestsellerProductPatchResult.undo();
156
+ if (supplierProductPatchResult)
157
+ supplierProductPatchResult.undo();
158
+ if (productDetailsPatchResult)
159
+ productDetailsPatchResult.undo();
160
+ if (supplierProductDetailsPatchResult)
161
+ supplierProductDetailsPatchResult.undo();
162
+ }
163
+ },
163
164
  }),
164
165
  deleteFavoriteMerchantItem: build.mutation({
165
166
  query: (arg) => ({
166
167
  url: 'v1/favorite',
167
168
  method: 'DELETE',
168
- body: { ...arg },
169
+ body: arg,
169
170
  }),
170
- // onQueryStarted: async (queryArgument, mutationLifeCycleApi) => {
171
- // let patchResult;
172
- // for (const {
173
- // endpointName,
174
- // originalArgs,
175
- // } of favoriteApi.util.selectInvalidatedBy(
176
- // mutationLifeCycleApi.getState(),
177
- // [{ type: 'FavoriteMerchantItem', id: queryArgument.productId }],
178
- // )) {
179
- // if (endpointName !== 'getFavoriteMerchantItems') continue;
180
- // patchResult = mutationLifeCycleApi.dispatch(
181
- // favoriteApi.util.updateQueryData(
182
- // 'getFavoriteMerchantItems',
183
- // originalArgs,
184
- // (draft) => {
185
- // draft.pages.forEach((favoriteMerchantItems) => {
186
- // favoriteMerchantItems.forEach((item, index) => {
187
- // if (item.id === queryArgument.productId) {
188
- // favoriteMerchantItems.splice(index, 1);
189
- // }
190
- // });
191
- // });
192
- // },
193
- // ),
194
- // );
195
- // }
196
- // const favoriteCountPatchResult = mutationLifeCycleApi.dispatch(
197
- // favoriteApi.util.updateQueryData(
198
- // 'getFavoriteCount',
199
- // undefined,
200
- // (draft) => {
201
- // draft.total_quantity -= 1;
202
- // },
203
- // ),
204
- // );
205
- // let productPatchResult;
206
- // let supplierProductPatchResult;
207
- // let productDetailsPatchResult;
208
- // let supplierProductDetailsPatchResult;
209
- // for (const {
210
- // endpointName,
211
- // originalArgs,
212
- // } of favoriteApi.util.selectInvalidatedBy(
213
- // mutationLifeCycleApi.getState(),
214
- // [{ type: 'Product', id: queryArgument.productId }],
215
- // )) {
216
- // if (endpointName !== 'getProductsSearch') continue;
217
- // productPatchResult = mutationLifeCycleApi.dispatch(
218
- // favoriteApi.util.updateQueryData(
219
- // 'getProductsSearch',
220
- // originalArgs,
221
- // (draft) => {
222
- // draft.pages.forEach((page) => {
223
- // page.forEach((product) => {
224
- // if (product.id === queryArgument.productId) {
225
- // product.in_favorite = false;
226
- // }
227
- // });
228
- // });
229
- // },
230
- // ),
231
- // );
232
- // }
233
- // for (const {
234
- // endpointName,
235
- // originalArgs,
236
- // } of favoriteApi.util.selectInvalidatedBy(
237
- // mutationLifeCycleApi.getState(),
238
- // [{ type: 'SupplierProduct', id: queryArgument.productId }],
239
- // )) {
240
- // if (endpointName !== 'getSupplierProducts') continue;
241
- // supplierProductPatchResult = mutationLifeCycleApi.dispatch(
242
- // favoriteApi.util.updateQueryData(
243
- // 'getSupplierProducts',
244
- // originalArgs,
245
- // (draft) => {
246
- // draft.pages.forEach((page) => {
247
- // page.data.forEach((product) => {
248
- // if (product.id === queryArgument.productId) {
249
- // product.in_favorite = false;
250
- // }
251
- // });
252
- // });
253
- // },
254
- // ),
255
- // );
256
- // }
257
- // for (const {
258
- // endpointName,
259
- // originalArgs,
260
- // } of favoriteApi.util.selectInvalidatedBy(
261
- // mutationLifeCycleApi.getState(),
262
- // [{ type: 'ProductDetails', id: queryArgument.productId }],
263
- // )) {
264
- // if (endpointName !== 'getProductDetails') continue;
265
- // productDetailsPatchResult = mutationLifeCycleApi.dispatch(
266
- // favoriteApi.util.updateQueryData(
267
- // 'getProductDetails',
268
- // originalArgs,
269
- // (draft) => {
270
- // draft.in_favorite = false;
271
- // },
272
- // ),
273
- // );
274
- // }
275
- // for (const {
276
- // endpointName,
277
- // originalArgs,
278
- // } of favoriteApi.util.selectInvalidatedBy(
279
- // mutationLifeCycleApi.getState(),
280
- // [{ type: 'SupplierProductDetails', id: queryArgument.productId }],
281
- // )) {
282
- // if (endpointName !== 'getSupplierProductDetails') continue;
283
- // supplierProductDetailsPatchResult = mutationLifeCycleApi.dispatch(
284
- // favoriteApi.util.updateQueryData(
285
- // 'getSupplierProductDetails',
286
- // originalArgs,
287
- // (draft) => {
288
- // draft.in_favorite = false;
289
- // },
290
- // ),
291
- // );
292
- // }
293
- // try {
294
- // await mutationLifeCycleApi.queryFulfilled;
295
- // } catch {
296
- // if (patchResult) patchResult.undo();
297
- // favoriteCountPatchResult.undo();
298
- // if (productPatchResult) productPatchResult.undo();
299
- // if (supplierProductPatchResult) supplierProductPatchResult.undo();
300
- // if (productDetailsPatchResult) productDetailsPatchResult.undo();
301
- // if (supplierProductDetailsPatchResult)
302
- // supplierProductDetailsPatchResult.undo();
303
- // }
304
- // },
171
+ onQueryStarted: async (queryArgument, mutationLifeCycleApi) => {
172
+ if (!queryArgument.optimisticUpdate)
173
+ return;
174
+ let patchResult;
175
+ for (const { endpointName, originalArgs, } of favoriteApi.util.selectInvalidatedBy(mutationLifeCycleApi.getState(), [
176
+ {
177
+ type: 'FavoriteMerchantItem',
178
+ id: queryArgument.optimisticUpdate.product.id,
179
+ },
180
+ ])) {
181
+ if (endpointName !== 'getFavoriteMerchantItems')
182
+ continue;
183
+ patchResult = mutationLifeCycleApi.dispatch(favoriteApi.util.updateQueryData('getFavoriteMerchantItems', originalArgs, (draft) => {
184
+ draft.pages.forEach((favoriteMerchantItems) => {
185
+ favoriteMerchantItems.data.forEach((item, index) => {
186
+ if (item.id === queryArgument.optimisticUpdate?.product.id) {
187
+ favoriteMerchantItems.data.splice(index, 1);
188
+ }
189
+ });
190
+ });
191
+ }));
192
+ }
193
+ const favoriteCountPatchResult = mutationLifeCycleApi.dispatch(favoriteApi.util.updateQueryData('getFavoriteCount', undefined, (draft) => {
194
+ draft.total_quantity -= 1;
195
+ }));
196
+ let productPatchResult;
197
+ let bestsellerProductPatchResult;
198
+ let supplierProductPatchResult;
199
+ let productDetailsPatchResult;
200
+ let supplierProductDetailsPatchResult;
201
+ for (const { endpointName, originalArgs, } of favoriteApi.util.selectInvalidatedBy(mutationLifeCycleApi.getState(), [
202
+ {
203
+ type: 'Product',
204
+ id: queryArgument.optimisticUpdate.product.id,
205
+ },
206
+ ])) {
207
+ if (endpointName !== 'getProducts')
208
+ continue;
209
+ productPatchResult = mutationLifeCycleApi.dispatch(favoriteApi.util.updateQueryData('getProducts', originalArgs, (draft) => {
210
+ draft.pages.forEach((page) => {
211
+ page.data.forEach((product) => {
212
+ if (product.id ===
213
+ queryArgument.optimisticUpdate?.product.id) {
214
+ product.in_favorite = false;
215
+ }
216
+ });
217
+ });
218
+ }));
219
+ }
220
+ for (const { endpointName, originalArgs, } of favoriteApi.util.selectInvalidatedBy(mutationLifeCycleApi.getState(), [
221
+ {
222
+ type: 'BestsellerProduct',
223
+ id: queryArgument.optimisticUpdate.product.id,
224
+ },
225
+ ])) {
226
+ if (endpointName !== 'getBestSellers')
227
+ continue;
228
+ bestsellerProductPatchResult = mutationLifeCycleApi.dispatch(favoriteApi.util.updateQueryData('getBestSellers', originalArgs, (draft) => {
229
+ draft.data.forEach((bestsellerProduct) => {
230
+ if (bestsellerProduct.id ===
231
+ queryArgument.optimisticUpdate?.product.id) {
232
+ bestsellerProduct.in_favorite = false;
233
+ }
234
+ });
235
+ }));
236
+ }
237
+ for (const { endpointName, originalArgs, } of favoriteApi.util.selectInvalidatedBy(mutationLifeCycleApi.getState(), [
238
+ {
239
+ type: 'SupplierProduct',
240
+ id: queryArgument.optimisticUpdate.product.id,
241
+ },
242
+ ])) {
243
+ if (endpointName !== 'getSupplierProducts')
244
+ continue;
245
+ supplierProductPatchResult = mutationLifeCycleApi.dispatch(favoriteApi.util.updateQueryData('getSupplierProducts', originalArgs, (draft) => {
246
+ draft.pages.forEach((page) => {
247
+ page.data.forEach((product) => {
248
+ if (product.id ===
249
+ queryArgument.optimisticUpdate?.product.id) {
250
+ product.in_favorite = false;
251
+ }
252
+ });
253
+ });
254
+ }));
255
+ }
256
+ for (const { endpointName, originalArgs, } of favoriteApi.util.selectInvalidatedBy(mutationLifeCycleApi.getState(), [
257
+ {
258
+ type: 'ProductDetails',
259
+ id: queryArgument.optimisticUpdate.product.id,
260
+ },
261
+ ])) {
262
+ if (endpointName !== 'getProductDetails')
263
+ continue;
264
+ productDetailsPatchResult = mutationLifeCycleApi.dispatch(favoriteApi.util.updateQueryData('getProductDetails', originalArgs, (draft) => {
265
+ draft.data.in_favorite = false;
266
+ }));
267
+ }
268
+ for (const { endpointName, originalArgs, } of favoriteApi.util.selectInvalidatedBy(mutationLifeCycleApi.getState(), [
269
+ {
270
+ type: 'SupplierProductDetails',
271
+ id: queryArgument.optimisticUpdate.product.id,
272
+ },
273
+ ])) {
274
+ if (endpointName !== 'getSupplierProductDetails')
275
+ continue;
276
+ supplierProductDetailsPatchResult = mutationLifeCycleApi.dispatch(favoriteApi.util.updateQueryData('getSupplierProductDetails', originalArgs, (draft) => {
277
+ draft.data.in_favorite = false;
278
+ }));
279
+ }
280
+ try {
281
+ await mutationLifeCycleApi.queryFulfilled;
282
+ }
283
+ catch {
284
+ if (patchResult)
285
+ patchResult.undo();
286
+ favoriteCountPatchResult.undo();
287
+ if (productPatchResult)
288
+ productPatchResult.undo();
289
+ if (bestsellerProductPatchResult)
290
+ bestsellerProductPatchResult.undo();
291
+ if (supplierProductPatchResult)
292
+ supplierProductPatchResult.undo();
293
+ if (productDetailsPatchResult)
294
+ productDetailsPatchResult.undo();
295
+ if (supplierProductDetailsPatchResult)
296
+ supplierProductDetailsPatchResult.undo();
297
+ }
298
+ },
305
299
  }),
306
300
  }),
307
301
  overrideExisting: false,
@@ -345,18 +339,42 @@ export const favoriteApi = productApi
345
339
  },
346
340
  },
347
341
  addFavoriteMerchantItem: {
348
- invalidatesTags: [
349
- { type: 'FavoriteMerchantItem', id: 'LIST' },
350
- { type: 'FavoriteMerchant', id: 'LIST' },
351
- { type: 'FavoriteCount', id: 'LIST' },
352
- ],
342
+ invalidatesTags: (_result, _error, arg, _meta) => {
343
+ return arg.optimisticUpdate
344
+ ? [
345
+ { type: 'FavoriteMerchant', id: 'LIST' },
346
+ { type: 'FavoriteMerchantItem', id: 'LIST' },
347
+ ]
348
+ : [
349
+ { type: 'FavoriteMerchant', id: 'LIST' },
350
+ { type: 'FavoriteMerchantItem', id: 'LIST' },
351
+ { type: 'FavoriteCount', id: 'LIST' },
352
+ { type: 'Product', id: arg.product_id },
353
+ { type: 'BestsellerProduct', id: arg.product_id },
354
+ { type: 'ProductDetails', id: arg.product_id },
355
+ { type: 'SupplierProduct', id: arg.product_id },
356
+ { type: 'SupplierProductDetails', id: arg.product_id },
357
+ ];
358
+ },
353
359
  },
354
360
  deleteFavoriteMerchantItem: {
355
- invalidatesTags: [
356
- { type: 'FavoriteMerchantItem', id: 'LIST' },
357
- { type: 'FavoriteMerchant', id: 'LIST' },
358
- { type: 'FavoriteCount', id: 'LIST' },
359
- ],
361
+ invalidatesTags: (_result, _error, arg, _meta) => {
362
+ return arg.optimisticUpdate
363
+ ? [
364
+ { type: 'FavoriteMerchant', id: 'LIST' },
365
+ { type: 'FavoriteMerchantItem', id: 'LIST' },
366
+ ]
367
+ : [
368
+ { type: 'FavoriteMerchant', id: 'LIST' },
369
+ { type: 'FavoriteMerchantItem', id: 'LIST' },
370
+ { type: 'FavoriteCount', id: 'LIST' },
371
+ { type: 'Product', id: arg.product_id },
372
+ { type: 'BestsellerProduct', id: arg.product_id },
373
+ { type: 'ProductDetails', id: arg.product_id },
374
+ { type: 'SupplierProduct', id: arg.product_id },
375
+ { type: 'SupplierProductDetails', id: arg.product_id },
376
+ ];
377
+ },
360
378
  },
361
379
  },
362
380
  });