Skip to content

Commit

Permalink
Properly reset chained flow on account logout
Browse files Browse the repository at this point in the history
  • Loading branch information
elboletaire committed Jun 14, 2024
1 parent e3a6bc5 commit c8ba12a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/components/Process/Chained.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ export const ChainedResults = ({ root }: ChainedProcessesProps) => {
const ChainedProcessesWrapper = () => {
// note election context refers to the root election here, ALWAYS
const { connected, election } = useElection()
const { processes, current, root, setCurrent } = useChainedProcesses()
const { processes, current, root, setCurrent, reset } = useChainedProcesses()

// set current to root if login out
useEffect(() => {
if (connected) return

setCurrent(root.id)
reset()
}, [connected])

if (!current || !processes[current] || !election || election instanceof InvalidElection) {
Expand Down
10 changes: 9 additions & 1 deletion src/components/Process/ChainedContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type ChainedContextState = {
root: PublishedElection
setProcess: (id: string, process: PublishedElection) => void
setCurrent: (id: string | null) => void
reset: () => void
}

type ChainedProviderProps = {
Expand All @@ -32,8 +33,15 @@ export const ChainedProvider: FC<PropsWithChildren<ChainedProviderProps>> = ({ c
}))
}

const reset = () => {
setProcesses((prev) => ({
[root.id]: prev[root.id],
}))
setCurrent(root.id)
}

return (
<ChainedContext.Provider value={{ processes, client, current, root, setProcess, setCurrent }}>
<ChainedContext.Provider value={{ processes, client, current, reset, root, setProcess, setCurrent }}>
{children}
</ChainedContext.Provider>
)
Expand Down

1 comment on commit c8ba12a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.