Skip to content
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
819 changes: 414 additions & 405 deletions apps/app/src/actions/organization/lib/utils.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,36 @@
* Evidence status types and constants
*/

import { EvidenceStatus } from "@bubba/db/types";

// Status priority and type definitions
export const STATUS_PRIORITY = [
"upToDate",
export const EVIDENCE_STATUS_PRIORITY: EvidenceStatus[] = [
"draft",
"needsReview",
"empty",
"not_relevant",
"published",
] as const;
export type StatusType = (typeof STATUS_PRIORITY)[number];
export type EvidenceStatusType = (typeof EVIDENCE_STATUS_PRIORITY)[number];

// Status color mapping for UI components
export const STATUS_COLORS = {
upToDate: "bg-primary",
export const EVIDENCE_STATUS_COLORS = {
draft: "bg-[var(--chart-open)]",
needsReview: "bg-[hsl(var(--destructive))]",
empty: "bg-[var(--chart-pending)]",
not_relevant: "bg-[hsl(var(--destructive))]",
published: "bg-[hsl(var(--destructive))]",
} as const;
Comment on lines +16 to 20

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Color inconsistency for "published" status.

There appears to be a inconsistency in the color scheme. The "published" status uses a destructive (likely red) color class, but this seems inappropriate for what appears to be a positive status. In the hex color definitions below, "published" correctly uses a green color.

export const EVIDENCE_STATUS_COLORS = {
  draft: "bg-[var(--chart-open)]",
  not_relevant: "bg-[hsl(var(--destructive))]",
-  published: "bg-[hsl(var(--destructive))]",
+  published: "bg-[hsl(var(--success))]",
} as const;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const EVIDENCE_STATUS_COLORS = {
draft: "bg-[var(--chart-open)]",
needsReview: "bg-[hsl(var(--destructive))]",
empty: "bg-[var(--chart-pending)]",
not_relevant: "bg-[hsl(var(--destructive))]",
published: "bg-[hsl(var(--destructive))]",
} as const;
export const EVIDENCE_STATUS_COLORS = {
draft: "bg-[var(--chart-open)]",
not_relevant: "bg-[hsl(var(--destructive))]",
published: "bg-[hsl(var(--success))]",
} as const;


// Status color hex values for charts
export const STATUS_HEX_COLORS: Record<StatusType, string> = {
upToDate: "#10b981",
export const EVIDENCE_STATUS_HEX_COLORS: Record<EvidenceStatusType, string> = {
draft: "#f59e0b",
needsReview: "#ef4444",
empty: "#6b7280",
not_relevant: "#ef4444",
published: "#10b981",
};

// Translation keys for evidence statuses
export const STATUS_TRANSLATION_KEYS: Record<StatusType, string> = {
upToDate: "evidence.status.up_to_date",
needsReview: "evidence.status.needs_review",
export const EVIDENCE_STATUS_TRANSLATION_KEYS: Record<
EvidenceStatusType,
string
> = {
draft: "evidence.status.draft",
empty: "evidence.status.empty",
not_relevant: "evidence.status.not_relevant",
published: "evidence.status.published",
};
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ const getEvidenceOverview = cache(async () => {
tx.evidence.count({
where: {
organizationId,
published: true,
status: "published",
},
}),
tx.evidence.count({
where: {
organizationId,
published: false,
status: "draft",
},
}),
tx.evidence.count({
where: {
organizationId,
isNotRelevant: true,
status: "not_relevant",
},
}),
tx.evidence.groupBy({
Expand All @@ -88,12 +88,15 @@ const getEvidenceOverview = cache(async () => {
assigneeId: { not: null },
},
select: {
published: true,
isNotRelevant: true,
status: true,
assignee: {
select: {
id: true,
name: true,
user: {
select: {
name: true,
},
},
},
},
},
Expand All @@ -110,7 +113,7 @@ const getEvidenceOverview = cache(async () => {
if (!evidenceAssigneeByStatus.has(assigneeId)) {
evidenceAssigneeByStatus.set(assigneeId, {
id: assigneeId,
name: evidence.assignee.name || "Unknown",
name: evidence.assignee.user.name || "Unknown",
total: 0,
published: 0,
draft: 0,
Expand All @@ -127,9 +130,9 @@ const getEvidenceOverview = cache(async () => {
// status = isNotRelevant if published is false and isNotRelevant is true
// status = needsReview if published is true and needs review

if (evidence.published) {
if (evidence.status === "published") {
assigneeData.published += 1;
} else if (evidence.isNotRelevant) {
} else if (evidence.status === "not_relevant") {
assigneeData.isNotRelevant += 1;
} else {
// If not published and not irrelevant, it's a draft
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"use server";

import { authActionClient } from "@/actions/safe-action";
import { db } from "@bubba/db";
import { Departments, Frequency } from "@bubba/db/types";
import { Evidence, EvidenceStatus, Role } from "@prisma/client";
import { z } from "zod";
import type { ActionResponse } from "@/actions/types";

const schema = z.object({
id: z.string(),
department: z.nativeEnum(Departments),
frequency: z.nativeEnum(Frequency).nullable(),
assigneeId: z.string().nullable(),
status: z.nativeEnum(EvidenceStatus).nullable(),
});

export const updateEvidenceDetails = authActionClient
.schema(schema)
.metadata({
name: "updateEvidenceDetails",
track: {
event: "update-evidence-details",
channel: "server",
},
})
.action(async ({ ctx, parsedInput }): Promise<ActionResponse> => {
const { session } = ctx;
const { id, department, frequency, assigneeId, status } = parsedInput;

if (!session.activeOrganizationId) {
return {
success: false,
error: "Not authorized - no organization found",
};
}

try {
// Verify the evidence exists and belongs to the organization
const evidence = await db.evidence.findFirst({
where: {
id,
organizationId: session.activeOrganizationId,
},
});

if (!evidence) {
return {
success: false,
error: "Evidence not found",
};
}

const payload: Pick<
Evidence,
"department" | "frequency" | "assigneeId" | "status" | "lastPublishedAt"
> = {
department,
frequency,
assigneeId,
lastPublishedAt: new Date(),
status,
};

// Update all evidence details in a single operation
const updatedEvidence = await db.evidence.update({
where: {
id,
},
data: payload,
});

return {
success: true,
data: updatedEvidence,
};
} catch (error) {
console.error("Error updating evidence details:", error);
return {
success: false,
error: "Failed to update evidence details",
};
}
});

This file was deleted.

Loading