chore: initial project import
Some checks failed
CI - Production Readiness / Verify (push) Has been cancelled

This commit is contained in:
Wira Basalamah
2026-04-21 09:29:29 +07:00
commit adde003fba
222 changed files with 37657 additions and 0 deletions

View File

@ -0,0 +1,70 @@
import Link from "next/link";
import { redirect } from "next/navigation";
import { ShellPage } from "@/components/page-templates";
import { Button, SectionCard } from "@/components/ui";
import { getSession } from "@/lib/auth";
import { updateTemplate } from "@/lib/admin-crud";
import { prisma } from "@/lib/prisma";
export default async function EditTemplatePage({ params }: { params: Promise<{ templateId: string }> }) {
const { templateId } = await params;
const session = await getSession();
if (!session) {
redirect("/login");
}
const template = await prisma.messageTemplate.findFirst({
where: { id: templateId, tenantId: session.tenantId }
});
if (!template) {
redirect("/templates?error=template_not_found");
}
const channels = await prisma.channel.findMany({
where: { tenantId: session.tenantId },
orderBy: { channelName: "asc" }
});
return (
<ShellPage shell="admin" title="Edit Template" description="Resubmit template yang ditolak atau update draft.">
<SectionCard title="Template form">
<form action={updateTemplate} className="grid gap-4 md:max-w-3xl">
<input type="hidden" name="templateId" value={template.id} />
<input name="name" required defaultValue={template.name} className="rounded-xl border border-line px-4 py-3" />
<input name="category" required defaultValue={template.category} className="rounded-xl border border-line px-4 py-3" />
<input
name="languageCode"
required
defaultValue={template.languageCode}
className="rounded-xl border border-line px-4 py-3"
/>
<label className="md:col-span-2 block text-sm">
<span className="text-on-surface-variant">Channel</span>
<select name="channelId" defaultValue={template.channelId} className="mt-2 w-full rounded-xl border border-line px-4 py-3">
{channels.map((channel) => (
<option key={channel.id} value={channel.id}>
{channel.channelName}
</option>
))}
</select>
</label>
<textarea
required
name="bodyText"
className="min-h-32 rounded-xl border border-line px-4 py-3"
defaultValue={template.bodyText}
/>
<div className="md:col-span-2 flex gap-3">
<Button type="submit" className="rounded-xl">
Save template
</Button>
<Link href={`/templates/${template.id}`} className="text-on-surface-variant hover:underline">
Cancel
</Link>
</div>
</form>
</SectionCard>
</ShellPage>
);
}

View File

@ -0,0 +1,54 @@
import { ShellPage } from "@/components/page-templates";
import { SectionCard } from "@/components/ui";
import { getSession } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { redirect } from "next/navigation";
export default async function TemplateDetailPage({ params }: { params: Promise<{ templateId: string }> }) {
const { templateId } = await params;
const session = await getSession();
if (!session) {
redirect("/login");
}
const template = await prisma.messageTemplate.findFirst({
where: { id: templateId, tenantId: session.tenantId },
include: { channel: true }
});
if (!template) {
redirect("/templates?error=template_not_found");
}
return (
<ShellPage shell="admin" title="Template Detail" description="Preview content, provider metadata, dan approval state.">
<div className="grid gap-6 xl:grid-cols-2">
<SectionCard title="Template preview">
<p className="text-sm text-on-surface-variant">
<strong>Name:</strong> {template.name}
</p>
<p className="text-sm text-on-surface-variant">
<strong>Category:</strong> {template.category}
</p>
<p className="text-sm text-on-surface-variant">
<strong>Language:</strong> {template.languageCode}
</p>
<p className="mt-4 rounded-xl border border-line bg-surface-container p-3 text-sm text-on-surface-variant">{template.bodyText}</p>
</SectionCard>
<SectionCard title="Provider status">
<p className="text-sm text-on-surface-variant">
<strong>Approval:</strong> {template.approvalStatus}
</p>
<p className="text-sm text-on-surface-variant">
<strong>Channel:</strong> {template.channel.channelName}
</p>
<p className="text-sm text-on-surface-variant">
<strong>Provider id:</strong> {template.providerTemplateId || "-"}
</p>
<p className="text-sm text-on-surface-variant">
<strong>Rejected reason:</strong> {template.rejectedReason || "-"}
</p>
</SectionCard>
</div>
</ShellPage>
);
}

View File

@ -0,0 +1,60 @@
import { redirect } from "next/navigation";
import { ShellPage } from "@/components/page-templates";
import { Button, SectionCard } from "@/components/ui";
import { getSession } from "@/lib/auth";
import { createTemplate } from "@/lib/admin-crud";
import { prisma } from "@/lib/prisma";
export default async function NewTemplatePage({
searchParams
}: {
searchParams?: Promise<{ error?: string }>;
}) {
const session = await getSession();
if (!session) {
redirect("/login");
}
const channels = await prisma.channel.findMany({
where: { tenantId: session.tenantId },
orderBy: { channelName: "asc" }
});
const params = await (searchParams ?? Promise.resolve({ error: undefined }));
const errorMessage = params.error === "missing_fields" ? "Lengkapi semua kolom wajib." : params.error === "invalid_channel" ? "Channel tidak valid." : null;
return (
<ShellPage shell="admin" title="Create Template Request" description="Form request template WhatsApp.">
<SectionCard title="Template builder">
<form action={createTemplate} className="grid gap-4 md:max-w-3xl">
{errorMessage ? (
<p className="rounded-xl border border-warning/30 bg-warning/10 p-3 text-sm text-warning md:col-span-2">{errorMessage}</p>
) : null}
<input required name="name" className="rounded-xl border border-line px-4 py-3" placeholder="Template name" />
<input required name="category" className="rounded-xl border border-line px-4 py-3" placeholder="Category" />
<input required name="languageCode" className="rounded-xl border border-line px-4 py-3" placeholder="Language code (id)" />
<label className="md:col-span-2 block text-sm">
<span className="text-on-surface-variant">Channel</span>
<select name="channelId" required className="mt-2 w-full rounded-xl border border-line px-4 py-3">
<option value="">Pilih channel</option>
{channels.map((channel) => (
<option key={channel.id} value={channel.id}>
{channel.channelName}
</option>
))}
</select>
</label>
<label className="md:col-span-2 block text-sm">
<span className="text-on-surface-variant">Template type</span>
<input name="templateType" defaultValue="text" className="mt-2 w-full rounded-xl border border-line px-4 py-3" />
</label>
<textarea required name="bodyText" className="min-h-32 rounded-xl border border-line px-4 py-3" placeholder="Body text" />
<Button type="submit" className="md:col-span-2 w-full">
Submit template
</Button>
</form>
</SectionCard>
</ShellPage>
);
}

62
app/templates/page.tsx Normal file
View File

@ -0,0 +1,62 @@
import Link from "next/link";
import { PlaceholderActions, ShellPage } from "@/components/page-templates";
import { TablePlaceholder } from "@/components/placeholders";
import { deleteTemplate } from "@/lib/admin-crud";
import { getSession } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
export default async function TemplatesPage({
searchParams
}: {
searchParams?: Promise<{ error?: string }>;
}) {
const params = await (searchParams ?? Promise.resolve({ error: undefined }));
const session = await getSession();
const templates = session
? await prisma.messageTemplate.findMany({
where: { tenantId: session.tenantId },
include: { channel: true },
orderBy: { updatedAt: "desc" }
})
: [];
const error = params.error;
const infoMessage =
error === "template_not_found" ? "Template tidak ditemukan." : error === "template_in_use" ? "Template masih digunakan campaign." : null;
return (
<ShellPage
shell="admin"
title="Templates"
description="Daftar template WhatsApp, approval status, dan akses ke request form."
actions={<PlaceholderActions primaryHref="/templates/new" primaryLabel="Create template request" />}
>
{infoMessage ? <p className="rounded-xl border border-warning/30 bg-warning/10 p-3 text-sm text-warning">{infoMessage}</p> : null}
<TablePlaceholder
title="Template list"
columns={["Name", "Category", "Language", "Channel", "Status", "Actions"]}
rows={templates.map((template) => [
template.name,
template.category,
template.languageCode,
template.channel.channelName,
template.approvalStatus,
<div key={template.id} className="flex gap-2">
<Link href={`/templates/${template.id}`} className="text-brand hover:underline">
Detail
</Link>
<Link href={`/templates/${template.id}/edit`} className="text-brand hover:underline">
Edit
</Link>
<form action={deleteTemplate} className="inline">
<input type="hidden" name="templateId" value={template.id} />
<button type="submit" className="text-danger hover:underline">
Delete
</button>
</form>
</div>
])}
/>
</ShellPage>
);
}