From d2a3f07a59174839e356d8e8b3f3c84ce8cd5cde Mon Sep 17 00:00:00 2001 From: Michael Albert Date: Tue, 14 Apr 2020 13:06:55 +0200 Subject: [PATCH] Fix QR code creation Change-Id: Ib6bbd1be6d4dca1f617043c3c2338924b2321ea3 --- package.json | 2 +- src/components/SaveQrButton.js | 32 ++++++++++++++++++++++++++++++++ src/components/ShowUserPdf.js | 1 - src/components/users.js | 3 ++- src/i18n/de.js | 15 +++++++++++++-- 5 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 src/components/SaveQrButton.js 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 => ( -