其他路径组件中的“渲染超时”对话框

DJ2

我有一个超时对话框,当令牌在X分钟后过期时,我想在各个组件中进行渲染(我已经硬编码了时间)。Material-UI对话框用于弹出对话框。我设置了两个超时时间,一个超时时间为29分钟:30秒,以发出警告消息,并且30分钟将强制注销。

我看了下面的示例以获取想法

const AlertDialog = props => {
  const [warningTimeout, setWarningTimeout] = useState(1770000);
  const [limitTimeout, setLimitTimeout] = useState(1800000);
  const [open, setOpen] = useState(true);

  const handleContinue = () => {
    //this will make an api call to refresh the token, where we must update the context with the new token
    setOpen(false);
  };

  const handleLogout = () => {
    //this will destroy the session, clear localstorage
  };

  const warn = () => {
    console.log("Warning, 30 minutes has past");
  };
  const logout = () => {
    console.log("You have been logged out");
  };

  const setTimeouts = () => {
    const warnTimeout = setTimeout(warn, warningTimeout);
    const logoutTimeout = setTimeout(logout, limitTimeout);
  };

  useEffect(() => {
    setTimeouts();
  });

  return (
    <div>
      <Dialog
        disableBackdropClick
        disableEscapeKeyDown
        open={open}
        aria-labelledby="alert-dialog-title"
        aria-describedby="alert-dialog-description"
      >
        <DialogTitle id="alert-dialog-title">{"Session Timeout"}</DialogTitle>
        <DialogContent>
          <DialogContentText id="alert-dialog-description">
            If you wish to continue the current session please press continue.
            You have 30 seconds to decide or you will be logged out.
          </DialogContentText>
        </DialogContent>
        <DialogActions>
          <Button onClick={handleLogout} color="primary">
            Logout
          </Button>
          <Button onClick={handleContinue} color="primary" autoFocus>
            Continue
          </Button>
        </DialogActions>
      </Dialog>
    </div>
  );
};

export default AlertDialog;

该项目具有受保护的路线,因此它们看起来像这样。我想将此警报对话框传递给所有<AdminPrivateRoute>

const Routes = () => (
  <UserProvider>
    <TokenProvider>
      <Router>
        <Switch>
          <Route exact path="/" component={LoginForm} />
          <AdminPrivateRoute path="/dashboard" component={Dashboard} />
          <AdminPrivateRoute path="/secondary-page" component={SecondaryPage} />
        </Switch>
      </Router>
    </TokenProvider>
  </UserProvider>
);

用警报对话框包装以上组件是否可行?<AdminPrivateRoute path="/dashbaord" component={AlertDialog(Dashboard)} />有没有更好的方法?

Codesandbox供参考,您可以使用任何凭据登录。

DJ2

<AlertDialog />组件放在外部<Switch />似乎可以解决问题。

const Routes = () => (
  <Router>
    <AlertDialog />
    <Switch>
      <Route exact path="/" component={LoginForm} />
      <AdminPrivateRoute path="/dashboard" component={Dashboard} />
    </Switch>
  </Router>
);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在其他树枝+模式对话框Symfony2中渲染视图

来自分类Dev

在React中从其他页面打开对话框

来自分类Dev

Ms BotBuilder:firstRun 对话框防止触发基于 LUIS 意图的其他对话框

来自分类Dev

在其他窗口和/或对话框中显示QLineEdit的输入?

来自分类Dev

Outlook加载项在其他打开的Outlook中显示相同的对话框

来自分类Dev

Chrome浏览器中的“模型”对话框是否有其他替代项

来自分类Dev

Django Inlining在添加对话框中显示其他字段

来自分类Dev

如何在Bot框架中添加其他对话框

来自分类Dev

对话框已请求其他空间

来自分类Dev

如何显示来自其他类的对话框

来自分类Dev

Azure Bot NodeJS 等待其他对话框完成

来自分类Dev

如何创建一个类似组件的对话框,允许在其中放置其他控件?

来自分类Dev

通过在bot框架v4中跳过第一个对话框的第一步,将第一个对话框的瀑布步骤调用到其他对话框中

来自分类Dev

从对话框中打开选定的路径

来自分类Dev

在组件的Angular 6中隐藏Bootstrap对话框

来自分类Dev

如何关闭组件文件中的 mdl 对话框

来自分类Dev

重新使用 angular 6 中的对话框组件

来自分类Dev

会话超时警告对话框mvc

来自分类Dev

如何在“以其他用户身份运行”对话框中删除多个智能卡条目?

来自分类Dev

如何处理来自Android中其他活动的警报对话框的肯定按钮上的事件?

来自分类Dev

在其他日期选择器对话框中基于所选日期禁用以前的日期

来自分类Dev

Bootstrap对话框渲染后缀

来自分类Dev

从openfile对话框获取路径

来自分类Dev

使用导航组件的对话框片段

来自分类Dev

从效果关闭对话框组件

来自分类Dev

子组件对话框未关闭

来自分类Dev

使用导航组件的对话框片段

来自分类Dev

对话框中的片段

来自分类Dev

对话框中的MapView

Related 相关文章

  1. 1

    如何在其他树枝+模式对话框Symfony2中渲染视图

  2. 2

    在React中从其他页面打开对话框

  3. 3

    Ms BotBuilder:firstRun 对话框防止触发基于 LUIS 意图的其他对话框

  4. 4

    在其他窗口和/或对话框中显示QLineEdit的输入?

  5. 5

    Outlook加载项在其他打开的Outlook中显示相同的对话框

  6. 6

    Chrome浏览器中的“模型”对话框是否有其他替代项

  7. 7

    Django Inlining在添加对话框中显示其他字段

  8. 8

    如何在Bot框架中添加其他对话框

  9. 9

    对话框已请求其他空间

  10. 10

    如何显示来自其他类的对话框

  11. 11

    Azure Bot NodeJS 等待其他对话框完成

  12. 12

    如何创建一个类似组件的对话框,允许在其中放置其他控件?

  13. 13

    通过在bot框架v4中跳过第一个对话框的第一步,将第一个对话框的瀑布步骤调用到其他对话框中

  14. 14

    从对话框中打开选定的路径

  15. 15

    在组件的Angular 6中隐藏Bootstrap对话框

  16. 16

    如何关闭组件文件中的 mdl 对话框

  17. 17

    重新使用 angular 6 中的对话框组件

  18. 18

    会话超时警告对话框mvc

  19. 19

    如何在“以其他用户身份运行”对话框中删除多个智能卡条目?

  20. 20

    如何处理来自Android中其他活动的警报对话框的肯定按钮上的事件?

  21. 21

    在其他日期选择器对话框中基于所选日期禁用以前的日期

  22. 22

    Bootstrap对话框渲染后缀

  23. 23

    从openfile对话框获取路径

  24. 24

    使用导航组件的对话框片段

  25. 25

    从效果关闭对话框组件

  26. 26

    子组件对话框未关闭

  27. 27

    使用导航组件的对话框片段

  28. 28

    对话框中的片段

  29. 29

    对话框中的MapView

热门标签

归档