Skip to content

Commit

Permalink
Merge pull request #486 from sparcs-kaist/feat/terminated-agenda-startAt
Browse files Browse the repository at this point in the history
feat: add start time on terminated agenda cards
  • Loading branch information
rjsdn0 authored May 1, 2024
2 parents d2a4cb7 + d2235bf commit 70ed9d3
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 20 deletions.
6 changes: 6 additions & 0 deletions packages/api/src/service/admin.agenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const selectAgendaDefaultFields = {
title: true,
resolution: true,
content: true,
startAt: true,
},
};

Expand Down Expand Up @@ -94,6 +95,7 @@ export const createAgenda = async ({
voted: [],
total: createdVoters.map(voter => voter.user),
},
startAt: "", // startAt is not displayed yet
};

return {
Expand Down Expand Up @@ -148,6 +150,7 @@ export const terminateAgenda = async (agendaId: number, user: User) => {
const {
voters: updatedVoters,
choices: updatedChoices,
startAt: agendaStartAt,
...updatedAgenda
} = await prisma.agenda.update({
data: {
Expand Down Expand Up @@ -203,6 +206,7 @@ export const terminateAgenda = async (agendaId: number, user: User) => {
voted: userVoted,
votable: userVotable,
},
startAt: agendaStartAt?.toISOString() || "", // startAt is not null with terminatedAgenda
};

return terminatedAgenda;
Expand Down Expand Up @@ -302,6 +306,7 @@ export const updateAgenda = async (agendaUpdate: schema.AdminAgendaUpdate) => {
voted: [],
total: voters.map(voter => voter.user),
},
startAt: "",
};
return {
voters: voters.map(voter => `user/${voter.user.username}`),
Expand Down Expand Up @@ -384,6 +389,7 @@ export const retrieveAll = async (): Promise<schema.AdminAgenda[]> => {
total: agenda.voters.map(user => user.user),
voted,
},
startAt: agenda.startAt?.toISOString() || "",
};
});

Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/service/agenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const retrieveAll = async (
),
total: agenda.voters.length,
},
startAt: agenda.startAt,
};

if (!agenda.startAt) {
Expand Down Expand Up @@ -83,6 +84,7 @@ export const retrieveAll = async (
name: choice.name,
count: choice.users.length,
})),
startAt: agenda.startAt.toISOString(),
};
});
if (!res) throw new BiseoError("failed to retrieve agenda");
Expand Down
1 change: 1 addition & 0 deletions packages/interface/src/admin/agenda/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const AdminAgenda = AgendaBase.omit({
}),
status: AdminAgendaStatus,
choices: z.array(ChoiceWithResult),
startAt: z.string(), // currently used only on terminated admin agendas
});
export type AdminAgenda = z.infer<typeof AdminAgenda>;

Expand Down
1 change: 1 addition & 0 deletions packages/interface/src/agenda/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const TerminatedAgenda = AgendaBase.extend({
voted: z.number().nullable(), // choiceId | null
}),
choices: z.array(ChoiceWithResult),
startAt: z.string(),
});
export type TerminatedAgenda = z.infer<typeof TerminatedAgenda>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import type { AdminAgenda } from "@biseo/interface/admin/agenda";
import { Card } from "@biseo/web/components/atoms";
import { AgendaTag } from "@biseo/web/components/molecules/AgendaTag";

import { column, gap, text } from "@biseo/web/styles";
import { align, column, gap, justify, row, text, w } from "@biseo/web/styles";
import { formatDateSimple } from "@biseo/web/utils/format";

const agendaTags = {
public: true,
Expand All @@ -24,14 +25,19 @@ export const AdminTerminatedAgendaCard: React.FC<Props> = ({ agenda }) => {

return (
<Card clickable onClick={openModal}>
<div css={[column, gap(8)]}>
<AgendaTag
tags={{
public: agendaTags.public,
identified: agendaTags.identified,
votable: agendaTags.votable,
}}
/>
<div css={[column, gap(8), w("fill")]}>
<div css={[row, justify.between, align.center]}>
<AgendaTag
tags={{
public: agendaTags.public,
identified: agendaTags.identified,
votable: agendaTags.votable,
}}
/>
<p css={[text.subtitle, text.gray400]}>
{formatDateSimple(agenda.startAt)}
</p>
</div>
<div css={[column, gap(2)]}>
<h1 css={[text.title2, text.black]}>{agenda.title}</h1>
<p css={[text.subtitle, text.gray500]}>{agenda.content}</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { OptionVoteResult } from "@biseo/web/components/molecules/OptionVoteResu
import { VoteResult } from "@biseo/web/components/molecules/VoteResult";
import { VoteDetail } from "@biseo/web/components/molecules/VoteDetail";
import { VoteParticipate } from "@biseo/web/components/molecules/VoteParticipate";

import { column, gap, text, w } from "@biseo/web/styles";
import { align, column, gap, justify, row, text, w } from "@biseo/web/styles";
import { formatDateSimple } from "@biseo/web/utils/format";

const agendaTags = {
public: true,
Expand Down Expand Up @@ -43,7 +43,12 @@ export const TerminatedAgendaCard: React.FC<Props> = ({ agenda }) => {
{enabled ? (
<div css={[column, gap(15), w("fill")]}>
<div css={[column, gap(2)]}>
<h1 css={[text.title2, text.black]}>{agenda.title}</h1>
<div css={[row, justify.between, align.center]}>
<h1 css={[text.title2, text.black]}>{agenda.title}</h1>
<p css={[text.subtitle, text.gray400]}>
{formatDateSimple(agenda.startAt)}
</p>
</div>
<p css={[text.subtitle, text.gray500]}>{agenda.content}</p>
</div>
<div>
Expand Down Expand Up @@ -74,14 +79,20 @@ export const TerminatedAgendaCard: React.FC<Props> = ({ agenda }) => {
<VoteDetail type={agendaTags.identified} />
</div>
) : (
<div css={[column, gap(8)]}>
<AgendaTag
tags={{
public: agendaTags.public,
identified: agendaTags.identified,
votable: agenda.user.votable,
}}
/>
<div css={[column, gap(8), w("fill")]}>
<div css={[row, justify.between, align.center]}>
<AgendaTag
tags={{
public: agendaTags.public,
identified: agendaTags.identified,
votable: agenda.user.votable,
}}
/>
<p css={[text.subtitle, text.gray400]}>
{formatDateSimple(agenda.startAt)}
</p>
</div>

<div css={[column, gap(2)]}>
<h1 css={[text.title2, text.black]}>{agenda.title}</h1>
<p css={[text.subtitle, text.gray500]}>{agenda.content}</p>
Expand Down
10 changes: 10 additions & 0 deletions packages/web/src/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ export const formatDate = (isoString: string) => {

return `${year}${month}${date}일 (${day})`;
};

export const formatDateSimple = (isoString: string) => {
const time = new Date(isoString);

const year = time.getFullYear();
const month = time.getMonth() + 1;
const date = time.getDate();

return `${year}-${month}-${date}`;
};

0 comments on commit 70ed9d3

Please sign in to comment.