首页 > 解决方案 > React-Admin I 自定义按钮无法获取表单数据

问题描述

我创建了一个自定义按钮来拒绝用户。我想发送拒绝但无法发送表单数据的原因。我在 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;

这是我的rejectButton 组件代码,因此我发送静态值,但我想发送我在TextArea 组件中输入的任何内容。

标签: reactjsreact-admin

解决方案


推荐阅读