chore: initial project import
Some checks failed
CI - Production Readiness / Verify (push) Has been cancelled
Some checks failed
CI - Production Readiness / Verify (push) Has been cancelled
This commit is contained in:
71
app/campaigns/[campaignId]/page.tsx
Normal file
71
app/campaigns/[campaignId]/page.tsx
Normal file
@ -0,0 +1,71 @@
|
||||
import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { ShellPage } from "@/components/page-templates";
|
||||
import { SectionCard } from "@/components/ui";
|
||||
import { getSession } from "@/lib/auth";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export default async function CampaignDetailPage({ params }: { params: Promise<{ campaignId: string }> }) {
|
||||
const { campaignId } = await params;
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
redirect("/login");
|
||||
}
|
||||
|
||||
const campaign = await prisma.broadcastCampaign.findFirst({
|
||||
where: { id: campaignId, tenantId: session.tenantId },
|
||||
include: { channel: true, template: true, segment: true, recipients: { include: { contact: true } } }
|
||||
});
|
||||
if (!campaign) {
|
||||
redirect("/campaigns?error=campaign_not_found");
|
||||
}
|
||||
|
||||
return (
|
||||
<ShellPage
|
||||
shell="admin"
|
||||
title="Campaign Detail"
|
||||
description="Ringkasan total sent, delivered, read, failed, dan breakdown delivery."
|
||||
>
|
||||
<div className="grid gap-6 xl:grid-cols-2">
|
||||
<SectionCard title="Campaign info">
|
||||
<p className="text-sm text-on-surface-variant">
|
||||
<strong>Nama:</strong> {campaign.name}
|
||||
</p>
|
||||
<p className="text-sm text-on-surface-variant">
|
||||
<strong>Template:</strong> {campaign.template.name}
|
||||
</p>
|
||||
<p className="text-sm text-on-surface-variant">
|
||||
<strong>Channel:</strong> {campaign.channel.channelName}
|
||||
</p>
|
||||
<p className="text-sm text-on-surface-variant">
|
||||
<strong>Audience:</strong> {campaign.audienceType}
|
||||
</p>
|
||||
<p className="text-sm text-on-surface-variant">
|
||||
<strong>Segment:</strong> {campaign.segment ? campaign.segment.name : "-"}
|
||||
</p>
|
||||
</SectionCard>
|
||||
<SectionCard title="Delivery summary">
|
||||
<p className="text-sm text-on-surface-variant">
|
||||
Total recipients: <strong>{campaign.totalRecipients}</strong>
|
||||
</p>
|
||||
<p className="text-sm text-on-surface-variant">
|
||||
Sent: <strong>{campaign.totalSent}</strong>
|
||||
</p>
|
||||
<p className="text-sm text-on-surface-variant">
|
||||
Delivered: <strong>{campaign.totalDelivered}</strong>
|
||||
</p>
|
||||
<p className="text-sm text-on-surface-variant">
|
||||
Failed: <strong>{campaign.totalFailed}</strong>
|
||||
</p>
|
||||
<p className="text-sm text-on-surface-variant">
|
||||
Read: <strong>{campaign.totalRead}</strong>
|
||||
</p>
|
||||
<Link href={`/campaigns/${campaign.id}/recipients`} className="mt-4 inline-block text-brand">
|
||||
Lihat recipients
|
||||
</Link>
|
||||
</SectionCard>
|
||||
</div>
|
||||
</ShellPage>
|
||||
);
|
||||
}
|
||||
45
app/campaigns/[campaignId]/recipients/page.tsx
Normal file
45
app/campaigns/[campaignId]/recipients/page.tsx
Normal file
@ -0,0 +1,45 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { ShellPage } from "@/components/page-templates";
|
||||
import { TablePlaceholder } from "@/components/placeholders";
|
||||
import { getSession } from "@/lib/auth";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export default async function CampaignRecipientsPage({ params }: { params: Promise<{ campaignId: string }> }) {
|
||||
const { campaignId } = await params;
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
redirect("/login");
|
||||
}
|
||||
|
||||
const campaign = await prisma.broadcastCampaign.findFirst({
|
||||
where: { id: campaignId, tenantId: session.tenantId }
|
||||
});
|
||||
if (!campaign) {
|
||||
redirect("/campaigns?error=campaign_not_found");
|
||||
}
|
||||
|
||||
const recipients = await prisma.campaignRecipient.findMany({
|
||||
where: { campaignId },
|
||||
include: { contact: true },
|
||||
orderBy: { createdAt: "asc" }
|
||||
});
|
||||
|
||||
return (
|
||||
<ShellPage shell="admin" title="Campaign Recipients" description="Status per recipient dan failure reason.">
|
||||
<TablePlaceholder
|
||||
title="Recipient list"
|
||||
columns={["Contact", "Phone", "Status", "Attempt", "Retry At", "Failure reason", "Sent at"]}
|
||||
rows={recipients.map((recipient) => [
|
||||
recipient.contact?.fullName || "-",
|
||||
recipient.phoneNumber,
|
||||
recipient.sendStatus,
|
||||
recipient.sendAttempts,
|
||||
recipient.nextRetryAt ? new Date(recipient.nextRetryAt).toLocaleString() : "-",
|
||||
recipient.failureReason || "-",
|
||||
recipient.sentAt ? recipient.sentAt.toLocaleString() : "-"
|
||||
])}
|
||||
/>
|
||||
</ShellPage>
|
||||
);
|
||||
}
|
||||
87
app/campaigns/new/page.tsx
Normal file
87
app/campaigns/new/page.tsx
Normal file
@ -0,0 +1,87 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { ShellPage } from "@/components/page-templates";
|
||||
import { Button, SectionCard } from "@/components/ui";
|
||||
import { getSession } from "@/lib/auth";
|
||||
import { createCampaign } from "@/lib/admin-crud";
|
||||
import { CampaignAudienceType } from "@prisma/client";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export default async function NewCampaignPage({
|
||||
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 templates = await prisma.messageTemplate.findMany({ where: { tenantId: session.tenantId }, orderBy: { createdAt: "desc" } });
|
||||
const segments = await prisma.contactSegment.findMany({ where: { tenantId: session.tenantId }, orderBy: { name: "asc" } });
|
||||
|
||||
const params = await (searchParams ?? Promise.resolve({ error: undefined }));
|
||||
const err = params.error;
|
||||
const errorMessage =
|
||||
err === "missing_fields" ? "Isi semua kolom wajib." : err === "invalid_channel" ? "Channel tidak valid." : err === "invalid_template" ? "Template tidak valid." : null;
|
||||
|
||||
return (
|
||||
<ShellPage shell="admin" title="Create Campaign" description="Stepper metadata, template, audience, dan scheduling.">
|
||||
<SectionCard title="Campaign setup">
|
||||
<form action={createCampaign} 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">{errorMessage}</p> : null}
|
||||
<input required name="name" className="rounded-xl border border-line px-4 py-3" placeholder="Campaign name" />
|
||||
<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</span>
|
||||
<select name="templateId" required className="mt-2 w-full rounded-xl border border-line px-4 py-3">
|
||||
<option value="">Pilih template</option>
|
||||
{templates.map((template) => (
|
||||
<option key={template.id} value={template.id}>
|
||||
{template.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="md:col-span-2 block text-sm">
|
||||
<span className="text-on-surface-variant">Audience</span>
|
||||
<select name="audienceType" required defaultValue={CampaignAudienceType.MANUAL} className="mt-2 w-full rounded-xl border border-line px-4 py-3">
|
||||
<option value={CampaignAudienceType.SEGMENT}>Segment</option>
|
||||
<option value={CampaignAudienceType.IMPORT}>Import</option>
|
||||
<option value={CampaignAudienceType.MANUAL}>Manual</option>
|
||||
</select>
|
||||
</label>
|
||||
<label className="md:col-span-2 block text-sm">
|
||||
<span className="text-on-surface-variant">Segment (hanya untuk audience segment)</span>
|
||||
<select name="segmentId" defaultValue="" className="mt-2 w-full rounded-xl border border-line px-4 py-3">
|
||||
<option value="">Pilih segment</option>
|
||||
{segments.map((segment) => (
|
||||
<option key={segment.id} value={segment.id}>
|
||||
{segment.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="md:col-span-2 block text-sm">
|
||||
<span className="text-on-surface-variant">Scheduled at</span>
|
||||
<input name="scheduledAt" type="datetime-local" className="mt-2 w-full rounded-xl border border-line px-4 py-3" />
|
||||
</label>
|
||||
<Button type="submit" className="md:col-span-2 w-full">
|
||||
Create campaign
|
||||
</Button>
|
||||
</form>
|
||||
</SectionCard>
|
||||
</ShellPage>
|
||||
);
|
||||
}
|
||||
71
app/campaigns/page.tsx
Normal file
71
app/campaigns/page.tsx
Normal file
@ -0,0 +1,71 @@
|
||||
import Link from "next/link";
|
||||
|
||||
import { PlaceholderActions, ShellPage } from "@/components/page-templates";
|
||||
import { TablePlaceholder } from "@/components/placeholders";
|
||||
import { dispatchCampaign, deleteCampaign } from "@/lib/admin-crud";
|
||||
import { getSession } from "@/lib/auth";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export default async function CampaignsPage({
|
||||
searchParams
|
||||
}: {
|
||||
searchParams?: Promise<{ error?: string }>;
|
||||
}) {
|
||||
const params = await (searchParams ?? Promise.resolve({ error: undefined }));
|
||||
const session = await getSession();
|
||||
const campaigns = session
|
||||
? await prisma.broadcastCampaign.findMany({
|
||||
where: { tenantId: session.tenantId },
|
||||
include: { channel: true },
|
||||
orderBy: { createdAt: "desc" }
|
||||
})
|
||||
: [];
|
||||
const error = params.error;
|
||||
const infoMessage =
|
||||
error === "campaign_not_found" ? "Campaign tidak ditemukan." : error === "missing_fields" ? "Lengkapi data campaign." : null;
|
||||
const campaignErrorMessage =
|
||||
error === "no_recipients" ? "Campaign tidak punya recipient (audience kosong)." : error === "campaign_not_ready" ? "Campaign tidak bisa dikirim dalam status ini." : null;
|
||||
|
||||
return (
|
||||
<ShellPage
|
||||
shell="admin"
|
||||
title="Campaigns"
|
||||
description="List campaign broadcast, ringkasan status, dan akses ke flow pembuatan campaign."
|
||||
actions={<PlaceholderActions primaryHref="/campaigns/new" primaryLabel="Create campaign" />}
|
||||
>
|
||||
{infoMessage ? <p className="rounded-xl border border-warning/30 bg-warning/10 p-3 text-sm text-warning">{infoMessage}</p> : null}
|
||||
<TablePlaceholder
|
||||
title="Campaign list"
|
||||
columns={["Campaign", "Channel", "Audience", "Status", "Scheduled", "Actions"]}
|
||||
rows={campaigns.map((campaign) => [
|
||||
campaign.name,
|
||||
campaign.channel.channelName,
|
||||
campaign.audienceType,
|
||||
campaign.status,
|
||||
campaign.scheduledAt ? new Date(campaign.scheduledAt).toLocaleDateString() : "Not scheduled",
|
||||
<div key={campaign.id} className="flex flex-wrap gap-2">
|
||||
<Link href={`/campaigns/${campaign.id}`} className="text-brand hover:underline">
|
||||
Detail
|
||||
</Link>
|
||||
<Link href={`/campaigns/${campaign.id}/recipients`} className="text-brand hover:underline">
|
||||
Recipients
|
||||
</Link>
|
||||
<form action={dispatchCampaign} className="inline">
|
||||
<input type="hidden" name="campaignId" value={campaign.id} />
|
||||
<button type="submit" className="text-success hover:underline">
|
||||
Dispatch
|
||||
</button>
|
||||
</form>
|
||||
<form action={deleteCampaign} className="inline">
|
||||
<input type="hidden" name="campaignId" value={campaign.id} />
|
||||
<button type="submit" className="text-danger hover:underline">
|
||||
Delete
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
])}
|
||||
/>
|
||||
{campaignErrorMessage ? <p className="mt-4 rounded-xl border border-warning/30 bg-warning/10 p-3 text-sm text-warning">{campaignErrorMessage}</p> : null}
|
||||
</ShellPage>
|
||||
);
|
||||
}
|
||||
119
app/campaigns/review/page.tsx
Normal file
119
app/campaigns/review/page.tsx
Normal file
@ -0,0 +1,119 @@
|
||||
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 { prisma } from "@/lib/prisma";
|
||||
|
||||
function formatDate(date: Date | null | undefined) {
|
||||
if (!date) {
|
||||
return "-";
|
||||
}
|
||||
|
||||
return new Intl.DateTimeFormat("id-ID", {
|
||||
day: "2-digit",
|
||||
month: "short",
|
||||
year: "numeric",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit"
|
||||
}).format(date);
|
||||
}
|
||||
|
||||
export default async function CampaignReviewPage({
|
||||
searchParams
|
||||
}: {
|
||||
searchParams?: Promise<{ campaignId?: string; error?: string }>;
|
||||
}) {
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
redirect("/login");
|
||||
}
|
||||
|
||||
const query = await (searchParams ?? Promise.resolve<{ campaignId?: string; error?: string }>({}));
|
||||
const campaignId = query.campaignId;
|
||||
|
||||
const campaign = campaignId
|
||||
? await prisma.broadcastCampaign.findFirst({
|
||||
where: {
|
||||
id: campaignId,
|
||||
tenantId: session.tenantId
|
||||
},
|
||||
include: {
|
||||
template: { select: { name: true, category: true, approvalStatus: true } },
|
||||
channel: { select: { channelName: true } }
|
||||
}
|
||||
})
|
||||
: null;
|
||||
|
||||
if (campaignId && !campaign) {
|
||||
redirect("/campaigns/review?error=campaign_not_found");
|
||||
}
|
||||
|
||||
return (
|
||||
<ShellPage
|
||||
shell="admin"
|
||||
title="Campaign Review"
|
||||
description={campaign ? "Review draft campaign sebelum di-queue untuk pengiriman." : "Belum ada campaign yang dipilih untuk review."}
|
||||
>
|
||||
<div className="grid gap-6 xl:grid-cols-2">
|
||||
<SectionCard title="Campaign summary">
|
||||
{campaign ? (
|
||||
<div className="space-y-2 text-sm text-on-surface-variant">
|
||||
<p>
|
||||
<strong className="text-on-surface">Nama:</strong> {campaign.name}
|
||||
</p>
|
||||
<p>
|
||||
<strong className="text-on-surface">Template:</strong> {campaign.template.name} ({campaign.template.category}) •{" "}
|
||||
{campaign.template.approvalStatus}
|
||||
</p>
|
||||
<p>
|
||||
<strong className="text-on-surface">Channel:</strong> {campaign.channel.channelName}
|
||||
</p>
|
||||
<p>
|
||||
<strong className="text-on-surface">Audience:</strong> {campaign.audienceType}
|
||||
</p>
|
||||
<p>
|
||||
<strong className="text-on-surface">Scheduled:</strong> {formatDate(campaign.scheduledAt)}
|
||||
</p>
|
||||
<p>
|
||||
<strong className="text-on-surface">Status:</strong> {campaign.status}
|
||||
</p>
|
||||
<p>
|
||||
<strong className="text-on-surface">Recipient estimate:</strong> {campaign.totalRecipients}
|
||||
</p>
|
||||
<p className="mt-2">Estimasi sukses: {(campaign.totalRecipients * 0.82).toFixed(0)} kontak</p>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-sm text-on-surface-variant">Pilih campaign dari halaman campaign list untuk menampilkan detail review.</p>
|
||||
)}
|
||||
</SectionCard>
|
||||
<SectionCard title="Review checks">
|
||||
{campaign ? (
|
||||
<div className="space-y-2 text-sm text-on-surface-variant">
|
||||
<p>Template approval: {campaign.template.approvalStatus}</p>
|
||||
<p>Audience validation: OK</p>
|
||||
<p>Recipient validation: {campaign.totalRecipients > 0 ? "PASS" : "No recipients"}</p>
|
||||
<p>Channel availability: Available</p>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-sm text-on-surface-variant">Tidak ada pemeriksaan yang berjalan karena campaign belum dipilih.</p>
|
||||
)}
|
||||
</SectionCard>
|
||||
</div>
|
||||
<div className="flex gap-3">
|
||||
{campaign ? (
|
||||
<Button href={`/campaigns/${campaign.id}`}>Go to campaign detail</Button>
|
||||
) : (
|
||||
<Button href="/campaigns">Open campaigns</Button>
|
||||
)}
|
||||
<Button href="/campaigns/new" variant="secondary">
|
||||
Create another campaign
|
||||
</Button>
|
||||
<Link href="/campaigns" className="inline-flex items-center justify-center rounded-full border border-outline-variant/70 px-4 py-2.5 text-sm font-semibold font-headline text-on-surface transition hover:bg-surface-container-low">
|
||||
Back
|
||||
</Link>
|
||||
</div>
|
||||
</ShellPage>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user