💄 filter by approval state

This commit is contained in:
Fred KISSIE
2026-01-14 02:24:11 +01:00
parent 4c78e93143
commit d5b6a426a9
4 changed files with 61 additions and 19 deletions

View File

@@ -36,15 +36,11 @@ export function ApprovalFeed({ orgId }: ApprovalFeedProps) {
);
const { data, isFetching, refetch } = useQuery(
approvalQueries.listApprovals(orgId)
approvalQueries.listApprovals(orgId, filters)
);
const approvals = data?.approvals ?? [];
console.log({
approvals
});
return (
<div className="flex flex-col gap-5">
<Card className="">
@@ -75,11 +71,16 @@ export function ApprovalFeed({ orgId }: ApprovalFeedProps) {
/>
</SelectTrigger>
<SelectContent className="w-full">
<SelectItem value="pending">Pending</SelectItem>
<SelectItem value="approved">
Approved
<SelectItem value="pending">
{t("pending")}
</SelectItem>
<SelectItem value="all">All</SelectItem>
<SelectItem value="approved">
{t("approved")}
</SelectItem>
<SelectItem value="denied">
{t("denied")}
</SelectItem>
<SelectItem value="all">{t("all")}</SelectItem>
</SelectContent>
</Select>
</div>

View File

@@ -321,13 +321,22 @@ export const approvalFiltersSchema = z.object({
});
export const approvalQueries = {
listApprovals: (orgId: string) =>
listApprovals: (
orgId: string,
filters: z.infer<typeof approvalFiltersSchema>
) =>
queryOptions({
queryKey: ["APPROVALS", orgId] as const,
queryKey: ["APPROVALS", orgId, filters] as const,
queryFn: async ({ signal, meta }) => {
const sp = new URLSearchParams();
if (filters.approvalState) {
sp.set("approvalState", filters.approvalState);
}
const res = await meta!.api.get<
AxiosResponse<ListApprovalsResponse>
>(`/org/${orgId}/approvals`, {
>(`/org/${orgId}/approvals?${sp.toString()}`, {
signal
});
return res.data.data;