Skip to content

Commit

Permalink
Use PATCH for all update requests, except for 'form'
Browse files Browse the repository at this point in the history
  • Loading branch information
alimpens committed May 2, 2024
1 parent 723fe49 commit e5e7432
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion apps/admin/src/app/dataProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getSession } from 'next-auth/react'
import simpleRestProvider from 'ra-data-simple-rest'
import type { DataProvider } from 'react-admin'
import { fetchUtils } from 'react-admin'

const fetchJson = async (url: string, options: fetchUtils.Options = {}) => {
Expand All @@ -19,4 +20,21 @@ const fetchJson = async (url: string, options: fetchUtils.Options = {}) => {
return fetchUtils.fetchJson(url, newOptions)
}

export const dataProvider = simpleRestProvider('http://localhost:8000', fetchJson)
const baseDataProvider = simpleRestProvider('http://localhost:8000', fetchJson)

export const dataProvider: DataProvider = {
...baseDataProvider,
update: (resource, params) => {
// 'form' updates use PUT requests, all other updates use PATCH requests
if (resource === 'form') {
return fetchJson(`http://localhost:8000/${resource}/${params.id}`, {
method: 'PUT',
body: JSON.stringify(params.data),
}).then(({ json }) => ({ data: json }))
}
return fetchJson(`http://localhost:8000/${resource}/${params.id}`, {
method: 'PATCH',
body: JSON.stringify(params.data),
}).then(({ json }) => ({ data: json }))
},
}
2 changes: 1 addition & 1 deletion apps/admin/src/components/admin/Admin/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FormList } from '../../form/FormList'
// import { MainForm } from '../MainForm'

const dataProvider = fakeDataProvider({
categories: [
classification: [
{
name: 'afval',
id: 1,
Expand Down

0 comments on commit e5e7432

Please sign in to comment.