0

Here I'm fetching data with ApiClient and after that I make operation to confirm to delete the current item. My question here is how i can reload the page after I click Yes ?

type Props = {
    resourceName: string,
    label: string,
    accessor: string,
    row: Object,
}

@withRouter
@connectAPI((apiClient: ApiClient, props: Props) => ({
    deleteObject: {
        send: (id: any) => apiClient.resources[props.resourceName].delete(id),
        success: () => {
          // TODO: ?
        },
    },
}))
class DeleteComponent extends React.Component<Props> {
    state = {
        open: false,
    };

    handleOpen = () => {
        this.setState({ open: true });
    };

    handleConfirm = (props: Props) => {
        const { accessor, row, deleteObject } = props;

        const id = row._original[accessor];

        deleteObject({
            id,
        });
    };

    render(): React.ReactNode {
        const { open } = this.state;
        let message = null;
        if (open) {
            message = (
                <MessageDialog
                    message="Are tou sure you want to delete ?"
                    actions={{
                        yes: {
                            label: 'Yes',
                            callback: this.handleConfirm,
                        },
                        no: {
                            label: 'No',
                            callback: (e: SyntheticMouseEvent<HTMLButtonElement>) => this.setState({ open: false }),
                        },
                    }}
                />
            );
        }

        return (
            <React.Fragment>
                <Button
                    position="right"
                    onClick={this.handleOpen}
                    hoverIndicator="light-1"
                />
                {message}
            </React.Fragment>
        );
    }
}

export default DeleteComponent;

  • 1
    Possible duplicate of [How to reload a page using JavaScript](https://stackoverflow.com/questions/3715047/how-to-reload-a-page-using-javascript) – Rainbow Apr 19 '19 at 14:17
  • need to pass a prop from the parent, e.g. `onDeleteSuccess`, and call it inside `success` - and in the parent it needs to remove `row` from the array of rows (or reload the data from server) – Aprillion Apr 19 '19 at 14:25

0 Answers0