Bernt Christian Egeland 9 miesięcy temu
rodzic
commit
44407d09a9

+ 1 - 1
src/app/(authenticated)/settings/payment/page.tsx

@@ -26,5 +26,5 @@ export default async function PaymentSettingsPage() {
   const result = await getSettings();
   const settings = result.success && result.data ? result.data : {};
 
-  return <PaymentSettings settings={settings} />;
+  return <PaymentSettings settings={settings} orgId={data.organizationId} />;
 }

+ 66 - 3
src/app/(authenticated)/settings/payment/payment-settings.tsx

@@ -1,10 +1,11 @@
 "use client";
 
-import { useState } from "react";
+import { useState, useEffect } from "react";
 import { useRouter } from "next/navigation";
 import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
 import { Input } from "@/components/ui/input";
 import { Label } from "@/components/ui/label";
+import { Textarea } from "@/components/ui/textarea";
 import { Button } from "@/components/ui/button";
 import { Separator } from "@/components/ui/separator";
 import { Switch } from "@/components/ui/switch";
@@ -14,13 +15,15 @@ import { SETTING_KEYS } from "@/features/settings/Schema/settingsSchema";
 import { Banknote, CreditCard, Loader2, Save, Copy, Check } from "lucide-react";
 import { ReadOnlyBanner, SaveButton, ReadOnlyWrapper } from "../read-only-guard";
 
-export function PaymentSettings({ settings }: { settings: Record<string, string> }) {
+export function PaymentSettings({ settings, orgId }: { settings: Record<string, string>; orgId: string }) {
   const router = useRouter();
   const [saving, setSaving] = useState(false);
 
   // Existing fields
   const [bankAccount, setBankAccount] = useState(settings[SETTING_KEYS.INVOICE_BANK_ACCOUNT] || "");
   const [paymentTerms, setPaymentTerms] = useState(settings[SETTING_KEYS.INVOICE_PAYMENT_TERMS] || "");
+  const [termsOfSale, setTermsOfSale] = useState(settings[SETTING_KEYS.PAYMENT_TERMS_OF_SALE] || "");
+  const [termsOfSaleUrl, setTermsOfSaleUrl] = useState(settings[SETTING_KEYS.PAYMENT_TERMS_OF_SALE_URL] || "");
 
   // Online payment providers
   const enabledRaw = settings[SETTING_KEYS.PAYMENT_PROVIDERS_ENABLED] || "";
@@ -42,8 +45,11 @@ export function PaymentSettings({ settings }: { settings: Record<string, string>
   const [vippsTestMode, setVippsTestMode] = useState(settings[SETTING_KEYS.PAYMENT_VIPPS_USE_TEST] === "true");
 
   const [copiedUrl, setCopiedUrl] = useState<string | null>(null);
+  const [appUrl, setAppUrl] = useState("");
 
-  const appUrl = typeof window !== "undefined" ? window.location.origin : "";
+  useEffect(() => {
+    setAppUrl(window.location.origin);
+  }, []);
 
   const handleSave = async () => {
     setSaving(true);
@@ -55,6 +61,8 @@ export function PaymentSettings({ settings }: { settings: Record<string, string>
     await setSettings({
       [SETTING_KEYS.INVOICE_BANK_ACCOUNT]: bankAccount,
       [SETTING_KEYS.INVOICE_PAYMENT_TERMS]: paymentTerms,
+      [SETTING_KEYS.PAYMENT_TERMS_OF_SALE]: termsOfSale,
+      [SETTING_KEYS.PAYMENT_TERMS_OF_SALE_URL]: termsOfSaleUrl,
       [SETTING_KEYS.PAYMENT_PROVIDERS_ENABLED]: providers.join(","),
       [SETTING_KEYS.PAYMENT_STRIPE_SECRET_KEY]: stripeSecretKey,
       [SETTING_KEYS.PAYMENT_STRIPE_PUBLISHABLE_KEY]: stripePublishableKey,
@@ -271,6 +279,61 @@ export function PaymentSettings({ settings }: { settings: Record<string, string>
                     </Button>
                   </div>
                 </div>
+
+                <Separator />
+
+                <div className="space-y-2">
+                  <Label htmlFor="termsOfSale">Terms of Sale (Salgsvilkår)</Label>
+                  <p className="text-xs text-muted-foreground">
+                    Required by Vipps. Customers can view these from the invoice page.
+                  </p>
+                  <Textarea
+                    id="termsOfSale"
+                    rows={10}
+                    placeholder={"1. Parties\n2. Payment\n3. Delivery\n4. Right of withdrawal\n5. Returns\n6. Complaints\n7. Disputes"}
+                    value={termsOfSale}
+                    onChange={(e) => setTermsOfSale(e.target.value)}
+                  />
+                </div>
+
+                <div className="space-y-2">
+                  <Label htmlFor="termsOfSaleUrl">External Terms URL (optional)</Label>
+                  <Input
+                    id="termsOfSaleUrl"
+                    type="url"
+                    placeholder="https://example.com/salgsvilkar"
+                    value={termsOfSaleUrl}
+                    onChange={(e) => setTermsOfSaleUrl(e.target.value)}
+                  />
+                  <p className="text-xs text-muted-foreground">
+                    Link to an external page with your terms. If set, the invoice will link here instead of the built-in terms page.
+                  </p>
+                </div>
+
+                {!termsOfSaleUrl && termsOfSale && (
+                  <div className="space-y-1">
+                    <Label className="text-xs text-muted-foreground">Public Terms URL</Label>
+                    <div className="flex items-center gap-2">
+                      <code className="flex-1 rounded bg-muted px-3 py-2 text-xs break-all">
+                        {appUrl}/share/terms/{orgId}
+                      </code>
+                      <Button
+                        variant="outline"
+                        size="sm"
+                        onClick={() => copyWebhookUrl(`${appUrl}/share/terms/${orgId}`)}
+                      >
+                        {copiedUrl === `${appUrl}/share/terms/${orgId}` ? (
+                          <Check className="h-3.5 w-3.5" />
+                        ) : (
+                          <Copy className="h-3.5 w-3.5" />
+                        )}
+                      </Button>
+                    </div>
+                    <p className="text-xs text-muted-foreground">
+                      Share this URL with Vipps or link it from your website.
+                    </p>
+                  </div>
+                )}
               </div>
             )}
           </div>

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

@@ -104,6 +104,7 @@ export function InvoiceView({
   showTorqvoiceBranding,
   dateFormat,
   timezone,
+  termsOfSaleUrl,
 }: {
   record: InvoiceRecord
   workshop: { name: string; address: string; phone: string; email: string }
@@ -118,6 +119,7 @@ export function InvoiceView({
   showTorqvoiceBranding?: boolean
   dateFormat?: string
   timezone?: string
+  termsOfSaleUrl?: string
 }) {
   const [carouselIndex, setCarouselIndex] = useState<number | null>(null)
   const [paymentAmount, setPaymentAmount] = useState('')
@@ -810,24 +812,36 @@ export function InvoiceView({
         )}
       </div>
 
-      {showTorqvoiceBranding ? (
-        <div className="mt-4 flex items-center justify-center gap-1.5">
-          <span className="text-xs text-gray-400">Powered by</span>
-          <img src="/torqvoice_app_logo.png" alt="Torqvoice" className="h-4 w-4" />
+      <div className="mt-4 flex flex-col items-center gap-1">
+        {showTorqvoiceBranding ? (
+          <div className="flex items-center justify-center gap-1.5">
+            <span className="text-xs text-gray-400">Powered by</span>
+            <img src="/torqvoice_app_logo.png" alt="Torqvoice" className="h-4 w-4" />
+            <a
+              href="https://torqvoice.com"
+              target="_blank"
+              rel="noopener noreferrer"
+              className="text-xs font-semibold text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300"
+            >
+              Torqvoice
+            </a>
+          </div>
+        ) : (
+          <p className="text-center text-xs text-gray-400">
+            {shopName}
+          </p>
+        )}
+        {termsOfSaleUrl && (
           <a
-            href="https://torqvoice.com"
+            href={termsOfSaleUrl}
             target="_blank"
             rel="noopener noreferrer"
-            className="text-xs font-semibold text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300"
+            className="text-xs text-gray-400 hover:text-gray-600"
           >
-            Torqvoice
+            Terms of Sale
           </a>
-        </div>
-      ) : (
-        <p className="mt-4 text-center text-xs text-gray-400">
-          {shopName}
-        </p>
-      )}
+        )}
+      </div>
 
       {/* Image Carousel Modal */}
       {carouselIndex !== null && imageAttachments[carouselIndex] && (

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

@@ -82,6 +82,8 @@ export default async function PublicInvoicePage({
             "invoice.showLogo",
             "invoice.showCompanyName",
             "payment.providersEnabled",
+            "payment.termsOfSale",
+            "payment.termsOfSaleUrl",
             "workshop.dateFormat",
             "workshop.timezone",
           ],
@@ -143,6 +145,9 @@ export default async function PublicInvoicePage({
       })),
   };
 
+  const termsOfSaleUrl = settingsMap["payment.termsOfSaleUrl"]
+    || (settingsMap["payment.termsOfSale"] ? `/share/terms/${orgId}` : undefined);
+
   return (
     <InvoiceView
       record={publicRecord}
@@ -158,6 +163,7 @@ export default async function PublicInvoicePage({
       showTorqvoiceBranding={!features.brandingRemoved}
       dateFormat={settingsMap["workshop.dateFormat"] || undefined}
       timezone={settingsMap["workshop.timezone"] || undefined}
+      termsOfSaleUrl={termsOfSaleUrl}
     />
   );
 }

+ 96 - 0
src/app/(public)/share/terms/[orgId]/page.tsx

@@ -0,0 +1,96 @@
+import { db } from "@/lib/db";
+import { notFound } from "next/navigation";
+import type { Metadata } from "next";
+
+export const revalidate = 60;
+
+export const metadata: Metadata = {
+  robots: { index: false, follow: false },
+};
+
+export default async function PublicTermsPage({
+  params,
+}: {
+  params: Promise<{ orgId: string }>;
+}) {
+  const { orgId } = await params;
+
+  const [settings, org] = await Promise.all([
+    db.appSetting.findMany({
+      where: {
+        organizationId: orgId,
+        key: {
+          in: [
+            "payment.termsOfSale",
+            "workshop.address",
+            "workshop.phone",
+            "workshop.email",
+            "workshop.logo",
+          ],
+        },
+      },
+    }),
+    db.organization.findUnique({
+      where: { id: orgId },
+      select: { name: true },
+    }),
+  ]);
+
+  if (!org) notFound();
+
+  const settingsMap: Record<string, string> = {};
+  for (const s of settings) settingsMap[s.key] = s.value;
+
+  const termsContent = settingsMap["payment.termsOfSale"];
+  if (!termsContent) notFound();
+
+  const workshopName = org.name || "";
+  const logoUrl = settingsMap["workshop.logo"] || "";
+  const address = settingsMap["workshop.address"] || "";
+  const phone = settingsMap["workshop.phone"] || "";
+  const email = settingsMap["workshop.email"] || "";
+
+  return (
+    <div className="mx-auto max-w-3xl p-4 sm:p-8">
+      <div className="rounded-xl border bg-white p-6 shadow-sm sm:p-8">
+        {/* Header */}
+        <div className="border-b pb-6">
+          <div className="flex items-center gap-4">
+            {logoUrl && (
+              <img
+                src={logoUrl}
+                alt={workshopName}
+                className="max-h-16 max-w-[180px] object-contain object-left"
+              />
+            )}
+            {workshopName && (
+              <h1 className="text-xl font-bold text-amber-600 sm:text-2xl">
+                {workshopName}
+              </h1>
+            )}
+          </div>
+          <h2 className="mt-4 text-lg font-semibold">Terms of Sale (Salgsvilkår)</h2>
+        </div>
+
+        {/* Terms Content */}
+        <div className="mt-6">
+          <p className="whitespace-pre-wrap text-sm text-gray-700">
+            {termsContent}
+          </p>
+        </div>
+
+        {/* Footer */}
+        {(address || phone || email) && (
+          <div className="mt-8 border-t pt-4">
+            <p className="text-xs font-bold uppercase text-gray-400">Contact</p>
+            <div className="mt-1 space-y-0.5 text-sm text-gray-500">
+              {address && <p>{address}</p>}
+              {phone && <p>Tel: {phone}</p>}
+              {email && <p>{email}</p>}
+            </div>
+          </div>
+        )}
+      </div>
+    </div>
+  );
+}

+ 2 - 0
src/features/settings/Schema/settingsSchema.ts

@@ -41,6 +41,8 @@ export const SETTING_KEYS = {
   PAYMENT_VIPPS_SUBSCRIPTION_KEY: "payment.vipps.subscriptionKey",
   PAYMENT_VIPPS_MSN: "payment.vipps.merchantSerialNumber",
   PAYMENT_VIPPS_USE_TEST: "payment.vipps.useTestMode",
+  PAYMENT_TERMS_OF_SALE: "payment.termsOfSale",
+  PAYMENT_TERMS_OF_SALE_URL: "payment.termsOfSaleUrl",
   LICENSE_KEY: "license.key",
   LICENSE_VALID: "license.valid",
   LICENSE_CHECKED_AT: "license.checkedAt",