@tagadapay/plugin-sdk 2.4.22 → 2.4.24
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.
|
@@ -4,17 +4,24 @@ import { useEffect, useState } from 'react';
|
|
|
4
4
|
* useCustomer - Hook to access current customer data
|
|
5
5
|
*/
|
|
6
6
|
import { useTagadaContext } from '../providers/TagadaProvider';
|
|
7
|
+
import { usePluginConfig } from './usePluginConfig';
|
|
7
8
|
import { useSession } from './useSession';
|
|
8
9
|
export function useCustomer() {
|
|
10
|
+
const { storeId } = usePluginConfig();
|
|
9
11
|
const { customerId } = useSession();
|
|
10
12
|
const [customer, setCustomer] = useState(null);
|
|
11
13
|
const { apiService } = useTagadaContext();
|
|
12
14
|
const [isLoading, setIsLoading] = useState(false);
|
|
13
15
|
const [error, setError] = useState(null);
|
|
14
|
-
const fetchCustomer = async (customerId) => {
|
|
16
|
+
const fetchCustomer = async (customerId, storeId) => {
|
|
15
17
|
try {
|
|
16
18
|
setIsLoading(true);
|
|
17
|
-
const customer = await apiService.fetch(`/api/v1/customers
|
|
19
|
+
const customer = await apiService.fetch(`/api/v1/customers/${customerId}`, {
|
|
20
|
+
method: 'GET',
|
|
21
|
+
params: {
|
|
22
|
+
storeId,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
18
25
|
console.log('customer', customer);
|
|
19
26
|
setCustomer(customer);
|
|
20
27
|
return customer;
|
|
@@ -28,15 +35,18 @@ export function useCustomer() {
|
|
|
28
35
|
}
|
|
29
36
|
};
|
|
30
37
|
useEffect(() => {
|
|
31
|
-
if (customerId) {
|
|
32
|
-
fetchCustomer(customerId);
|
|
38
|
+
if (customerId && storeId) {
|
|
39
|
+
fetchCustomer(customerId, storeId);
|
|
33
40
|
}
|
|
34
|
-
}, [customerId]);
|
|
41
|
+
}, [customerId, storeId]);
|
|
35
42
|
const refreshCustomer = async () => {
|
|
36
43
|
if (!customerId) {
|
|
37
44
|
throw new Error('No customer ID available');
|
|
38
45
|
}
|
|
39
|
-
|
|
46
|
+
if (!storeId) {
|
|
47
|
+
throw new Error('No store ID available');
|
|
48
|
+
}
|
|
49
|
+
return await fetchCustomer(customerId, storeId);
|
|
40
50
|
};
|
|
41
51
|
return {
|
|
42
52
|
customer,
|