Skip to content

Commit

Permalink
editting templates
Browse files Browse the repository at this point in the history
  • Loading branch information
armintalaie committed Jan 10, 2025
1 parent 497e7c0 commit 58d73ac
Show file tree
Hide file tree
Showing 21 changed files with 598 additions and 47 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"json-2-csv": "^5.5.7",
"lucide-react": "^0.428.0",
"mailgun.js": "^10.3.0",
"marked": "^15.0.6",
"next": "14.2.10",
"next-themes": "^0.3.0",
"path": "^0.12.7",
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,25 @@ tbody {
-ms-overflow-style: none;
scrollbar-width: none;
}

/* For Chrome, Safari, and newer versions of Edge */
.scrollbar {
scrollbar-width: thin; /* For Firefox */
@apply overflow-x-auto;
}

.scrollbar::-webkit-scrollbar {
@apply h-1.5; /* height for horizontal scrollbar */
}

.scrollbar::-webkit-scrollbar-track {
@apply bg-background-800 rounded-full;
}

.scrollbar::-webkit-scrollbar-thumb {
@apply bg-background-600 rounded-full;
}

.scrollbar::-webkit-scrollbar-thumb:hover {
@apply bg-background-500;
}
4 changes: 3 additions & 1 deletion src/app/portal/admin/actions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"use server";
import { db } from "@/db";
import { FormStep } from "@/lib/types/questions";
import { FormFields } from "@/app/portal/admin/forms/[id]/submissions/columns";
import { FormFields } from "@/components/forms/applications/columns";
import { sendEmail } from "@/lib/utils/forms/email";
import { MarkdownTemplate } from "@/components/forms/emailTemplates/markdownTemplate";
import { render } from "@react-email/components";
import { object } from "zod";

export async function getForms() {
return db.forms.findMany();
Expand Down Expand Up @@ -99,6 +100,7 @@ export async function getAllFormDetails(
formId: bigint,
): Promise<{ rawForm: any; formFields: FormFields; submissions: any[] }> {
try {
console.log("retrieving form details");
const form = await db.forms.findFirst({
where: { id: formId },
});
Expand Down
8 changes: 6 additions & 2 deletions src/app/portal/admin/forms/[id]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { Suspense } from "react";
import FormTabView, { Tab } from "@/components/layouts/formTabView";
import { getAdminMembers, getAllFormDetails } from "@/app/portal/admin/actions";

Expand All @@ -21,11 +21,15 @@ export default async function Layout({
label: "Support",
route: `/portal/admin/forms/${params.id}/support`,
},
{
label: "Settings",
route: `/portal/admin/forms/${params.id}/settings`,
},
];

return (
<FormTabView tabs={tabs} form={formDetails} members={members}>
{children}
<Suspense fallback={<div>Loading...</div>}>{children}</Suspense>
</FormTabView>
);
}
55 changes: 55 additions & 0 deletions src/app/portal/admin/forms/[id]/settings/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"use server";
import { db } from "@/db";

type EmailTemplate = {
title: string;
content: string;
};

export async function updateOrCreateEmailTemplate(
formId: number,
status: string,
template: EmailTemplate,
) {
try {
// First get the current form to access existing config
const form = await db.forms.findFirst({
where: { id: BigInt(formId) },
});

if (!form) {
throw new Error(`Form with id ${formId} not found`);
}

// Get existing config or initialize if doesn't exist
const currentConfig = (form.config as Record<string, any>) || {};

// Safely create nested structure if it doesn't exist
const updatedConfig = {
...currentConfig,
application: {
...currentConfig.application,
emails: {
...(currentConfig.application?.emails || {}),
status: {
...(currentConfig.application?.emails?.status || {}),
[status]: template,
},
},
},
};

// Update only the config field
await db.forms.update({
where: { id: BigInt(formId) },
data: {
config: updatedConfig,
},
});

return { success: true };
} catch (error) {
console.error("Error updating email template:", error);
throw error;
}
}
Loading

0 comments on commit 58d73ac

Please sign in to comment.