Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/Identified vote final #480

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5ab3463
fix: wrong environt variable in schema db
rjsdn0 Feb 1, 2024
cf09b49
feat: identified vote schema
rjsdn0 Feb 1, 2024
412a83f
feat: prisma migration
rjsdn0 Feb 3, 2024
7edce79
feat: merge identified vote back
rjsdn0 Feb 8, 2024
d93af0a
refactor: updated votedetail
rjsdn0 Feb 14, 2024
18b8f69
feat: connected identified vote front with back
rjsdn0 Feb 15, 2024
8cdf3ea
feat: connect agenda tags with back
rjsdn0 Feb 15, 2024
b776556
feat: add toggle buttons to change vote types
rjsdn0 Mar 3, 2024
56aec1a
feat: updated adminagendatags
rjsdn0 Mar 4, 2024
d9a3b46
fix: identified vote logic and ui
rjsdn0 Mar 22, 2024
51b8888
Merge branch 'main' of https://github.com/sparcs-kaist/biseo
rjsdn0 Mar 22, 2024
4edd70d
fix: fix conflict
rjsdn0 Mar 22, 2024
1a25bb3
feat: automatically reveal choice when identified vote
rjsdn0 Mar 22, 2024
6ba99fb
feat: private vote UI
rjsdn0 Mar 22, 2024
f76c9b3
feat: distinguish clicking and dragging on terminated agenda card
rjsdn0 Mar 22, 2024
f3c3ae9
fix: adminagendatagsselect error
rjsdn0 Mar 22, 2024
9e1280e
fix: optionvoteresult error
rjsdn0 Mar 22, 2024
6eac878
Merge branch 'main' of https://github.com/sparcs-kaist/biseo into test
rjsdn0 Mar 27, 2024
73c4905
fix: prreview
rjsdn0 Mar 27, 2024
f45e0bc
Merge branch 'main' into identified-vote-final
rjsdn0 Mar 29, 2024
60398f1
Merge branch 'main' of github.com:sparcs-kaist/biseo into test
rjsdn0 Mar 29, 2024
d8ede40
fix: prreview2-design
rjsdn0 Apr 24, 2024
7e206ea
fix: prreview3-toggle button design
rjsdn0 Apr 29, 2024
ecb67df
Merge branch 'identified-vote-final' of github.com:sparcs-kaist/biseo…
rjsdn0 Apr 29, 2024
8901431
fix: drag bug
rjsdn0 May 8, 2024
fe9fa41
fix: resolve conflict
rjsdn0 May 8, 2024
213b40c
fix: resolve conflict
rjsdn0 May 23, 2024
a21e32b
fix: text color
rjsdn0 Sep 24, 2024
6498012
fix: test for typecheck
rjsdn0 Sep 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE `agenda` ADD COLUMN `isNamed` BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN `isPublic` BOOLEAN NOT NULL DEFAULT true;
12 changes: 10 additions & 2 deletions packages/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ generator client {

datasource db {
provider = "mysql"
url = env("DB_URL")
url = env("DATABASE_URL")
rjsdn0 marked this conversation as resolved.
Show resolved Hide resolved
}

model Agenda {
id Int @id @default(autoincrement())
title String
resolution String
content String
// type AgendaType
isNamed Boolean @default(false)
isPublic Boolean @default(true)
startAt DateTime? @map("start_at")
endAt DateTime? @map("end_at")
createdAt DateTime @default(now()) @map("created_at")
Expand All @@ -24,6 +27,11 @@ model Agenda {
@@map("agenda")
}

// type AgendaType {
yumincho marked this conversation as resolved.
Show resolved Hide resolved
// named Boolean @default(false)
// private Boolean @default(false)
// }

model User {
id Int @id @default(autoincrement())
username String @unique
Expand Down Expand Up @@ -122,4 +130,4 @@ enum ChatType {
notice

@@map("chat_type")
}
}
40 changes: 40 additions & 0 deletions packages/api/src/service/admin.agenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,27 @@ const selectAgendaDefaultFields = {
},
};

const selectAgendaTypeFields = {
select: {
isNamed: true,
isPublic: true,
},
};

export const createAgenda = async ({
title,
resolution,
content,
type,
choices,
voters,
}: schema.AdminAgendaCreate) => {
const createAgendaQuery: Prisma.AgendaCreateInput = {
title,
resolution,
content,
isNamed: type.named,
isPublic: type.public,
choices: {
create: choices.map(name => ({ name })),
},
Expand All @@ -58,13 +68,18 @@ export const createAgenda = async ({
data: createAgendaQuery,
select: {
...selectAgendaDefaultFields.select,
...selectAgendaTypeFields.select,
choices: true,
voters: selectOnlyUser,
},
});

const agendaVotable: PreparingAgenda = {
...createdAgenda,
type: {
named: createdAgenda.isNamed,
public: createdAgenda.isPublic,
},
status: "preparing",
choices: createdChoices,
voters: {
Expand Down Expand Up @@ -117,6 +132,7 @@ export const startAgenda = async (agendaId: number, user: User) => {
},
select: {
...selectAgendaDefaultFields.select,
...selectAgendaTypeFields.select,
choices: {
include: {
users: true,
Expand All @@ -131,6 +147,10 @@ export const startAgenda = async (agendaId: number, user: User) => {
const ongoingAgenda: OngoingAgenda = {
...updatedAgenda,
status: "ongoing",
type: {
named: updatedAgenda.isNamed,
public: updatedAgenda.isPublic,
},
voters: {
voted: 0,
total: updatedVoters.length,
Expand Down Expand Up @@ -163,6 +183,7 @@ export const terminateAgenda = async (agendaId: number, user: User) => {
},
select: {
...selectAgendaDefaultFields.select,
...selectAgendaTypeFields.select,
choices: {
include: {
users: true,
Expand Down Expand Up @@ -192,6 +213,10 @@ export const terminateAgenda = async (agendaId: number, user: User) => {
// eslint-disable-next-line no-underscore-dangle
count: choice._count.users,
})),
type: {
named: updatedAgenda.isNamed,
public: updatedAgenda.isPublic,
},
voters: {
voted: updatedChoices.reduce(
(acc, choice) => acc + choice.users.length,
Expand Down Expand Up @@ -254,6 +279,7 @@ export const updateAgenda = async (agendaUpdate: schema.AdminAgendaUpdate) => {
},
select: {
...selectAgendaDefaultFields.select,
...selectAgendaTypeFields.select,
choices: true,
voters: selectOnlyUser,
},
Expand All @@ -274,6 +300,10 @@ export const updateAgenda = async (agendaUpdate: schema.AdminAgendaUpdate) => {
id: choice.id,
name: choice.name,
})),
type: {
named: updatedAgenda.isNamed,
public: updatedAgenda.isPublic,
},
voters: {
voted: 0,
total: voters.length,
Expand All @@ -298,6 +328,10 @@ export const updateAgenda = async (agendaUpdate: schema.AdminAgendaUpdate) => {
name: choice.name,
count: 0,
})),
type: {
named: updatedAgenda.isNamed,
public: updatedAgenda.isPublic,
},
voters: {
voted: [],
total: voters.map(voter => voter.user),
Expand Down Expand Up @@ -344,6 +378,7 @@ export const retrieveAll = async (): Promise<schema.AdminAgenda[]> => {
where: { deletedAt: null },
select: {
...selectAgendaDefaultFields.select,
...selectAgendaTypeFields.select,
startAt: true,
endAt: true,
deletedAt: true,
Expand Down Expand Up @@ -372,6 +407,11 @@ export const retrieveAll = async (): Promise<schema.AdminAgenda[]> => {
content: agenda.content,
resolution: agenda.resolution,
status,
// TODO: remove workaround
type: {
named: agenda.isNamed,
public: agenda.isPublic,
},
choices: agenda.choices.map(choice => ({
id: choice.id,
name: choice.name,
Expand Down
32 changes: 27 additions & 5 deletions packages/api/src/service/agenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ export const retrieveAll = async (
select: {
id: true,
name: true,
users: true,
users: {
select: {
userId: true,
choiceId: true,
user: {
select: {
displayName: true,
},
},
},
},
},
},
},
Expand All @@ -32,11 +42,23 @@ export const retrieveAll = async (
title: agenda.title,
content: agenda.content,
resolution: agenda.resolution,
type: { named: agenda.isNamed, public: agenda.isPublic },
voters: {
voted: agenda.choices.reduce(
(acc, choice) => acc + choice.users.length,
0,
),
voted: agenda.isNamed
? agenda.choices.reduce(
(acc, choice) => [
...acc,
...choice.users.map(u => ({
displayName: u.user.displayName,
choiceId: u.choiceId,
})),
],
[] as { displayName: string; choiceId: number }[],
)
: agenda.choices.reduce(
(acc, choice) => acc + choice.users.length,
0,
),
total: agenda.voters.length,
},
};
Expand Down
13 changes: 7 additions & 6 deletions packages/interface/src/admin/agenda/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,19 @@ import { User } from "@/user";
* AdminAgendaStatus
* some description about admin agenda status type goes here
*/
export const AdminAgendaStatus = z.enum([...AgendaStatus.options, "preparing"]);
export const AdminAgendaStatus = z.enum([...AgendaStatus.options]);
rjsdn0 marked this conversation as resolved.
Show resolved Hide resolved
export type AdminAgendaStatus = z.infer<typeof AdminAgendaStatus>;

/**
* AdminAgenda
* some description about admin agenda schema goes here
*/
export const AdminAgenda = AgendaBase.omit({
voters: true,
status: true,
}).extend({
export const AdminAgenda = AgendaBase.extend({
status: AdminAgendaStatus,
voters: z.object({
voted: z.array(User),
total: z.array(User),
}),
status: AdminAgendaStatus,
choices: z.array(ChoiceWithResult),
});
export type AdminAgenda = z.infer<typeof AdminAgenda>;
Expand All @@ -35,6 +32,10 @@ export const AdminAgendaCreate = z.object({
title: z.string().min(1).max(255),
content: z.string().min(1).max(255),
resolution: z.string().min(1).max(255),
type: z.object({
named: z.boolean(),
public: z.boolean(),
}),
choices: z.array(z.string().min(1).max(255)).min(1),
voters: z.object({
total: z.array(z.number()),
Expand Down
15 changes: 14 additions & 1 deletion packages/interface/src/agenda/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,22 @@ export const AgendaBase = z.object({
title: z.string(),
content: z.string(),
resolution: z.string(),
type: z.object({
named: z.boolean(),
public: z.boolean(),
}),
status: z.never(), // Must be overridden
voters: z.object({
voted: z.number(),
voted: z.union([
z.number(),
z.array(
z.object({
// userId: z.number(),
displayName: z.string(),
choiceId: z.number(),
}),
),
]),
total: z.number(),
}),
});
Expand Down
53 changes: 53 additions & 0 deletions packages/web/src/components/atoms/Toggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import styled from "@emotion/styled";
import { css } from "@emotion/react";

type Size = number | "hug" | "fill";

const calcSize = (size: Size) => {
if (size === "fill") return "fill";
if (size === "hug") return "fit-content";
return `${size}px`;
};

export const ToggleContainor = styled.div<{
w?: Size;
h?: Size;
}>(
({ w = "fill", h = 20 }) => css`
display: flex;
width: ${calcSize(w)};
height: ${calcSize(h)};
border-radius: 5px;
border: none;
justify-content: center;
align-items: center;
overflow: hidden;
`,
);

export const ToggleButton = styled.div<{
selected: boolean;
isLeft: boolean;
}>(
({ selected, isLeft = true, theme }) => css`
display: flex;
width: fill;
height: 100%;
padding: 0px;
border-style: solid;
border-width: 1px;
rjsdn0 marked this conversation as resolved.
Show resolved Hide resolved
border-radius: ${isLeft ? "5px 0px 0px 5px" : "0px 5px 5px 0px"};
border-color: ${selected ? theme.colors.blue300 : theme.colors.gray400};
rjsdn0 marked this conversation as resolved.
Show resolved Hide resolved
justify-content: center;
align-items: center;
line-height: 28px;
padding: 4px 5px 4px 5px;
background-color: ${selected ? theme.colors.blue200 : theme.colors.white};
transition-duration: 0.25s;
transition-property: background-color;

&:hover {
background-color: ${theme.colors.blue200};
yumincho marked this conversation as resolved.
Show resolved Hide resolved
}
`,
);
1 change: 1 addition & 0 deletions packages/web/src/components/atoms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export * from "./TaggersBox";
export * from "./HyperText";
export * from "./PresetOption";
export * from "./TagSelect";
export * from "./Toggle";
Loading
Loading