-
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 delete address mutation (#759)
- Loading branch information
1 parent
622f257
commit 3602d91
Showing
2 changed files
with
52 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 delete customer address mutation |
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,47 @@ | ||
import { getSessionCustomerId } from '~/auth'; | ||
|
||
import { client } from '..'; | ||
import { graphql, VariablesOf } from '../graphql'; | ||
|
||
const DELETE_CUSTOMER_ADDRESS_MUTATION = graphql(` | ||
mutation DeleteCustomerAddress( | ||
$reCaptcha: ReCaptchaV2Input | ||
$input: DeleteCustomerAddressInput! | ||
) { | ||
customer { | ||
deleteCustomerAddress(reCaptchaV2: $reCaptcha, input: $input) { | ||
errors { | ||
__typename | ||
... on CustomerAddressDeletionError { | ||
__typename | ||
message | ||
} | ||
... on CustomerNotLoggedInError { | ||
__typename | ||
message | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
|
||
type AddressId = VariablesOf<typeof DELETE_CUSTOMER_ADDRESS_MUTATION>['input']['addressEntityId']; | ||
|
||
export const deleteCustomerAddress = async (addressId: AddressId, reCaptchaToken?: string) => { | ||
const customerId = await getSessionCustomerId(); | ||
|
||
const response = await client.fetch({ | ||
document: DELETE_CUSTOMER_ADDRESS_MUTATION, | ||
customerId, | ||
fetchOptions: { cache: 'no-store' }, | ||
variables: { | ||
input: { | ||
addressEntityId: addressId, | ||
}, | ||
...(reCaptchaToken && { reCaptcha: { token: reCaptchaToken } }), | ||
}, | ||
}); | ||
|
||
return response.data; | ||
}; |