-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
upcoming: [M3-7716] - Add session expiry confirmation dialog for proxy users #10152
Changes from all commits
61cc974
bc8b9ff
55ecc91
883c1fe
87d83e4
f8c00cc
27a85e6
7f986f7
64b1067
bd4d9cc
4f83961
7b7ac4f
b72e574
4f7e8c5
f0d81d2
80aac99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Upcoming Features | ||
--- | ||
|
||
Add session expiry confirmation dialog for proxy to parent user account switching ([#10152](https://github.com/linode/manager/pull/10152)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as React from 'react'; | ||
|
||
import { DialogContextProps, defaultContext } from './useDialogContext'; | ||
|
||
export const switchAccountSessionContext = React.createContext<DialogContextProps>( | ||
defaultContext | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,51 @@ | ||
import { createContext, useCallback, useState } from 'react'; | ||
import { useCallback, useState } from 'react'; | ||
|
||
export interface DialogContextProps { | ||
[key: string]: | ||
| (() => void) | ||
| ((newState: UseDialogContextOptions) => void) | ||
| boolean; | ||
close: () => void; | ||
isOpen: boolean; | ||
open: () => void; | ||
updateState: (newState: UseDialogContextOptions) => void; | ||
} | ||
|
||
export const defaultContext = { | ||
export type UseDialogContextOptions = { | ||
[key: string]: boolean; | ||
}; | ||
|
||
export const defaultContext: DialogContextProps = { | ||
close: () => void 0, | ||
isOpen: false, | ||
open: () => void 0, | ||
updateState: () => void 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll be able to remove these 3 as well in upcoming PR |
||
}; | ||
|
||
export const dialogContext = createContext<DialogContextProps>(defaultContext); | ||
export const useDialogContext = ( | ||
initialState: UseDialogContextOptions = {} | ||
): DialogContextProps => { | ||
const [state, setState] = useState({ ...defaultContext, ...initialState }); | ||
|
||
// TODO: We no longer need the open and close functions after we update other references | ||
const open = useCallback( | ||
() => setState((prevState) => ({ ...prevState, isOpen: true })), | ||
[] | ||
); | ||
const close = useCallback( | ||
() => setState((prevState) => ({ ...prevState, isOpen: false })), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added TODO since |
||
[] | ||
); | ||
const updateState = useCallback( | ||
(newState: UseDialogContextOptions) => | ||
setState((prevState) => ({ ...prevState, ...newState })), | ||
[] | ||
); | ||
|
||
export const useDialogContext = (): DialogContextProps => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const open = useCallback(() => setIsOpen(true), [setIsOpen]); | ||
const close = useCallback(() => setIsOpen(false), [setIsOpen]); | ||
return { | ||
...state, | ||
close, | ||
isOpen, | ||
open, | ||
updateState, | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only change here was adding the Provider wrapper (rest is context shift)