@jobber/components-native 0.81.1 → 0.81.2-cleanup-fo-1e1db4e.33

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components-native",
3
- "version": "0.81.1",
3
+ "version": "0.81.2-cleanup-fo-1e1db4e.33+1e1db4e5",
4
4
  "license": "MIT",
5
5
  "description": "React Native implementation of Atlantis",
6
6
  "repository": {
@@ -80,5 +80,5 @@
80
80
  "react-native-safe-area-context": "^4.5.2",
81
81
  "react-native-svg": ">=12.0.0"
82
82
  },
83
- "gitHead": "a560cd303472b8638a3ef95fe3f26ac4afa2f607"
83
+ "gitHead": "1e1db4e51bfb455c15a597be0e3e882044b7da01"
84
84
  }
@@ -300,6 +300,32 @@ describe("Form", () => {
300
300
  });
301
301
  });
302
302
 
303
+ it("should call onSubmitSuccess after submit promise resolves", async () => {
304
+ onSubmitMock.mockImplementationOnce(() => {
305
+ return Promise.resolve({
306
+ resolvedPromiseData: "passed",
307
+ });
308
+ });
309
+ const { getByLabelText } = render(<FormTest onSubmit={onSubmitMock} />);
310
+ const saveButton = getByLabelText(saveButtonText);
311
+
312
+ const newValue = "New Value";
313
+ fireEvent.changeText(getByLabelText(testInputTextPlaceholder), newValue);
314
+ expect(onChangeMock).toHaveBeenCalled();
315
+
316
+ fireEvent(getByLabelText(switchLabel), "onValueChange", true);
317
+ expect(onChangeSwitchMock).toHaveBeenCalled();
318
+
319
+ fireEvent.press(saveButton);
320
+
321
+ await waitFor(() => {
322
+ expect(onSubmitMock).toHaveBeenCalled();
323
+ });
324
+ expect(onSuccessMock).toHaveBeenCalledWith({
325
+ resolvedPromiseData: "passed",
326
+ });
327
+ });
328
+
303
329
  it("should dismiss keyboard when form is saved", async () => {
304
330
  const keyboardDismissSpy = jest.spyOn(Keyboard, "dismiss");
305
331
  const { getByLabelText } = render(<FormTest onSubmit={onSubmitMock} />);
package/src/Form/Form.tsx CHANGED
@@ -152,7 +152,7 @@ function InternalForm<T extends FieldValues, S>({
152
152
 
153
153
  <FormBody
154
154
  keyboardHeight={calculateSaveButtonOffset()}
155
- submit={handleSubmit(internalSubmit)}
155
+ submit={callHandleSubmit}
156
156
  isFormSubmitting={isSubmitting}
157
157
  saveButtonLabel={saveButtonLabel}
158
158
  shouldRenderActionBar={saveButtonPosition === "sticky"}
@@ -195,13 +195,13 @@ function InternalForm<T extends FieldValues, S>({
195
195
  <View style={styles.fixedSaveButton}>
196
196
  {renderStickySection ? (
197
197
  renderStickySection(
198
- handleSubmit(internalSubmit),
198
+ callHandleSubmit,
199
199
  saveButtonLabel,
200
200
  isSubmitting,
201
201
  )
202
202
  ) : (
203
203
  <FormSaveButton
204
- primaryAction={handleSubmit(internalSubmit)}
204
+ primaryAction={callHandleSubmit}
205
205
  label={saveButtonLabel}
206
206
  loading={isSubmitting}
207
207
  secondaryActions={secondaryActions}
@@ -247,6 +247,18 @@ function InternalForm<T extends FieldValues, S>({
247
247
  setKeyboardScreenY(0);
248
248
  }
249
249
 
250
+ async function callHandleSubmit() {
251
+ let result: S | undefined;
252
+
253
+ await handleSubmit(async data => {
254
+ const saveResult = await internalSubmit(data);
255
+ result = saveResult as S;
256
+ })();
257
+
258
+ removeListenerRef.current?.();
259
+ onSubmitSuccess(result as S);
260
+ }
261
+
250
262
  async function internalSubmit(data: FormValues<T>) {
251
263
  let performSubmit = true;
252
264
 
@@ -257,12 +269,7 @@ function InternalForm<T extends FieldValues, S>({
257
269
  if (performSubmit) {
258
270
  Keyboard.dismiss();
259
271
 
260
- return onSubmit(data)
261
- .then((result: S) => {
262
- removeListenerRef.current?.();
263
- onSubmitSuccess(result);
264
- })
265
- .catch(handleSubmitCatch);
272
+ return onSubmit(data).catch(handleSubmitCatch);
266
273
  }
267
274
  }
268
275
 
@@ -289,7 +296,7 @@ function InternalForm<T extends FieldValues, S>({
289
296
  function handleRetry() {
290
297
  clearFormErrors();
291
298
 
292
- return handleSubmit(internalSubmit)();
299
+ return callHandleSubmit();
293
300
  }
294
301
 
295
302
  function calculateSaveButtonOffset() {