SoftwareBrothers / adminjs

AdminJS is an admin panel for apps written in node.js
https://adminjs.co
MIT License
8.06k stars 646 forks source link

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

Closed tamertwitter closed 3 months ago

tamertwitter commented 4 months ago

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

tamertwitter commented 4 months ago

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;