From 5ef1972106742042532f61fa27160b73fdc79830 Mon Sep 17 00:00:00 2001 From: tedraykov Date: Wed, 3 Jul 2024 13:49:13 +0300 Subject: [PATCH] refine button loading and order actions --- components/loading-dots.tsx | 2 +- components/orders/activate-warranty.tsx | 5 +++++ components/orders/order-confirmation-modal.tsx | 7 +++---- components/profile/popover.tsx | 16 +++++++++++----- components/ui/button.tsx | 17 ++++++++++------- 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/components/loading-dots.tsx b/components/loading-dots.tsx index 778348d00..ff2cafafb 100644 --- a/components/loading-dots.tsx +++ b/components/loading-dots.tsx @@ -4,7 +4,7 @@ import { VariantProps, tv } from 'tailwind-variants'; const loadingDots = tv({ slots: { root: 'mx-2 inline-flex items-center', - dots: 'bg-content inline-block animate-blink rounded-full' + dots: 'bg-content inline-block animate-blink rounded-full' }, variants: { size: { diff --git a/components/orders/activate-warranty.tsx b/components/orders/activate-warranty.tsx index 42afa2989..c894ea588 100644 --- a/components/orders/activate-warranty.tsx +++ b/components/orders/activate-warranty.tsx @@ -15,6 +15,11 @@ const ActivateWarranty = ({ order }: ActivateWarrantyModalProps) => { const [isOpen, setIsOpen] = useState(false); const isWarrantyActivated = order?.warrantyStatus?.value === WarrantyStatus.Activated; const isPassDeadline = isBeforeToday(order?.warrantyActivationDeadline?.value); + const isOrderConfirmed = order?.orderConfirmation?.value; + + if (!isOrderConfirmed) { + return null; + } if (isWarrantyActivated) { return ; diff --git a/components/orders/order-confirmation-modal.tsx b/components/orders/order-confirmation-modal.tsx index c698085ac..892f17a1a 100644 --- a/components/orders/order-confirmation-modal.tsx +++ b/components/orders/order-confirmation-modal.tsx @@ -189,10 +189,9 @@ export default function OrderConfirmationModal({ onClose: () => void; }) { const [loading, setLoading] = useState(true); - const [submitting, setSubmitting] = useState(false); const [orderConfirmationContent, setOrderConfirmationContent] = useState(); - const [, startTransition] = useTransition(); + const [submitting, startTransition] = useTransition(); const formRef = useRef(null); useEffect(() => { @@ -210,12 +209,11 @@ export default function OrderConfirmationModal({ const handleSubmit: FormEventHandler = (event) => { event.preventDefault(); - setSubmitting(true); const form = formRef.current; if (!form) return; - const formData = new FormData(form); startTransition(async () => { + const formData = new FormData(form); await confirmOrder({ order, content: orderConfirmationContent!, @@ -269,6 +267,7 @@ export default function OrderConfirmationModal({ color="primary" disabled={submitting || loading} isLoading={submitting} + loadingText="Submitting" > Submit diff --git a/components/profile/popover.tsx b/components/profile/popover.tsx index c8b605e2b..eaae0fbf5 100644 --- a/components/profile/popover.tsx +++ b/components/profile/popover.tsx @@ -22,11 +22,10 @@ function SignInButton({ message }: { message: string | null }) { {message &&
{message}
} ); }; + const ProfilePopover = ({ menu }: ProfilePopoverProps) => { const [message, action] = useFormState(doLogin, null); const [, logoutAction] = useFormState(doLogout, null); diff --git a/components/ui/button.tsx b/components/ui/button.tsx index db4c381c9..f48c1b51a 100644 --- a/components/ui/button.tsx +++ b/components/ui/button.tsx @@ -19,7 +19,8 @@ const buttonVariants = tv({ 'disabled:pointer-events-none disabled:shadow-none', focusInput ], - loading: 'pointer-events-none flex shrink-0 items-center justify-center gap-1.5' + loading: 'pointer-events-none flex shrink-0 items-center justify-center gap-1.5', + loadingDots: '' }, variants: { size: { @@ -39,13 +40,15 @@ const buttonVariants = tv({ }, variant: { solid: { - root: 'border border-transparent shadow-sm' + root: 'shadow-sm', + loadingDots: 'bg-white' }, outlined: { - root: 'border bg-white shadow-sm' + root: 'bg-white shadow-sm ring-1 ring-inset ring-gray-300', + loadingDots: 'bg-content' }, text: { - root: 'border border-transparent' + loadingDots: 'bg-content' } } }, @@ -161,7 +164,7 @@ const Button = React.forwardRef( className, disabled, isLoading, - loadingText = 'Loading', + loadingText, size, color, variant, @@ -170,7 +173,7 @@ const Button = React.forwardRef( }: ButtonProps, forwardedRef ) => { - const { loading, root } = buttonVariants({ variant, size, color }); + const { loading, loadingDots, root } = buttonVariants({ variant, size, color }); const Component = as || 'button'; return ( @@ -183,7 +186,7 @@ const Button = React.forwardRef( > {isLoading ? ( - + {loadingText} {loadingText}