-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathPreview.js
More file actions
57 lines (54 loc) · 1.69 KB
/
Preview.js
File metadata and controls
57 lines (54 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { StyledStatusPill } from 'components';
import { CommunityName } from 'components/ProposalInformation';
import { FilterValues } from 'const';
import { parseDateToServer } from 'utils';
import { SingleChoiceVote } from '../Proposal';
const Preview = ({ stepsData }) => {
const [
{ name, communityId, body },
{ choices } = { choices: [] },
{ endDate, endTime, startDate, startTime } = {},
] = Object.values(stepsData);
// use a date here to allow VoteOptions to show the correct message
const date = new Date();
const proposal = {
endTime:
endDate && endTime
? parseDateToServer(endDate, endTime)
: new Date().setDate(date.getDate() + 2),
startTime:
startDate && startTime
? parseDateToServer(startDate, startTime)
: new Date().setDate(date.getDate() + 1),
winCount: 0,
choices:
choices.length >= 2 && choices.every((el) => el.value !== '')
? choices
.sort((a, b) => (a.value > b.value ? 1 : -1))
.map((choice) => ({
...choice,
label: choice.value,
}))
: null,
};
console.log(proposal.choices);
return (
<div>
<h1 className="title mt-5 is-3">{name}</h1>
<div className="is-flex is-align-items-center">
<CommunityName communityId={communityId} classNames="mr-3" />
<StyledStatusPill status={FilterValues.draft} />
</div>
<div
className="mt-6 mb-5 proposal-copy content"
dangerouslySetInnerHTML={{
__html: body,
}}
/>
{Boolean(proposal.choices) && (
<SingleChoiceVote proposal={proposal} readOnly />
)}
</div>
);
};
export default Preview;