diff --git a/apps/admin/src/app/dataProvider.ts b/apps/admin/src/app/dataProvider.ts index a4314f30..e3680568 100644 --- a/apps/admin/src/app/dataProvider.ts +++ b/apps/admin/src/app/dataProvider.ts @@ -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 = {}) => { @@ -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 })) + }, +} diff --git a/apps/admin/src/components/admin/Admin/Admin.tsx b/apps/admin/src/components/admin/Admin/Admin.tsx index b4733a96..43573c67 100644 --- a/apps/admin/src/components/admin/Admin/Admin.tsx +++ b/apps/admin/src/components/admin/Admin/Admin.tsx @@ -11,7 +11,7 @@ import { FormList } from '../../form/FormList' // import { MainForm } from '../MainForm' const dataProvider = fakeDataProvider({ - categories: [ + classification: [ { name: 'afval', id: 1,