diff --git a/package.json b/package.json index f7eac73..de2920c 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "qrcode.react": "^1.0.0", "ra-language-german": "^2.1.2", "react": "^16.12.0", - "react-admin": "^3.1.3", + "react-admin": "^3.4", "react-dom": "^16.12.0", "react-scripts": "^3.3.0" }, diff --git a/src/components/SaveQrButton.js b/src/components/SaveQrButton.js new file mode 100644 index 0000000..2f01e93 --- /dev/null +++ b/src/components/SaveQrButton.js @@ -0,0 +1,32 @@ +import React, { useCallback } from "react"; +import { SaveButton, useCreate, useRedirect, useNotify } from "react-admin"; + +const SaveQrButton = props => { + const [create] = useCreate('users'); + const redirectTo = useRedirect(); + const notify = useNotify(); + const { basePath } = props; + + const handleSave = useCallback( + (values, redirect) => { + create( + { + payload: { data: { ...values } }, + }, + { + onSuccess: ({ data: newRecord }) => { + notify('ra.notification.created', 'info', { + smart_count: 1, + }); + redirectTo(redirect, basePath, newRecord.id, { password: values.password, ...newRecord }); + }, + } + ); + }, + [create, notify, redirectTo, basePath] + ); + + return ; +}; + +export default SaveQrButton; diff --git a/src/components/ShowUserPdf.js b/src/components/ShowUserPdf.js index 124d749..c235199 100644 --- a/src/components/ShowUserPdf.js +++ b/src/components/ShowUserPdf.js @@ -47,7 +47,6 @@ const ShowUserPdf = props => { marginTop: 15, }, logo: { - height: 90, width: 90, marginTop: 20, marginRight: 32, diff --git a/src/components/users.js b/src/components/users.js index 1675dc0..3ac6575 100644 --- a/src/components/users.js +++ b/src/components/users.js @@ -17,6 +17,7 @@ import { Toolbar, regex, } from "react-admin"; +import SaveQrButton from "./SaveQrButton"; const UserFilter = props => ( @@ -117,7 +118,7 @@ const redirect = (basePath, id, data) => { const UserCreateToolbar = props => ( -