DDBS UI
commerce

Promo Code Form

A promo code field with inline error, and an applied state with a remove button.

npx shadcn@latest add https://ui.develop-better-solutions.com/r/store-promo-form.json
Dependencies:lucide-react
Fullscreen

Usage

store-promo-form-example.tsx
"use client";

import { useState } from "react";
import { PromoForm, normalisePromo } from "@dbs/ui";
import { StoreScope } from "./_store";

export default function StorePromoFormExample() {
  const [promo, setPromo] = useState<string | null>(null);
  return (
    <div className="w-full max-w-md">
      <StoreScope minHeight={0}>
        <PromoForm
          promo={promo}
          applyPromo={(code) => {
            if (normalisePromo(code) !== "WELCOME10") return "That code is not valid. Try WELCOME10.";
            setPromo("WELCOME10");
            return null;
          }}
          clearPromo={() => setPromo(null)}
          describe={() => "10% off"}
        />
      </StoreScope>
    </div>
  );
}