diff --git a/src/components/fields/types.ts b/src/components/fields/types.ts index 2e35d712..f8e93572 100644 --- a/src/components/fields/types.ts +++ b/src/components/fields/types.ts @@ -88,8 +88,8 @@ export interface ISideDrawerFieldProps { /** Update the local value. Also calls onDirty */ onChange: (value: T) => void; /** Call when user input is ready to be saved (e.g. onBlur) */ - onSubmit: () => void; + onSubmit: () => void; /** Field locked. Do NOT check `column.locked` */ disabled: boolean; diff --git a/src/hooks/useFirestoreCollectionWithAtom.ts b/src/hooks/useFirestoreCollectionWithAtom.ts index 355ceaa1..8e870dd9 100644 --- a/src/hooks/useFirestoreCollectionWithAtom.ts +++ b/src/hooks/useFirestoreCollectionWithAtom.ts @@ -16,6 +16,7 @@ import { setDoc, doc, deleteDoc, + updateDoc, deleteField, CollectionReference, Query, @@ -263,7 +264,7 @@ export function useFirestoreCollectionWithAtom< // set the atom’s value to a function that updates a doc in the collection if (updateDocAtom) { setUpdateDocAtom( - () => (path: string, update: T, deleteFields?: string[]) => { + () => async (path: string, update: T, deleteFields?: string[]) => { const updateToDb = { ...update }; if (Array.isArray(deleteFields)) { @@ -271,8 +272,13 @@ export function useFirestoreCollectionWithAtom< set(updateToDb as any, field, deleteField()); } } - - return setDoc(doc(firebaseDb, path), updateToDb, { merge: true }); + try { + return await updateDoc(doc(firebaseDb, path), updateToDb); + } catch (e) { + return await setDoc(doc(firebaseDb, path), updateToDb, { + merge: true, + }); + } } ); }