From abb31a9b6645aff8ad176740c72eab86d3e5dd03 Mon Sep 17 00:00:00 2001 From: davy-c Date: Mon, 13 Dec 2021 06:51:28 +0900 Subject: [PATCH] correct typing for bulk action res --- .../contents/SmartView/ConditionValueControl.tsx | 2 +- .../contents/SmartView/CreateSmartViewModal.tsx | 2 +- .../contents/SmartView/UpdateSmartViewModal.tsx | 2 +- src/cloud/components/Props/PropPicker.tsx | 2 +- src/cloud/components/Props/PropSelectorModal.tsx | 2 +- .../Views/Calendar/CalendarWatchedPropContext.tsx | 2 +- .../Views/Kanban/KanbanWatchedPropSetter.tsx | 2 +- .../Views/Table/TableAddPropertyContext.tsx | 4 ++-- .../Views/Table/TablePropertiesContext.tsx | 2 +- src/cloud/components/Views/ViewsSelector.tsx | 6 +++--- src/cloud/lib/hooks/views/tableView.ts | 12 +++++++----- src/cloud/lib/hooks/views/viewHandler.ts | 14 ++++++++------ src/design/lib/hooks/useBulkApi.ts | 2 +- .../organisms/modals/SmartViewUpdateModal.tsx | 2 +- 14 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/cloud/components/Modal/contents/SmartView/ConditionValueControl.tsx b/src/cloud/components/Modal/contents/SmartView/ConditionValueControl.tsx index 0b6c475935..525dad5dda 100644 --- a/src/cloud/components/Modal/contents/SmartView/ConditionValueControl.tsx +++ b/src/cloud/components/Modal/contents/SmartView/ConditionValueControl.tsx @@ -101,7 +101,7 @@ const PropConditionValueControl = ({ const fetchProperties = useCallback( async (body: ListPropertySuggestionsRequestBody) => { const res = await fetchPropertySuggestionsApi(body) - if (!res.err) { + if (res != null && !res.err) { setSuggestions( (res.data as ListPropertySuggestionsResponseBody).data .filter((property) => property.type === body.propertyType) diff --git a/src/cloud/components/Modal/contents/SmartView/CreateSmartViewModal.tsx b/src/cloud/components/Modal/contents/SmartView/CreateSmartViewModal.tsx index 954eaad4d9..92be6d3c58 100644 --- a/src/cloud/components/Modal/contents/SmartView/CreateSmartViewModal.tsx +++ b/src/cloud/components/Modal/contents/SmartView/CreateSmartViewModal.tsx @@ -27,7 +27,7 @@ const CreateSmartViewModal = ({ onCreate }: CreateSmartViewModalProps) => { setSending(true) const res = await createSmartViewApi(team.id, body) - if (!res.err) { + if (res != null && !res.err) { const { data: smartView } = res.data as CreateSmartViewResponseBody closeModal() if (onCreate != null) { diff --git a/src/cloud/components/Modal/contents/SmartView/UpdateSmartViewModal.tsx b/src/cloud/components/Modal/contents/SmartView/UpdateSmartViewModal.tsx index 3035451ead..6c4ec4339e 100644 --- a/src/cloud/components/Modal/contents/SmartView/UpdateSmartViewModal.tsx +++ b/src/cloud/components/Modal/contents/SmartView/UpdateSmartViewModal.tsx @@ -39,7 +39,7 @@ const UpdateSmartViewModal = ({ const res = await updateSmartViewApi(smartView, body) - if (!res.err) { + if (res != null && !res.err) { closeModal() if (onUpdate != null) { return onUpdate((res.data as UpdateSmartViewResponseBody).data) diff --git a/src/cloud/components/Props/PropPicker.tsx b/src/cloud/components/Props/PropPicker.tsx index 76671f902c..05f818ff6c 100644 --- a/src/cloud/components/Props/PropPicker.tsx +++ b/src/cloud/components/Props/PropPicker.tsx @@ -44,7 +44,7 @@ const PropPicker = ({ }) } - if (!res.err && onUpdate != null) { + if (res != null && !res.err && onUpdate != null) { const props = res.data as { data: Props } diff --git a/src/cloud/components/Props/PropSelectorModal.tsx b/src/cloud/components/Props/PropSelectorModal.tsx index 57aab0887a..a45df68d41 100644 --- a/src/cloud/components/Props/PropSelectorModal.tsx +++ b/src/cloud/components/Props/PropSelectorModal.tsx @@ -33,7 +33,7 @@ const PropSelectorModal = ({ team: doc.teamId, doc: doc.id, }) - if (!res.err) { + if (res != null && !res.err) { return (res.data as ListPropertySuggestionsResponseBody).data } else { return [] diff --git a/src/cloud/components/Views/Calendar/CalendarWatchedPropContext.tsx b/src/cloud/components/Views/Calendar/CalendarWatchedPropContext.tsx index db368f948a..b3168f1109 100644 --- a/src/cloud/components/Views/Calendar/CalendarWatchedPropContext.tsx +++ b/src/cloud/components/Views/Calendar/CalendarWatchedPropContext.tsx @@ -77,7 +77,7 @@ const CalendarWatchedPropContext = ({ } const res = await fetchPropertySuggestionsApi(body) - if (!res.err) { + if (res != null && !res.err) { setSuggestions( filterIter( (val) => isPropType(val.type), diff --git a/src/cloud/components/Views/Kanban/KanbanWatchedPropSetter.tsx b/src/cloud/components/Views/Kanban/KanbanWatchedPropSetter.tsx index c301b5223f..cc915ae33e 100644 --- a/src/cloud/components/Views/Kanban/KanbanWatchedPropSetter.tsx +++ b/src/cloud/components/Views/Kanban/KanbanWatchedPropSetter.tsx @@ -65,7 +65,7 @@ const KanbanWatchedPropSetter = ({ } const res = await fetchPropertySuggestionsApi(body) - if (!res.err) { + if (res != null && !res.err) { setSuggestions( filterIter( (val) => isPropType(val.type), diff --git a/src/cloud/components/Views/Table/TableAddPropertyContext.tsx b/src/cloud/components/Views/Table/TableAddPropertyContext.tsx index 152c17acf3..f4574a8e56 100644 --- a/src/cloud/components/Views/Table/TableAddPropertyContext.tsx +++ b/src/cloud/components/Views/Table/TableAddPropertyContext.tsx @@ -25,7 +25,7 @@ interface TableAddPropertyContextProps { view: SerializedView teamId: string columns: Record - addColumn: (col: Column) => Promise | undefined + addColumn: (col: Column) => Promise | undefined close: () => void } @@ -55,7 +55,7 @@ const TableAddPropertyContext = ({ } const res = await fetchPropertySuggestionsApi(body) - if (!res.err) { + if (res != null && !res.err) { return (res.data as ListPropertySuggestionsResponseBody).data } else { return [] diff --git a/src/cloud/components/Views/Table/TablePropertiesContext.tsx b/src/cloud/components/Views/Table/TablePropertiesContext.tsx index e075a57ef3..ce5e47cfe8 100644 --- a/src/cloud/components/Views/Table/TablePropertiesContext.tsx +++ b/src/cloud/components/Views/Table/TablePropertiesContext.tsx @@ -36,7 +36,7 @@ const TablePropertiesContext = ({ setSending(`${col.id}-delete`) const res = await tableActionsRef.current.removeColumn(col) - if (!res.err) { + if (res != null && !res.err) { setActiveColumns((prev) => { return prev.slice().filter((elem) => elem.id !== col.id) }) diff --git a/src/cloud/components/Views/ViewsSelector.tsx b/src/cloud/components/Views/ViewsSelector.tsx index d17a2e6911..8d4d4fbc1a 100644 --- a/src/cloud/components/Views/ViewsSelector.tsx +++ b/src/cloud/components/Views/ViewsSelector.tsx @@ -194,7 +194,7 @@ const ViewContextModal = ({ const deleteView = useCallback( async (view: SerializedView) => { const res = await actionsRef.current.deleteView(view) - if (!res.err) { + if (res != null && !res.err) { closeLastModal() } }, @@ -206,7 +206,7 @@ const ViewContextModal = ({ setSending(move) const res = await actionsRef.current.moveView(view, move) setSending(undefined) - if (!res.err) { + if (res != null && !res.err) { closeLastModal() } }, @@ -218,7 +218,7 @@ const ViewContextModal = ({ setSending('name') const res = await actionsRef.current.updateView(view, { name: newName }) setSending(undefined) - if (!res.err) { + if (res != null && !res.err) { closeLastModal() } }, diff --git a/src/cloud/lib/hooks/views/tableView.ts b/src/cloud/lib/hooks/views/tableView.ts index 4daeebae2e..88f6b9d726 100644 --- a/src/cloud/lib/hooks/views/tableView.ts +++ b/src/cloud/lib/hooks/views/tableView.ts @@ -24,13 +24,15 @@ interface TableViewStoreProps { } export type TableViewActionsRef = React.MutableRefObject<{ - updateTableSort: (sort: ViewTableSortingOptions) => Promise - addColumn: (col: Column) => Promise | undefined - removeColumn: (col: Column) => Promise + updateTableSort: ( + sort: ViewTableSortingOptions + ) => Promise + addColumn: (col: Column) => Promise | undefined + removeColumn: (col: Column) => Promise moveColumn: ( column: Column, move: ColumnMoveType - ) => Promise | undefined + ) => Promise | undefined }> export function useTableView({ @@ -55,7 +57,7 @@ export function useTableView({ { data: newState } ) ) - if (!res.err) { + if (res != null && !res.err) { selectNewView((res.data as CreateViewResponseBody).data.id) } return res diff --git a/src/cloud/lib/hooks/views/viewHandler.ts b/src/cloud/lib/hooks/views/viewHandler.ts index 4f02f2936e..db87a973f7 100644 --- a/src/cloud/lib/hooks/views/viewHandler.ts +++ b/src/cloud/lib/hooks/views/viewHandler.ts @@ -25,16 +25,18 @@ interface ViewHandlerStoreProps { } export type ViewHandlerActionsRef = React.MutableRefObject<{ - createNewView: (type: SupportedViewTypes) => Promise + createNewView: ( + type: SupportedViewTypes + ) => Promise updateView: ( view: SerializedView, body: Omit - ) => Promise - deleteView: (view: SerializedView) => Promise + ) => Promise + deleteView: (view: SerializedView) => Promise moveView: ( view: SerializedView, move: ViewMoveType - ) => Promise + ) => Promise }> export function useViewHandler({ @@ -89,7 +91,7 @@ export function useViewHandler({ ? { workspace: parent.target.id, type, name } : { smartView: parent.target.id, type, name } ) - if (!res.err) { + if (res != null && !res.err) { const view = (res.data as CreateViewResponseBody).data trackEvent(MixpanelActionTrackTypes.ViewCreate, { trueEventName: `view.${view.type}.create`, @@ -105,7 +107,7 @@ export function useViewHandler({ const deleteView = useCallback( async (view: SerializedView) => { const res = await deleteViewApi(view) - if (!res.err) { + if (res != null && !res.err) { trackEvent(MixpanelActionTrackTypes.ViewDelete, { trueEventName: `view.${view.type}.delete`, view: view.id, diff --git a/src/design/lib/hooks/useBulkApi.ts b/src/design/lib/hooks/useBulkApi.ts index 8002c326af..d5a4404116 100644 --- a/src/design/lib/hooks/useBulkApi.ts +++ b/src/design/lib/hooks/useBulkApi.ts @@ -9,7 +9,7 @@ export type BulkApiAction = ( id: string, act: string, body: { api: (args: any) => Promise; cb?: (res: any) => any } -) => Promise +) => Promise interface UseBulkApiRes { sendingMap: Map diff --git a/src/mobile/components/organisms/modals/SmartViewUpdateModal.tsx b/src/mobile/components/organisms/modals/SmartViewUpdateModal.tsx index bfc46eeae1..7e0fc7bbee 100644 --- a/src/mobile/components/organisms/modals/SmartViewUpdateModal.tsx +++ b/src/mobile/components/organisms/modals/SmartViewUpdateModal.tsx @@ -38,7 +38,7 @@ const SmartViewUpdateModal = ({ const res = await updateSmartViewApi(smartView, body) - if (!res.err) { + if (res != null && !res.err) { closeModal() if (onUpdate != null) { return onUpdate((res.data as UpdateSmartViewResponseBody).data)