@graphcommerce/react-hook-form 9.0.4-canary.9 → 9.1.0-canary.16
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.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 9.1.0-canary.16
|
|
4
|
+
|
|
5
|
+
## 9.1.0-canary.15
|
|
6
|
+
|
|
7
|
+
## 9.0.4-canary.14
|
|
8
|
+
|
|
9
|
+
## 9.0.4-canary.13
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`9aa9a3c`](https://github.com/graphcommerce-org/graphcommerce/commit/9aa9a3cc25c121e217f64efc0cfd19e3b90d15aa) - useFormGql and all derivivatives now get the form as an argument in onComplete for easier form resets. ([@paales](https://github.com/paales))
|
|
14
|
+
|
|
15
|
+
## 9.0.4-canary.12
|
|
16
|
+
|
|
17
|
+
## 9.0.4-canary.11
|
|
18
|
+
|
|
19
|
+
## 9.0.4-canary.10
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- [#2487](https://github.com/graphcommerce-org/graphcommerce/pull/2487) [`935f8f9`](https://github.com/graphcommerce-org/graphcommerce/commit/935f8f9ebe5e79b336e56d40cb1ec96ce17b84d7) - Remove dependency on Magento for @graphcommerec/react-hook-form ([@paales](https://github.com/paales))
|
|
24
|
+
|
|
3
25
|
## 9.0.4-canary.9
|
|
4
26
|
|
|
5
27
|
## 9.0.4-canary.8
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/react-hook-form",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "9.0
|
|
5
|
+
"version": "9.1.0-canary.16",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
15
|
"@apollo/client": "*",
|
|
16
|
-
"@graphcommerce/eslint-config-pwa": "^9.0
|
|
17
|
-
"@graphcommerce/prettier-config-pwa": "^9.0
|
|
18
|
-
"@graphcommerce/typescript-config-pwa": "^9.0
|
|
16
|
+
"@graphcommerce/eslint-config-pwa": "^9.1.0-canary.16",
|
|
17
|
+
"@graphcommerce/prettier-config-pwa": "^9.1.0-canary.16",
|
|
18
|
+
"@graphcommerce/typescript-config-pwa": "^9.1.0-canary.16",
|
|
19
19
|
"@mui/utils": "^5",
|
|
20
20
|
"graphql": "^16.6.0",
|
|
21
21
|
"react": "^18.2.0",
|
package/src/useFormGql.tsx
CHANGED
|
@@ -17,12 +17,7 @@ import type { UseGqlDocumentHandler } from './useGqlDocumentHandler'
|
|
|
17
17
|
import { useGqlDocumentHandler } from './useGqlDocumentHandler'
|
|
18
18
|
import { tryAsync } from './utils/tryTuple'
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
data: FetchResult<MaybeMasked<Q>>,
|
|
22
|
-
variables: V,
|
|
23
|
-
) => void | Promise<void>
|
|
24
|
-
|
|
25
|
-
type UseFormGraphQLCallbacks<Q, V> = {
|
|
20
|
+
type UseFormGraphQLCallbacks<Q, V extends FieldValues> = {
|
|
26
21
|
/**
|
|
27
22
|
* Allows you to modify the variablels computed by the form to make it compatible with the GraphQL
|
|
28
23
|
* Mutation.
|
|
@@ -30,13 +25,17 @@ type UseFormGraphQLCallbacks<Q, V> = {
|
|
|
30
25
|
* When returning false, it will silently stop the submission. When an error is thrown, it will be
|
|
31
26
|
* set as an ApolloError
|
|
32
27
|
*/
|
|
33
|
-
onBeforeSubmit?: (variables: V) => V | false | Promise<V | false>
|
|
28
|
+
onBeforeSubmit?: (variables: V, form?: UseFormReturn<V>) => V | false | Promise<V | false>
|
|
34
29
|
/**
|
|
35
30
|
* Called after the mutation has been executed. Allows you to handle the result of the mutation.
|
|
36
31
|
*
|
|
37
32
|
* When an error is thrown, it will be set as an ApolloError
|
|
38
33
|
*/
|
|
39
|
-
onComplete?:
|
|
34
|
+
onComplete?: (
|
|
35
|
+
data: FetchResult<MaybeMasked<Q>>,
|
|
36
|
+
variables: V,
|
|
37
|
+
form?: UseFormReturn<V>,
|
|
38
|
+
) => void | Promise<void>
|
|
40
39
|
|
|
41
40
|
/**
|
|
42
41
|
* @deprecated Not used anymore, is now the default
|
|
@@ -174,7 +173,7 @@ export function useFormGql<Q, V extends FieldValues>(
|
|
|
174
173
|
let variables = !deprecated_useV1 ? formValues : encode({ ...defaultValues, ...formValues })
|
|
175
174
|
|
|
176
175
|
// Wait for the onBeforeSubmit to complete
|
|
177
|
-
const [onBeforeSubmitResult, onBeforeSubmitError] = await beforeSubmit(variables)
|
|
176
|
+
const [onBeforeSubmitResult, onBeforeSubmitError] = await beforeSubmit(variables, form)
|
|
178
177
|
if (onBeforeSubmitError) {
|
|
179
178
|
if (isApolloError(onBeforeSubmitError)) {
|
|
180
179
|
returnedError.current = onBeforeSubmitError
|
|
@@ -219,7 +218,7 @@ export function useFormGql<Q, V extends FieldValues>(
|
|
|
219
218
|
return
|
|
220
219
|
}
|
|
221
220
|
|
|
222
|
-
const [, onCompleteError] = await complete(result, variables)
|
|
221
|
+
const [, onCompleteError] = await complete(result, variables, form)
|
|
223
222
|
if (onCompleteError) {
|
|
224
223
|
if (isApolloError(onCompleteError)) {
|
|
225
224
|
returnedError.current = onCompleteError
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
mutation TestShippingAddressForm(
|
|
2
|
-
$cartId: String!
|
|
3
|
-
$address: CartAddressInput!
|
|
4
|
-
$customerNote: String = "joi"
|
|
5
|
-
) {
|
|
6
|
-
setShippingAddressesOnCart(
|
|
7
|
-
input: {
|
|
8
|
-
cart_id: $cartId
|
|
9
|
-
shipping_addresses: [{ address: $address, customer_notes: $customerNote }]
|
|
10
|
-
}
|
|
11
|
-
) {
|
|
12
|
-
cart {
|
|
13
|
-
id
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
-
import { ApolloClient, InMemoryCache } from '@apollo/client'
|
|
3
|
-
import { renderHook } from '@testing-library/react'
|
|
4
|
-
import { TestShippingAddressFormDocument } from '../__mocks__/TestShippingAddressForm.gql'
|
|
5
|
-
import { useFormGqlMutation } from '../src/useFormGqlMutation'
|
|
6
|
-
|
|
7
|
-
describe('useFormGqlMutation', () => {
|
|
8
|
-
const { result } = renderHook(() =>
|
|
9
|
-
useFormGqlMutation(
|
|
10
|
-
TestShippingAddressFormDocument,
|
|
11
|
-
{},
|
|
12
|
-
{
|
|
13
|
-
client: new ApolloClient({
|
|
14
|
-
cache: new InMemoryCache(),
|
|
15
|
-
}),
|
|
16
|
-
},
|
|
17
|
-
),
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
it('can register stuff', () => {
|
|
21
|
-
result.current.register('address.telephone')
|
|
22
|
-
result.current.register('customerNote')
|
|
23
|
-
result.current.register('address.street.0')
|
|
24
|
-
|
|
25
|
-
// @ts-expect-error should not be posssible
|
|
26
|
-
result.current.register('address.street.hoi')
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('extracts required fields correctly', () => {
|
|
30
|
-
expect(result.current.required).toEqual({ address: true, cartId: true, customerNote: false })
|
|
31
|
-
})
|
|
32
|
-
it('extracts defaults correctly', () => {
|
|
33
|
-
expect(result.current.defaultVariables).toEqual({ customerNote: 'joi' })
|
|
34
|
-
})
|
|
35
|
-
})
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { TestShippingAddressFormDocument } from '../__mocks__/TestShippingAddressForm.gql'
|
|
2
|
-
import { handlerFactory } from '../src/useGqlDocumentHandler'
|
|
3
|
-
|
|
4
|
-
describe('useGqlDocumentHandler', () => {
|
|
5
|
-
const {
|
|
6
|
-
required,
|
|
7
|
-
defaultVariables: defaults,
|
|
8
|
-
encode,
|
|
9
|
-
} = handlerFactory(TestShippingAddressFormDocument)
|
|
10
|
-
|
|
11
|
-
const address = {
|
|
12
|
-
cartId: '12',
|
|
13
|
-
customerNote: 'hoi',
|
|
14
|
-
address: {
|
|
15
|
-
firstname: 'Firstname',
|
|
16
|
-
lastname: 'Lastname',
|
|
17
|
-
company: 'GraphComemrce',
|
|
18
|
-
country_code: 'NL',
|
|
19
|
-
street: ['Streetline 1', 'Streetline 2'],
|
|
20
|
-
city: 'City',
|
|
21
|
-
telephone: '0987654321',
|
|
22
|
-
postcode: '1234AB',
|
|
23
|
-
save_in_address_book: true,
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
it('extracts required fields correctly', () => {
|
|
28
|
-
expect(required).toEqual({ address: true, cartId: true, customerNote: false })
|
|
29
|
-
})
|
|
30
|
-
it('extracts defaults correctly', () => {
|
|
31
|
-
expect(defaults).toEqual({ customerNote: 'joi' })
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it('encodes objects correctly', () => {
|
|
35
|
-
const result = encode(address)
|
|
36
|
-
expect(result).toEqual({
|
|
37
|
-
cartId: '12',
|
|
38
|
-
customerNote: 'hoi',
|
|
39
|
-
address: {
|
|
40
|
-
firstname: 'Firstname',
|
|
41
|
-
lastname: 'Lastname',
|
|
42
|
-
company: 'GraphComemrce',
|
|
43
|
-
country_code: 'NL',
|
|
44
|
-
street: ['Streetline 1', 'Streetline 2'],
|
|
45
|
-
city: 'City',
|
|
46
|
-
telephone: '0987654321',
|
|
47
|
-
postcode: '1234AB',
|
|
48
|
-
save_in_address_book: true,
|
|
49
|
-
},
|
|
50
|
-
})
|
|
51
|
-
})
|
|
52
|
-
})
|