feat(helpdesk): load vote summaries on ticket pages
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
parent
0fa636439a
commit
f869f4e4cc
2 changed files with 18 additions and 5 deletions
|
|
@ -7,6 +7,7 @@ import { TicketDetail } from "@/components/frontend/helpdesk/TicketDetail";
|
||||||
import { hasPermission } from "@/utils/access-control/hasPermission";
|
import { hasPermission } from "@/utils/access-control/hasPermission";
|
||||||
import { ArrowLeftIcon, LifeBuoyIcon } from "lucide-react";
|
import { ArrowLeftIcon, LifeBuoyIcon } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { getTicketVoteSummaries } from "@/lib/tickets/voteState";
|
||||||
|
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
title: "Ticket — Polaris Task Force",
|
title: "Ticket — Polaris Task Force",
|
||||||
|
|
@ -42,8 +43,11 @@ export default async function TicketPage({ params }: TicketPageProps) {
|
||||||
notFound();
|
notFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
const typedTicket = ticket as unknown as Ticket;
|
const typedTicket = ticket as unknown as Ticket;
|
||||||
const isStaff = await hasPermission(payload, user, "tickets:staff");
|
const [isStaff, voteSummaries] = await Promise.all([
|
||||||
|
hasPermission(payload, user, "tickets:staff"),
|
||||||
|
getTicketVoteSummaries(payload, user.id, [typedTicket.id]),
|
||||||
|
]);
|
||||||
const assigneeOptions = isStaff
|
const assigneeOptions = isStaff
|
||||||
? (
|
? (
|
||||||
await payload.find({
|
await payload.find({
|
||||||
|
|
@ -79,6 +83,7 @@ export default async function TicketPage({ params }: TicketPageProps) {
|
||||||
currentUserId={user.id}
|
currentUserId={user.id}
|
||||||
isStaff={isStaff}
|
isStaff={isStaff}
|
||||||
assigneeOptions={assigneeOptions}
|
assigneeOptions={assigneeOptions}
|
||||||
|
voteSummary={voteSummaries[0] ?? { ticketId: typedTicket.id, voteCount: 0, voted: false }}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import type { Ticket } from "@/payload-types";
|
||||||
import { TicketsView } from "@/components/frontend/helpdesk/TicketsView";
|
import { TicketsView } from "@/components/frontend/helpdesk/TicketsView";
|
||||||
import { hasPermission } from "@/utils/access-control/hasPermission";
|
import { hasPermission } from "@/utils/access-control/hasPermission";
|
||||||
import { LifeBuoyIcon } from "lucide-react";
|
import { LifeBuoyIcon } from "lucide-react";
|
||||||
|
import { getTicketVoteSummaries } from "@/lib/tickets/voteState";
|
||||||
|
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
title: "Helpdesk — Polaris Task Force",
|
title: "Helpdesk — Polaris Task Force",
|
||||||
|
|
@ -30,8 +31,15 @@ export default async function HelpdeskPage() {
|
||||||
limit: 200,
|
limit: 200,
|
||||||
depth: 2,
|
depth: 2,
|
||||||
});
|
});
|
||||||
const tickets = ticketsRes.docs as unknown as Ticket[];
|
const tickets = ticketsRes.docs as unknown as Ticket[];
|
||||||
const isStaff = await hasPermission(payload, user, "tickets:staff");
|
const [isStaff, voteSummaries] = await Promise.all([
|
||||||
|
hasPermission(payload, user, "tickets:staff"),
|
||||||
|
getTicketVoteSummaries(
|
||||||
|
payload,
|
||||||
|
user.id,
|
||||||
|
tickets.map((ticket) => ticket.id),
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-6 p-5">
|
<div className="flex flex-col gap-6 p-5">
|
||||||
|
|
@ -43,7 +51,7 @@ export default async function HelpdeskPage() {
|
||||||
<p className="text-sm text-muted-foreground">Submit and track support requests.</p>
|
<p className="text-sm text-muted-foreground">Submit and track support requests.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<TicketsView tickets={tickets} currentUserId={user.id} isStaff={isStaff} />
|
<TicketsView tickets={tickets} voteSummaries={voteSummaries} isStaff={isStaff} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue