-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:threshold-network/token-dashboard i…
…nto e2e-environment-setup
- Loading branch information
Showing
19 changed files
with
254 additions
and
103 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 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,30 @@ | ||
import { | ||
Button, | ||
ModalBody, | ||
ModalCloseButton, | ||
ModalFooter, | ||
ModalHeader, | ||
} from "@chakra-ui/react" | ||
import { FC } from "react" | ||
import withBaseModal from "./withBaseModal" | ||
import { BaseModalProps } from "../../types" | ||
|
||
const ExampleModal: FC<{ name: string } & BaseModalProps> = ({ | ||
name, | ||
closeModal, | ||
}) => { | ||
return ( | ||
<> | ||
<ModalHeader>Modal Title</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody>Hello {name}!</ModalBody> | ||
<ModalFooter> | ||
<Button colorScheme="blue" mr={3} onClick={closeModal}> | ||
Close | ||
</Button> | ||
<Button variant="ghost">Secondary Action</Button> | ||
</ModalFooter> | ||
</> | ||
) | ||
} | ||
export default withBaseModal(ExampleModal) |
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,15 @@ | ||
import { useModal } from "../../hooks/useModal" | ||
import { MODAL_TYPES } from "../../types" | ||
|
||
const ModalRoot = () => { | ||
const { modalType, modalProps, closeModal } = useModal() | ||
|
||
if (!modalType) { | ||
return <></> | ||
} | ||
|
||
const SpecificModal = MODAL_TYPES[modalType] | ||
return <SpecificModal closeModal={closeModal} {...modalProps} /> | ||
} | ||
|
||
export default ModalRoot |
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,3 @@ | ||
import ModalRoot from "./ModalRoot" | ||
|
||
export default ModalRoot |
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,20 @@ | ||
import { ComponentType } from "react" | ||
import { Modal, ModalContent, ModalOverlay } from "@chakra-ui/react" | ||
import { BaseModalProps } from "../../types" | ||
|
||
function withBaseModal<T extends BaseModalProps>( | ||
WrappedModalContent: ComponentType<T> | ||
) { | ||
return (props: T) => { | ||
return ( | ||
<Modal isOpen onClose={props.closeModal}> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<WrappedModalContent {...props} /> | ||
</ModalContent> | ||
</Modal> | ||
) | ||
} | ||
} | ||
|
||
export default withBaseModal |
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 @@ | ||
export * from "./modal" |
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,3 @@ | ||
export enum ModalType { | ||
Example = "EXAMPLE", | ||
} |
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,26 @@ | ||
import { useSelector, useDispatch } from "react-redux" | ||
import { UseModal } from "../types" | ||
import { | ||
openModal as openModalAction, | ||
closeModal as closeModalAction, | ||
} from "../store/modal" | ||
import { RootState } from "../store" | ||
import { ModalType } from "../enums" | ||
|
||
export const useModal: UseModal = () => { | ||
const modalType = useSelector((state: RootState) => state.modal.modalType) | ||
const modalProps = useSelector((state: RootState) => state.modal.props) | ||
const dispatch = useDispatch() | ||
|
||
const openModal = (modalType: ModalType, props: any) => | ||
dispatch(openModalAction({ modalType, props })) | ||
|
||
const closeModal = () => dispatch(closeModalAction()) | ||
|
||
return { | ||
modalType, | ||
modalProps, | ||
openModal, | ||
closeModal, | ||
} | ||
} |
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,12 @@ | ||
import { configureStore } from "@reduxjs/toolkit" | ||
import { modalSlice } from "./modal" | ||
|
||
const store = configureStore({ | ||
reducer: { | ||
modal: modalSlice.reducer, | ||
}, | ||
}) | ||
|
||
export type RootState = ReturnType<typeof store.getState> | ||
|
||
export default store |
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 @@ | ||
export * from "./modalSlice" |
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,21 @@ | ||
import { createSlice } from "@reduxjs/toolkit" | ||
|
||
export const modalSlice = createSlice({ | ||
name: "modal", | ||
initialState: { | ||
modalType: null, | ||
props: {}, | ||
}, | ||
reducers: { | ||
openModal: (state, action) => { | ||
state.modalType = action.payload.modalType | ||
state.props = action.payload.props | ||
}, | ||
closeModal: (state) => { | ||
state.modalType = null | ||
state.props = {} | ||
}, | ||
}, | ||
}) | ||
|
||
export const { openModal, closeModal } = modalSlice.actions |
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 |
---|---|---|
@@ -1,5 +1,2 @@ | ||
import { ReactElement } from "react" | ||
|
||
export interface IIconMap { | ||
[key: string]: ReactElement | ||
} | ||
export * from "./modal" | ||
export * from "./utils" |
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,31 @@ | ||
import { ModalType } from "../enums" | ||
import { ElementType } from "react" | ||
import ExampleModal from "../components/Modal/ExampleModal" | ||
|
||
export const MODAL_TYPES: Record<ModalType, ElementType> = { | ||
[ModalType.Example]: ExampleModal, | ||
} | ||
|
||
export interface BaseModalProps { | ||
closeModal: () => void | ||
} | ||
|
||
export interface OpenModal { | ||
payload: { | ||
modalType: ModalType | ||
props: any | ||
} | ||
} | ||
|
||
export interface CloseModal {} | ||
|
||
export type ModalActionTypes = OpenModal | CloseModal | ||
|
||
export interface UseModal { | ||
(): { | ||
modalType: ModalType | null | ||
modalProps: any | ||
openModal: (type: ModalType, props?: any) => ModalActionTypes | ||
closeModal: () => ModalActionTypes | ||
} | ||
} |
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 @@ | ||
import { ReactElement } from "react" | ||
|
||
export interface IconMap { | ||
[key: string]: ReactElement | ||
} |
Oops, something went wrong.