SoftwareBrothers / adminjs

AdminJS is an admin panel for apps written in node.js

Home Page:https://adminjs.co

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature]: how i can redirect to url from actions handler

tamertwitter opened this issue · comments

Description

I try redirect but it is not work.

 return {
  record: record.toJSON(currentAdmin),
  redirectUrl: 'https://google.com'
};

response:

http://localhost:3000/admin/resources/user/http://google.com?refresh=true

SCR-20240228-tqsw-2

Suggested Solution

 return {
  record: record.toJSON(currentAdmin),
  redirectUrl: 'https://google.com',
  forceReload: true, // or whatever key can be
};

Alternatives

No response

Additional Context

No response

Okay I get it.

I added to component from my action and more global think...

import React from 'react';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { Box, H5, Button, Text } from '@adminjs/design-system';
// import { ActionProps } from 'adminjs';

const RedirectToUrlAction = (props: any) => {
  const { record, msg } = props;
  // redirect to the URL to 5 seconds
  setTimeout(() => {
    window.location = record.params.url;
  }, 3 * 1000);

  return (
    <Box>
      <H5>{record.params.msg}</H5>
      <Box>
        <Text textAlign="center">
          <Button href={record.params.url}>
            Link to Request
          </Button>
        </Text>
      </Box>
    </Box>
  );
};

export default RedirectToUrlAction;