import LandlordLayout from "@/Layouts/LandlordLayout"; import { Link, useForm } from "@inertiajs/react"; import { Button } from "@/Components/ui/button"; import { Input } from "@/Components/ui/input"; import { Label } from "@/Components/ui/label"; import { Card } from "@/Components/ui/card"; import { ArrowLeft, LayoutDashboard } from "lucide-react"; import { FormEventHandler, useState } from "react"; import { toast } from "sonner"; import { generateLightestColor } from "@/utils/colorUtils"; interface Tenant { id: string; name: string; branding?: { logo_path?: string; primary_color?: string; text_color?: string; }; } interface BrandingProps { tenant: Tenant; logo_url?: string; } export default function Branding({ tenant, logo_url }: BrandingProps) { const { data, setData, post, processing, errors } = useForm({ logo: null as File | null, primary_color: tenant.branding?.primary_color || '#01ab83', }); const [logoPreview, setLogoPreview] = useState(logo_url || null); const handleLogoChange = (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (file) { setData('logo', file); const reader = new FileReader(); reader.onloadend = () => { setLogoPreview(reader.result as string); }; reader.readAsDataURL(file); } }; const submit: FormEventHandler = (e) => { e.preventDefault(); post(route('landlord.tenants.branding.update', tenant.id), { onSuccess: () => { toast.success('樣式設定已更新'); }, onError: () => { toast.error('更新失敗,請檢查輸入'); }, }); }; return (
{/* Header */}

客戶樣式管理

{tenant.name}

{/* Branding Form */}
{/* Logo Upload */}

上傳客戶專屬 Logo,建議尺寸 200×200 px,最大 2MB

{errors.logo && (

{errors.logo}

)} {logoPreview && (

預覽:

Logo Preview
)}
{/* Primary Color */}

設定客戶後台的主要品牌色(按鈕、連結等)

setData('primary_color', e.target.value)} className="w-16 h-10 cursor-pointer" /> setData('primary_color', e.target.value)} pattern="^#[0-9A-Fa-f]{6}$" className="w-32" placeholder="#01ab83" />
{errors.primary_color && (

{errors.primary_color}

)} {/* Preview */}

預覽效果:

{/* 按鈕預覽 */}

按鈕

{/* 側邊欄選中狀態預覽 */}

側邊欄選中狀態

儀表板
{/* Submit Button */}
); }