Reactjs React Admin I自定义按钮无法获取表单数据

Reactjs React Admin I自定义按钮无法获取表单数据,reactjs,react-admin,Reactjs,React Admin,我创建了一个自定义按钮来拒绝用户。我想发送拒绝的原因,但无法发送表单数据。我正在userEdit组件中使用“FormWithRedirect” import React from 'react'; import PropTypes from 'prop-types'; import { makeStyles } from '@material-ui/core/styles'; import Button from '@material-ui/core/Button'; import ThumbD

我创建了一个自定义按钮来拒绝用户。我想发送拒绝的原因,但无法发送表单数据。我正在userEdit组件中使用“FormWithRedirect”

import React from 'react';
import PropTypes from 'prop-types';
import { makeStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
import ThumbDown from '@material-ui/icons/ThumbDown';
import { useUpdate, useNotify, useRedirect } from 'react-admin';

/**
 * This custom button demonstrate using a custom action to update data
 */

const useStyles = makeStyles((theme) => ({
    button: {
      color: 'red',
      borderColor: 'red',
      "&:hover": {
        color: '#fff',
        background: 'red',
        borderColor: 'red',
      }
    },
}));

const RejectButton = ({ record }: any) => {
    const notify = useNotify();
    const redirectTo = useRedirect();

    const classes = useStyles();

    const [reject, { loading }] = useUpdate(
        `users/${record.id}/_reject`,
        '',
        { reason: 'Due to missinng information or may be the license picture is not visible. Please upload again.' },
        record,
        {
            undoable: true,
            onSuccess: () => {
                notify(
                    'User profile rejected!',
                    'info',
                    {},
                    true
                );
                redirectTo('/users');
            },
            onFailure: (error: any) => notify(`Error: ${error.error}`, 'warning'),
        }
    );

    return (
        <Button
            variant="outlined"
            color="primary"
            size="small"
            onClick={reject}
            disabled={loading}
            className={classes.button}
            startIcon={<ThumbDown />}
        >
            Reject
        </Button>
    );
};

RejectButton.propTypes = {
    record: PropTypes.object,
};

export default RejectButton;
从“React”导入React;
从“道具类型”导入道具类型;
从'@material ui/core/styles'导入{makeStyles};
从“@material ui/core/Button”导入按钮;
从“@material ui/icons/ThumbDown”导入缩略图;
从“react admin”导入{useUpdate、useNotify、useRedirect};
/**
*此自定义按钮演示如何使用自定义操作更新数据
*/
const useStyles=makeStyles((主题)=>({
按钮:{
颜色:“红色”,
边框颜色:“红色”,
“&:悬停”:{
颜色:“#fff”,
背景:“红色”,
边框颜色:“红色”,
}
},
}));
const RejectButton=({record}:any)=>{
const notify=useNotify();
const redirectTo=useRedirect();
const classes=useStyles();
常量[reject,{loading}]=useUpdate(
`用户/${record.id}/\u拒绝`,
'',
{原因:'由于缺少信息或可能是许可证图片不可见。请重新上载。'},
记录,
{
可撤销的:是的,
onSuccess:()=>{
通知(
“用户配置文件被拒绝!”,
“信息”,
{},
真的
);
重定向到('/users');
},
onFailure:(error:any)=>notify(`error:${error.error}`,'warning'),
}
);
返回(
拒绝
);
};
RejectButton.propTypes={
记录:PropTypes.object,
};
导出默认拒绝按钮;
这是我的rejectButton组件代码,因此我发送静态值,但我想发送我在TextArea组件中键入的任何内容

import React from 'react';
import PropTypes from 'prop-types';
import { makeStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
import ThumbDown from '@material-ui/icons/ThumbDown';
import { useUpdate, useNotify, useRedirect } from 'react-admin';

/**
 * This custom button demonstrate using a custom action to update data
 */

const useStyles = makeStyles((theme) => ({
    button: {
      color: 'red',
      borderColor: 'red',
      "&:hover": {
        color: '#fff',
        background: 'red',
        borderColor: 'red',
      }
    },
}));

const RejectButton = ({ record }: any) => {
    const notify = useNotify();
    const redirectTo = useRedirect();

    const classes = useStyles();

    const [reject, { loading }] = useUpdate(
        `users/${record.id}/_reject`,
        '',
        { reason: 'Due to missinng information or may be the license picture is not visible. Please upload again.' },
        record,
        {
            undoable: true,
            onSuccess: () => {
                notify(
                    'User profile rejected!',
                    'info',
                    {},
                    true
                );
                redirectTo('/users');
            },
            onFailure: (error: any) => notify(`Error: ${error.error}`, 'warning'),
        }
    );

    return (
        <Button
            variant="outlined"
            color="primary"
            size="small"
            onClick={reject}
            disabled={loading}
            className={classes.button}
            startIcon={<ThumbDown />}
        >
            Reject
        </Button>
    );
};

RejectButton.propTypes = {
    record: PropTypes.object,
};

export default RejectButton;