React-Admin I Custom button not able to get form data

Viewed 190

I have created a custom button to reject a user. I want to send the reason for rejecting but not able to send the form data.I am using "FormWithRedirect" in userEdit component.

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;

this is my code for rejectButton component and in reason I am sending the static value but I want to send whatever I typed in TextArea component.

0 Answers
Related