-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upcoming: [M3-7716] - Add session expiry confirmation dialog for prox…
…y users (#10152) Co-authored-by: Jaalah Ramos <jaalah.ramos@gmail.com> Co-authored-by: Mariah Jacobs <114685994+mjac0bs@users.noreply.github.com>
- Loading branch information
1 parent
66fe7fa
commit 22eb025
Showing
16 changed files
with
434 additions
and
120 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-10152-upcoming-features-1707246537679.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
|
||
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 })), | ||
[] | ||
); | ||
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.