Skip to content

Commit

Permalink
modal & options added
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiolalombardim committed Jul 13, 2023
1 parent e131f4e commit 9dd5085
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/modules/common/SmallButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export const SmallButton = styled(Button)({
"transition": ".15s ease-out",
"textTransform": "capitalize",
"borderRadius": 8,
"backgroundColor": "#81feb7 !important",
"color": "#1c1f23",

"&$disabled": {
boxShadow: "none"
Expand Down
1 change: 1 addition & 0 deletions src/modules/explorer/components/ResponsiveDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const TitleText = styled(Typography)(({ theme }) => ({
fontWeight: 550,
lineHeight: ".80",
textTransform: "capitalize",
fontSize: 20,
[theme.breakpoints.down("sm")]: {
fontSize: 18
}
Expand Down
71 changes: 52 additions & 19 deletions src/modules/explorer/pages/User/components/DelegationBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import React, { useState } from "react"
import React, { Fragment, useEffect, useState } from "react"
import { Grid, Theme, Typography, styled } from "@material-ui/core"
import { useDAO } from "services/services/dao/hooks/useDAO"
import { Edit } from "@material-ui/icons"
import { DelegationDialog } from "./DelegationModal"

export enum DelegationsType {
ACCEPTING_DELEGATION = "ACCEPTING_DELEGATION",
NOT_ACCEPTING_DELEGATION = "NOT_ACCEPTING_DELEGATION",
DELEGATING = "DELEGATING"
}

interface DelegationStatus {
status: DelegationsType.ACCEPTING_DELEGATION | DelegationsType.NOT_ACCEPTING_DELEGATION | DelegationsType.DELEGATING
}

const DelegationBox = styled(Grid)(({ theme }: { theme: Theme }) => ({
minHeight: "178px",
padding: "46px 55px",
Expand All @@ -33,26 +31,37 @@ const Balance = styled(Typography)({
fontWeight: 200
})

export const matchTextToStatus = (value: DelegationsType | undefined) => {
switch (value) {
case DelegationsType.ACCEPTING_DELEGATION:
return "Accepting delegations"
case DelegationsType.NOT_ACCEPTING_DELEGATION:
return "Not currently accepting delegations or delegating"
case DelegationsType.DELEGATING:
return "Delegating to "
default:
return
}
}

export const Delegation: React.FC<{ voteWeight: any; daoId: string }> = ({ voteWeight, daoId }) => {
const { data: dao } = useDAO(daoId)
const [delegationStatus, setDelegationStatus] = useState<DelegationsType>(DelegationsType.NOT_ACCEPTING_DELEGATION)
const [delegationStatus, setDelegationStatus] = useState<DelegationsType | undefined>(
DelegationsType.NOT_ACCEPTING_DELEGATION
)
const [openModal, setOpenModal] = useState(false)

const matchTextToStatus = (value: DelegationsType) => {
switch (value) {
case DelegationsType.ACCEPTING_DELEGATION:
return "Accepting delegations"
case DelegationsType.NOT_ACCEPTING_DELEGATION:
return "Not currently accepting delegations or delegating"
case DelegationsType.DELEGATING:
return "Delegating to "
default:
return
}
const onCloseAction = () => {
setOpenModal(false)
}

useEffect(() => {
console.log("se actualizó", delegationStatus)
}, [delegationStatus])

return (
<DelegationBox container direction="column">
<Grid container style={{ gap: 12 }}>
<Grid container style={{ gap: 12 }} direction="column">
<Typography variant="h4" color="textPrimary">
Off-chain Delegation
</Typography>
Expand All @@ -67,9 +76,33 @@ export const Delegation: React.FC<{ voteWeight: any; daoId: string }> = ({ voteW
</Grid>
)}
<Grid container style={{ gap: 12 }} direction="column">
<Typography color="textPrimary">Delegation Status</Typography>
<Grid container direction="row" justifyContent="space-between" alignItems="center">
<Grid item xs={6}>
<Typography color="textPrimary">Delegation Status</Typography>
</Grid>
<Grid
item
container
direction="row"
xs={6}
alignItems="center"
justifyContent="flex-end"
style={{ gap: 4, cursor: "pointer" }}
>
<Edit color="secondary" fontSize="small" onClick={() => setOpenModal(true)} />
<Typography color="secondary" onClick={() => setOpenModal(true)}>
Edit
</Typography>
</Grid>
</Grid>
<Subtitle variant="body1">{matchTextToStatus(delegationStatus)}</Subtitle>
</Grid>
<DelegationDialog
open={openModal}
onClose={onCloseAction}
status={delegationStatus}
setDelegationStatus={setDelegationStatus}
/>
</DelegationBox>
)
}
146 changes: 146 additions & 0 deletions src/modules/explorer/pages/User/components/DelegationModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import { Grid, Radio, TextField, Typography, styled } from "@material-ui/core"
import React, { useEffect, useState } from "react"
import { DelegationsType, matchTextToStatus } from "./DelegationBanner"
import { ResponsiveDialog } from "modules/explorer/components/ResponsiveDialog"
import { SmallButton } from "modules/common/SmallButton"

const AddressTextField = styled(TextField)({
"backgroundColor": "#2f3438",
"borderRadius": 8,
"height": 56,
"padding": "0px 24px",
"alignItems": "flex-start",
"boxSizing": "border-box",
"justifyContent": "center",
"display": "flex",
"& .MuiInputBase-root": {
"width": "100%",
"& input": {
textAlign: "initial"
}
}
})

export enum ActionTypes {
ACCEPT_DELEGATIONS = "ACCEPT_DELEGATIONS",
DELEGATE = "DELEGATE",
CHANGE_DELEGATE = "CHANGE_DELEGATE",
STOP_ACCEPTING_DELEGATIONS = "STOP_ACCEPTING_DELEGATIONS",
STOP_DELEGATING = "STOP_DELEGATING"
}

const matchTextToAction = (value: ActionTypes) => {
switch (value) {
case ActionTypes.ACCEPT_DELEGATIONS:
return "Accept Delegations"
case ActionTypes.DELEGATE:
return "Delegate"
case ActionTypes.CHANGE_DELEGATE:
return "Change Delegate"
case ActionTypes.STOP_ACCEPTING_DELEGATIONS:
return "Stop Accepting Delegations"
case ActionTypes.STOP_DELEGATING:
return "Stop Delegating"
default:
return
}
}

export const DelegationDialog: React.FC<{
open: boolean
onClose: () => void
status: DelegationsType | undefined
setDelegationStatus: (value: DelegationsType | undefined) => void
}> = ({ status, onClose, open, setDelegationStatus }) => {
const [options, setOptions] = useState<ActionTypes[]>([])
const [selectedOption, setSelectedOption] = useState()

useEffect(() => {
getOptionsByStatus(status)
}, [status])

const closeDialog = () => {
setSelectedOption(undefined)
onClose()
}

const saveInfo = () => {
updateStatus()
closeDialog()
}

const updateStatus = () => {
if (selectedOption === ActionTypes.DELEGATE || selectedOption === ActionTypes.CHANGE_DELEGATE) {
return setDelegationStatus(DelegationsType.DELEGATING)
}
if (selectedOption === ActionTypes.STOP_ACCEPTING_DELEGATIONS || ActionTypes.STOP_DELEGATING) {
return setDelegationStatus(DelegationsType.NOT_ACCEPTING_DELEGATION)
}
if (selectedOption === ActionTypes.ACCEPT_DELEGATIONS) {
return setDelegationStatus(DelegationsType.ACCEPTING_DELEGATION)
}
}

const getOptionsByStatus = (status: DelegationsType | undefined) => {
switch (status) {
case DelegationsType.NOT_ACCEPTING_DELEGATION:
const optionsOne = [ActionTypes.ACCEPT_DELEGATIONS, ActionTypes.DELEGATE]
setOptions(optionsOne)
break
case DelegationsType.ACCEPTING_DELEGATION:
const optionsTwo = [ActionTypes.STOP_ACCEPTING_DELEGATIONS, ActionTypes.DELEGATE]
setOptions(optionsTwo)
break
case DelegationsType.DELEGATING:
const optionsThree = [ActionTypes.CHANGE_DELEGATE, ActionTypes.STOP_DELEGATING, ActionTypes.ACCEPT_DELEGATIONS]
setOptions(optionsThree)
break
}
}

return (
<ResponsiveDialog open={open} onClose={closeDialog} title={"Delegation Status"}>
<Grid container direction={"column"} style={{ gap: 20 }}>
<Grid item style={{ gap: 8 }} container direction="column">
<Typography color="textPrimary">Current Status</Typography>
<Typography color="secondary" style={{ fontWeight: 200 }}>
{matchTextToStatus(status)}
</Typography>
</Grid>

{options.map(item => {
return (
<>
<Grid
key={item}
item
style={{ gap: 8 }}
container
direction="row"
alignItems="center"
justifyContent="space-between"
>
<Typography color="textPrimary">{matchTextToAction(item)}</Typography>
<Radio
checked={selectedOption === item}
onChange={(e: any) => setSelectedOption(e.target.value)}
value={item}
name="radio-buttons"
inputProps={{ "aria-label": "A" }}
/>
{item === selectedOption &&
(selectedOption === ActionTypes.DELEGATE || selectedOption === ActionTypes.CHANGE_DELEGATE) ? (
<AddressTextField type="text" placeholder="Enter Address" InputProps={{ disableUnderline: true }} />
) : null}
</Grid>
</>
)
})}

<Grid container direction="row" justifyContent="flex-end">
<SmallButton onClick={saveInfo}>Submit</SmallButton>
</Grid>
</Grid>
</ResponsiveDialog>
)
}

0 comments on commit 9dd5085

Please sign in to comment.