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: show end time on terminated agenda card #493

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 9 additions & 5 deletions packages/api/src/listener/admin.agenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,26 @@ router.on(

const startNotice = await createNotice(ongoingAgenda, user);
io.emit("chat.received", startNotice);
break;

io.to("admin").emit("admin.agenda.statusUpdated", req);
return {};
}
case "terminated": {
const terminatedAgenda = await terminateAgenda(req.id, user);
io.emit("agenda.terminated", terminatedAgenda);

const terminateNotice = await createNotice(terminatedAgenda, user);
io.emit("chat.received", terminateNotice);
break;

io.to("admin").emit("admin.agenda.statusUpdated", {
...req,
endAt: terminatedAgenda.endAt,
});
return {};
}
default:
return {};
}

io.to("admin").emit("admin.agenda.statusUpdated", req);
return {};
},
);

Expand Down
1 change: 1 addition & 0 deletions packages/interface/src/admin/agenda/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type RetrieveAllCb = z.infer<typeof RetrieveAllCb>;
export const StatusUpdate = z.object({
id: z.number(),
status: AgendaStatus,
endAt: z.string().optional(),
});
export type StatusUpdate = z.infer<typeof StatusUpdate>;
export const StatusUpdateCb = z.object({});
Expand Down
1 change: 1 addition & 0 deletions packages/interface/src/admin/agenda/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type Created = z.infer<typeof Created>;
export const StatusUpdated = z.object({
id: z.number(),
status: AgendaStatus,
endAt: z.string().optional(),
});
export type StatusUpdated = z.infer<typeof StatusUpdated>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,21 @@ 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 { align, column, gap, justify, row, text, w } from "@biseo/web/styles";
import { formatDateSimple } from "@biseo/web/utils/format";
import {
align,
center,
column,
gap,
justify,
row,
text,
w,
} from "@biseo/web/styles";
import {
formatDate,
formatDateSimple,
formatTime,
} from "@biseo/web/utils/format";

const agendaTags = {
public: true,
Expand Down Expand Up @@ -43,18 +56,20 @@ export const TerminatedAgendaCard: React.FC<Props> = ({ agenda }) => {
{enabled ? (
<div css={[column, gap(15), w("fill")]}>
<div css={[column, gap(2)]}>
<div css={[row, justify.between, align.center]}>
<h1 css={[text.title2, text.black]}>{agenda.title}</h1>
<p css={[text.subtitle, text.gray400]}>
{formatDateSimple(agenda.endAt)}
</p>
</div>
<h1 css={[text.title2, text.black]}>{agenda.title}</h1>
<p css={[text.subtitle, text.gray500]}>{agenda.content}</p>
</div>
<div>
<p css={[text.body, text.blue600]}>{agenda.resolution}</p>
</div>
<Divider />
<div css={[row, center, justify.between, text.subtitle, text.black]}>
<span>투표 일시</span>
<span css={[row, gap(4)]}>
<span>{formatDate(agenda.endAt)}</span>
<span>{formatTime(agenda.endAt)}</span>
</span>
</div>
<VoteParticipate
voted={agenda.voters.voted}
total={agenda.voters.total}
Expand Down
9 changes: 5 additions & 4 deletions packages/web/src/services/admin-agenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface AdminAgendaState {
adminAgendas: AdminAgenda[];
createAgenda: (agenda: AdminAgendaCreate) => void;
retrieveAll: () => void;
statusUpdate: (id: number, status: AgendaStatus) => void;
statusUpdate: (id: number, status: AgendaStatus, endAt?: string) => void;
updateAgenda: (agenda: AdminAgendaUpdate) => void;
deleteAgenda: (id: number) => void;
remindAgenda: (id: number) => void;
Expand Down Expand Up @@ -39,11 +39,12 @@ export const useAdminAgenda = create<AdminAgendaState>(set => ({
// TODO: handle error
}
},
statusUpdate: async (id, status) => {
statusUpdate: async (id, status, endAt) => {
try {
await socket.emitAsync("admin.agenda.statusUpdate", {
id,
status,
endAt,
});
} catch {
// TODO: handle error
Expand Down Expand Up @@ -81,11 +82,11 @@ socket.on("admin.agenda.created", adminAgenda => {
}));
});

socket.on("admin.agenda.statusUpdated", ({ id, status }) => {
socket.on("admin.agenda.statusUpdated", ({ id, status, endAt }) => {
useAdminAgenda.setState(state => {
const newAdminAgendas: AdminAgenda[] = state.adminAgendas.map(agenda => {
if (agenda.id === id) {
return { ...agenda, status };
return { ...agenda, status, endAt: endAt || "" };
}
return agenda;
});
Expand Down
Loading