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
76 changes: 76 additions & 0 deletions apps/app/src/actions/policies/archive-policy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"use server";

import { db } from "@bubba/db";
import { revalidatePath, revalidateTag } from "next/cache";
import { authActionClient } from "../safe-action";
import { z } from "zod";

const archivePolicySchema = z.object({
id: z.string(),
action: z.enum(["archive", "restore"]).optional(),
});

export const archivePolicyAction = authActionClient
.schema(archivePolicySchema)
.metadata({
name: "archive-policy",
track: {
event: "archive-policy",
channel: "server",
},
})
.action(async ({ parsedInput, ctx }) => {
const { id, action } = parsedInput;
const { user } = ctx;

if (!user.id || !user.organizationId) {
return {
success: false,
error: "Not authorized",
};
}

try {
const policy = await db.organizationPolicy.findUnique({
where: {
id,
organizationId: user.organizationId,
},
});

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

// Determine if we should archive or restore based on action or current state
const shouldArchive =
action === "archive" || (action === undefined && !policy.isArchived);

await db.organizationPolicy.update({
where: { id },
data: {
isArchived: shouldArchive,
archivedAt: shouldArchive ? new Date() : null,
},
});

revalidatePath(`/${user.organizationId}/policies/all/${id}`);
revalidatePath(`/${user.organizationId}/policies/all`);
revalidatePath(`/${user.organizationId}/policies`);
revalidateTag("policies");

return {
success: true,
isArchived: shouldArchive,
};
} catch (error) {
console.error(error);
return {
success: false,
error: "Failed to update policy archive status",
};
}
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { EmployeeInviteSheet } from "@/components/sheets/invite-user-sheet";
import { EmployeeInviteSheet } from "@/components/sheets/add-employee-sheet";
import { DataTable } from "@/components/ui/data-table";
import { Plus } from "lucide-react";
import { useParams, useRouter } from "next/navigation";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import useSWR from "swr";
import { getOrganizationEvidenceTasks } from "../actions/getOrganizationEvidenceTasks";
import type { PaginationMetadata } from "../actions/getOrganizationEvidenceTasks";
import type { Frequency, OrganizationEvidence, Departments } from "@bubba/db/types";
import type {
Frequency,
OrganizationEvidence,
Departments,
} from "@bubba/db/types";

// Define the props interface with clear types
interface UseOrganizationEvidenceTasksProps {
Expand Down Expand Up @@ -96,8 +100,6 @@ export function useOrganizationEvidenceTasks(
})
);

console.log("useOrganizationEvidenceTasks data:", data);

return {
data: data?.data ?? [],
pagination: data?.pagination,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ function FrameworkCard({
return (
<Link
href={`/${orgId}/overview/frameworks/${framework.framework.id}`}
className="flex items-start gap-4 rounded-lg p-4 hover:bg-zinc-800/40 transition-colors duration-200"
className="flex items-start gap-4 rounded-lg p-4 hover:bg-muted/40 transition-colors duration-200"
>
<div className="flex-shrink-0 h-12 w-12 rounded-full overflow-hidden bg-zinc-800 flex items-center justify-center">
<div className="text-lg font-bold text-zinc-400">
<div className="flex-shrink-0 h-12 w-12 rounded-full overflow-hidden bg-muted flex items-center justify-center">
<div className="text-lg font-bold text-muted-foreground">
{framework.framework.name.substring(0, 2).toUpperCase()}
</div>
</div>
Expand All @@ -50,7 +50,7 @@ function FrameworkCard({
</div>
<Progress
value={compliance}
className="h-2 bg-zinc-800 [&>div]:bg-emerald-500"
className="h-2 bg-secondary [&>div]:bg-primary"
/>
</div>
</Link>
Expand All @@ -67,7 +67,7 @@ export function RequirementStatus({
if (!frameworks.length || !frameworksWithCompliance.length) return null;

return (
<Card className="border border-border bg-background select-none">
<Card className="select-none">
<CardHeader className="flex flex-row items-center justify-between">
<CardTitle>{t("frameworks.title")}</CardTitle>
</CardHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ export function FrameworkOverview({
}
}).length;

// Calculate compliance metrics
const compliancePercentage =
totalRequirements > 0
? Math.round((completedRequirements / totalRequirements) * 100)
: 0;

// Count controls
const allControls = organizationCategories.flatMap(
(category) => category.organizationControl,
Expand Down Expand Up @@ -69,6 +63,12 @@ export function FrameworkOverview({
return completedControlRequirements === controlRequirements.length;
}).length;

// Calculate compliance percentage based on compliant controls
const compliancePercentage =
totalControls > 0
? Math.round((compliantControls / totalControls) * 100)
: 0;

return (
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
<Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const getPoliciesOverview = async () => {
tx.organizationPolicy.count({
where: {
organizationId,
status: "archived",
isArchived: true,
},
}),
tx.organizationPolicy.count({
Expand Down
Loading