diff --git a/src/atoms/tableScope/rowActions.ts b/src/atoms/tableScope/rowActions.ts index edcb8361..4185fa24 100644 --- a/src/atoms/tableScope/rowActions.ts +++ b/src/atoms/tableScope/rowActions.ts @@ -146,11 +146,7 @@ export const addRowAtom = atom( // Write to database if no required fields are missing else { - await updateRowDb( - row._rowy_ref.path, - omitRowyFields(rowValues), - undefined - ); + await updateRowDb(row._rowy_ref.path, omitRowyFields(rowValues)); } if (auditChange) auditChange("ADD_ROW", row._rowy_ref.path); @@ -341,8 +337,6 @@ export interface IUpdateFieldOptions { useArrayRemove?: boolean; /** Optionally, used to locate the row in ArraySubTable. */ arrayTableData?: ArrayTableRowData; - /** Optionally, explicitly specify to use firestore's update method. Required in case of JSON field update. */ - // useUpdate?: boolean; } /** * Set function updates or deletes a field in a row. diff --git a/src/components/fields/types.ts b/src/components/fields/types.ts index 0308112d..6fb37ed2 100644 --- a/src/components/fields/types.ts +++ b/src/components/fields/types.ts @@ -88,6 +88,7 @@ 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; /** Field locked. Do NOT check `column.locked` */ disabled: boolean; diff --git a/src/hooks/useFirestoreCollectionWithAtom.ts b/src/hooks/useFirestoreCollectionWithAtom.ts index dc3520d2..fd0fa39e 100644 --- a/src/hooks/useFirestoreCollectionWithAtom.ts +++ b/src/hooks/useFirestoreCollectionWithAtom.ts @@ -1,7 +1,7 @@ import { useState, useEffect } from "react"; import useMemoValue from "use-memo-value"; import { useAtom, PrimitiveAtom, useSetAtom, SetStateAction } from "jotai"; -import { set, update } from "lodash-es"; +import { set } from "lodash-es"; import { Firestore, query, @@ -36,7 +36,6 @@ import { TableFilter, TableSort, TableRow, - UpdateRowOptions, } from "@src/types/table"; import { firebaseDbAtom } from "@src/sources/ProjectSourceFirebase"; import { COLLECTION_PAGE_SIZE } from "@src/config/db"; @@ -257,28 +256,22 @@ export function useFirestoreCollectionWithAtom< // set the atom’s value to a function that updates a doc in the collection if (updateDocAtom) { setUpdateDocAtom( - () => - async ( - path: string, - update: T, - deleteFields?: string[], - options?: UpdateRowOptions - ) => { - const updateToDb = { ...update }; + () => async (path: string, update: T, deleteFields?: string[]) => { + const updateToDb = { ...update }; - if (Array.isArray(deleteFields)) { - for (const field of deleteFields) { - set(updateToDb as any, field, deleteField()); - } - } - try { - return await updateDoc(doc(firebaseDb, path), updateToDb); - } catch (e) { - return await setDoc(doc(firebaseDb, path), updateToDb, { - merge: true, - }); + if (Array.isArray(deleteFields)) { + for (const field of deleteFields) { + set(updateToDb as any, field, deleteField()); } } + try { + return await updateDoc(doc(firebaseDb, path), updateToDb); + } catch (e) { + return await setDoc(doc(firebaseDb, path), updateToDb, { + merge: true, + }); + } + } ); } diff --git a/src/types/table.d.ts b/src/types/table.d.ts index a9b44d66..3ed4b7c3 100644 --- a/src/types/table.d.ts +++ b/src/types/table.d.ts @@ -32,7 +32,7 @@ export type UpdateCollectionDocFunction = ( path: string, update: Partial, deleteFields?: string[], - options?: ArrayTableRowData & UpdateRowOptions + options?: ArrayTableRowData ) => Promise; /** @@ -211,10 +211,6 @@ export type TableSort = { direction: Parameters[1]; }; -export type UpdateRowOptions = { - useUpdate?: boolean; -}; - export type ArrayTableRowData = { index?: number; parentField?: string;