Skip to content

Commit

Permalink
initial commit - dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiolalombardim committed Jun 12, 2024
1 parent c040f6e commit 97e46ff
Show file tree
Hide file tree
Showing 3 changed files with 252 additions and 13 deletions.
26 changes: 16 additions & 10 deletions src/modules/explorer/components/FiltersUserDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ interface Props {

const SectionTitle = styled(Typography)({
fontSize: "18px !important",
fontWeight: 600
fontWeight: 600,
color: "#fff !important"
})

const Container = styled(Grid)({
Expand All @@ -43,6 +44,7 @@ const Container = styled(Grid)({
const StatusButton = styled(Grid)(({ theme }) => ({
"background": theme.palette.primary.main,
"padding": "8px 16px",
"color": theme.palette.text.primary,
"borderRadius": 50,
"marginRight": 16,
"marginBottom": 16,
Expand Down Expand Up @@ -155,30 +157,34 @@ export const FilterUserProposalsDialog: React.FC<Props> = ({ open, handleClose,
</Container> */}
<Container container direction="column">
<Grid item>
<SectionTitle>Type</SectionTitle>
<SectionTitle color="textPrimary">Type</SectionTitle>
</Grid>
<Grid item container direction="row">
<StatusButton
item
onClick={() => saveType(ProposalType.ON_CHAIN)}
style={proposalType === ProposalType.ON_CHAIN ? { backgroundColor: "#fff", color: "#1c1f23" } : {}}
style={
proposalType === ProposalType.ON_CHAIN ? { backgroundColor: "#fff", color: "#1c1f23 !important" } : {}
}
>
<Typography>On-chain</Typography>
<Typography color="textPrimary">On-chain</Typography>
</StatusButton>
<StatusButton
item
onClick={() => saveType(ProposalType.OFF_CHAIN)}
style={proposalType === ProposalType.OFF_CHAIN ? { backgroundColor: "#fff", color: "#1c1f23" } : {}}
style={
proposalType === ProposalType.OFF_CHAIN ? { backgroundColor: "#fff", color: "#1c1f23 !important" } : {}
}
>
<Typography>Off-chain</Typography>
<Typography color="textPrimary">Off-chain</Typography>
</StatusButton>
</Grid>
</Container>

{proposalType === ProposalType.ON_CHAIN ? (
<Container container direction="column">
<Grid item>
<SectionTitle>On-Chain Proposal Status</SectionTitle>
<SectionTitle color="textPrimary">On-Chain Proposal Status</SectionTitle>
</Grid>
<Grid item container direction="row">
{onchainStatus.length > 0 &&
Expand All @@ -200,22 +206,22 @@ export const FilterUserProposalsDialog: React.FC<Props> = ({ open, handleClose,
{proposalType === ProposalType.OFF_CHAIN ? (
<Container container direction="column">
<Grid item>
<SectionTitle>Off-Chain Proposal Status</SectionTitle>
<SectionTitle color="textPrimary">Off-Chain Proposal Status</SectionTitle>
</Grid>
<Grid item container direction="row">
<StatusButton
item
onClick={() => saveOffchainStatus(OffchainStatus.ACTIVE)}
style={offchainStatus === OffchainStatus.ACTIVE ? { backgroundColor: "#fff", color: "#1c1f23" } : {}}
>
<Typography>Active</Typography>
<Typography color="textPrimary">Active</Typography>
</StatusButton>
<StatusButton
item
onClick={() => saveOffchainStatus(OffchainStatus.CLOSED)}
style={offchainStatus === OffchainStatus.CLOSED ? { backgroundColor: "#fff", color: "#1c1f23" } : {}}
>
<Typography>Closed</Typography>
<Typography color="textPrimary">Closed</Typography>
</StatusButton>
</Grid>
</Container>
Expand Down
204 changes: 204 additions & 0 deletions src/modules/explorer/components/FiltersUserTransactionsDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
import React, { useEffect, useState } from "react"
import { ResponsiveDialog } from "./ResponsiveDialog"
import { Grid, TextField, styled, withStyles } from "@material-ui/core"
import { Typography } from "@mui/material"
import { Dropdown } from "./Dropdown"
import { ProposalStatus } from "services/services/dao/mappers/proposal/types"
import { SmallButton } from "modules/common/SmallButton"
import { Filters, TrxFilters } from "../pages/User/components/UserMovements"

export enum TrxStatus {
COMPLETED = "completed",
PENDING = "pending",
FAILED = "failed"
}

interface Props {
open: boolean
handleClose: () => void
saveFilters: (filters: TrxFilters) => void
}

const SectionTitle = styled(Typography)({
fontSize: "18px !important",
fontWeight: 600,
color: "#fff !important"
})

const Container = styled(Grid)(({ theme }) => ({
marginTop: 6,
gap: 24,
[theme.breakpoints.down("sm")]: {
marginTop: 30
}
}))

const CustomTextField = withStyles({
root: {
"& .MuiInput-root": {
fontWeight: 300,
textAlign: "initial"
},
"& .MuiInputBase-input": {
textAlign: "initial",
background: "#2F3438",
borderRadius: 8,
padding: 16
},
"& p": {
position: "absolute",
right: 16,
fontWeight: 300
},
"& .MuiInputBase-root": {
textWeight: 300
},
"& .MuiInput-underline": {
borderBottom: "none !important"
},
"& .MuiInput-underline:before": {
borderBottom: "none !important"
},
"& .MuiInput-underline:hover:before": {
borderBottom: "none !important"
},
"& .MuiInput-underline:after": {
borderBottom: "none !important"
},
"& .MuiInput-underline:hover:not(.Mui-disabled):before": {
borderBottom: "none !important"
}
}
})(TextField)

const StatusButton = styled(Grid)(({ theme }) => ({
"background": theme.palette.primary.main,
"padding": "8px 16px",
"color": theme.palette.text.primary,
"borderRadius": 50,
"marginRight": 16,
"marginBottom": 16,
"cursor": "pointer",
"textTransform": "capitalize",
"&:hover": {
background: "rgba(129, 254, 183, .4)"
}
}))

const ariaLabel = { "aria-label": "description" }

export interface StatusOption {
label: string
}

export const FilterUserTransactionsDialog: React.FC<Props> = ({ open, handleClose, saveFilters }) => {
const [token, setToken] = useState<string | null>("")
const [receiver, setReceiver] = useState<string | null>("")
const [sender, setSender] = useState<string | null>("")
const [status, setStatus] = useState<StatusOption[]>([])
const [filters, setFilters] = useState<StatusOption>()

const findStatus = () => {
const values = Object.values(TrxStatus)
for (const item in values) {
const obj = {
label: values[item]
}
setStatus(oldArray => [...oldArray, obj])
}
}

useEffect(() => {
setStatus([])
findStatus()
}, [])

const isSelected = (item: StatusOption) => {
return filters && filters.label === item.label ? true : false
}

const saveStatus = (status: StatusOption) => {
if (status.label === filters?.label) {
setFilters(undefined)
} else {
setFilters(status)
}
}

const showFilters = () => {
console.log("filters")
}
return (
<>
<ResponsiveDialog open={open} onClose={handleClose} title={"Filter"} template="sm">
<Container container direction="column">
<Grid item>
<SectionTitle color="textPrimary">Transaction Status</SectionTitle>
</Grid>
<Grid item container direction="row">
{status.length > 0 &&
status.map((item, index) => {
return (
<StatusButton
item
key={`status-${index}`}
style={isSelected(item) ? { backgroundColor: "#fff", color: "#1c1f23" } : {}}
>
<Typography onClick={() => saveStatus(item)}>{item.label}</Typography>
</StatusButton>
)
})}
</Grid>

<Grid item>
<SectionTitle color="textPrimary">Token</SectionTitle>
</Grid>
<Grid item xs={12}>
<CustomTextField
onChange={event => setToken(event.target.value)}
style={{ width: "40%" }}
name="test"
value={token}
placeholder="Token"
inputProps={ariaLabel}
/>
</Grid>

<Grid item>
<SectionTitle color="textPrimary">Receiving Address</SectionTitle>
</Grid>
<Grid item xs={12}>
<CustomTextField
onChange={event => setReceiver(event.target.value)}
style={{ width: "100%" }}
name="test"
value={receiver}
placeholder="Address"
inputProps={ariaLabel}
/>
</Grid>

<Grid item>
<SectionTitle color="textPrimary">Sending Address</SectionTitle>
</Grid>
<Grid item xs={12}>
<CustomTextField
onChange={event => setSender(event.target.value)}
style={{ width: "100%" }}
name="test"
value={sender}
placeholder="Address"
inputProps={ariaLabel}
/>
</Grid>
</Container>

<Container container direction="row" justifyContent="flex-end">
<SmallButton color="secondary" variant="contained" onClick={showFilters}>
Apply
</SmallButton>
</Container>
</ResponsiveDialog>
</>
)
}
35 changes: 32 additions & 3 deletions src/modules/explorer/pages/User/components/UserMovements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
import { useUserVotes } from "modules/lite/explorer/hooks/useUserVotes"
import { usePolls } from "modules/lite/explorer/hooks/usePolls"
import { useDAO } from "services/services/dao/hooks/useDAO"
import { FilterUserTransactionsDialog, TrxStatus } from "modules/explorer/components/FiltersUserTransactionsDialog"

const TabsContainer = styled(Grid)(({ theme }) => ({
borderRadius: 8,
Expand Down Expand Up @@ -122,6 +123,13 @@ export interface Filters {
order: Order
}

export interface TrxFilters {
status: TrxStatus
token: string
receiver: string
sender: string
}

export const UserMovements: React.FC<{
daoId: string
proposalsCreated: Proposal[]
Expand All @@ -136,7 +144,10 @@ export const UserMovements: React.FC<{
const theme = useTheme()
const isMobileSmall = useMediaQuery(theme.breakpoints.down("sm"))
const [openFiltersDialog, setOpenFiltersDialog] = useState(false)
const [openFiltersTrxDialog, setOpenFiltersTrxDialog] = useState(false)

const [filters, setFilters] = useState<Filters>()
const [trxFilters, setTrxFilters] = useState<TrxFilters>()

const { data } = useDAO(daoId)
const { data: polls } = usePolls(data?.liteDAOData?._id)
Expand Down Expand Up @@ -193,10 +204,18 @@ export const UserMovements: React.FC<{
setOpenFiltersDialog(false)
}

const handleCloseTrxFiltersModal = () => {
setOpenFiltersTrxDialog(false)
}

const handleFilters = (filters: Filters) => {
setFilters(filters)
}

const handleTrxFilters = (filters: TrxFilters) => {
setTrxFilters(filters)
}

return (
<Grid item>
{showActivity ? (
Expand Down Expand Up @@ -262,14 +281,18 @@ export const UserMovements: React.FC<{
<Typography color="secondary">View All</Typography>
</Grid>
</ViewAll>
) : selectedTab !== 2 ? (
<ViewAll item xs={isMobileSmall ? 12 : 2} onClick={() => setOpenFiltersDialog(true)}>
) : (
<ViewAll
item
xs={isMobileSmall ? 12 : 2}
onClick={() => (selectedTab !== 2 ? setOpenFiltersDialog(true) : setOpenFiltersTrxDialog(true))}
>
<Grid item container direction="row" alignItems="center">
<FilterAltIcon color="secondary" />
<Typography color="secondary">Filter & Sort</Typography>
</Grid>
</ViewAll>
) : null}
)}

<Grid item>
<TabPanel value={selectedTab} index={0}>
Expand Down Expand Up @@ -361,6 +384,12 @@ export const UserMovements: React.FC<{
handleClose={handleCloseFiltersModal}
saveFilters={handleFilters}
/>

<FilterUserTransactionsDialog
open={openFiltersTrxDialog}
handleClose={handleCloseTrxFiltersModal}
saveFilters={handleTrxFilters}
/>
</Grid>
)
}

0 comments on commit 97e46ff

Please sign in to comment.