-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathuse-current-customer.js
More file actions
37 lines (35 loc) · 960 Bytes
/
use-current-customer.js
File metadata and controls
37 lines (35 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* Copyright (c) 2022, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import {useCustomer, useCustomerId, useCustomerType} from '@salesforce/commerce-sdk-react'
/**
* A hook that returns the current customer.
*
*/
export const useCurrentCustomer = () => {
const customerId = useCustomerId()
const {isRegistered, isGuest, customerType} = useCustomerType()
const query = useCustomer(
{
parameters: {
customerId,
expand: ['paymentmethodreferences']
}
},
{enabled: !!customerId && isRegistered}
)
const value = {
...query,
data: {
...query.data,
customerType,
customerId,
isRegistered,
isGuest
}
}
return value
}