Skip to content

Commit

Permalink
feat: get endAt on termination to update admin state
Browse files Browse the repository at this point in the history
  • Loading branch information
yumincho committed May 18, 2024
1 parent 0a63f7d commit 487632f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
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
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

0 comments on commit 487632f

Please sign in to comment.