Преглед изворни кода

fix shared link layout to use correct template

Bernt Christian Egeland пре 9 месеци
родитељ
комит
0269eb2194

+ 97 - 38
src/app/(public)/share/invoice/[orgId]/[token]/invoice-view.tsx

@@ -106,6 +106,8 @@ export function InvoiceView({
   dateFormat,
   timezone,
   termsOfSaleUrl,
+  primaryColor = '#d97706',
+  headerStyle = 'standard',
 }: {
   record: InvoiceRecord
   workshop: { name: string; address: string; phone: string; email: string }
@@ -121,6 +123,8 @@ export function InvoiceView({
   dateFormat?: string
   timezone?: string
   termsOfSaleUrl?: string
+  primaryColor?: string
+  headerStyle?: string
 }) {
   const [carouselIndex, setCarouselIndex] = useState<number | null>(null)
   const [paymentAmount, setPaymentAmount] = useState('')
@@ -294,7 +298,8 @@ export function InvoiceView({
         <h1 className="text-2xl font-bold">Invoice</h1>
         <button
           onClick={handleDownloadPDF}
-          className="inline-flex items-center gap-2 rounded-lg bg-amber-600 px-4 py-2 text-sm font-medium text-white hover:bg-amber-700"
+          className="inline-flex items-center gap-2 rounded-lg px-4 py-2 text-sm font-medium text-white"
+          style={{ backgroundColor: primaryColor }}
         >
           <Download className="h-4 w-4" />
           Download PDF
@@ -454,40 +459,93 @@ export function InvoiceView({
 
       <div className="rounded-xl border bg-white p-6 shadow-sm sm:p-8 dark:bg-gray-900">
         {/* Header */}
-        <div className="flex flex-col gap-4 border-b-2 border-amber-500 pb-6 sm:flex-row sm:items-start sm:justify-between">
-          <div>
-            {showLogo && logoUrl && (
-              <img
-                src={logoUrl}
-                alt={shopName}
-                className="mb-2 max-h-16 max-w-[180px] object-contain object-left"
-              />
-            )}
-            {showCompanyName && (
-              <h2 className="text-xl font-bold text-amber-600 sm:text-2xl">{shopName}</h2>
-            )}
-            {workshop.address && <p className="mt-1 text-sm text-gray-500">{workshop.address}</p>}
-            {workshop.phone && <p className="text-sm text-gray-500">Tel: {workshop.phone}</p>}
-            {workshop.email && <p className="text-sm text-gray-500">{workshop.email}</p>}
-          </div>
-          <div className="sm:text-right">
-            {showTorqvoiceBranding && (
-              <div className="mb-2 inline-flex items-center gap-1.5 rounded-full bg-gray-100 px-2.5 py-1 dark:bg-gray-800">
-                <img src="/torqvoice_app_logo.png" alt="Torqvoice" className="h-4 w-4" />
-                <span className="text-xs font-semibold text-gray-500 dark:text-gray-400">Torqvoice</span>
+        {headerStyle === 'modern' ? (
+          <>
+            <div className="rounded-lg p-6 text-center text-white" style={{ backgroundColor: primaryColor }}>
+              {showLogo && logoUrl && (
+                <img
+                  src={logoUrl}
+                  alt={shopName}
+                  className="mx-auto mb-2 max-h-16 max-w-[180px] object-contain"
+                />
+              )}
+              {showCompanyName && (
+                <h2 className="text-xl font-bold sm:text-2xl">{shopName}</h2>
+              )}
+              {workshop.address && <p className="mt-1 text-sm opacity-80">{workshop.address}</p>}
+              <div className="mt-1 flex flex-wrap justify-center gap-3 text-sm opacity-70">
+                {workshop.phone && <span>Tel: {workshop.phone}</span>}
+                {workshop.email && <span>{workshop.email}</span>}
               </div>
-            )}
-            <h3 className="text-xl font-bold">INVOICE</h3>
-            <p className="mt-1 text-sm text-gray-500">{invoiceNum}</p>
-            <p className="text-sm text-gray-500">{serviceDate}</p>
+            </div>
+            <div className="mt-4 flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
+              <h3 className="text-xl font-bold">INVOICE</h3>
+              <div className="flex gap-3 text-sm text-gray-500">
+                <span>{invoiceNum}</span>
+                <span>{serviceDate}</span>
+              </div>
+            </div>
+          </>
+        ) : headerStyle === 'compact' ? (
+          <div className="flex flex-col gap-4 border-b pb-6 sm:flex-row sm:items-center sm:justify-between" style={{ borderColor: '#e5e7eb' }}>
+            <div className="flex items-center gap-3">
+              {showLogo && logoUrl && (
+                <img
+                  src={logoUrl}
+                  alt={shopName}
+                  className="h-12 w-12 rounded object-contain"
+                />
+              )}
+              <div>
+                {showCompanyName && (
+                  <h2 className="text-lg font-bold" style={{ color: primaryColor }}>{shopName}</h2>
+                )}
+                {workshop.address && <p className="text-sm text-gray-500">{workshop.address}</p>}
+              </div>
+            </div>
+            <div className="sm:text-right">
+              <h3 className="text-lg font-bold">INVOICE</h3>
+              <p className="text-sm text-gray-500">{invoiceNum}</p>
+              <p className="text-sm text-gray-500">{serviceDate}</p>
+            </div>
           </div>
-        </div>
+        ) : (
+          /* Standard */
+          <div className="flex flex-col gap-4 border-b-2 pb-6 sm:flex-row sm:items-start sm:justify-between" style={{ borderColor: primaryColor }}>
+            <div>
+              {showLogo && logoUrl && (
+                <img
+                  src={logoUrl}
+                  alt={shopName}
+                  className="mb-2 max-h-16 max-w-[180px] object-contain object-left"
+                />
+              )}
+              {showCompanyName && (
+                <h2 className="text-xl font-bold sm:text-2xl" style={{ color: primaryColor }}>{shopName}</h2>
+              )}
+              {workshop.address && <p className="mt-1 text-sm text-gray-500">{workshop.address}</p>}
+              {workshop.phone && <p className="text-sm text-gray-500">Tel: {workshop.phone}</p>}
+              {workshop.email && <p className="text-sm text-gray-500">{workshop.email}</p>}
+            </div>
+            <div className="sm:text-right">
+              {showTorqvoiceBranding && (
+                <div className="mb-2 inline-flex items-center gap-1.5 rounded-full bg-gray-100 px-2.5 py-1 dark:bg-gray-800">
+                  <img src="/torqvoice_app_logo.png" alt="Torqvoice" className="h-4 w-4" />
+                  <span className="text-xs font-semibold text-gray-500 dark:text-gray-400">Torqvoice</span>
+                </div>
+              )}
+              <h3 className="text-xl font-bold" style={{ color: primaryColor }}>INVOICE</h3>
+              <p className="mt-1 text-sm text-gray-500">{invoiceNum}</p>
+              <p className="text-sm text-gray-500">{serviceDate}</p>
+            </div>
+          </div>
+        )}
 
         {/* Info Boxes */}
         <div className="mt-6 grid grid-cols-1 gap-4 sm:grid-cols-3">
           {record.vehicle.customer && (
             <div className="rounded-lg bg-gray-50 p-4 dark:bg-gray-800">
-              <p className="mb-1 text-xs font-bold uppercase text-amber-600">Bill To</p>
+              <p className="mb-1 text-xs font-bold uppercase" style={{ color: primaryColor }}>Bill To</p>
               <p className="font-semibold">{record.vehicle.customer.name}</p>
               {record.vehicle.customer.company && (
                 <p className="text-sm">{record.vehicle.customer.company}</p>
@@ -504,7 +562,7 @@ export function InvoiceView({
             </div>
           )}
           <div className="rounded-lg bg-gray-50 p-4 dark:bg-gray-800">
-            <p className="mb-1 text-xs font-bold uppercase text-amber-600">Vehicle</p>
+            <p className="mb-1 text-xs font-bold uppercase" style={{ color: primaryColor }}>Vehicle</p>
             <p className="font-semibold">{vehicleName}</p>
             {record.vehicle.vin && (
               <p className="text-sm text-gray-500">VIN: {record.vehicle.vin}</p>
@@ -514,7 +572,7 @@ export function InvoiceView({
             )}
           </div>
           <div className="rounded-lg bg-gray-50 p-4 dark:bg-gray-800">
-            <p className="mb-1 text-xs font-bold uppercase text-amber-600">Service</p>
+            <p className="mb-1 text-xs font-bold uppercase" style={{ color: primaryColor }}>Service</p>
             <p className="font-semibold">{record.title}</p>
             <p className="text-sm text-gray-500">Type: {record.type}</p>
             {record.techName && <p className="text-sm text-gray-500">Tech: {record.techName}</p>}
@@ -528,7 +586,7 @@ export function InvoiceView({
             <div className="-mx-6 overflow-x-auto px-6 sm:mx-0 sm:px-0">
               <table className="w-full min-w-125 text-sm">
                 <thead>
-                  <tr className="border-b bg-amber-50 text-left dark:bg-amber-900/20">
+                  <tr className="border-b text-left" style={{ backgroundColor: `${primaryColor}15` }}>
                     <th className="p-2 font-medium">Part #</th>
                     <th className="p-2 font-medium">Description</th>
                     <th className="p-2 text-right font-medium">Qty</th>
@@ -563,7 +621,7 @@ export function InvoiceView({
             <div className="-mx-6 overflow-x-auto px-6 sm:mx-0 sm:px-0">
               <table className="w-full min-w-112.5 text-sm">
                 <thead>
-                  <tr className="border-b bg-amber-50 text-left dark:bg-amber-900/20">
+                  <tr className="border-b text-left" style={{ backgroundColor: `${primaryColor}15` }}>
                     <th className="p-2 font-medium">Description</th>
                     <th className="p-2 text-right font-medium">Hours</th>
                     <th className="p-2 text-right font-medium">Rate</th>
@@ -612,13 +670,14 @@ export function InvoiceView({
             </div>
           )}
           <div
-            className={`border-t pt-2 ${totalPaid > 0 ? 'border-gray-200' : 'border-amber-500'}`}
+            className={`border-t pt-2 ${totalPaid > 0 ? 'border-gray-200' : ''}`}
+            style={totalPaid > 0 ? undefined : { borderColor: primaryColor }}
           >
             <div
               className={`flex justify-between ${totalPaid > 0 ? 'text-sm text-gray-500' : 'text-lg font-bold'}`}
             >
               <span>Total</span>
-              <span className={totalPaid > 0 ? '' : 'text-amber-600'}>
+              <span style={totalPaid > 0 ? undefined : { color: primaryColor }}>
                 {formatCurrency(displayTotal, currencyCode)}
               </span>
             </div>
@@ -664,8 +723,8 @@ export function InvoiceView({
           (invoiceSettings.bankAccount ||
             invoiceSettings.orgNumber ||
             invoiceSettings.paymentTerms) && (
-            <div className="mt-6 rounded-lg border border-amber-200 bg-amber-50/50 p-4 dark:border-amber-800 dark:bg-amber-900/10">
-              <p className="mb-2 text-xs font-bold uppercase text-amber-600">Payment Information</p>
+            <div className="mt-6 rounded-lg border p-4" style={{ borderColor: `${primaryColor}40`, backgroundColor: `${primaryColor}08` }}>
+              <p className="mb-2 text-xs font-bold uppercase" style={{ color: primaryColor }}>Payment Information</p>
               <div className="grid grid-cols-1 gap-3 text-sm sm:grid-cols-2">
                 {invoiceSettings.showBankAccount && invoiceSettings.bankAccount && (
                   <div>
@@ -810,7 +869,7 @@ export function InvoiceView({
         {/* Notes */}
         {record.invoiceNotes && (
           <div className="mt-6 rounded-lg bg-gray-50 p-4 dark:bg-gray-800">
-            <p className="mb-1 text-xs font-bold uppercase text-amber-600">Notes</p>
+            <p className="mb-1 text-xs font-bold uppercase" style={{ color: primaryColor }}>Notes</p>
             <div
               className="notes-content text-sm text-gray-600 dark:text-gray-400"
               dangerouslySetInnerHTML={{ __html: sanitizeHtml(record.invoiceNotes) }}
@@ -819,7 +878,7 @@ export function InvoiceView({
         )}
         {record.diagnosticNotes && (
           <div className="mt-4 rounded-lg bg-gray-50 p-4 dark:bg-gray-800">
-            <p className="mb-1 text-xs font-bold uppercase text-amber-600">Diagnostic Notes</p>
+            <p className="mb-1 text-xs font-bold uppercase" style={{ color: primaryColor }}>Diagnostic Notes</p>
             <div
               className="notes-content text-sm text-gray-600 dark:text-gray-400"
               dangerouslySetInnerHTML={{ __html: sanitizeHtml(record.diagnosticNotes) }}

+ 4 - 0
src/app/(public)/share/invoice/[orgId]/[token]/page.tsx

@@ -81,6 +81,8 @@ export default async function PublicInvoicePage({
             "invoice.dueDays",
             "invoice.showLogo",
             "invoice.showCompanyName",
+            "invoice.primaryColor",
+            "invoice.headerStyle",
             "payment.providersEnabled",
             "payment.termsOfSale",
             "payment.termsOfSaleUrl",
@@ -164,6 +166,8 @@ export default async function PublicInvoicePage({
       dateFormat={settingsMap["workshop.dateFormat"] || undefined}
       timezone={settingsMap["workshop.timezone"] || undefined}
       termsOfSaleUrl={termsOfSaleUrl}
+      primaryColor={settingsMap["invoice.primaryColor"] || "#d97706"}
+      headerStyle={settingsMap["invoice.headerStyle"] || "standard"}
     />
   );
 }

+ 103 - 34
src/app/(public)/share/quote/[orgId]/[token]/quote-view.tsx

@@ -128,42 +128,111 @@ export function QuoteView({
 
       <div className="rounded-xl border bg-white p-6 shadow-sm sm:p-8 dark:bg-gray-900">
         {/* Header */}
-        <div className="flex flex-col gap-4 border-b-2 pb-6 sm:flex-row sm:items-start sm:justify-between" style={{ borderColor: primaryColor }}>
-          <div>
-            <img
-              src={logoUrl || "/torqvoice_app_logo.png"}
-              alt={shopName}
-              className="mb-2 max-h-16 max-w-[180px] object-contain object-left"
-            />
-            <h2 className="text-xl font-bold sm:text-2xl" style={{ color: primaryColor }}>{shopName}</h2>
-            {workshop.address && <p className="mt-1 text-sm text-gray-500">{workshop.address}</p>}
-            {workshop.phone && <p className="text-sm text-gray-500">Tel: {workshop.phone}</p>}
-            {workshop.email && <p className="text-sm text-gray-500">{workshop.email}</p>}
-          </div>
-          <div className="sm:text-right">
-            {showTorqvoiceBranding && (
-              <div className="mb-2 inline-flex items-center gap-1.5 rounded-full bg-gray-100 px-2.5 py-1 dark:bg-gray-800">
-                <img src="/torqvoice_app_logo.png" alt="Torqvoice" className="h-4 w-4" />
-                <span className="text-xs font-semibold text-gray-500 dark:text-gray-400">Torqvoice</span>
+        {headerStyle === "modern" ? (
+          <>
+            <div className="rounded-lg p-6 text-center text-white" style={{ backgroundColor: primaryColor }}>
+              <img
+                src={logoUrl || "/torqvoice_app_logo.png"}
+                alt={shopName}
+                className="mx-auto mb-2 max-h-16 max-w-[180px] object-contain"
+              />
+              <h2 className="text-xl font-bold sm:text-2xl">{shopName}</h2>
+              {workshop.address && <p className="mt-1 text-sm opacity-80">{workshop.address}</p>}
+              <div className="mt-1 flex flex-wrap justify-center gap-3 text-sm opacity-70">
+                {workshop.phone && <span>Tel: {workshop.phone}</span>}
+                {workshop.email && <span>{workshop.email}</span>}
+              </div>
+            </div>
+            <div className="mt-4 flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
+              <div className="flex items-center gap-3">
+                <h3 className="text-xl font-bold">QUOTE</h3>
+                <span className={`inline-block rounded-full px-2.5 py-0.5 text-xs font-semibold capitalize ${
+                  quote.status === "accepted"
+                    ? "bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400"
+                    : quote.status === "rejected"
+                    ? "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400"
+                    : "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400"
+                }`}>
+                  {statusLabels[quote.status] || quote.status}
+                </span>
               </div>
-            )}
-            <h3 className="text-xl font-bold">QUOTE</h3>
-            <p className="mt-1 text-sm text-gray-500">{quoteNum}</p>
-            <p className="text-sm text-gray-500">{createdDate}</p>
-            {validUntilDate && (
-              <p className="text-sm text-gray-500">Valid until: {validUntilDate}</p>
-            )}
-            <span className={`mt-2 inline-block rounded-full px-2.5 py-0.5 text-xs font-semibold capitalize ${
-              quote.status === "accepted"
-                ? "bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400"
-                : quote.status === "rejected"
-                ? "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400"
-                : "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400"
-            }`}>
-              {statusLabels[quote.status] || quote.status}
-            </span>
+              <div className="flex gap-3 text-sm text-gray-500">
+                <span>{quoteNum}</span>
+                <span>{createdDate}</span>
+                {validUntilDate && <span>Valid until: {validUntilDate}</span>}
+              </div>
+            </div>
+          </>
+        ) : headerStyle === "compact" ? (
+          <div className="flex flex-col gap-4 border-b pb-6 sm:flex-row sm:items-center sm:justify-between" style={{ borderColor: "#e5e7eb" }}>
+            <div className="flex items-center gap-3">
+              <img
+                src={logoUrl || "/torqvoice_app_logo.png"}
+                alt={shopName}
+                className="h-12 w-12 rounded object-contain"
+              />
+              <div>
+                <h2 className="text-lg font-bold" style={{ color: primaryColor }}>{shopName}</h2>
+                {workshop.address && <p className="text-sm text-gray-500">{workshop.address}</p>}
+              </div>
+            </div>
+            <div className="sm:text-right">
+              <h3 className="text-lg font-bold">QUOTE</h3>
+              <p className="text-sm text-gray-500">{quoteNum}</p>
+              <p className="text-sm text-gray-500">{createdDate}</p>
+              {validUntilDate && (
+                <p className="text-sm text-gray-500">Valid until: {validUntilDate}</p>
+              )}
+              <span className={`mt-1 inline-block rounded-full px-2.5 py-0.5 text-xs font-semibold capitalize ${
+                quote.status === "accepted"
+                  ? "bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400"
+                  : quote.status === "rejected"
+                  ? "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400"
+                  : "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400"
+              }`}>
+                {statusLabels[quote.status] || quote.status}
+              </span>
+            </div>
           </div>
-        </div>
+        ) : (
+          /* Standard */
+          <div className="flex flex-col gap-4 border-b-2 pb-6 sm:flex-row sm:items-start sm:justify-between" style={{ borderColor: primaryColor }}>
+            <div>
+              <img
+                src={logoUrl || "/torqvoice_app_logo.png"}
+                alt={shopName}
+                className="mb-2 max-h-16 max-w-[180px] object-contain object-left"
+              />
+              <h2 className="text-xl font-bold sm:text-2xl" style={{ color: primaryColor }}>{shopName}</h2>
+              {workshop.address && <p className="mt-1 text-sm text-gray-500">{workshop.address}</p>}
+              {workshop.phone && <p className="text-sm text-gray-500">Tel: {workshop.phone}</p>}
+              {workshop.email && <p className="text-sm text-gray-500">{workshop.email}</p>}
+            </div>
+            <div className="sm:text-right">
+              {showTorqvoiceBranding && (
+                <div className="mb-2 inline-flex items-center gap-1.5 rounded-full bg-gray-100 px-2.5 py-1 dark:bg-gray-800">
+                  <img src="/torqvoice_app_logo.png" alt="Torqvoice" className="h-4 w-4" />
+                  <span className="text-xs font-semibold text-gray-500 dark:text-gray-400">Torqvoice</span>
+                </div>
+              )}
+              <h3 className="text-xl font-bold" style={{ color: primaryColor }}>QUOTE</h3>
+              <p className="mt-1 text-sm text-gray-500">{quoteNum}</p>
+              <p className="text-sm text-gray-500">{createdDate}</p>
+              {validUntilDate && (
+                <p className="text-sm text-gray-500">Valid until: {validUntilDate}</p>
+              )}
+              <span className={`mt-2 inline-block rounded-full px-2.5 py-0.5 text-xs font-semibold capitalize ${
+                quote.status === "accepted"
+                  ? "bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400"
+                  : quote.status === "rejected"
+                  ? "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400"
+                  : "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400"
+              }`}>
+                {statusLabels[quote.status] || quote.status}
+              </span>
+            </div>
+          </div>
+        )}
 
         {/* Info Boxes */}
         <div className="mt-6 grid grid-cols-1 gap-4 sm:grid-cols-3">