feat: implement Sonner notifications, add Setting model, and reorganize user management into settings navigation.
This commit is contained in:
@@ -17,10 +17,12 @@
|
|||||||
"bcryptjs": "^3.0.3",
|
"bcryptjs": "^3.0.3",
|
||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
|
"cn": "^0.2.6",
|
||||||
"date-fns": "^4.4.0",
|
"date-fns": "^4.4.0",
|
||||||
"jose": "^6.2.10",
|
"jose": "^6.2.10",
|
||||||
"lucide-react": "^1.34.0",
|
"lucide-react": "^1.34.0",
|
||||||
"next": "16.3.3",
|
"next": "16.3.3",
|
||||||
|
"next-themes": "^0.4.6",
|
||||||
"prisma": "^5.22.0",
|
"prisma": "^5.22.0",
|
||||||
"react": "19.2.8",
|
"react": "19.2.8",
|
||||||
"react-day-picker": "^10.0.1",
|
"react-day-picker": "^10.0.1",
|
||||||
@@ -28,6 +30,7 @@
|
|||||||
"react-hook-form": "^7.86.0",
|
"react-hook-form": "^7.86.0",
|
||||||
"recharts": "^3.10.1",
|
"recharts": "^3.10.1",
|
||||||
"shadcn": "^4.19.0",
|
"shadcn": "^4.19.0",
|
||||||
|
"sonner": "^2.0.8",
|
||||||
"tailwind-merge": "^3.6.0",
|
"tailwind-merge": "^3.6.0",
|
||||||
"tw-animate-css": "^1.4.0",
|
"tw-animate-css": "^1.4.0",
|
||||||
"uuid": "^14.0.2",
|
"uuid": "^14.0.2",
|
||||||
|
|||||||
+23
-20
@@ -1,6 +1,3 @@
|
|||||||
// This is your Prisma schema file,
|
|
||||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
||||||
|
|
||||||
generator client {
|
generator client {
|
||||||
provider = "prisma-client-js"
|
provider = "prisma-client-js"
|
||||||
}
|
}
|
||||||
@@ -25,28 +22,28 @@ model User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Order {
|
model Order {
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
title String
|
title String
|
||||||
description String?
|
date DateTime
|
||||||
date DateTime
|
allow_custom Boolean @default(false)
|
||||||
allow_custom Boolean @default(false)
|
status String @default("DRAFT")
|
||||||
status String @default("DRAFT")
|
creator_id String
|
||||||
creator_id String
|
created_at DateTime @default(now())
|
||||||
creator User @relation("CreatedOrders", fields: [creator_id], references: [id])
|
updated_at DateTime @updatedAt
|
||||||
|
description String?
|
||||||
available_items AvailableItem[]
|
available_items AvailableItem[]
|
||||||
submissions Submission[]
|
creator User @relation("CreatedOrders", fields: [creator_id], references: [id])
|
||||||
created_at DateTime @default(now())
|
submissions Submission[]
|
||||||
updated_at DateTime @updatedAt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
model AvailableItem {
|
model AvailableItem {
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
order_id String
|
order_id String
|
||||||
name String
|
name String
|
||||||
|
created_at DateTime @default(now())
|
||||||
|
updated_at DateTime @updatedAt
|
||||||
is_sold_out Boolean @default(false)
|
is_sold_out Boolean @default(false)
|
||||||
order Order @relation(fields: [order_id], references: [id], onDelete: Cascade)
|
order Order @relation(fields: [order_id], references: [id], onDelete: Cascade)
|
||||||
created_at DateTime @default(now())
|
|
||||||
updated_at DateTime @updatedAt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
model Submission {
|
model Submission {
|
||||||
@@ -54,13 +51,13 @@ model Submission {
|
|||||||
order_id String
|
order_id String
|
||||||
user_id String
|
user_id String
|
||||||
bill Int?
|
bill Int?
|
||||||
paid_amount Int?
|
|
||||||
payment_status String @default("BELUM_BAYAR")
|
payment_status String @default("BELUM_BAYAR")
|
||||||
|
created_at DateTime @default(now())
|
||||||
|
updated_at DateTime @updatedAt
|
||||||
|
paid_amount Int?
|
||||||
order Order @relation(fields: [order_id], references: [id], onDelete: Cascade)
|
order Order @relation(fields: [order_id], references: [id], onDelete: Cascade)
|
||||||
user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
|
user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
|
||||||
items SubmissionItem[]
|
items SubmissionItem[]
|
||||||
created_at DateTime @default(now())
|
|
||||||
updated_at DateTime @updatedAt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
model SubmissionItem {
|
model SubmissionItem {
|
||||||
@@ -69,7 +66,13 @@ model SubmissionItem {
|
|||||||
name String
|
name String
|
||||||
qty Int @default(1)
|
qty Int @default(1)
|
||||||
is_custom Boolean @default(false)
|
is_custom Boolean @default(false)
|
||||||
submission Submission @relation(fields: [submission_id], references: [id], onDelete: Cascade)
|
|
||||||
created_at DateTime @default(now())
|
created_at DateTime @default(now())
|
||||||
updated_at DateTime @updatedAt
|
updated_at DateTime @updatedAt
|
||||||
|
submission Submission @relation(fields: [submission_id], references: [id], onDelete: Cascade)
|
||||||
|
}
|
||||||
|
|
||||||
|
model Setting {
|
||||||
|
key String @id
|
||||||
|
value String
|
||||||
|
updated_at DateTime @updatedAt
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -283,6 +283,7 @@ export default function OrderDetailPage() {
|
|||||||
{order.status === 'OPEN' && (
|
{order.status === 'OPEN' && (
|
||||||
<ShareButton
|
<ShareButton
|
||||||
orderId={order.id}
|
orderId={order.id}
|
||||||
|
orderTitle={order.title}
|
||||||
className="h-8.5 text-xs font-bold rounded-xl border-slate-200 dark:border-slate-700 text-slate-700 dark:text-slate-300 gap-1.5"
|
className="h-8.5 text-xs font-bold rounded-xl border-slate-200 dark:border-slate-700 text-slate-700 dark:text-slate-300 gap-1.5"
|
||||||
showText={true}
|
showText={true}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -0,0 +1,132 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { getSettings, updateSettings } from '@/app/actions'
|
||||||
|
import { toast } from 'sonner'
|
||||||
|
import { Loader2, Save, MessageSquare, MessageCircle, AlertCircle } from 'lucide-react'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { Input } from '@/components/ui/input'
|
||||||
|
import { Label } from '@/components/ui/label'
|
||||||
|
import { Textarea } from '@/components/ui/textarea'
|
||||||
|
|
||||||
|
export default function IntegrationsPage() {
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
const [saving, setSaving] = useState(false)
|
||||||
|
const [settings, setSettings] = useState({
|
||||||
|
MATTERMOST_WEBHOOK_URL: '',
|
||||||
|
MATTERMOST_TEMPLATE: '',
|
||||||
|
WHATSAPP_TEMPLATE: ''
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchSettings = async () => {
|
||||||
|
const data = await getSettings()
|
||||||
|
if (data) {
|
||||||
|
setSettings({
|
||||||
|
MATTERMOST_WEBHOOK_URL: data.MATTERMOST_WEBHOOK_URL || '',
|
||||||
|
MATTERMOST_TEMPLATE: data.MATTERMOST_TEMPLATE || 'Halo tim! Lagi ada orderan open nih untuk {title}. Mumpung belum di-checkout, yang mau ikutan nitip bisa langsung cek ke sini ya: {url}',
|
||||||
|
WHATSAPP_TEMPLATE: data.WHATSAPP_TEMPLATE || 'Halo tim! Lagi ada orderan open nih untuk {title}. Mumpung belum di-checkout, yang mau ikutan nitip bisa langsung cek ke sini ya: {url}'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
fetchSettings()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const handleChange = (key: string, value: string) => {
|
||||||
|
setSettings(prev => ({ ...prev, [key]: value }))
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSave = async () => {
|
||||||
|
setSaving(true)
|
||||||
|
const res = await updateSettings(settings)
|
||||||
|
if (res.success) {
|
||||||
|
toast.success('Berhasil Disimpan', {
|
||||||
|
description: 'Pengaturan integrasi berhasil disimpan!',
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
toast.error('Gagal', {
|
||||||
|
description: 'Gagal menyimpan pengaturan',
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
|
}
|
||||||
|
setSaving(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<div className="flex justify-center items-center h-64">
|
||||||
|
<Loader2 className="w-8 h-8 animate-spin text-[#1B2CC1]" />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-6 space-y-8">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-xl font-bold text-slate-900 dark:text-white">Integrasi & Sharing</h2>
|
||||||
|
<p className="text-xs text-slate-500 mt-1">Konfigurasi endpoint API dan template pesan otomatis.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-6 max-w-3xl">
|
||||||
|
{/* Mattermost Section */}
|
||||||
|
<div className="p-5 rounded-2xl border border-slate-200 dark:border-slate-800 bg-slate-50/50 dark:bg-slate-900/50 space-y-4">
|
||||||
|
<div className="flex items-center gap-2 text-indigo-600 dark:text-indigo-400 font-black">
|
||||||
|
<MessageSquare className="w-5 h-5" />
|
||||||
|
<h3>Mattermost Webhook</h3>
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-slate-500">Gunakan URL Incoming Webhook dari Mattermost untuk mengirim broadcast PO baru secara otomatis.</p>
|
||||||
|
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label className="text-xs font-bold uppercase text-slate-700">Webhook URL</Label>
|
||||||
|
<Input
|
||||||
|
value={settings.MATTERMOST_WEBHOOK_URL}
|
||||||
|
onChange={e => handleChange('MATTERMOST_WEBHOOK_URL', e.target.value)}
|
||||||
|
className="h-11 rounded-xl bg-white dark:bg-slate-950"
|
||||||
|
placeholder="https://mattermost.yourdomain.com/hooks/xxx"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label className="text-xs font-bold uppercase text-slate-700">Pesan Template</Label>
|
||||||
|
<Textarea
|
||||||
|
value={settings.MATTERMOST_TEMPLATE}
|
||||||
|
onChange={e => handleChange('MATTERMOST_TEMPLATE', e.target.value)}
|
||||||
|
className="rounded-xl min-h-[100px] bg-white dark:bg-slate-950"
|
||||||
|
placeholder="Template pesan..."
|
||||||
|
/>
|
||||||
|
<p className="text-[10px] text-slate-500 flex items-center gap-1"><AlertCircle className="w-3 h-3"/> Gunakan variabel: {'{title}'}, {'{url}'}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* WhatsApp Section */}
|
||||||
|
<div className="p-5 rounded-2xl border border-slate-200 dark:border-slate-800 bg-slate-50/50 dark:bg-slate-900/50 space-y-4">
|
||||||
|
<div className="flex items-center gap-2 text-emerald-600 dark:text-emerald-400 font-black">
|
||||||
|
<MessageCircle className="w-5 h-5" />
|
||||||
|
<h3>WhatsApp Share Template</h3>
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-slate-500">Atur template teks default saat user menekan tombol share ke WhatsApp.</p>
|
||||||
|
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label className="text-xs font-bold uppercase text-slate-700">Pesan Template</Label>
|
||||||
|
<Textarea
|
||||||
|
value={settings.WHATSAPP_TEMPLATE}
|
||||||
|
onChange={e => handleChange('WHATSAPP_TEMPLATE', e.target.value)}
|
||||||
|
className="rounded-xl min-h-[100px] bg-white dark:bg-slate-950"
|
||||||
|
placeholder="Template pesan..."
|
||||||
|
/>
|
||||||
|
<p className="text-[10px] text-slate-500 flex items-center gap-1"><AlertCircle className="w-3 h-3"/> Gunakan variabel: {'{title}'}, {'{url}'}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="pt-2">
|
||||||
|
<Button onClick={handleSave} disabled={saving} className="bg-[#1B2CC1] hover:bg-[#15229E] text-white rounded-xl h-11 px-8 font-bold shadow-md w-full sm:w-auto">
|
||||||
|
{saving ? <Loader2 className="w-4 h-4 animate-spin mr-2" /> : <Save className="w-4 h-4 mr-2" />}
|
||||||
|
Simpan Konfigurasi
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import Link from 'next/link'
|
||||||
|
import { usePathname } from 'next/navigation'
|
||||||
|
import { cn } from '@/lib/utils'
|
||||||
|
import { User, Share2 } from 'lucide-react'
|
||||||
|
|
||||||
|
export default function SettingsLayout({ children }: { children: React.ReactNode }) {
|
||||||
|
const pathname = usePathname()
|
||||||
|
|
||||||
|
const tabs = [
|
||||||
|
{ name: 'User Management', href: '/settings/users', icon: User },
|
||||||
|
{ name: 'Integrations & Share', href: '/settings/integrations', icon: Share2 },
|
||||||
|
]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6 animate-in fade-in duration-500 pb-12">
|
||||||
|
{/* Settings Navigation Tabs */}
|
||||||
|
<div className="flex flex-col md:flex-row items-start md:items-center gap-4 bg-white dark:bg-slate-900 p-4 rounded-2xl border border-slate-200/80 dark:border-slate-800 shadow-sm overflow-x-auto">
|
||||||
|
<div className="flex items-center bg-slate-100 dark:bg-slate-800/80 p-1 rounded-xl text-xs font-bold w-full md:w-auto">
|
||||||
|
{tabs.map((tab) => {
|
||||||
|
const isActive = pathname === tab.href
|
||||||
|
const Icon = tab.icon
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
key={tab.href}
|
||||||
|
href={tab.href}
|
||||||
|
className={cn(
|
||||||
|
"flex items-center gap-2 px-4 py-2 rounded-lg transition-all duration-200 whitespace-nowrap",
|
||||||
|
isActive
|
||||||
|
? "bg-white dark:bg-slate-900 text-[#1B2CC1] dark:text-blue-400 shadow-sm font-black"
|
||||||
|
: "text-slate-500 hover:text-slate-900 dark:hover:text-white"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Icon className="w-4 h-4" />
|
||||||
|
{tab.name}
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Settings Content */}
|
||||||
|
<div className="bg-white dark:bg-slate-900 rounded-2xl border border-slate-200/80 dark:border-slate-800 shadow-sm overflow-hidden">
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -100,19 +100,18 @@ export default function UsersPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6 animate-in fade-in duration-500 pb-12">
|
<div className="p-6">
|
||||||
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
|
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 mb-6">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-2xl font-black text-slate-900 dark:text-white">Manajemen Pengguna</h1>
|
<h2 className="text-xl font-bold text-slate-900 dark:text-white">Manajemen Pengguna</h2>
|
||||||
<p className="text-sm text-slate-500 mt-1">Kelola data seluruh pengguna TitipIn.</p>
|
<p className="text-xs text-slate-500 mt-1">Kelola data seluruh pengguna TitipIn.</p>
|
||||||
</div>
|
</div>
|
||||||
<Button onClick={() => setIsCreateOpen(true)} className="bg-[#1B2CC1] hover:bg-[#15229E] text-white rounded-xl h-11 px-5 shadow-md">
|
<Button onClick={() => setIsCreateOpen(true)} className="bg-[#1B2CC1] hover:bg-[#15229E] text-white rounded-xl h-10 px-4 shadow-sm text-xs font-bold">
|
||||||
<Plus className="w-4 h-4 mr-2" /> Tambah User
|
<Plus className="w-4 h-4 mr-1.5" /> Tambah User
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Card className="rounded-3xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 overflow-hidden shadow-sm">
|
<div className="overflow-x-auto">
|
||||||
<div className="overflow-x-auto">
|
|
||||||
<table className="w-full text-sm text-left">
|
<table className="w-full text-sm text-left">
|
||||||
<thead className="bg-slate-50/50 dark:bg-slate-800/50 border-b border-slate-100 dark:border-slate-800 text-xs uppercase font-bold text-slate-500">
|
<thead className="bg-slate-50/50 dark:bg-slate-800/50 border-b border-slate-100 dark:border-slate-800 text-xs uppercase font-bold text-slate-500">
|
||||||
<tr>
|
<tr>
|
||||||
@@ -232,7 +231,6 @@ export default function UsersPage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* CREATE MODAL */}
|
{/* CREATE MODAL */}
|
||||||
<Dialog open={isCreateOpen} onOpenChange={setIsCreateOpen}>
|
<Dialog open={isCreateOpen} onOpenChange={setIsCreateOpen}>
|
||||||
@@ -723,3 +723,64 @@ export async function deleteSubmission(submission_id: string, user_id: string) {
|
|||||||
return { success: false, error: 'Gagal membatalkan pesanan' };
|
return { success: false, error: 'Gagal membatalkan pesanan' };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- SETTINGS ACTIONS ---
|
||||||
|
|
||||||
|
export async function getSettings() {
|
||||||
|
const settings = await prisma.setting.findMany()
|
||||||
|
const obj: Record<string, string> = {}
|
||||||
|
settings.forEach(s => {
|
||||||
|
obj[s.key] = s.value
|
||||||
|
})
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateSettings(settings: Record<string, string>) {
|
||||||
|
try {
|
||||||
|
for (const key of Object.keys(settings)) {
|
||||||
|
await prisma.setting.upsert({
|
||||||
|
where: { key },
|
||||||
|
update: { value: settings[key] },
|
||||||
|
create: { key, value: settings[key] }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return { success: true }
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
return { success: false, error: 'Gagal update settings' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- BROADCAST ACTIONS ---
|
||||||
|
|
||||||
|
export async function broadcastToMattermost(orderId: string, orderUrl: string) {
|
||||||
|
try {
|
||||||
|
const order = await prisma.order.findUnique({
|
||||||
|
where: { id: orderId }
|
||||||
|
})
|
||||||
|
if (!order) return { success: false, error: 'Order not found' }
|
||||||
|
|
||||||
|
const settings = await getSettings()
|
||||||
|
const webhookUrl = settings.MATTERMOST_WEBHOOK_URL
|
||||||
|
let template = settings.MATTERMOST_TEMPLATE || 'Halo tim! Lagi ada orderan open nih untuk {title}. Mumpung belum di-checkout, yang mau ikutan nitip bisa langsung cek ke sini ya: {url}'
|
||||||
|
|
||||||
|
if (!webhookUrl) return { success: false, error: 'Webhook URL belum di-setting' }
|
||||||
|
|
||||||
|
const message = template.replace('{title}', order.title).replace('{url}', orderUrl)
|
||||||
|
|
||||||
|
const res = await fetch(webhookUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ text: message })
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(`Mattermost API Error: ${res.statusText}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return { success: true }
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
return { success: false, error: 'Gagal mengirim ke Mattermost' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { Metadata, Viewport } from "next";
|
import type { Metadata, Viewport } from "next";
|
||||||
import { Roboto, Open_Sans } from "next/font/google";
|
import { Roboto, Open_Sans } from "next/font/google";
|
||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
|
import { Toaster } from "@/components/ui/sonner";
|
||||||
|
|
||||||
|
|
||||||
const roboto = Roboto({
|
const roboto = Roboto({
|
||||||
@@ -64,6 +65,7 @@ export default function RootLayout({
|
|||||||
className="min-h-full flex flex-col bg-[#F4F6FB] dark:bg-[#0B0F19] font-sans antialiased"
|
className="min-h-full flex flex-col bg-[#F4F6FB] dark:bg-[#0B0F19] font-sans antialiased"
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
<Toaster position="top-center" />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { usePathname } from 'next/navigation'
|
import { usePathname } from 'next/navigation'
|
||||||
import { Menu, Calendar, Store, ClipboardList, Package, User, FileText, BarChart2 } from 'lucide-react'
|
import { Menu, Calendar, Store, ClipboardList, Package, User, FileText, BarChart2, Settings } from 'lucide-react'
|
||||||
import { buttonVariants } from '@/components/ui/button'
|
import { buttonVariants } from '@/components/ui/button'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
@@ -54,12 +54,13 @@ export function Header({ onMenuClick }: { onMenuClick: () => void }) {
|
|||||||
badge: 'Laporan',
|
badge: 'Laporan',
|
||||||
Icon: BarChart2
|
Icon: BarChart2
|
||||||
}
|
}
|
||||||
case '/users':
|
case '/settings/users':
|
||||||
|
case '/settings/integrations':
|
||||||
return {
|
return {
|
||||||
title: 'Manajemen Pengguna',
|
title: 'Pengaturan Aplikasi',
|
||||||
subtitle: 'Kelola data pengguna, role, dan status aktif.',
|
subtitle: 'Konfigurasi integrasi, role, dan sistem.',
|
||||||
badge: 'Superadmin',
|
badge: 'Superadmin',
|
||||||
Icon: User
|
Icon: Settings
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if (pathname.startsWith('/my-orders/')) {
|
if (pathname.startsWith('/my-orders/')) {
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ export function OrderCard({ order }: { order: any }) {
|
|||||||
|
|
||||||
<ShareButton
|
<ShareButton
|
||||||
orderId={order.id}
|
orderId={order.id}
|
||||||
|
orderTitle={order.title}
|
||||||
className="flex-1 h-9 rounded-xl font-bold text-xs gap-1.5 shadow-sm bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-700 hover:bg-slate-50 dark:hover:bg-slate-800 hover:text-slate-900 transition-all text-slate-700 dark:text-slate-300 px-1"
|
className="flex-1 h-9 rounded-xl font-bold text-xs gap-1.5 shadow-sm bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-700 hover:bg-slate-50 dark:hover:bg-slate-800 hover:text-slate-900 transition-all text-slate-700 dark:text-slate-300 px-1"
|
||||||
showText={true}
|
showText={true}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -2,52 +2,111 @@
|
|||||||
|
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Share2, Check } from 'lucide-react'
|
import { Dialog, DialogContent, DialogTitle, DialogTrigger } from '@/components/ui/dialog'
|
||||||
|
import { Share2, Check, Copy, MessageCircle, MessageSquare, Loader2 } from 'lucide-react'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
|
import { broadcastToMattermost, getSettings } from '@/app/actions'
|
||||||
|
import { toast } from 'sonner'
|
||||||
|
|
||||||
interface ShareButtonProps {
|
interface ShareButtonProps {
|
||||||
orderId: string
|
orderId: string
|
||||||
|
orderTitle?: string
|
||||||
className?: string
|
className?: string
|
||||||
variant?: "link" | "default" | "destructive" | "outline" | "secondary" | "ghost"
|
variant?: "link" | "default" | "destructive" | "outline" | "secondary" | "ghost"
|
||||||
size?: "default" | "sm" | "lg" | "icon"
|
size?: "default" | "sm" | "lg" | "icon"
|
||||||
showText?: boolean
|
showText?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ShareButton({ orderId, className, variant = "outline", size = "sm", showText = true }: ShareButtonProps) {
|
export function ShareButton({ orderId, orderTitle = 'Pesanan', className, variant = "outline", size = "sm", showText = true }: ShareButtonProps) {
|
||||||
const [copied, setCopied] = useState(false)
|
const [copied, setCopied] = useState(false)
|
||||||
|
const [open, setOpen] = useState(false)
|
||||||
|
const [broadcasting, setBroadcasting] = useState(false)
|
||||||
|
|
||||||
const handleShare = () => {
|
const handleCopyLink = () => {
|
||||||
const url = `${window.location.origin}/order/${orderId}`
|
const url = `${window.location.origin}/order/${orderId}`
|
||||||
navigator.clipboard.writeText(url)
|
navigator.clipboard.writeText(url)
|
||||||
setCopied(true)
|
setCopied(true)
|
||||||
setTimeout(() => setCopied(false), 2000)
|
setTimeout(() => setCopied(false), 2000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleShareWA = async () => {
|
||||||
|
const settings = await getSettings()
|
||||||
|
let template = settings.WHATSAPP_TEMPLATE || 'Halo tim! Lagi ada orderan open nih untuk {title}. Mumpung belum di-checkout, yang mau ikutan nitip bisa langsung cek ke sini ya: {url}'
|
||||||
|
|
||||||
|
const url = `${window.location.origin}/order/${orderId}`
|
||||||
|
const text = template.replace('{title}', orderTitle).replace('{url}', url)
|
||||||
|
|
||||||
|
window.open(`https://api.whatsapp.com/send?text=${encodeURIComponent(text)}`, '_blank')
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleBroadcastMattermost = async () => {
|
||||||
|
setBroadcasting(true)
|
||||||
|
const url = `${window.location.origin}/order/${orderId}`
|
||||||
|
const res = await broadcastToMattermost(orderId, url)
|
||||||
|
if (res.success) {
|
||||||
|
toast.success('Broadcast Terkirim!', {
|
||||||
|
description: 'Berhasil mengirim pesan ke Mattermost.',
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
|
setOpen(false)
|
||||||
|
} else {
|
||||||
|
toast.error('Gagal Broadcast', {
|
||||||
|
description: res.error || 'Terjadi kesalahan saat mengirim.',
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
|
}
|
||||||
|
setBroadcasting(false)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<>
|
||||||
variant={variant}
|
<Button
|
||||||
size={size}
|
variant={variant}
|
||||||
onClick={handleShare}
|
size={size}
|
||||||
className={cn(
|
className={cn("transition-all", className)}
|
||||||
"transition-all",
|
title="Bagikan PO"
|
||||||
copied
|
onClick={() => setOpen(true)}
|
||||||
? "bg-emerald-50 text-emerald-600 border-emerald-200 hover:bg-emerald-100 hover:text-emerald-700 dark:bg-emerald-950/30 dark:text-emerald-400 dark:border-emerald-800"
|
>
|
||||||
: "",
|
<Share2 className="w-3.5 h-3.5 shrink-0" />
|
||||||
className
|
{showText && <span className="truncate hidden sm:inline">Bagikan</span>}
|
||||||
)}
|
</Button>
|
||||||
title="Bagikan PO"
|
|
||||||
>
|
<Dialog open={open} onOpenChange={setOpen}>
|
||||||
{copied ? (
|
<DialogContent className="sm:max-w-xs p-6 rounded-3xl border-slate-200/90 dark:border-slate-800">
|
||||||
<>
|
<DialogTitle className="text-xl font-black text-center text-slate-900 dark:text-white mb-2">Bagikan Pesanan</DialogTitle>
|
||||||
<Check className="w-3.5 h-3.5 shrink-0" />
|
<p className="text-sm text-slate-500 text-center mb-4">
|
||||||
{showText && <span className="truncate hidden sm:inline">Tersalin</span>}
|
Pilih metode untuk membagikan PO ini ke teman atau tim Anda.
|
||||||
</>
|
</p>
|
||||||
) : (
|
|
||||||
<>
|
<div className="space-y-3">
|
||||||
<Share2 className="w-3.5 h-3.5 shrink-0" />
|
<Button
|
||||||
{showText && <span className="truncate hidden sm:inline">Bagikan</span>}
|
variant="outline"
|
||||||
</>
|
onClick={handleCopyLink}
|
||||||
)}
|
className="w-full h-11 rounded-xl justify-start font-bold gap-3 text-slate-700 dark:text-slate-300"
|
||||||
</Button>
|
>
|
||||||
|
{copied ? <Check className="w-4 h-4 text-emerald-500" /> : <Copy className="w-4 h-4" />}
|
||||||
|
{copied ? 'Tautan Disalin!' : 'Salin Tautan'}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
onClick={handleShareWA}
|
||||||
|
className="w-full h-11 rounded-xl justify-start font-bold gap-3 bg-[#25D366] hover:bg-[#20bd5a] text-white"
|
||||||
|
>
|
||||||
|
<MessageCircle className="w-4 h-4" />
|
||||||
|
Kirim ke WhatsApp
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
onClick={handleBroadcastMattermost}
|
||||||
|
disabled={broadcasting}
|
||||||
|
className="w-full h-11 rounded-xl justify-start font-bold gap-3 bg-[#0668E1] hover:bg-[#0557bc] text-white"
|
||||||
|
>
|
||||||
|
{broadcasting ? <Loader2 className="w-4 h-4 animate-spin" /> : <MessageSquare className="w-4 h-4" />}
|
||||||
|
{broadcasting ? 'Mengirim...' : 'Broadcast ke Mattermost'}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ import {
|
|||||||
ArrowUpRight,
|
ArrowUpRight,
|
||||||
Info,
|
Info,
|
||||||
BarChart2,
|
BarChart2,
|
||||||
Wallet
|
Wallet,
|
||||||
|
Settings
|
||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
|
|
||||||
const menuItems = [
|
const menuItems = [
|
||||||
@@ -63,7 +64,7 @@ export function Sidebar({ isOpen, onClose }: { isOpen?: boolean; onClose?: () =>
|
|||||||
// Dynamic Menu Items based on role
|
// Dynamic Menu Items based on role
|
||||||
const finalMenuItems = [...menuItems]
|
const finalMenuItems = [...menuItems]
|
||||||
if (userRole === 'superadmin') {
|
if (userRole === 'superadmin') {
|
||||||
finalMenuItems.push({ name: 'User Management', href: '/users', icon: UserCircle, desc: 'Kelola pengguna' })
|
finalMenuItems.push({ name: 'Pengaturan', href: '/settings/users', icon: Settings, desc: 'Konfigurasi aplikasi' })
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useTheme } from "next-themes"
|
||||||
|
import { Toaster as Sonner, type ToasterProps } from "sonner"
|
||||||
|
import { CircleCheckIcon, InfoIcon, TriangleAlertIcon, OctagonXIcon, Loader2Icon } from "lucide-react"
|
||||||
|
|
||||||
|
const Toaster = ({ ...props }: ToasterProps) => {
|
||||||
|
const { theme = "system" } = useTheme()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Sonner
|
||||||
|
theme={theme as ToasterProps["theme"]}
|
||||||
|
className="toaster group"
|
||||||
|
icons={{
|
||||||
|
success: (
|
||||||
|
<CircleCheckIcon className="size-4" />
|
||||||
|
),
|
||||||
|
info: (
|
||||||
|
<InfoIcon className="size-4" />
|
||||||
|
),
|
||||||
|
warning: (
|
||||||
|
<TriangleAlertIcon className="size-4" />
|
||||||
|
),
|
||||||
|
error: (
|
||||||
|
<OctagonXIcon className="size-4" />
|
||||||
|
),
|
||||||
|
loading: (
|
||||||
|
<Loader2Icon className="size-4 animate-spin" />
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
style={
|
||||||
|
{
|
||||||
|
"--normal-bg": "var(--popover)",
|
||||||
|
"--normal-text": "var(--popover-foreground)",
|
||||||
|
"--normal-border": "var(--border)",
|
||||||
|
"--border-radius": "var(--radius)",
|
||||||
|
} as React.CSSProperties
|
||||||
|
}
|
||||||
|
toastOptions={{
|
||||||
|
classNames: {
|
||||||
|
toast: "cn-toast group-[.toaster]:bg-white dark:group-[.toaster]:bg-slate-950 group-[.toaster]:text-slate-950 dark:group-[.toaster]:text-slate-50 group-[.toaster]:border-slate-200 dark:group-[.toaster]:border-slate-800",
|
||||||
|
title: "font-bold",
|
||||||
|
description: "!text-slate-700 dark:!text-slate-300",
|
||||||
|
success: "group-[.toaster]:border-emerald-500 group-[.toaster]:bg-emerald-50 dark:group-[.toaster]:bg-emerald-950/50 group-[.toaster]:text-emerald-900 dark:group-[.toaster]:text-emerald-100 [&_svg]:text-emerald-600 dark:[&_svg]:text-emerald-400 [&_[data-description]]:!text-emerald-700 dark:[&_[data-description]]:!text-emerald-300",
|
||||||
|
error: "group-[.toaster]:border-red-500 group-[.toaster]:bg-red-50 dark:group-[.toaster]:bg-red-950/50 group-[.toaster]:text-red-900 dark:group-[.toaster]:text-red-100 [&_svg]:text-red-600 dark:[&_svg]:text-red-400 [&_[data-description]]:!text-red-700 dark:[&_[data-description]]:!text-red-300",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Toaster }
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
import { cn } from "cn"
|
||||||
|
|
||||||
|
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
||||||
|
return (
|
||||||
|
<textarea
|
||||||
|
data-slot="textarea"
|
||||||
|
className={cn(
|
||||||
|
"flex field-sizing-content min-h-16 w-full rounded-lg border border-input bg-transparent px-2.5 py-2 text-base transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Textarea }
|
||||||
@@ -2714,6 +2714,11 @@ clsx@^2.1.1:
|
|||||||
resolved "https://registry.yarnpkg.com/clsx/-/clsx-2.1.1.tgz#eed397c9fd8bd882bfb18deab7102049a2f32999"
|
resolved "https://registry.yarnpkg.com/clsx/-/clsx-2.1.1.tgz#eed397c9fd8bd882bfb18deab7102049a2f32999"
|
||||||
integrity sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==
|
integrity sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==
|
||||||
|
|
||||||
|
cn@^0.2.6:
|
||||||
|
version "0.2.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/cn/-/cn-0.2.6.tgz#16e7a9f1746efcb104fbea027806c17810b5ee6a"
|
||||||
|
integrity sha512-+i4L0zUGgRcEnhsxueVrP7iBGxBx5iD0WOTYg1MwFEu2ZyCmH5Ov2V1cul2Ht5UchRQQgftCf4be/RxspuW6QQ==
|
||||||
|
|
||||||
code-block-writer@^13.0.3:
|
code-block-writer@^13.0.3:
|
||||||
version "13.0.3"
|
version "13.0.3"
|
||||||
resolved "https://registry.yarnpkg.com/code-block-writer/-/code-block-writer-13.0.3.tgz#90f8a84763a5012da7af61319dd638655ae90b5b"
|
resolved "https://registry.yarnpkg.com/code-block-writer/-/code-block-writer-13.0.3.tgz#90f8a84763a5012da7af61319dd638655ae90b5b"
|
||||||
@@ -4923,6 +4928,11 @@ negotiator@^1.0.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
content-type "^2.1.0"
|
content-type "^2.1.0"
|
||||||
|
|
||||||
|
next-themes@^0.4.6:
|
||||||
|
version "0.4.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/next-themes/-/next-themes-0.4.6.tgz#8d7e92d03b8fea6582892a50a928c9b23502e8b6"
|
||||||
|
integrity sha512-pZvgD5L0IEvX5/9GWyHMf3m8BKiVQwsCMHfoFosXtXBMnaS0ZnIJ9ST4b4NqLVKDEm8QBxoNNGNaBv2JNF6XNA==
|
||||||
|
|
||||||
next@16.3.3:
|
next@16.3.3:
|
||||||
version "16.3.3"
|
version "16.3.3"
|
||||||
resolved "https://registry.yarnpkg.com/next/-/next-16.3.3.tgz#dc062aa903c34e2af41a0ffa2ad99c9369447d07"
|
resolved "https://registry.yarnpkg.com/next/-/next-16.3.3.tgz#dc062aa903c34e2af41a0ffa2ad99c9369447d07"
|
||||||
@@ -5906,6 +5916,11 @@ socks@^2.8.8:
|
|||||||
ip-address "^10.1.1"
|
ip-address "^10.1.1"
|
||||||
smart-buffer "^4.2.0"
|
smart-buffer "^4.2.0"
|
||||||
|
|
||||||
|
sonner@^2.0.8:
|
||||||
|
version "2.0.8"
|
||||||
|
resolved "https://registry.yarnpkg.com/sonner/-/sonner-2.0.8.tgz#dbfa02bb4eb0924616800a4594e9a455a9a195ac"
|
||||||
|
integrity sha512-UM/ByIoFra8yzV75n1o0Puu0bw5U/9UNnDacrJNspekBewIfsQ3D6ez1nvlWpt7aTsO6rujQtifBpycwIivqlg==
|
||||||
|
|
||||||
source-list-map@^2.0.0:
|
source-list-map@^2.0.0:
|
||||||
version "2.0.1"
|
version "2.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.1.tgz#3993bd873bfc48479cca9ea3a547835c7c154b34"
|
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.1.tgz#3993bd873bfc48479cca9ea3a547835c7c154b34"
|
||||||
|
|||||||
Reference in New Issue
Block a user