-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add get customer query (#768)
- Loading branch information
1 parent
30c7624
commit 39feb4a
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": patch | ||
--- | ||
|
||
add get customer query |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { cache } from 'react'; | ||
|
||
import { client } from '..'; | ||
import { graphql } from '../graphql'; | ||
|
||
const GET_CUSTOMER_QUERY = graphql(` | ||
query getCustomer { | ||
customer { | ||
entityId | ||
company | ||
firstName | ||
lastName | ||
phone | ||
formFields { | ||
entityId | ||
name | ||
__typename | ||
... on CheckboxesFormFieldValue { | ||
valueEntityIds | ||
values | ||
} | ||
... on DateFormFieldValue { | ||
date { | ||
utc | ||
} | ||
} | ||
... on MultipleChoiceFormFieldValue { | ||
valueEntityId | ||
value | ||
} | ||
... on NumberFormFieldValue { | ||
number | ||
} | ||
... on PasswordFormFieldValue { | ||
password | ||
} | ||
... on TextFormFieldValue { | ||
text | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
|
||
export const getCustomer = cache(async (customerId: string) => { | ||
const response = await client.fetch({ | ||
document: GET_CUSTOMER_QUERY, | ||
fetchOptions: { cache: 'no-store' }, | ||
customerId, | ||
}); | ||
|
||
const customer = response.data.customer; | ||
|
||
if (!customer) { | ||
return null; | ||
} | ||
|
||
return customer; | ||
}); |