Skip to content

Commit 4c4f2e7

Browse files
committed
Add status on proposals
1 parent 0fa562e commit 4c4f2e7

File tree

7 files changed

+56
-16
lines changed

7 files changed

+56
-16
lines changed

backend/api/src/create-vote.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const createVote: APIHandler<
1818
title,
1919
description,
2020
is_anonymous: isAnonymous,
21+
status: 'voting_open',
2122
})
2223
)
2324

backend/supabase/vote_results.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ create or replace function get_votes_with_results(order_by text default 'recent'
4444
created_time timestamptz,
4545
creator_id TEXT,
4646
is_anonymous boolean,
47+
status text,
4748
votes_for int,
4849
votes_against int,
4950
votes_abstain int,
@@ -58,6 +59,7 @@ with results as (
5859
v.created_time,
5960
v.creator_id,
6061
v.is_anonymous,
62+
v.status,
6163
COALESCE(SUM(CASE WHEN r.choice = 1 THEN 1 ELSE 0 END), 0) AS votes_for,
6264
COALESCE(SUM(CASE WHEN r.choice = -1 THEN 1 ELSE 0 END), 0) AS votes_against,
6365
COALESCE(SUM(CASE WHEN r.choice = 0 THEN 1 ELSE 0 END), 0) AS votes_abstain,
@@ -73,6 +75,7 @@ SELECT
7375
created_time,
7476
creator_id,
7577
is_anonymous,
78+
status,
7679
votes_for,
7780
votes_against,
7881
votes_abstain,

backend/supabase/votes.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ CREATE TABLE IF NOT EXISTS votes (
44
creator_id TEXT NOT NULL,
55
title TEXT NOT NULL,
66
is_anonymous BOOLEAN NOT NULL,
7-
description JSONB
7+
description JSONB,
8+
status TEXT
89
);
910

1011
-- Foreign Keys

common/src/supabase/schema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,7 @@ export type Database = {
945945
description: Json | null
946946
id: number
947947
is_anonymous: boolean | null
948+
status: string | null
948949
title: string
949950
}
950951
Insert: {
@@ -953,6 +954,7 @@ export type Database = {
953954
description?: Json | null
954955
id?: never
955956
is_anonymous?: boolean | null
957+
status?: string | null
956958
title: string
957959
}
958960
Update: {
@@ -961,6 +963,7 @@ export type Database = {
961963
description?: Json | null
962964
id?: never
963965
is_anonymous?: boolean | null
966+
status?: string | null
964967
title?: string
965968
}
966969
Relationships: [
@@ -1009,6 +1012,7 @@ export type Database = {
10091012
id: number
10101013
is_anonymous: boolean
10111014
priority: number
1015+
status: string
10121016
title: string
10131017
votes_abstain: number
10141018
votes_against: number

common/src/votes/constants.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
export const ORDER_BY = ['recent', 'mostVoted', 'priority'] as const
22
export type OrderBy = typeof ORDER_BY[number]
3-
export const Constants: Record<OrderBy, string> = {
3+
export const ORDER_BY_CHOICES: Record<OrderBy, string> = {
44
recent: 'Most recent',
55
mostVoted: 'Most voted',
66
priority: 'Highest Priority',
7-
}
7+
}
8+
9+
export const STATUS_CHOICES: Record<string, string> = {
10+
draft: "Draft",
11+
under_review: "Under Review",
12+
voting_open: "Voting Open",
13+
voting_closed: "Voting Closed",
14+
accepted: "Accepted",
15+
pending: "Pending Implementation",
16+
implemented: "Implemented ✔️",
17+
rejected: "Rejected ❌",
18+
cancelled: "Cancelled 🚫",
19+
superseded: "Superseded",
20+
expired: "Expired ⌛",
21+
archived: "Archived",
22+
}
23+
24+
export const REVERSED_STATUS_CHOICES: Record<string, string> = Object.fromEntries(
25+
Object.entries(STATUS_CHOICES).map(([key, value]) => [value, key])
26+
)

web/components/votes/vote-buttons.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ export function VoteButtons(props: {
4242
counts: { for: number; abstain: number; against: number }
4343
onVoted?: () => void | Promise<void>
4444
className?: string
45+
disabled?: boolean
4546
}) {
47+
const {voteId, counts, onVoted, className, disabled: disabledProp} = props
4648
const user = useUser()
47-
const {voteId, counts, onVoted, className} = props
4849
const [loading, setLoading] = useState<VoteChoice | null>(null)
4950
const [showPriority, setShowPriority] = useState(false)
5051
const containerRef = useRef<HTMLDivElement>(null)
51-
const disabled = loading !== null
52+
const disabled = disabledProp || loading !== null
5253

5354
// Close the dropdown when clicking outside or pressing Escape
5455
useEffect(() => {

web/components/votes/vote-item.tsx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import {VoteButtons} from 'web/components/votes/vote-buttons'
77
import {getVoteCreator} from "web/lib/supabase/votes";
88
import {useEffect, useState} from "react";
99
import Link from "next/link";
10+
import {STATUS_CHOICES} from "common/votes/constants";
1011

1112
export type Vote = rowFor<'votes'> & {
1213
votes_for: number
1314
votes_against: number
1415
votes_abstain: number
1516
priority: number
17+
status?: string
1618
}
1719

1820
export function VoteItem(props: {
@@ -24,7 +26,7 @@ export function VoteItem(props: {
2426
useEffect(() => {
2527
getVoteCreator(vote.creator_id).then(setCreator)
2628
}, [vote.creator_id])
27-
// console.debug('creator', creator)
29+
// console.debug('creator', creator, vote)
2830
return (
2931
<Col className={'mb-4 rounded-lg border border-canvas-200 p-4'}>
3032
<Row className={'mb-2'}>
@@ -35,19 +37,28 @@ export function VoteItem(props: {
3537
</Col>
3638
<Row className={'gap-2 mt-2 items-center justify-between w-full custom-link flex-wrap'}>
3739
{!!vote.priority ? <div>Priority: {vote.priority.toFixed(0)}%</div> : <p></p>}
38-
{!vote.is_anonymous && creator?.username && <Link href={`/${creator.username}`} className="custom-link">{creator.username}</Link>}
40+
{!vote.is_anonymous && creator?.username &&
41+
<Link href={`/${creator.username}`} className="custom-link">{creator.username}</Link>}
3942
</Row>
40-
<VoteButtons
41-
voteId={vote.id}
42-
counts={{
43-
for: vote.votes_for,
44-
abstain: vote.votes_abstain,
45-
against: vote.votes_against,
46-
}}
47-
onVoted={onVoted}
48-
/>
4943
</Col>
5044
</Row>
45+
<Row className="flex-wrap gap-2 items-center justify-between">
46+
<VoteButtons
47+
voteId={vote.id}
48+
counts={{
49+
for: vote.votes_for,
50+
abstain: vote.votes_abstain,
51+
against: vote.votes_against,
52+
}}
53+
onVoted={onVoted}
54+
disabled={vote.status !== 'voting_open'}
55+
/>
56+
{vote.status && (
57+
<p className="text-ink-500">
58+
{STATUS_CHOICES[vote.status]}
59+
</p>
60+
)}
61+
</Row>
5162
</Col>
5263
)
5364
}

0 commit comments

Comments
 (0)