import { Form, Head } from '@inertiajs/react'; import { Plus, Trash2 } from 'lucide-react'; import { useState } from 'react'; import { toast } from 'sonner'; import { FileUpload } from '@/components/inputs'; import { InputError } from '@/components/ui'; import { PhoneNumberInput } from '@/components/inputs'; import { RupiahInput } from '@/components/inputs'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'; import { Separator } from '@/components/ui/separator'; import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { Textarea } from '@/components/ui/textarea'; import { cn } from '@/lib/utils'; import { updateHomepage, updateHr, updateMarketplace, updateSocialMedia, updateSystem, } from '@/routes/admin/settings'; type MarketplaceFeeRule = { base: string; type: string; value: number; }; type Props = { system: { app_name: string; about_app: string; address: string; email: string; phone: string; }; homepage: { hero_image_url: string; hero_image_key: string; about_image_url: string; about_image_key: string; gallery_images: string[]; gallery_image_keys: string[]; }; socialMedia: { instagram_url: string; facebook_url: string; tiktok_url: string; }; marketplace: { tiktok_shop: Record; shopee: Record; }; hr: { scheduled_check_in_time: string; scheduled_check_out_time: string; late_penalty_amount: number; absent_penalty_amount: number; }; }; type HomepageSettingsTabProps = { homepage: Props['homepage']; }; function HomepageSettingsTab({ homepage }: HomepageSettingsTabProps) { const [heroKey, setHeroKey] = useState( homepage.hero_image_key ?? null, ); const [heroUploading, setHeroUploading] = useState(false); const [aboutKey, setAboutKey] = useState( homepage.about_image_key ?? null, ); const [aboutUploading, setAboutUploading] = useState(false); const [galleryKeys, setGalleryKeys] = useState( homepage.gallery_image_keys ?? [], ); const [galleryUploading, setGalleryUploading] = useState(false); function addGalleryImage() { setGalleryKeys((prev) => [...prev, '']); } function removeGalleryImage(index: number) { setGalleryKeys((prev) => prev.filter((_, i) => i !== index)); } function updateGalleryKey(index: number, key: string | null) { setGalleryKeys((prev) => prev.map((k, i) => (i === index ? (key ?? '') : k)), ); } return (
{ toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); }} > {({ processing, errors }) => (
Homepage {galleryKeys.map((key, index) => ( ))}
{galleryKeys.map((key, index) => (
updateGalleryKey( index, k, ) } folder="homepage/gallery" existingUrl={ homepage.gallery_images[ index ] ?? null } onUploadingChange={ setGalleryUploading } />
))} {galleryKeys.length === 0 && (

Belum ada gambar. Klik "Tambah" untuk menambahkan gambar galeri.

)}
)}
); } const sidebarTabs = [ { key: 'sistem', label: 'Sistem' }, { key: 'homepage', label: 'Homepage' }, { key: 'media-sosial', label: 'Media Sosial' }, { key: 'marketplace', label: 'Marketplace' }, { key: 'hr', label: 'HR' }, ] as const; type TabKey = (typeof sidebarTabs)[number]['key']; function MarketplaceVariableInput({ label, prefix, data, }: { label: string; prefix: string; data: MarketplaceFeeRule; }) { const [type, setType] = useState(data.type); return (
{label}
Dasar
Tipe
Nilai {type === 'flat' ? ( ) : ( )}
); } function MarketplaceColumnHeader() { return (
Biaya
Dasar Tipe Nilai
); } function MarketplaceCard({ title, variables, }: { title: string; variables: { label: string; prefix: string; data: MarketplaceFeeRule }[]; }) { return ( {title} {variables.map((v) => ( ))} ); } export default function AdminSettings({ system, homepage, socialMedia, marketplace, hr, }: Props) { const [activeTab, setActiveTab] = useState('sistem'); const [marketplaceTab, setMarketplaceTab] = useState< 'tiktok-shop' | 'shopee' >('tiktok-shop'); const tiktokShopVariables = [ { label: 'Komisi Platform', prefix: 'tiktok_shop_platform_commission', data: marketplace.tiktok_shop.platform_commission, }, { label: 'Layanan Logistik', prefix: 'tiktok_shop_logistics_service_fee', data: marketplace.tiktok_shop.logistics_service_fee, }, { label: 'Komisi Dinamis', prefix: 'tiktok_shop_dynamic_commission', data: marketplace.tiktok_shop.dynamic_commission, }, { label: 'Pemrosesan Pesanan', prefix: 'tiktok_shop_order_processing_fee', data: marketplace.tiktok_shop.order_processing_fee, }, { label: 'Affiliate', prefix: 'tiktok_shop_affiliate', data: marketplace.tiktok_shop.affiliate, }, { label: 'Layanan PO', prefix: 'tiktok_shop_pre_order_service_fee', data: marketplace.tiktok_shop.pre_order_service_fee, }, ]; const shopeeVariables = [ { label: 'Biaya Administrasi', prefix: 'shopee_admin_fee', data: marketplace.shopee.admin_fee, }, { label: 'Biaya Program', prefix: 'shopee_program_fee', data: marketplace.shopee.program_fee, }, { label: 'Hemat Biaya Kirim', prefix: 'shopee_shipping_savings', data: marketplace.shopee.shipping_savings, }, { label: 'Premi', prefix: 'shopee_premium', data: marketplace.shopee.premium, }, { label: 'Biaya Layanan', prefix: 'shopee_service_fee', data: marketplace.shopee.service_fee, }, { label: 'Biaya Proses Pesanan', prefix: 'shopee_order_processing_fee', data: marketplace.shopee.order_processing_fee, }, { label: 'Biaya Komisi AMS', prefix: 'shopee_ams_commission_fee', data: marketplace.shopee.ams_commission_fee, }, { label: 'PO', prefix: 'shopee_pre_order', data: marketplace.shopee.pre_order, }, { label: 'Live Extra', prefix: 'shopee_live_extra', data: marketplace.shopee.live_extra, }, ]; return ( <>

Pengaturan

{activeTab === 'sistem' && (
{ toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); }} > {({ processing, errors }) => (
Sistem