@jobber/components-native 0.89.4 → 0.89.5-JOB-139254-4e3c64d.7

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.
@@ -2,7 +2,7 @@ import type { DeepPartial, FieldValues, UseFormHandleSubmit, UseFormReturn } fro
2
2
  import type { MutableRefObject, RefObject } from "react";
3
3
  import type { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
4
4
  import type { InternalFormProps } from "../types";
5
- type UseInternalFormProps<T extends FieldValues, SubmitResponseType> = Pick<InternalFormProps<T, SubmitResponseType>, "mode" | "reValidateMode" | "initialValues" | "formRef" | "localCacheKey" | "localCacheExclude" | "localCacheId"> & {
5
+ type UseInternalFormProps<T extends FieldValues, SubmitResponseType> = Pick<InternalFormProps<T, SubmitResponseType>, "mode" | "reValidateMode" | "initialValues" | "formRef" | "localCacheKey" | "localCacheExclude" | "localCacheId" | "removeLocalCacheOnBackOffline"> & {
6
6
  scrollViewRef?: RefObject<KeyboardAwareScrollView>;
7
7
  readonly saveButtonHeight: number;
8
8
  readonly messageBannerHeight: number;
@@ -15,5 +15,5 @@ interface UseInternalForm<T extends FieldValues> {
15
15
  readonly removeListenerRef: MutableRefObject<() => void>;
16
16
  readonly setLocalCache: (data: DeepPartial<T>) => void;
17
17
  }
18
- export declare function useInternalForm<T extends FieldValues, SubmitResponseType>({ mode, reValidateMode, initialValues, formRef, localCacheKey, localCacheId, scrollViewRef, saveButtonHeight, messageBannerHeight, }: UseInternalFormProps<T, SubmitResponseType>): UseInternalForm<T>;
18
+ export declare function useInternalForm<T extends FieldValues, SubmitResponseType>({ mode, reValidateMode, initialValues, formRef, localCacheKey, localCacheId, scrollViewRef, saveButtonHeight, messageBannerHeight, removeLocalCacheOnBackOffline, }: UseInternalFormProps<T, SubmitResponseType>): UseInternalForm<T>;
19
19
  export {};
@@ -131,6 +131,12 @@ export interface FormProps<T extends FieldValues, SubmitResponseType> {
131
131
  * If a user opens the same form the data will only be loaded if the `localCacheId` matches
132
132
  */
133
133
  localCacheId?: string | string[];
134
+ /**
135
+ * If true, the local cache will be removed when the user navigates away from
136
+ * the dirty form even when offline. By default, cache is only removed on back when online.
137
+ * Defaults to false.
138
+ */
139
+ removeLocalCacheOnBackOffline?: boolean;
134
140
  /**
135
141
  * Secondary Action for ButtonGroup
136
142
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components-native",
3
- "version": "0.89.4",
3
+ "version": "0.89.5-JOB-139254-4e3c64d.7+4e3c64d19",
4
4
  "license": "MIT",
5
5
  "description": "React Native implementation of Atlantis",
6
6
  "repository": {
@@ -94,5 +94,5 @@
94
94
  "react-native-safe-area-context": "^5.4.0",
95
95
  "react-native-svg": ">=12.0.0"
96
96
  },
97
- "gitHead": "adc76ab79cbad1b62fa1d3ff35020f061b390292"
97
+ "gitHead": "4e3c64d1982cb68580827ad583b4812b3a240e7c"
98
98
  }
package/src/Form/Form.tsx CHANGED
@@ -66,6 +66,7 @@ function InternalForm<T extends FieldValues, S>({
66
66
  saveButtonOffset,
67
67
  showStickySaveButton = false,
68
68
  renderFooter,
69
+ removeLocalCacheOnBackOffline,
69
70
  }: InternalFormProps<T, S>) {
70
71
  const { scrollViewRef, bottomViewRef, scrollToTop } = useFormViewRefs();
71
72
  const [saveButtonHeight, setSaveButtonHeight] = useState(0);
@@ -87,6 +88,7 @@ function InternalForm<T extends FieldValues, S>({
87
88
  scrollViewRef,
88
89
  saveButtonHeight,
89
90
  messageBannerHeight,
91
+ removeLocalCacheOnBackOffline,
90
92
  });
91
93
  const { windowHeight, headerHeight } = useScreenInformation();
92
94
  const [keyboardHeight, setKeyboardHeight] = useState(0);
@@ -20,6 +20,7 @@ type UseInternalFormProps<T extends FieldValues, SubmitResponseType> = Pick<
20
20
  | "localCacheKey"
21
21
  | "localCacheExclude"
22
22
  | "localCacheId"
23
+ | "removeLocalCacheOnBackOffline"
23
24
  > & {
24
25
  scrollViewRef?: RefObject<KeyboardAwareScrollView>;
25
26
  readonly saveButtonHeight: number;
@@ -45,6 +46,7 @@ export function useInternalForm<T extends FieldValues, SubmitResponseType>({
45
46
  scrollViewRef,
46
47
  saveButtonHeight,
47
48
  messageBannerHeight,
49
+ removeLocalCacheOnBackOffline = false,
48
50
  }: UseInternalFormProps<T, SubmitResponseType>): UseInternalForm<T> {
49
51
  const { useConfirmBeforeBack, useInternalFormLocalCache } =
50
52
  useAtlantisFormContext();
@@ -82,11 +84,16 @@ export function useInternalForm<T extends FieldValues, SubmitResponseType>({
82
84
  };
83
85
  }
84
86
 
87
+ const shouldRemoveCacheOnBack = removeLocalCacheOnBackOffline
88
+ ? true
89
+ : isOnline;
90
+
85
91
  const removeListenerRef = useConfirmBeforeBack({
86
92
  alwaysPreventBack: isSubmitting,
87
93
  shouldShowAlert: isDirty,
88
- onAcceptEvent: isOnline ? removeLocalCache : undefined,
89
- showLostProgressMessage: isOnline || !clientSideSaveOn ? true : false,
94
+ onAcceptEvent: shouldRemoveCacheOnBack ? removeLocalCache : undefined,
95
+ showLostProgressMessage:
96
+ shouldRemoveCacheOnBack || !clientSideSaveOn ? true : false,
90
97
  });
91
98
 
92
99
  return {
package/src/Form/types.ts CHANGED
@@ -171,6 +171,13 @@ export interface FormProps<T extends FieldValues, SubmitResponseType> {
171
171
  */
172
172
  localCacheId?: string | string[];
173
173
 
174
+ /**
175
+ * If true, the local cache will be removed when the user navigates away from
176
+ * the dirty form even when offline. By default, cache is only removed on back when online.
177
+ * Defaults to false.
178
+ */
179
+ removeLocalCacheOnBackOffline?: boolean;
180
+
174
181
  /**
175
182
  * Secondary Action for ButtonGroup
176
183
  */