@tagadapay/plugin-sdk 2.4.23 → 2.4.25
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.
|
@@ -1,49 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
3
2
|
/**
|
|
4
3
|
* useCustomer - Hook to access current customer data
|
|
5
4
|
*/
|
|
6
5
|
import { useTagadaContext } from '../providers/TagadaProvider';
|
|
7
|
-
import { useSession } from './useSession';
|
|
8
6
|
export function useCustomer() {
|
|
9
|
-
const {
|
|
10
|
-
const [customer, setCustomer] = useState(null);
|
|
11
|
-
const { apiService } = useTagadaContext();
|
|
12
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
13
|
-
const [error, setError] = useState(null);
|
|
14
|
-
const fetchCustomer = async (customerId) => {
|
|
15
|
-
try {
|
|
16
|
-
setIsLoading(true);
|
|
17
|
-
const customer = await apiService.fetch(`/api/v1/customers/${customerId}`);
|
|
18
|
-
console.log('customer', customer);
|
|
19
|
-
setCustomer(customer);
|
|
20
|
-
return customer;
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
setError(error);
|
|
24
|
-
console.error('Error fetching customer:', error);
|
|
25
|
-
}
|
|
26
|
-
finally {
|
|
27
|
-
setIsLoading(false);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
if (customerId) {
|
|
32
|
-
fetchCustomer(customerId);
|
|
33
|
-
}
|
|
34
|
-
}, [customerId]);
|
|
35
|
-
const refreshCustomer = async () => {
|
|
36
|
-
if (!customerId) {
|
|
37
|
-
throw new Error('No customer ID available');
|
|
38
|
-
}
|
|
39
|
-
return await fetchCustomer(customerId);
|
|
40
|
-
};
|
|
7
|
+
const { customer, isLoading } = useTagadaContext();
|
|
41
8
|
return {
|
|
42
9
|
customer,
|
|
43
10
|
isAuthenticated: customer?.isAuthenticated || false,
|
|
44
11
|
isLoading,
|
|
45
12
|
isAnonymous: customer?.role === 'anonymous',
|
|
46
|
-
refreshCustomer,
|
|
47
|
-
error,
|
|
48
13
|
};
|
|
49
14
|
}
|
|
@@ -211,6 +211,7 @@ localConfig, blockUntilSessionReady = false, // Default to new non-blocking beha
|
|
|
211
211
|
storeId: sessionData.storeId,
|
|
212
212
|
accountId: sessionData.accountId,
|
|
213
213
|
customerId: sessionData.customerId,
|
|
214
|
+
role: sessionData.role,
|
|
214
215
|
browserLocale,
|
|
215
216
|
queryLocale: urlParams.locale,
|
|
216
217
|
queryCurrency: urlParams.currency,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EnvironmentConfig } from '../types';
|
|
1
|
+
import { EnvironmentConfig, SessionRole } from '../types';
|
|
2
2
|
export interface ApiServiceOptions {
|
|
3
3
|
environmentConfig: EnvironmentConfig;
|
|
4
4
|
token?: string | null;
|
|
@@ -39,7 +39,7 @@ export interface SessionInitResponse {
|
|
|
39
39
|
lastName?: string;
|
|
40
40
|
phone?: string;
|
|
41
41
|
isAuthenticated: boolean;
|
|
42
|
-
role:
|
|
42
|
+
role: SessionRole;
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
export declare class ApiService {
|
|
@@ -75,6 +75,7 @@ export declare class ApiService {
|
|
|
75
75
|
storeId: string;
|
|
76
76
|
accountId: string;
|
|
77
77
|
customerId: string;
|
|
78
|
+
role: SessionRole;
|
|
78
79
|
browserLocale?: string;
|
|
79
80
|
queryLocale?: string;
|
|
80
81
|
queryCurrency?: string;
|
package/dist/react/types.d.ts
CHANGED
|
@@ -31,12 +31,13 @@ export interface Customer {
|
|
|
31
31
|
isAuthenticated: boolean;
|
|
32
32
|
role: 'authenticated' | 'anonymous';
|
|
33
33
|
}
|
|
34
|
+
export type SessionRole = 'authenticated' | 'anonymous';
|
|
34
35
|
export interface Session {
|
|
35
36
|
sessionId: string;
|
|
36
37
|
storeId: string;
|
|
37
38
|
accountId: string;
|
|
38
39
|
customerId: string;
|
|
39
|
-
role:
|
|
40
|
+
role: SessionRole;
|
|
40
41
|
isValid: boolean;
|
|
41
42
|
isLoading: boolean;
|
|
42
43
|
}
|