-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change the approach to opening modals
We should have one modal and change the content in it.
- Loading branch information
1 parent
1d4e834
commit dcac86c
Showing
18 changed files
with
202 additions
and
179 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
import React from "react" | ||
import { Button, ModalBody, ModalCloseButton } from "@chakra-ui/react" | ||
import { TextMd } from "../Typography" | ||
import { ModalStep } from "../../contexts" | ||
|
||
export default function StakeModal({ goNext }: ModalStep) { | ||
return ( | ||
<> | ||
<ModalCloseButton /> | ||
<ModalBody> | ||
<TextMd>Stake modal</TextMd> | ||
<Button width="100%" onClick={goNext}> | ||
Stake | ||
</Button> | ||
</ModalBody> | ||
</> | ||
) | ||
} |
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,11 +1,25 @@ | ||
import React from "react" | ||
import { ModalHeader } from "@chakra-ui/react" | ||
import BaseModal from "./BaseModal" | ||
import { | ||
Button, | ||
ModalBody, | ||
ModalCloseButton, | ||
ModalFooter, | ||
} from "@chakra-ui/react" | ||
import { TextMd } from "../Typography" | ||
import { ModalStep } from "../../contexts" | ||
|
||
export default function StakingOverviewModal() { | ||
export default function StakingOverviewModal({ goNext }: ModalStep) { | ||
return ( | ||
<BaseModal> | ||
<ModalHeader textAlign="center">Staking overview</ModalHeader> | ||
</BaseModal> | ||
<> | ||
<ModalCloseButton /> | ||
<ModalBody> | ||
<TextMd>Staking overview</TextMd> | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button width="100%" onClick={goNext}> | ||
Get started | ||
</Button> | ||
</ModalFooter> | ||
</> | ||
) | ||
} |
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 was deleted.
Oops, something went wrong.
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,34 @@ | ||
import React from "react" | ||
import { useModalFlowContext } from "../../hooks" | ||
import StakeModal from "../Modals/StakeModal" | ||
import StakingOverviewModal from "../Modals/StakingOverviewModal" | ||
import ModalBase from "../shared/ModalBase" | ||
|
||
function StakingModalSteps() { | ||
const { activeStep, goNext } = useModalFlowContext() | ||
|
||
console.log("activeStep ", activeStep) | ||
|
||
switch (activeStep) { | ||
case "overview": | ||
return <StakingOverviewModal goNext={goNext} /> | ||
case "stake": | ||
return <StakeModal goNext={goNext} /> | ||
default: | ||
return null | ||
} | ||
} | ||
|
||
export default function StakingModal({ | ||
isOpen, | ||
onClose, | ||
}: { | ||
isOpen: boolean | ||
onClose: () => void | ||
}) { | ||
return ( | ||
<ModalBase isOpen={isOpen} onClose={onClose} steps={["overview", "stake"]}> | ||
<StakingModalSteps /> | ||
</ModalBase> | ||
) | ||
} |
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,73 @@ | ||
import React, { useCallback, useEffect, useMemo, useState } from "react" | ||
import { Modal, ModalContent, ModalOverlay } from "@chakra-ui/react" | ||
import { HEADER_HEIGHT } from "../../Header" | ||
import { ModalFlowContext, ModalFlowContextValue } from "../../../contexts" | ||
import { useSidebar } from "../../../hooks" | ||
|
||
export default function ModalBase({ | ||
isOpen, | ||
onClose, | ||
steps, | ||
defaultIndex = 0, | ||
children, | ||
}: { | ||
isOpen: boolean | ||
onClose: () => void | ||
steps: string[] | ||
defaultIndex?: number | ||
children: React.ReactNode | ||
}) { | ||
const { onOpen: openSideBar, onClose: closeSidebar } = useSidebar() | ||
|
||
const [activeStep, setActiveStep] = useState(steps[defaultIndex]) | ||
const [index, setIndex] = useState(defaultIndex) | ||
|
||
const handleGoNext = useCallback(() => { | ||
setIndex((prevIndex) => prevIndex + 1) | ||
}, []) | ||
|
||
const handleClose = useCallback(() => { | ||
onClose() | ||
}, [onClose]) | ||
|
||
useEffect(() => { | ||
if (index >= steps.length) { | ||
handleClose() | ||
} else { | ||
setActiveStep(steps[index]) | ||
} | ||
}, [steps, index, handleClose]) | ||
|
||
useEffect(() => { | ||
if (!isOpen) { | ||
closeSidebar() | ||
|
||
const timeout = setTimeout(() => { | ||
setActiveStep(steps[defaultIndex]) | ||
setIndex(defaultIndex) | ||
}, 100) | ||
return () => clearTimeout(timeout) | ||
} else { | ||
openSideBar() | ||
} | ||
}, [isOpen, steps, defaultIndex, closeSidebar, openSideBar]) | ||
|
||
const contextValue: ModalFlowContextValue = useMemo<ModalFlowContextValue>( | ||
() => ({ | ||
steps, | ||
activeStep, | ||
onClose: handleClose, | ||
goNext: handleGoNext, | ||
}), | ||
[activeStep, steps, handleGoNext, handleClose], | ||
) | ||
|
||
return ( | ||
<ModalFlowContext.Provider value={contextValue}> | ||
<Modal size="md" isOpen={isOpen} onClose={handleClose}> | ||
<ModalOverlay mt={HEADER_HEIGHT} /> | ||
<ModalContent mt={2 * HEADER_HEIGHT}>{children}</ModalContent> | ||
</Modal> | ||
</ModalFlowContext.Provider> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
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,19 @@ | ||
import { createContext } from "react" | ||
|
||
export type ModalStep = { | ||
goNext: () => void | ||
} | ||
|
||
export type ModalFlowContextValue = { | ||
activeStep?: string | ||
steps: string[] | ||
onClose: () => void | ||
goNext: () => void | ||
} | ||
|
||
export const ModalFlowContext = createContext<ModalFlowContextValue>({ | ||
activeStep: undefined, | ||
steps: [], | ||
goNext: () => {}, | ||
onClose: () => {}, | ||
}) |
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.