Skip to content

Commit

Permalink
fix(modelview): validate prevdata before saving
Browse files Browse the repository at this point in the history
  • Loading branch information
Birkbjo committed Dec 6, 2023
1 parent e0b1756 commit 8d803e4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/sectionList/listView/useModelListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const useModelListView = () => {
})

// 404 errors are expected when user havent saved any views
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (query.error && (query.error as any).details?.httpStatusCode !== 404) {
console.error(query.error)
}
Expand Down Expand Up @@ -163,11 +164,14 @@ export const useMutateModelListViews = () => {
// it's exact data as we got from the request
const prevData: WrapInResult<DataStoreModelListViews> | undefined =
queryClient.getQueryData(valuesQueryKey)
if (!prevData) {

// need to validate here since we're not using a selector
const validView = modelListViewsSchema.safeParse(prevData?.result)
if (!validView.success) {
return {}
}

return prevData.result
return validView.data
}, [queryClient])

const saveView = useCallback(
Expand Down

0 comments on commit 8d803e4

Please sign in to comment.