-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1871 from daostack/cw-1864-proposal-resolution-type
New approval (proposal) card #1864
- Loading branch information
Showing
16 changed files
with
265 additions
and
40 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
16 changes: 16 additions & 0 deletions
16
...nents/ProposalFeedCard/components/ImmediateProposalInfo/ImmediateProposalInfo.module.scss
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,16 @@ | ||
@import "../../../../../../constants"; | ||
|
||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
margin-bottom: 2rem; | ||
} | ||
|
||
.title { | ||
font-size: $moderate-small-2; | ||
} | ||
|
||
.subtitle { | ||
font-size: $mobile-title; | ||
color: var(--gray-60); | ||
} |
33 changes: 33 additions & 0 deletions
33
...on/components/ProposalFeedCard/components/ImmediateProposalInfo/ImmediateProposalInfo.tsx
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,33 @@ | ||
import React from "react"; | ||
import { getVotersString } from "@/pages/OldCommon/containers/ProposalContainer/helpers"; | ||
import { Governance, Proposal } from "@/shared/models"; | ||
import styles from "./ImmediateProposalInfo.module.scss"; | ||
|
||
interface ImmediateProposalInfoProps { | ||
proposal: Proposal; | ||
governanceCircles: Governance["circles"]; | ||
proposerUserName: string; | ||
} | ||
|
||
export const ImmediateProposalInfo = ({ | ||
proposal, | ||
governanceCircles, | ||
proposerUserName, | ||
}: ImmediateProposalInfoProps) => { | ||
const votersString = getVotersString( | ||
proposal.global.weights, | ||
governanceCircles, | ||
); | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<div className={styles.title}> | ||
{`${proposerUserName} requests to join ${votersString} circle`} | ||
</div> | ||
{/* Show this only when the required number of voters is greater than 1. Logic for this will be added in the future, see detalis here https://github.com/daostack/common-backend/issues/1844 */} | ||
{/* <div className={styles.subtitle}> | ||
{`Approval by ${votersString} (1 from ${proposal.votes.totalMembersWithVotingRight} required)`} | ||
</div> */} | ||
</div> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
src/pages/common/components/ProposalFeedCard/components/ImmediateProposalInfo/index.ts
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 "./ImmediateProposalInfo"; |
19 changes: 19 additions & 0 deletions
19
...oposalFeedCard/components/ImmediateProposalVoteInfo/ImmediateProposalVoteInfo.module.scss
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 "../../../../../../constants"; | ||
|
||
.container { | ||
display: flex; | ||
} | ||
|
||
.voteInfo { | ||
flex-direction: column; | ||
margin-left: 0.8rem; | ||
} | ||
|
||
.title { | ||
font-size: $moderate-small-2; | ||
} | ||
|
||
.subtitle { | ||
font-size: $mobile-title; | ||
color: var(--gray-60); | ||
} |
93 changes: 93 additions & 0 deletions
93
...nents/ProposalFeedCard/components/ImmediateProposalVoteInfo/ImmediateProposalVoteInfo.tsx
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,93 @@ | ||
import React, { ReactNode, useEffect } from "react"; | ||
import { useSelector } from "react-redux"; | ||
import { selectUser } from "@/pages/Auth/store/selectors"; | ||
import { useEligibleVoters } from "@/shared/hooks/useCases"; | ||
import { VoteAbstain, VoteAgainst, VoteFor } from "@/shared/icons"; | ||
import { | ||
DateFormat, | ||
Proposal, | ||
ProposalState, | ||
Vote, | ||
VoteOutcome, | ||
} from "@/shared/models"; | ||
import { Loader } from "@/shared/ui-kit"; | ||
import { formatDate } from "@/shared/utils"; | ||
import styles from "./ImmediateProposalVoteInfo.module.scss"; | ||
|
||
interface ImmediateProposalVoteInfoProps { | ||
proposal: Proposal; | ||
userVote: Vote | null; | ||
} | ||
|
||
const VOTE_OUTCOME_TO_TEXT_MAP: Record<VoteOutcome, string> = { | ||
[VoteOutcome.Approved]: "Approved", | ||
[VoteOutcome.Abstained]: "Abstained", | ||
[VoteOutcome.Rejected]: "Rejected", | ||
}; | ||
|
||
const VOTE_OUTCOME_TO_ICON_MAP: Record<VoteOutcome, ReactNode> = { | ||
[VoteOutcome.Approved]: <VoteFor className={styles.icon} />, | ||
[VoteOutcome.Abstained]: <VoteAbstain className={styles.icon} />, | ||
[VoteOutcome.Rejected]: <VoteAgainst className={styles.icon} />, | ||
}; | ||
|
||
export const ImmediateProposalVoteInfo = ({ | ||
proposal, | ||
userVote, | ||
}: ImmediateProposalVoteInfoProps) => { | ||
const user = useSelector(selectUser()); | ||
const { loading, voters, fetchEligibleVoters, error } = useEligibleVoters(); | ||
|
||
const isExpired = | ||
proposal.state === ProposalState.FAILED && proposal.votes.total === 0; | ||
|
||
/** | ||
* For now we assume that IMMEDIATE proposal is always a single vote proposal. | ||
* In future we would want to support more than a single vote so the logic and the UI might change. | ||
* See more details here https://github.com/daostack/common-backend/issues/1844. | ||
*/ | ||
const vote = voters && voters.length > 0 ? voters[0] : undefined; | ||
|
||
useEffect(() => { | ||
if (!isExpired) { | ||
fetchEligibleVoters(proposal.id); | ||
} | ||
}, [proposal.id, isExpired]); | ||
|
||
if (error) { | ||
return ( | ||
<div> | ||
Oops! Something went wrong while loading the vote info. Please try again | ||
later. | ||
</div> | ||
); | ||
} | ||
|
||
if (!isExpired && loading) { | ||
return <Loader />; | ||
} | ||
|
||
const outcome = userVote?.outcome || vote?.vote?.outcome; | ||
const userId = userVote?.voterId || vote?.userId; | ||
const createdAt = | ||
userVote?.createdAt.seconds || vote?.vote?.createdAt.seconds; | ||
|
||
return ( | ||
<div className={styles.container}> | ||
{outcome && VOTE_OUTCOME_TO_ICON_MAP[outcome]} | ||
<div className={styles.voteInfo}> | ||
<div className={styles.title}> | ||
{isExpired && "Expired"} | ||
{outcome && | ||
`${VOTE_OUTCOME_TO_TEXT_MAP[outcome]} by ${ | ||
user?.uid === userId ? "You" : vote?.user.displayName | ||
}`} | ||
</div> | ||
<div className={styles.subtitle}> | ||
{createdAt && | ||
formatDate(new Date(createdAt * 1000), DateFormat.LongHuman)} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
src/pages/common/components/ProposalFeedCard/components/ImmediateProposalVoteInfo/index.ts
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 "./ImmediateProposalVoteInfo"; |
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
Oops, something went wrong.